Files
query-orchestration/internal/test/queryAPI/service_test.go
T
Michael McGuinness 555b6d420b Merged in feature/docresult (pull request #105)
Document Result Endpoint

* testing

* cleantesting

* progress

* query

* lint

* readme

* dockerclient

* api

* passtest

* tests

* test
2025-03-17 18:14:15 +00:00

81 lines
1.9 KiB
Go

package queryapitest_test
import (
"context"
"testing"
queryapitest "queryorchestration/internal/test/queryAPI"
queryapimock "queryorchestration/mocks/queryapi"
queryapi "queryorchestration/pkg/queryAPI"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestCreateClientWithSync(t *testing.T) {
ctx := context.Background()
svcClient := queryapimock.NewMockClientWithResponsesInterface(t)
svcClient.EXPECT().CreateClientWithResponse(
mock.Anything,
mock.MatchedBy(func(create queryapi.ClientCreate) bool {
return create.Name == "example_name" && create.Id == "ID"
}),
mock.Anything,
).Return(&queryapi.CreateClientResponse{
JSON201: &queryapi.ClientIDBody{
Id: "ID",
},
}, nil)
svcClient.EXPECT().UpdateClientWithResponse(
mock.Anything,
mock.MatchedBy(func(id string) bool {
return id == "ID"
}),
mock.MatchedBy(func(create queryapi.ClientUpdate) bool {
return *create.CanSync == true
}),
mock.Anything,
).Return(&queryapi.UpdateClientResponse{}, nil)
svcClient.EXPECT().GetClientWithResponse(
mock.Anything,
mock.MatchedBy(func(id string) bool {
return id == "ID"
}),
mock.Anything,
).Return(&queryapi.GetClientResponse{
JSON200: &queryapi.DocClient{
Id: "ID",
},
}, nil)
client := queryapitest.CreateClientWithSync(t, ctx, svcClient)
assert.NotNil(t, client)
assert.NotNil(t, client)
assert.EqualExportedValues(t, queryapi.DocClient{
Id: "ID",
}, *client)
}
func TestWaitForClientStatus(t *testing.T) {
ctx := context.Background()
client := queryapimock.NewMockClientWithResponsesInterface(t)
client.EXPECT().GetStatusByClientIdWithResponse(
mock.Anything,
mock.MatchedBy(func(id string) bool {
return id == "id"
}),
).Return(&queryapi.GetStatusByClientIdResponse{
JSON200: &queryapi.ClientStatusBody{
Status: queryapi.INSYNC,
},
}, nil)
queryapitest.WaitForClientStatus(t, ctx, client, "id", queryapi.INSYNC)
}