Files
query-orchestration/api/queryAPI/status_test.go
T

63 lines
1.7 KiB
Go
Raw Normal View History

package queryapi_test
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
queryapi "queryorchestration/api/queryAPI"
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetClientStatus(t *testing.T) {
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Client: client.New(cfg),
})
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
clientId := uuid.New()
id := "clientid"
pool.ExpectQuery("name: GetClientByExternalId :one").WithArgs(id).WillReturnRows(
pgxmock.NewRows([]string{"id", "externalId", "name", "can_sync"}).
AddRow(database.MustToDBUUID(clientId), id, "name", true),
)
pool.ExpectQuery("name: IsClientSynced :one").WithArgs(database.MustToDBUUID(clientId)).WillReturnRows(
pgxmock.NewRows([]string{"issynced"}).
AddRow(true),
)
err = cons.GetStatusByClientId(ctx, id)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryapi.ClientStatusBody
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, queryapi.ClientStatusBody{
Status: queryapi.INSYNC,
}, res)
}