Files
query-orchestration/internal/client/create_test.go
T
Jay Brown c45e1dd427 Merged in feature/textExtractionsPart1 (pull request #192)
all schema and rest apis for text extraction support

* in progress

* stage 8 complete

* phase 9 completed

* phase 9 complete

* ongoing - s3 path fix

* working

* optimize ci build

* e2e tests

* missing test
2025-11-26 19:23:42 +00:00

75 lines
1.9 KiB
Go

package client_test
import (
"testing"
"queryorchestration/internal/client"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type TestConfig struct {
serviceconfig.BaseConfig
}
func TestCreate(t *testing.T) {
ctx := t.Context()
cfg := &TestConfig{}
test.CreateDB(t, cfg)
svc := client.New(cfg)
params := client.CreateParams{
Name: "client_name",
ID: "external_id",
}
id, err := svc.Create(ctx, params)
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)
}