Files
query-orchestration/internal/job/update_test.go
T
Michael McGuinness 4ec1d51a12 Merged in feature/jobcrud (pull request #35)
Job CRUD + Collector Integration

* startedcreate

* openapispec

* createjobintegration

* jobgetcontroller

* jobcreateclient

* updatejob

* job

* collector
2025-01-24 14:52:56 +00:00

63 lines
1.7 KiB
Go

package job_test
import (
"context"
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/job"
"testing"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestUpdate(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 := job.New(db, &job.Services{
Client: client.New(db),
})
j := job.Job{
ID: uuid.New(),
ClientID: uuid.New(),
CanSync: true,
}
pool.ExpectQuery("name: GetJob :one").WithArgs(database.MustToDBUUID(j.ID)).WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "canSync"}).
AddRow(database.MustToDBUUID(j.ID), database.MustToDBUUID(j.ClientID), j.CanSync),
)
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(j.ClientID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "name", "canSync"}).
AddRow(database.MustToDBUUID(j.ClientID), "client_name", true),
)
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(j.ClientID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "name", "canSync"}).
AddRow(database.MustToDBUUID(j.ClientID), "client_name", true),
)
ucs := !j.CanSync
pool.ExpectExec("name: UpdateJob :exec").WithArgs(ucs, database.MustToDBUUID(j.ID)).
WillReturnResult(pgxmock.NewResult("", 1))
err = svc.Update(ctx, &job.Update{
ID: j.ID,
CanSync: &ucs,
})
assert.Nil(t, err)
}