package query_test import ( "testing" "queryorchestration/internal/database/repository" "queryorchestration/internal/query" resultprocessor "queryorchestration/internal/query/result/processor" "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestParseQuery(t *testing.T) { cfg := "example" q := &query.Query{ ID: uuid.New(), Type: resultprocessor.TypeJsonExtractor, ActiveVersion: int32(1), LatestVersion: int32(2), RequiredQueryIDs: &[]uuid.UUID{ uuid.New(), }, Config: &cfg, } out := query.ParseQuery(q) assert.EqualExportedValues(t, resultprocessor.Query{ ID: q.ID, Type: q.Type, Version: q.ActiveVersion, RequiredQueryIDs: q.RequiredQueryIDs, Config: q.Config, }, *out) } func TestParseFullActiveQuery(t *testing.T) { q := &repository.Fullactivequery{ ID: uuid.New(), Type: repository.QuerytypeContextFull, Activeversion: int32(1), Latestversion: int32(2), Requiredids: []uuid.UUID{ uuid.New(), }, Config: []byte("example"), } out, err := query.ParseFullActiveQuery(q) require.NoError(t, err) bcfg := string(q.Config) assert.EqualExportedValues(t, query.Query{ ID: q.ID, Type: resultprocessor.TypeContextFull, ActiveVersion: q.Activeversion, LatestVersion: q.Latestversion, RequiredQueryIDs: &[]uuid.UUID{ q.Requiredids[0], }, Config: &bcfg, }, *out) } func TestFullActiveQueryEmpty(t *testing.T) { dbQuery := &repository.Fullactivequery{ ID: uuid.New(), Type: repository.QuerytypeContextFull, Activeversion: int32(1), Latestversion: int32(2), } out, err := query.ParseFullActiveQuery(dbQuery) require.NoError(t, err) assert.EqualExportedValues(t, query.Query{ ID: dbQuery.ID, Type: resultprocessor.TypeContextFull, ActiveVersion: int32(1), LatestVersion: int32(2), }, *out) } func TestFullActiveQueryWithNullUUID(t *testing.T) { dbQuery := &repository.Fullactivequery{ ID: uuid.New(), Type: repository.QuerytypeContextFull, Activeversion: int32(1), Latestversion: int32(2), } out, err := query.ParseFullActiveQuery(dbQuery) require.NoError(t, err) assert.EqualExportedValues(t, query.Query{ ID: dbQuery.ID, Type: resultprocessor.TypeContextFull, ActiveVersion: int32(1), LatestVersion: int32(2), }, *out) } func TestFullActiveQueryArray(t *testing.T) { dbQueries := []*repository.Fullactivequery{ { ID: uuid.New(), Type: repository.QuerytypeContextFull, Activeversion: int32(1), Latestversion: int32(2), }, } out, err := query.ParseFullActiveQueryArray(dbQueries) require.NoError(t, err) assert.EqualExportedValues(t, []*query.Query{ { ID: dbQueries[0].ID, Type: resultprocessor.TypeContextFull, ActiveVersion: int32(1), LatestVersion: int32(2), }, }, out) }