Files
query-orchestration/internal/document/get_test.go
T
Michael McGuinness 81e7223560 Merged in feature/textextraction (pull request #110)
Text Extraction

* bases

* go

* splitting

* structure

* movetoasync

* movetoasync

* settinguptrigger

* reorder

* storevent

* standardisepollingvalidation

* unittests

* fixlint

* fixlint

* awscfg

* generatesample

* followthrough

* tests

* clena

* store

* externalidcleanup

* clientid

* local

* baseunittests

* putobjecttests

* tests
2025-04-02 18:50:03 +00:00

76 lines
1.7 KiB
Go

package document_test
import (
"context"
"testing"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"queryorchestration/internal/serviceconfig"
"github.com/stretchr/testify/require"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestGetSummary(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := document.New(cfg)
doc := document.DocumentSummary{
ID: uuid.New(),
ClientID: "example",
Hash: "example_hash",
}
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(doc.ID).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
AddRow(doc.ID, doc.ClientID, doc.Hash),
)
adoc, err := svc.GetSummary(ctx, doc.ID)
require.NoError(t, err)
assert.Equal(t, &doc, adoc)
}
func TestGetExternal(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := document.New(cfg)
doc := document.DocumentExternal{
Id: uuid.New(),
ClientID: "externalID",
Hash: "example",
Fields: map[string]interface{}{
"json": "hello",
},
}
pool.ExpectQuery("name: GetDocumentExternal :one").WithArgs(doc.Id).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash", "fields"}).
AddRow(doc.Id, "externalID", "example", []byte(`{"json": "hello"}`)),
)
adoc, err := svc.GetExternal(ctx, doc.Id)
require.NoError(t, err)
assert.Equal(t, &doc, adoc)
}