package docsyncrunner_test import ( "context" "fmt" "testing" docsyncrunner "queryorchestration/api/docSyncRunner" "queryorchestration/internal/client" "queryorchestration/internal/database/repository" "queryorchestration/internal/document" documentsync "queryorchestration/internal/document/sync" "queryorchestration/internal/server/runner" "queryorchestration/internal/serviceconfig/queue/documentclean" 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 DocSyncConfig struct { runner.BaseConfig[docsyncrunner.Body] documentclean.DocCleanConfig } func TestDocInitRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() require.NoError(t, err) cfg := &DocSyncConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) mockSQS := queuemock.NewMockSQSClient(t) cfg.QueueClient = mockSQS runner := docsyncrunner.New(&docsyncrunner.Services{ Document: documentsync.New(cfg, &documentsync.Services{ Document: document.New(cfg), Client: client.New(cfg), }), }) t.Run("valid", func(t *testing.T) { j := client.Client{ ID: "hello", } docinfo := document.DocumentSummary{ ID: uuid.New(), ClientID: j.ID, } doc := docsyncrunner.Body{ DocumentID: docinfo.ID, } pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(docinfo.ID). WillReturnRows( pgxmock.NewRows([]string{"id", "clientId", "hash"}). AddRow(docinfo.ID, docinfo.ClientID, "example"), ) pool.ExpectQuery("name: GetClient :one").WithArgs(j.ID). WillReturnRows( pgxmock.NewRows([]string{"id", "name", "canSync"}). AddRow(j.ID, "client_name", true), ) mockSQS.EXPECT(). SendMessage( mock.Anything, mock.MatchedBy(func(in *sqs.SendMessageInput) bool { return *in.QueueUrl == cfg.DocumentCleanURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", doc.DocumentID) }), mock.Anything, ). Return(&sqs.SendMessageOutput{}, nil) assert.True(t, runner.Process(ctx, doc)) }) }