edc50c7510
Size Import Parts * parts * think * workingpart * textout
86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
package documenttext
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
objectstoremock "queryorchestration/mocks/objectstore"
|
|
textractmock "queryorchestration/mocks/textract"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/textract"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
)
|
|
|
|
func TestTriggerExtract(t *testing.T) {
|
|
ctx := context.Background()
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
|
|
cfg := &DocTextConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
mockS3 := objectstoremock.NewMockS3Client(t)
|
|
cfg.StoreClient = mockS3
|
|
mockTextract := textractmock.NewMockTextractClient(t)
|
|
cfg.TextractClient = mockTextract
|
|
|
|
svc := Service{
|
|
cfg: cfg,
|
|
}
|
|
|
|
t.Run("successful clean", func(t *testing.T) {
|
|
cleanId := uuid.New()
|
|
bucket := "bucket_name"
|
|
key := "/i/am/here"
|
|
hash := "hhasshhh"
|
|
clientId := "AA"
|
|
|
|
jobId := "hello"
|
|
triggerId := uuid.New()
|
|
pool.ExpectBegin()
|
|
pool.ExpectQuery("name: GetTextractOutputCurrentPart :one").WithArgs(&clientId, pgxmock.AnyArg()).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"part", "count"}).
|
|
AddRow(0, 2),
|
|
)
|
|
|
|
pool.ExpectQuery("name: AddDocumentTextTrigger :one").WithArgs(cleanId, pgxmock.AnyArg(), pgxmock.AnyArg(), uint16(0)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id"}).AddRow(triggerId),
|
|
)
|
|
|
|
mockTextract.EXPECT().
|
|
StartDocumentTextDetection(
|
|
mock.Anything,
|
|
mock.MatchedBy(func(in *textract.StartDocumentTextDetectionInput) bool {
|
|
return true
|
|
}),
|
|
mock.Anything,
|
|
).
|
|
Return(&textract.StartDocumentTextDetectionOutput{
|
|
JobId: &jobId,
|
|
}, nil)
|
|
|
|
pool.ExpectExec("name: AddDocumentTextTriggerJobId :exec").WithArgs(&jobId, triggerId).
|
|
WillReturnResult(pgxmock.NewResult("", 1))
|
|
pool.ExpectCommit()
|
|
|
|
err = svc.triggerExtract(ctx, &repository.Currentcleanentry{
|
|
ID: cleanId,
|
|
Clientid: clientId,
|
|
Key: &key,
|
|
Bucket: &bucket,
|
|
Hash: &hash,
|
|
Mimetype: repository.NullCleanmimetype{
|
|
Valid: true,
|
|
Cleanmimetype: repository.CleanmimetypeApplicationPdf,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
})
|
|
}
|