ee776d2681
Single Mock Server * mockserver * mockserver * reqs * mockserver * slowrunner * someoptimisedqueries * passedfullsuite * passedfullsuite
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
package clientsyncrunner_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
clientsyncrunner "queryorchestration/api/clientSyncRunner"
|
|
clientsync "queryorchestration/internal/client/sync"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/server/runner"
|
|
"queryorchestration/internal/serviceconfig/queue/documentsync"
|
|
queuemock "queryorchestration/mocks/queue"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type ClientSyncConfig struct {
|
|
runner.BaseConfig[clientsyncrunner.Body]
|
|
documentsync.DocSyncConfig
|
|
}
|
|
|
|
func TestQueryRunner(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
|
|
cfg := &ClientSyncConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
mockSQS := queuemock.NewMockSQSClient(t)
|
|
cfg.QueueClient = mockSQS
|
|
cfg.DocumentSyncURL = "/i/am/here"
|
|
|
|
svc := clientsync.New(cfg)
|
|
|
|
runner := clientsyncrunner.New(&clientsyncrunner.Services{
|
|
ClientSync: svc,
|
|
})
|
|
|
|
t.Run("valid", func(t *testing.T) {
|
|
bod := clientsyncrunner.Body{
|
|
ClientID: "hello",
|
|
}
|
|
|
|
docId := uuid.New()
|
|
|
|
total := int64(1)
|
|
pool.ExpectQuery("name: ListDocumentIDsBatch :many").WithArgs(bod.ClientID, int32(100), int32(0)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "totalCount"}).
|
|
AddRow(&docId, &total),
|
|
)
|
|
mockSQS.EXPECT().
|
|
SendMessage(
|
|
mock.Anything,
|
|
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
|
return *in.QueueUrl == cfg.DocumentSyncURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", docId.String())
|
|
}),
|
|
mock.Anything,
|
|
).
|
|
Return(&sqs.SendMessageOutput{}, nil)
|
|
|
|
assert.True(t, runner.Process(ctx, bod))
|
|
})
|
|
}
|