Files
query-orchestration/test/unit/internal/result/store_test.go
T
Michael McGuinness f230465523 fixexistingtests
2025-01-07 13:58:11 +00:00

51 lines
1.5 KiB
Go

package document_test
import (
"context"
"fmt"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/result"
"testing"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestStore(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)
resultStore := result.ResultStore{
QueryID: uuid.New(),
DocumentID: uuid.New(),
Value: "val",
CleanVersion: int32(1),
TextVersion: int32(1),
QueryVersion: int32(1),
}
pool.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).AddRow(pgtype.UUID{}),
)
id, err := result.Store(ctx, queries, &resultStore)
assert.Nil(t, err)
assert.NotNil(t, id)
errr := "database failing"
pool.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
WillReturnError(fmt.Errorf(errr))
id, err = result.Store(ctx, queries, &resultStore)
assert.EqualError(t, err, errr)
assert.Equal(t, uuid.Nil, id)
}