generated from PenaSide/GolangTemplate
111 lines
2.7 KiB
Go
111 lines
2.7 KiB
Go
|
package integration
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/labstack/echo/v4"
|
||
|
"github.com/pioz/faker"
|
||
|
"go.uber.org/zap"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"net/http/httptest"
|
||
|
"penahub.gitlab.yandexcloud.net/backend/penahub_common/mongo"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/repository"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/swagger"
|
||
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||
|
"strconv"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func TestLogostat(t *testing.T) {
|
||
|
logger, err := zap.NewProduction(zap.AddStacktrace(zap.DPanicLevel))
|
||
|
if err != nil {
|
||
|
log.Fatalf("failed to init zap logger: %v", err)
|
||
|
}
|
||
|
ctx := context.Background()
|
||
|
mongoDB, err := mongo.Connect(ctx, &mongo.ConnectDeps{
|
||
|
Configuration: &mongo.Configuration{
|
||
|
Host: "localhost",
|
||
|
Port: "27024",
|
||
|
User: "test",
|
||
|
Password: "test",
|
||
|
Auth: "admin",
|
||
|
DatabaseName: "admin",
|
||
|
},
|
||
|
Timeout: 10 * time.Second,
|
||
|
})
|
||
|
|
||
|
repoAc := repository.NewAccountRepository2(logger, mongoDB.Collection("accounts"))
|
||
|
repoHi := repository.NewHistoryRepository2(logger, mongoDB.Collection("histories"))
|
||
|
InsertToDB(ctx, repoAc, repoHi)
|
||
|
|
||
|
api := swagger.NewAPI2(logger, mongoDB, nil, nil, nil, nil)
|
||
|
|
||
|
e := echo.New()
|
||
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||
|
rec := httptest.NewRecorder()
|
||
|
c := e.NewContext(req, rec)
|
||
|
|
||
|
requestBody := swagger.QuizLogoStatJSONRequestBody{
|
||
|
From: new(int),
|
||
|
Limit: new(int),
|
||
|
Page: new(int),
|
||
|
To: new(int),
|
||
|
}
|
||
|
*requestBody.From = 1713087258
|
||
|
*requestBody.Limit = 10
|
||
|
*requestBody.Page = 1
|
||
|
*requestBody.To = 1713260058
|
||
|
|
||
|
c.SetRequest(c.Request().WithContext(context.WithValue(c.Request().Context(), "requestBody", requestBody)))
|
||
|
|
||
|
err = api.QuizLogoStat(c)
|
||
|
}
|
||
|
|
||
|
func InsertToDB(ctx context.Context, acc repository.AccountRepository, history repository.HistoryRepository) {
|
||
|
partner1 := "partner1"
|
||
|
partner2 := "partner2"
|
||
|
qid1 := "qid1"
|
||
|
qid2 := "qid2"
|
||
|
acc.Insert(ctx, &models.Account{
|
||
|
ID: "1",
|
||
|
UserID: partner1,
|
||
|
CreatedAt: time.Now(),
|
||
|
})
|
||
|
acc.Insert(ctx, &models.Account{
|
||
|
ID: "2",
|
||
|
UserID: partner2,
|
||
|
CreatedAt: time.Now(),
|
||
|
})
|
||
|
|
||
|
for i := 1; i < 101; i++ {
|
||
|
var partnerID string
|
||
|
var qid string
|
||
|
if i%2 == 0 {
|
||
|
partnerID = partner2
|
||
|
qid = qid2
|
||
|
} else {
|
||
|
partnerID = partner1
|
||
|
qid = qid1
|
||
|
}
|
||
|
|
||
|
acc.Insert(ctx, &models.Account{
|
||
|
ID: "IDUSER" + strconv.Itoa(i),
|
||
|
UserID: strconv.Itoa(i),
|
||
|
CreatedAt: time.Now(),
|
||
|
From: qid,
|
||
|
Partner: partnerID,
|
||
|
})
|
||
|
|
||
|
history.Insert(ctx, &models.History{
|
||
|
ID: "IDHISTORY" + strconv.Itoa(i),
|
||
|
UserID: strconv.Itoa(i),
|
||
|
RawDetails: models.RawDetails{
|
||
|
Price: int64(faker.Uint64()),
|
||
|
},
|
||
|
})
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|