15adaebfcd
DRAFT PR : WIP working through ideas for integration * movearound * attempttwo * openapi * further sanding * fix * start on tests * runthroughsingleconfig * somechanges * reflectissue * removeerrs * mostlyremovepanic * removeenv * noncfgtests * go * repo * fix service config test * add PWD to all * test fix * fix lint * todo for later * passingunittests * alltests * testlogger * testloggername * clean
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package repository_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"queryorchestration/internal/test"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestClient(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
err := serviceconfig.InitializeConfig(cfg)
|
|
assert.Nil(t, err)
|
|
|
|
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
|
Cfg: cfg,
|
|
RunMigrations: true,
|
|
})
|
|
defer cleanup()
|
|
|
|
queries := cfg.DBQueries
|
|
|
|
id, err := queries.CreateClient(ctx, "example_client")
|
|
assert.Nil(t, err)
|
|
assert.NotEmpty(t, id)
|
|
|
|
client, err := queries.GetClient(ctx, id)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
|
ID: id,
|
|
Name: "example_client",
|
|
Cansync: false,
|
|
}, client)
|
|
|
|
err = queries.UpdateClient(ctx, &repository.UpdateClientParams{
|
|
ID: id,
|
|
Name: "updated_client",
|
|
})
|
|
assert.Nil(t, err)
|
|
|
|
client, err = queries.GetClient(ctx, id)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
|
ID: id,
|
|
Name: "updated_client",
|
|
Cansync: false,
|
|
}, client)
|
|
|
|
err = queries.AddClientCanSync(ctx, &repository.AddClientCanSyncParams{
|
|
Clientid: id,
|
|
Cansync: true,
|
|
})
|
|
assert.Nil(t, err)
|
|
|
|
client, err = queries.GetClient(ctx, id)
|
|
assert.Nil(t, err)
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
|
ID: id,
|
|
Name: "updated_client",
|
|
Cansync: true,
|
|
}, client)
|
|
}
|