package document_test import ( "context" "queryorchestration/internal/database" "queryorchestration/internal/database/repository" "queryorchestration/internal/document" "queryorchestration/internal/serviceconfig" "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) } cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) svc := document.New(cfg) 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) }