package jobsyncrunner_test import ( "context" "encoding/json" "fmt" jobsyncrunner "queryorchestration/api/jobSyncRunner" "queryorchestration/internal/database" "queryorchestration/internal/database/repository" jobsync "queryorchestration/internal/job/sync" "queryorchestration/internal/server/runner" "queryorchestration/internal/serviceconfig/queue/documentsync" queuemock "queryorchestration/mocks/queue" "testing" "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/aws/aws-sdk-go-v2/service/sqs/types" "github.com/go-playground/validator/v10" "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 JobSyncConfig struct { runner.BaseConfig documentsync.DocSyncConfig } func TestQueryRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() require.NoError(t, err) cfg := &JobSyncConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) mockSQS := queuemock.NewMockSQSClient(t) cfg.QueueClient = mockSQS cfg.DocumentSyncURL = "/i/am/here" svc := jobsync.New(cfg) runner := jobsyncrunner.New(validator.New(), &jobsyncrunner.Services{ JobSync: svc, }) assert.NotNil(t, runner) bod := jobsyncrunner.Body{ ID: uuid.New(), } bodyBytes, err := json.Marshal(bod) assert.NoError(t, err) body := string(bodyBytes) msg := &types.Message{ Body: &body, } docId := uuid.New() total := int64(1) pool.ExpectQuery("name: ListJobDocumentIDsBatch :many").WithArgs(database.MustToDBUUID(bod.ID), int32(100), int32(0)). WillReturnRows( pgxmock.NewRows([]string{"id", "totalCount"}). AddRow(database.MustToDBUUID(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) err = runner.Process(ctx, msg) assert.NoError(t, err) }