Files
query-orchestration/internal/query/result/set_test.go
T
Michael McGuinness 0ac5ff9e15 Merged in feature/testquery (pull request #39)
Test Query

* depstextandclean

* startedcleaningresult

* resulttidyup

* roundone

* cleaning

* unsyncedquery

* startedtestsandsimplification

* api

* querytests

* resultprocessortests

* unittests

* cleanup
2025-01-29 11:52:37 +00:00

68 lines
1.9 KiB
Go

package result
import (
"context"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
resultprocessor "queryorchestration/internal/query/result/processor"
"testing"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestSet(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
queries := repository.New(pool)
db := &database.Connection{
Queries: queries,
Pool: pool,
}
svc := Service{
db: db,
}
rid := uuid.New()
cfg := "{\"path\":\"examplekey\"}"
params := Set{
DocumentID: uuid.New(),
CleanVersion: 1,
TextVersion: 3,
Query: &resultprocessor.Query{
ID: uuid.New(),
Version: 2,
Config: &cfg,
RequiredQueryIDs: &[]uuid.UUID{
uuid.New(),
},
},
}
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(database.MustToDBUUID(params.Query.ID), params.Query.Version, database.MustToDBUUID(params.DocumentID), params.CleanVersion, params.TextVersion).
WillReturnRows(
pgxmock.NewRows([]string{"queryId", "value", "type"}).
AddRow(database.MustToDBUUID((*params.Query.RequiredQueryIDs)[0]), "{\"examplekey\":\"example_value\"}", repository.QuerytypeContextFull),
)
pool.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(params.Query.ID), params.Query.Version).WillReturnRows(
pgxmock.NewRows([]string{"id", "config"}).
AddRow(pgtype.UUID{}, []byte(cfg)),
)
pool.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(params.Query.ID), database.MustToDBUUID(params.DocumentID), pgxmock.AnyArg(), params.CleanVersion, params.TextVersion, params.Query.Version).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).
AddRow(database.MustToDBUUID(rid)),
)
id, err := svc.Set(ctx, &params)
assert.Nil(t, err)
assert.Equal(t, rid, id)
}