0ac5ff9e15
Test Query * depstextandclean * startedcleaningresult * resulttidyup * roundone * cleaning * unsyncedquery * startedtestsandsimplification * api * querytests * resultprocessortests * unittests * cleanup
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package result
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestListQueryRequirementValues(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,
|
|
}
|
|
|
|
params := &ListQueryRequirementValuesParams{
|
|
QueryID: uuid.New(),
|
|
QueryVersion: 1,
|
|
DocumentID: uuid.New(),
|
|
MinCleanVersion: 2,
|
|
MinTextVersion: 3,
|
|
}
|
|
|
|
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(database.MustToDBUUID(params.QueryID), params.QueryVersion, database.MustToDBUUID(params.DocumentID), params.MinCleanVersion, params.MinTextVersion).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"queryId", "value", "type"}).
|
|
AddRow(pgtype.UUID{}, "example_value", repository.QuerytypeJsonExtractor),
|
|
)
|
|
|
|
val, err := svc.ListQueryRequirementValues(ctx, params)
|
|
assert.Nil(t, err)
|
|
assert.ElementsMatch(t, []resultprocessor.Value{
|
|
jsonextractor.NewResult("example_value"),
|
|
}, *val)
|
|
}
|
|
|
|
func TestParseQueryRequirementValueArray(t *testing.T) {
|
|
in := []*repository.ListQueryRequirementValuesRow{
|
|
{
|
|
Queryid: database.MustToDBUUID(uuid.New()),
|
|
Value: "example_value",
|
|
Type: repository.QuerytypeJsonExtractor,
|
|
},
|
|
}
|
|
|
|
out, err := parseQueryRequirementValueArray(in)
|
|
assert.Nil(t, err)
|
|
assert.ElementsMatch(t, []resultprocessor.Value{
|
|
jsonextractor.NewResult("example_value"),
|
|
}, *out)
|
|
}
|