2025-01-21 18:24:14 +00:00
|
|
|
package repository_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
|
|
|
|
"queryorchestration/internal/database"
|
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
|
|
|
"queryorchestration/internal/test"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestClient(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
|
|
|
|
Migrations: &database.MigrationConfig{
|
|
|
|
|
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
|
|
|
|
}})
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
queries := repository.New(db.Pool)
|
|
|
|
|
|
|
|
|
|
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)
|
2025-01-29 16:26:11 +00:00
|
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
2025-01-21 18:24:14 +00:00
|
|
|
ID: id,
|
|
|
|
|
Name: "example_client",
|
|
|
|
|
Cansync: false,
|
|
|
|
|
}, client)
|
|
|
|
|
|
|
|
|
|
err = queries.UpdateClient(ctx, &repository.UpdateClientParams{
|
2025-01-29 16:26:11 +00:00
|
|
|
ID: id,
|
|
|
|
|
Name: "updated_client",
|
|
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
client, err = queries.GetClient(ctx, id)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
2025-01-21 18:24:14 +00:00
|
|
|
ID: id,
|
|
|
|
|
Name: "updated_client",
|
2025-01-29 16:26:11 +00:00
|
|
|
Cansync: false,
|
|
|
|
|
}, client)
|
|
|
|
|
|
|
|
|
|
err = queries.AddClientCanSync(ctx, &repository.AddClientCanSyncParams{
|
|
|
|
|
Clientid: id,
|
|
|
|
|
Cansync: true,
|
2025-01-21 18:24:14 +00:00
|
|
|
})
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
client, err = queries.GetClient(ctx, id)
|
|
|
|
|
assert.Nil(t, err)
|
2025-01-29 16:26:11 +00:00
|
|
|
assert.EqualExportedValues(t, &repository.GetClientRow{
|
2025-01-21 18:24:14 +00:00
|
|
|
ID: id,
|
|
|
|
|
Name: "updated_client",
|
|
|
|
|
Cansync: true,
|
|
|
|
|
}, client)
|
|
|
|
|
}
|