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
This commit is contained in:
@@ -1,81 +1,74 @@
|
||||
package client
|
||||
package client_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"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)
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := client.New(cfg)
|
||||
|
||||
svc := New(cfg)
|
||||
|
||||
params := CreateParams{
|
||||
params := client.CreateParams{
|
||||
Name: "client_name",
|
||||
ID: "external_id",
|
||||
}
|
||||
|
||||
pool.ExpectExec("name: CreateClient :exec").WithArgs(params.ID, params.Name).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
|
||||
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 TestNormalizeCreate(t *testing.T) {
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
func TestCreate_RootFolderIsOnlyFolderWithNullParent(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
cfg := &TestConfig{}
|
||||
test.CreateDB(t, cfg)
|
||||
|
||||
svc := New(cfg)
|
||||
svc := client.New(cfg)
|
||||
|
||||
t.Run("no change", func(t *testing.T) {
|
||||
params := &CreateParams{
|
||||
Name: "client_name",
|
||||
ID: "external_id",
|
||||
}
|
||||
|
||||
err := svc.normalizeCreate(params)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "client_name", params.Name)
|
||||
assert.Equal(t, "external_id", params.ID)
|
||||
})
|
||||
t.Run("all change", func(t *testing.T) {
|
||||
params := &CreateParams{
|
||||
Name: " client_name",
|
||||
ID: " external_id",
|
||||
}
|
||||
|
||||
err := svc.normalizeCreate(params)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "client_name", params.Name)
|
||||
assert.Equal(t, "external_id", params.ID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestNormalizeID(t *testing.T) {
|
||||
externalIds := []string{
|
||||
"ABC",
|
||||
"ABC_XYZ",
|
||||
"A12B",
|
||||
params := client.CreateParams{
|
||||
Name: "test_client_root_parent",
|
||||
ID: "test-client-root-parent",
|
||||
}
|
||||
|
||||
for _, id := range externalIds {
|
||||
assert.Nil(t, normalizeID(&id))
|
||||
}
|
||||
_, err := svc.Create(ctx, params)
|
||||
require.NoError(t, err)
|
||||
|
||||
id := " ABC\t"
|
||||
assert.Nil(t, normalizeID(&id))
|
||||
assert.Equal(t, "ABC", id)
|
||||
// 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user