ee776d2681
Single Mock Server * mockserver * mockserver * reqs * mockserver * slowrunner * someoptimisedqueries * passedfullsuite * passedfullsuite
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package queryapi_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
queryapi "queryorchestration/api/queryAPI"
|
|
"queryorchestration/internal/client"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/export"
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
"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(&queryapi.Services{
|
|
Client: client.New(cfg),
|
|
Export: export.New(),
|
|
})
|
|
|
|
e := echo.New()
|
|
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
|
|
rec := httptest.NewRecorder()
|
|
ctx := e.NewContext(req, rec)
|
|
|
|
clientId := "clientid"
|
|
|
|
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "name", "can_sync"}).
|
|
AddRow(clientId, "name", true),
|
|
)
|
|
pool.ExpectQuery("name: IsClientSynced :one").WithArgs(&clientId).WillReturnRows(
|
|
pgxmock.NewRows([]string{"issynced"}).
|
|
AddRow(true),
|
|
)
|
|
|
|
err = cons.GetStatusByClientId(ctx, clientId)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, http.StatusOK, rec.Code)
|
|
|
|
var res queryapi.ClientStatusBody
|
|
err = json.Unmarshal(rec.Body.Bytes(), &res)
|
|
require.NoError(t, err)
|
|
assert.EqualExportedValues(t, queryapi.ClientStatusBody{
|
|
Status: queryapi.INSYNC,
|
|
}, res)
|
|
}
|