Files
query-orchestration/internal/client/create_test.go
T

75 lines
1.9 KiB
Go
Raw Normal View History

package client_test
2025-01-21 18:24:14 +00:00
import (
2025-03-05 12:05:46 +00:00
"testing"
"queryorchestration/internal/client"
2025-01-21 18:24:14 +00:00
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/test"
2025-01-21 18:24:14 +00:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2025-01-21 18:24:14 +00:00
)
type TestConfig struct {
serviceconfig.BaseConfig
}
2025-01-21 18:24:14 +00:00
func TestCreate(t *testing.T) {
2025-06-03 13:52:10 +00:00
ctx := t.Context()
cfg := &TestConfig{}
test.CreateDB(t, cfg)
2025-01-21 18:24:14 +00:00
svc := client.New(cfg)
2025-01-21 18:24:14 +00:00
params := client.CreateParams{
Name: "client_name",
ID: "external_id",
}
2025-01-21 18:24:14 +00:00
id, err := svc.Create(ctx, params)
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
assert.Equal(t, params.ID, id)
// Verify client was created
c, err := cfg.GetDBQueries().GetClient(ctx, params.ID)
require.NoError(t, err)
assert.Equal(t, params.Name, c.Name)
// Verify root folder was created automatically
rootFolder, err := cfg.GetDBQueries().GetFolderByPath(ctx, &repository.GetFolderByPathParams{
Clientid: params.ID,
Path: client.RootFolderPath,
})
require.NoError(t, err, "Root folder should be created automatically")
assert.Equal(t, client.RootFolderPath, rootFolder.Path)
assert.Nil(t, rootFolder.Parentid, "Root folder should have no parent")
assert.Equal(t, params.ID, rootFolder.Clientid)
assert.Equal(t, client.SystemEmail, rootFolder.Createdby)
}
func TestCreate_RootFolderIsOnlyFolderWithNullParent(t *testing.T) {
ctx := t.Context()
cfg := &TestConfig{}
test.CreateDB(t, cfg)
svc := client.New(cfg)
params := client.CreateParams{
Name: "test_client_root_parent",
ID: "test-client-root-parent",
}
_, err := svc.Create(ctx, params)
require.NoError(t, err)
// Get all folders with null parent for this client
rootFolders, err := cfg.GetDBQueries().GetRootFolders(ctx, params.ID)
require.NoError(t, err)
// Should only have one folder with null parent (the root folder)
assert.Len(t, rootFolders, 1)
assert.Equal(t, client.RootFolderPath, rootFolders[0].Path)
}