package queryservice_test import ( "encoding/json" "net/http" "net/http/httptest" "strings" "testing" queryservice "queryorchestration/api/queryService" "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 := queryservice.NewControllers(validator.New(), &queryservice.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 queryservice.ClientStatusBody err = json.Unmarshal(rec.Body.Bytes(), &res) assert.NoError(t, err) assert.EqualExportedValues(t, queryservice.ClientStatusBody{ Status: queryservice.INSYNC, }, res) }