555b6d420b
Document Result Endpoint * testing * cleantesting * progress * query * lint * readme * dockerclient * api * passtest * tests * test
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package document_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/database"
|
|
"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: uuid.New(),
|
|
Hash: "example_hash",
|
|
}
|
|
|
|
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(doc.ID)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
|
AddRow(database.MustToDBUUID(doc.ID), database.MustToDBUUID(doc.ClientID), doc.Hash),
|
|
)
|
|
|
|
adoc, err := svc.GetSummary(ctx, doc.ID)
|
|
assert.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(database.MustToDBUUID(doc.Id)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "clientId", "hash", "fields"}).
|
|
AddRow(database.MustToDBUUID(doc.Id), "externalID", "example", []byte(`{"json": "hello"}`)),
|
|
)
|
|
|
|
adoc, err := svc.GetExternal(ctx, doc.Id)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, &doc, adoc)
|
|
}
|