Merged in feature/document (pull request #36)
Document CRUD * doccreate * dochashlocandget * depsandtodo
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user