Files
query-orchestration/internal/document/create_test.go
T

49 lines
1.0 KiB
Go
Raw Normal View History

package document_test
import (
"context"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"testing"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestCreate(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 := document.New(db)
doc := document.Document{
ID: uuid.New(),
JobID: uuid.New(),
Location: "example_location",
}
pool.ExpectQuery("name: CreateDocument :one").WithArgs(database.MustToDBUUID(doc.JobID), pgxmock.AnyArg(), doc.Location).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).
AddRow(database.MustToDBUUID(doc.ID)),
)
id, err := svc.Create(ctx, &document.Create{
JobID: doc.JobID,
Location: doc.Location,
})
assert.Nil(t, err)
assert.Equal(t, doc.ID, id)
}