d91ef1832b
Function Test Coverage * test * scripts
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package queryservice_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
queryservice "queryorchestration/api/queryService"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/document"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"queryorchestration/internal/serviceconfig/queue/jobsync"
|
|
queuemock "queryorchestration/mocks/queue"
|
|
"strings"
|
|
"testing"
|
|
|
|
"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 TestListDocumentsByJobId(t *testing.T) {
|
|
pool, err := pgxmock.NewPool()
|
|
require.NoError(t, err)
|
|
cfg := &struct {
|
|
serviceconfig.BaseConfig
|
|
jobsync.JobSyncConfig
|
|
}{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
mockSQS := queuemock.NewMockSQSClient(t)
|
|
cfg.QueueClient = mockSQS
|
|
|
|
jobId := uuid.New()
|
|
|
|
e := echo.New()
|
|
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
|
|
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
|
rec := httptest.NewRecorder()
|
|
ctx := e.NewContext(req, rec)
|
|
|
|
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
|
Document: document.New(cfg),
|
|
})
|
|
|
|
ctx.Set("id", jobId)
|
|
doc := queryservice.ListDocuments{
|
|
{
|
|
Id: uuid.New(),
|
|
Bucket: "bucketone",
|
|
Key: "keyone",
|
|
},
|
|
}
|
|
|
|
pool.ExpectQuery("name: ListDocumentsByJobId :many").WithArgs(database.MustToDBUUID(jobId)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "bucket", "key"}).
|
|
AddRow(database.MustToDBUUID(doc[0].Id), doc[0].Bucket, doc[0].Key),
|
|
)
|
|
|
|
err = cons.ListDocumentsByJobId(ctx, jobId)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, http.StatusOK, rec.Code)
|
|
|
|
var res queryservice.ListDocuments
|
|
err = json.Unmarshal(rec.Body.Bytes(), &res)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, doc, res)
|
|
}
|