2025-02-12 19:00:25 +00:00
|
|
|
package endtoend
|
2025-01-21 18:24:14 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-03-18 13:06:42 +00:00
|
|
|
"net/http"
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-01-21 18:24:14 +00:00
|
|
|
"queryorchestration/internal/test"
|
2025-03-17 18:14:15 +00:00
|
|
|
queryapi "queryorchestration/pkg/queryAPI"
|
2025-01-21 18:24:14 +00:00
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-03-19 11:54:14 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2025-01-21 18:24:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestClient(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
c, cleanup := test.CreateAPINetwork(t, ctx, &test.ServiceNetworkConfig{
|
|
|
|
|
API: test.QueryAPI,
|
2025-02-03 17:30:50 +00:00
|
|
|
})
|
2025-01-21 18:24:14 +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-21 18:24:14 +00:00
|
|
|
|
2025-03-18 13:06:42 +00:00
|
|
|
clientErrRes, err := client.GetClientWithResponse(ctx, "INVALID")
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-03-18 13:06:42 +00:00
|
|
|
assert.Equal(t, http.StatusBadRequest, clientErrRes.StatusCode())
|
|
|
|
|
assert.Equal(t, "Unable to get client: no rows in result set", clientErrRes.JSON400.Message)
|
|
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
idRes, err := client.CreateClientWithResponse(ctx, queryapi.ClientCreate{
|
2025-01-21 18:24:14 +00:00
|
|
|
Name: "example_name",
|
2025-03-11 16:31:06 +00:00
|
|
|
Id: "EXA",
|
2025-01-21 18:24:14 +00:00
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Equal(t, http.StatusCreated, idRes.StatusCode())
|
2025-01-21 18:24:14 +00:00
|
|
|
assert.NotNil(t, idRes.JSON201)
|
2025-03-19 11:54:14 +00:00
|
|
|
assert.Equal(t, "EXA", idRes.JSON201.Id)
|
2025-01-21 18:24:14 +00:00
|
|
|
id := idRes.JSON201.Id
|
|
|
|
|
|
|
|
|
|
clientRes, err := client.GetClientWithResponse(ctx, id)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Equal(t, http.StatusOK, clientRes.StatusCode())
|
2025-01-21 18:24:14 +00:00
|
|
|
assert.Equal(t, id, clientRes.JSON200.Id)
|
|
|
|
|
assert.Equal(t, "example_name", clientRes.JSON200.Name)
|
|
|
|
|
assert.False(t, clientRes.JSON200.CanSync)
|
|
|
|
|
|
|
|
|
|
updateName := "update_name"
|
|
|
|
|
updateCanSync := true
|
2025-03-17 18:14:15 +00:00
|
|
|
updateRes, err := client.UpdateClientWithResponse(ctx, id, queryapi.ClientUpdate{
|
2025-01-21 18:24:14 +00:00
|
|
|
Name: &updateName,
|
|
|
|
|
CanSync: &updateCanSync,
|
|
|
|
|
})
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-21 18:24:14 +00:00
|
|
|
assert.NotNil(t, updateRes)
|
|
|
|
|
|
|
|
|
|
clientRes, err = client.GetClientWithResponse(ctx, id)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-21 18:24:14 +00:00
|
|
|
assert.Equal(t, id, clientRes.JSON200.Id)
|
|
|
|
|
assert.Equal(t, updateName, clientRes.JSON200.Name)
|
|
|
|
|
assert.True(t, clientRes.JSON200.CanSync)
|
|
|
|
|
}
|