generated from PenaSide/GolangTemplate
test cool
This commit is contained in:
parent
78c0748c13
commit
25ee1c1a4a
@ -16,7 +16,7 @@ ADD ./tools/migrate /bin/golang-migrate/
|
||||
ADD . .
|
||||
RUN git config --global url."https://buildToken:glpat-axA8ttckx3aPf_xd2Dym@penahub.gitlab.yandexcloud.net/".insteadOf "https://penahub.gitlab.yandexcloud.net/"
|
||||
# Download go depences
|
||||
RUN go mod download
|
||||
RUN go mod download
|
||||
# Build app
|
||||
RUN GOOS=linux go build -o bin ./...
|
||||
|
||||
|
1
go.mod
1
go.mod
@ -14,6 +14,7 @@ require (
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/labstack/echo/v4 v4.11.4
|
||||
github.com/oapi-codegen/runtime v1.1.1
|
||||
github.com/pioz/faker v1.7.3
|
||||
github.com/sethvargo/go-envconfig v1.0.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/twmb/franz-go v1.16.1
|
||||
|
3
go.sum
3
go.sum
@ -105,6 +105,8 @@ github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX
|
||||
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
|
||||
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
|
||||
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
github.com/pioz/faker v1.7.3 h1:Tez8Emuq0UN+/d6mo3a9m/9ZZ/zdfJk0c5RtRatrceM=
|
||||
github.com/pioz/faker v1.7.3/go.mod h1:xSpay5w/oz1a6+ww0M3vfpe40pSIykeUPeWEc3TvVlc=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
@ -123,6 +125,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
|
@ -915,12 +915,13 @@ func (api *API2) QuizLogoStat(ctx echo.Context) error {
|
||||
currentItem := resp.Items[partner]
|
||||
currentItem.Regs++
|
||||
currentItem.Money += history.RawDetails.Price
|
||||
resp.Items[partner] = currentItem
|
||||
currentQuizes := currentItem.Quizes[quizFrom]
|
||||
// первый элемент это регистрации по квизу
|
||||
currentQuizes[0]++
|
||||
currentQuizes[0] = currentQuizes[0] + 1
|
||||
// второй элемент прайс по квизу
|
||||
currentQuizes[1] += int(history.RawDetails.Price)
|
||||
currentQuizes[1] = currentQuizes[1] + int(history.RawDetails.Price)
|
||||
currentItem.Quizes[quizFrom] = currentQuizes
|
||||
resp.Items[partner] = currentItem
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,9 @@ func (receiver *Account) Sanitize() *Account {
|
||||
receiver.Status = DefaultAccountStatus
|
||||
receiver.CreatedAt = now
|
||||
receiver.UpdatedAt = now
|
||||
receiver.From = ""
|
||||
receiver.Partner = ""
|
||||
// закоментил, потому что при инзерте они всегда будут ""
|
||||
//receiver.From = ""
|
||||
//receiver.Partner = ""
|
||||
receiver.DeletedAt = nil
|
||||
receiver.Deleted = false
|
||||
|
||||
|
110
tests/integration/logostat_test.go
Normal file
110
tests/integration/logostat_test.go
Normal file
@ -0,0 +1,110 @@
|
||||
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()),
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user