2025-01-24 16:12:25 +00:00
|
|
|
package document_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-01-24 16:12:25 +00:00
|
|
|
"queryorchestration/internal/database"
|
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
|
|
|
"queryorchestration/internal/document"
|
2025-01-31 13:43:55 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
2025-01-24 16:12:25 +00:00
|
|
|
|
2025-03-04 15:51:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
2025-01-24 16:12:25 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
func TestGetSummary(t *testing.T) {
|
2025-01-24 16:12:25 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
pool, err := pgxmock.NewPool()
|
2025-03-04 15:51:03 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-31 13:43:55 +00:00
|
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
|
|
|
cfg.DBPool = pool
|
|
|
|
|
cfg.DBQueries = repository.New(pool)
|
2025-01-24 16:12:25 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
svc := document.New(cfg)
|
2025-01-24 16:12:25 +00:00
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
doc := document.DocumentSummary{
|
2025-03-10 11:03:00 +00:00
|
|
|
ID: uuid.New(),
|
|
|
|
|
ClientID: uuid.New(),
|
|
|
|
|
Hash: "example_hash",
|
2025-01-24 16:12:25 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(doc.ID)).
|
2025-01-24 16:12:25 +00:00
|
|
|
WillReturnRows(
|
2025-03-10 11:03:00 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
|
|
|
|
AddRow(database.MustToDBUUID(doc.ID), database.MustToDBUUID(doc.ClientID), doc.Hash),
|
2025-01-24 16:12:25 +00:00
|
|
|
)
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
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)
|
2025-02-03 17:30:50 +00:00
|
|
|
assert.NoError(t, err)
|
2025-01-24 16:12:25 +00:00
|
|
|
assert.Equal(t, &doc, adoc)
|
|
|
|
|
}
|