Merged in feature/checkbox (pull request #145)
Checkbox Primary Edge Cases * hascheckboxlogic * gen * preppinggen * exploringcheckbox * removeunselected * tests * failingtest * failintests * nomockqueryapi * db * name * nocontainer * deleterow * cnc * extradocsandupdatetextracts * moretables * appndedtables * baseversion
This commit is contained in:
+50
-29
@@ -1,60 +1,81 @@
|
||||
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"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"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)
|
||||
t.Parallel()
|
||||
cfg := &ClientConfig{}
|
||||
net := test.GetNetwork(t)
|
||||
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
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)
|
||||
ctx, rec := createContext(t)
|
||||
|
||||
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 := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
|
||||
Clientid: clientId,
|
||||
Name: "client_name",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = cfg.GetDBQueries().AddClientCanSync(t.Context(), &repository.AddClientCanSyncParams{
|
||||
Clientid: clientId,
|
||||
Cansync: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
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{
|
||||
assertBody(t, rec, queryapi.ClientStatusBody{
|
||||
Status: queryapi.INSYNC,
|
||||
}, res)
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkGetClientStatus(b *testing.B) {
|
||||
cfg := &ClientConfig{}
|
||||
net := test.GetNetwork(b)
|
||||
test.CreateDB(b, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
cons := queryapi.NewControllers(&queryapi.Services{
|
||||
Client: client.New(cfg),
|
||||
Export: export.New(),
|
||||
})
|
||||
|
||||
ctx, _ := createContext(b)
|
||||
|
||||
clientId := "clientid"
|
||||
|
||||
err := cfg.GetDBQueries().CreateClient(b.Context(), &repository.CreateClientParams{
|
||||
Clientid: clientId,
|
||||
Name: "client_name",
|
||||
})
|
||||
require.NoError(b, err)
|
||||
err = cfg.GetDBQueries().AddClientCanSync(b.Context(), &repository.AddClientCanSyncParams{
|
||||
Clientid: clientId,
|
||||
Cansync: true,
|
||||
})
|
||||
require.NoError(b, err)
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for b.Loop() {
|
||||
_ = cons.GetStatusByClientId(ctx, clientId)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user