Merged in feature/e2etest (pull request #74)
Feature/e2etest * e2etest * testcleanups
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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"
|
||||
)
|
||||
|
||||
func TestListDocumentsByJobId(t *testing.T) {
|
||||
pool, err := pgxmock.NewPool()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", 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)
|
||||
}
|
||||
Reference in New Issue
Block a user