2024-04-15 12:12:21 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-05-20 12:32:59 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2024-04-15 12:12:21 +00:00
|
|
|
"github.com/pioz/faker"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/penahub_common/mongo"
|
2024-05-20 12:32:59 +00:00
|
|
|
http2 "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http"
|
2024-04-15 12:12:21 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/repository"
|
|
|
|
"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",
|
2024-04-24 12:20:21 +00:00
|
|
|
Port: "27020",
|
2024-04-15 12:12:21 +00:00
|
|
|
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)
|
|
|
|
|
2024-05-20 12:32:59 +00:00
|
|
|
api := http2.NewAPI2(logger, mongoDB, nil, nil, nil, nil)
|
2024-04-15 12:12:21 +00:00
|
|
|
|
2024-05-20 12:32:59 +00:00
|
|
|
app := fiber.New()
|
2024-04-15 12:12:21 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
2024-05-20 12:32:59 +00:00
|
|
|
req.Header.Set("Content-Type", "application/json")
|
2024-04-15 12:12:21 +00:00
|
|
|
|
2024-05-20 12:32:59 +00:00
|
|
|
requestBody := struct {
|
|
|
|
From int
|
|
|
|
Limit int
|
|
|
|
Page int
|
|
|
|
To int
|
|
|
|
}{
|
|
|
|
From: 1713087258,
|
|
|
|
Limit: 10,
|
|
|
|
Page: 1,
|
|
|
|
To: 1713260058,
|
2024-04-15 12:12:21 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 12:32:59 +00:00
|
|
|
req = req.WithContext(context.WithValue(req.Context(), "requestBody", requestBody))
|
|
|
|
resp := httptest.NewRecorder()
|
2024-04-15 12:12:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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()),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|