0ac5ff9e15
Test Query * depstextandclean * startedcleaningresult * resulttidyup * roundone * cleaning * unsyncedquery * startedtestsandsimplification * api * querytests * resultprocessortests * unittests * cleanup
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package result_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/query/result"
|
|
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 TestListUnsyncedQueriesByDocId(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 := result.New(db)
|
|
|
|
documentId := uuid.New()
|
|
actualQs := []*resultprocessor.Query{
|
|
{
|
|
ID: uuid.New(),
|
|
Type: resultprocessor.TypeJsonExtractor,
|
|
Version: 2,
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: ListUnsyncedQueriesByDocId :many").WithArgs(database.MustToDBUUID(documentId)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(actualQs[0].ID), repository.QuerytypeJsonExtractor, actualQs[0].Version, actualQs[0].Version, nil, []pgtype.UUID{}),
|
|
)
|
|
|
|
val, err := svc.ListUnsyncedQueriesByDocId(ctx, documentId)
|
|
assert.Nil(t, err)
|
|
assert.ElementsMatch(t, actualQs, val)
|
|
}
|