2025-02-12 19:00:25 +00:00
|
|
|
package endtoend_test
|
2025-01-13 15:02:43 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-03-05 12:05:46 +00:00
|
|
|
"regexp"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2025-01-13 15:02:43 +00:00
|
|
|
"queryorchestration/internal/test"
|
2025-03-17 18:14:15 +00:00
|
|
|
queryapi "queryorchestration/pkg/queryAPI"
|
2025-01-13 15:02:43 +00:00
|
|
|
|
2025-03-19 11:54:14 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
2025-01-24 14:52:56 +00:00
|
|
|
"github.com/oapi-codegen/runtime/types"
|
2025-01-13 15:02:43 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
func TestQueryAPI(t *testing.T) {
|
2025-01-13 15:02:43 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
cfg := &Config{}
|
2025-02-14 10:56:24 +00:00
|
|
|
test.SetCfgProvider(t, cfg)
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
deps, clean := test.CreateFullDependencies(t, ctx, cfg)
|
2025-02-14 10:56:24 +00:00
|
|
|
defer clean()
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
c, cleanup := test.CreateAPINetwork(t, ctx, cfg, &test.ServiceNetworkConfig{
|
|
|
|
|
Network: deps.Network,
|
2025-03-17 18:14:15 +00:00
|
|
|
API: test.QueryAPI,
|
2025-02-03 17:30:50 +00:00
|
|
|
})
|
2025-01-13 15:02:43 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
client, err := queryapi.NewClientWithResponses(c.URI)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-13 15:02:43 +00:00
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
idRes, err := client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
|
|
|
|
|
Type: queryapi.CONTEXTFULL,
|
2025-01-13 15:02:43 +00:00
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-15 19:45:51 +00:00
|
|
|
assert.NotNil(t, idRes)
|
|
|
|
|
assert.NotNil(t, idRes.JSON201)
|
2025-01-20 13:31:48 +00:00
|
|
|
contextID := idRes.JSON201.Id
|
|
|
|
|
assert.NotEmpty(t, contextID)
|
2025-01-13 15:02:43 +00:00
|
|
|
|
2025-02-11 15:22:59 +00:00
|
|
|
jcfg := "{}"
|
2025-03-17 18:14:15 +00:00
|
|
|
idRes, err = client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
|
|
|
|
|
Type: queryapi.JSONEXTRACTOR,
|
2025-02-11 15:22:59 +00:00
|
|
|
Config: &jcfg,
|
2025-01-20 13:31:48 +00:00
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.NotNil(t, idRes)
|
|
|
|
|
assert.NotNil(t, idRes.JSON201)
|
2025-01-20 13:31:48 +00:00
|
|
|
jsonID := idRes.JSON201.Id
|
|
|
|
|
|
2025-01-21 18:24:14 +00:00
|
|
|
queryRes, err := client.GetQueryWithResponse(ctx, jsonID)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-20 13:31:48 +00:00
|
|
|
assert.Equal(t, jsonID, queryRes.JSON200.Id)
|
2025-03-17 18:14:15 +00:00
|
|
|
assert.Equal(t, queryapi.JSONEXTRACTOR, queryRes.JSON200.Type)
|
2025-01-15 19:45:51 +00:00
|
|
|
assert.Equal(t, int32(1), queryRes.JSON200.ActiveVersion)
|
|
|
|
|
assert.Equal(t, int32(1), queryRes.JSON200.LatestVersion)
|
2025-02-11 15:22:59 +00:00
|
|
|
assert.Equal(t, jcfg, *queryRes.JSON200.Config)
|
2025-01-15 19:45:51 +00:00
|
|
|
assert.Nil(t, queryRes.JSON200.RequiredQueries)
|
|
|
|
|
|
|
|
|
|
queriesRes, err := client.ListQueriesWithResponse(ctx)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-20 13:31:48 +00:00
|
|
|
assert.Len(t, queriesRes.JSON200.Queries, 2)
|
2025-01-15 19:45:51 +00:00
|
|
|
|
2025-01-20 13:31:48 +00:00
|
|
|
aV := int32(2)
|
2025-03-17 18:14:15 +00:00
|
|
|
res, err := client.UpdateQueryWithResponse(ctx, jsonID, queryapi.QueryUpdate{
|
2025-01-20 13:31:48 +00:00
|
|
|
ActiveVersion: &aV,
|
2025-01-24 14:52:56 +00:00
|
|
|
RequiredQueries: &[]types.UUID{
|
2025-01-20 13:31:48 +00:00
|
|
|
contextID,
|
|
|
|
|
},
|
2025-01-13 15:02:43 +00:00
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-13 15:02:43 +00:00
|
|
|
assert.NotNil(t, res)
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
test.AssertMessageBody(t, ctx, cfg, deps.QueueURLs[test.QueryVersionSyncRunnerName], regexp.MustCompile(`{"id":".+"}`))
|
2025-02-14 10:56:24 +00:00
|
|
|
|
2025-01-21 18:24:14 +00:00
|
|
|
queryRes, err = client.GetQueryWithResponse(ctx, jsonID)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-20 13:31:48 +00:00
|
|
|
assert.Equal(t, jsonID, queryRes.JSON200.Id)
|
2025-03-17 18:14:15 +00:00
|
|
|
assert.Equal(t, queryapi.JSONEXTRACTOR, queryRes.JSON200.Type)
|
2025-01-20 13:31:48 +00:00
|
|
|
assert.Equal(t, int32(2), queryRes.JSON200.ActiveVersion)
|
|
|
|
|
assert.Equal(t, int32(2), queryRes.JSON200.LatestVersion)
|
2025-02-11 15:22:59 +00:00
|
|
|
assert.Equal(t, jcfg, *queryRes.JSON200.Config)
|
2025-01-24 14:52:56 +00:00
|
|
|
assert.ElementsMatch(t, []types.UUID{contextID}, *queryRes.JSON200.RequiredQueries)
|
2025-01-13 15:02:43 +00:00
|
|
|
}
|