Files
query-orchestration/internal/job/update_test.go
T
Michael McGuinness 7001ca854c Merged in feature/docinitialisation (pull request #41)
Queuing Changes and Cfg Testing

* staarting

* staarting

* startedpush

* note

* save

* mocking

* removederrs

* fixtests

* cleanuperrs

* newenvsetup

* preppingtests

* queue

* mmovetocfgpassunittests

* sortoutconfig

* passinginteg

* deps

* fixtests
2025-02-03 17:30:50 +00:00

60 lines
1.5 KiB
Go

package job_test
import (
"context"
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/job"
"queryorchestration/internal/serviceconfig"
"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)
}
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := job.New(cfg, &job.Services{
Client: client.New(cfg),
})
j := job.Job{
ID: uuid.New(),
ClientID: uuid.New(),
CanSync: true,
}
ucs := !j.CanSync
u := &job.Update{
ID: j.ID,
CanSync: &ucs,
}
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.ExpectBegin()
pool.ExpectExec("name: AddJobCanSync :exec").WithArgs(*u.CanSync, database.MustToDBUUID(j.ID)).
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectCommit()
err = svc.Update(ctx, u)
assert.NoError(t, err)
}