add repository tests for current repo methods
This commit is contained in:
parent
8f3b0e5489
commit
7c3fd42b0c
15
deployments/local/docker-compose.yaml
Normal file
15
deployments/local/docker-compose.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mongo:
|
||||
image: mongo
|
||||
ports:
|
||||
- "27020:27017"
|
||||
environment:
|
||||
- MONGO_INITDB_ROOT_USERNAME=test
|
||||
- MONGO_INITDB_ROOT_PASSWORD=test
|
||||
- MONGO_INITDB_AUTH_MECHANISM=SCRAM-SHA-1
|
||||
volumes:
|
||||
- mongo_data:/data/db
|
||||
volumes:
|
||||
mongo_data:
|
0
deployments/main/docker-compose.yaml
Normal file
0
deployments/main/docker-compose.yaml
Normal file
0
deployments/staging/docker-compose.yaml
Normal file
0
deployments/staging/docker-compose.yaml
Normal file
15
deployments/test/docker-compose.yaml
Normal file
15
deployments/test/docker-compose.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mongo:
|
||||
image: mongo
|
||||
ports:
|
||||
- "27020:27017"
|
||||
environment:
|
||||
- MONGO_INITDB_ROOT_USERNAME=test
|
||||
- MONGO_INITDB_ROOT_PASSWORD=test
|
||||
- MONGO_INITDB_AUTH_MECHANISM=SCRAM-SHA-1
|
||||
volumes:
|
||||
- mongo_data:/data/db
|
||||
volumes:
|
||||
mongo_data:
|
5
go.mod
5
go.mod
@ -5,6 +5,8 @@ go 1.21.6
|
||||
require (
|
||||
github.com/caarlos0/env/v8 v8.0.0
|
||||
github.com/gofiber/fiber/v2 v2.52.4
|
||||
github.com/pioz/faker v1.7.3
|
||||
github.com/stretchr/testify v1.8.4
|
||||
go.mongodb.org/mongo-driver v1.14.0
|
||||
go.uber.org/zap v1.27.0
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6
|
||||
@ -14,6 +16,7 @@ require (
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
@ -22,6 +25,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/rs/xid v1.5.0 // indirect
|
||||
github.com/tealeg/xlsx v1.0.5 // indirect
|
||||
@ -37,4 +41,5 @@ require (
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.17.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
7
go.sum
7
go.sum
@ -2,6 +2,7 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0=
|
||||
github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4TDSSSzfo=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
|
||||
@ -31,12 +32,16 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1/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=
|
||||
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
|
||||
@ -97,8 +102,10 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA=
|
||||
|
@ -20,5 +20,5 @@ type Tag struct {
|
||||
/* - айдишник тега в амо*/
|
||||
Amoid int `json:"AmoID" bson:"amoid"`
|
||||
/* - цвет тега в амо*/
|
||||
Color string `json:"Color" bson:"color"`
|
||||
Color *string `json:"Color" bson:"color"`
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func (r *Repository) CheckFields(ctx context.Context, deps CheckFieldsDeps) erro
|
||||
Entity: deps.EntityType,
|
||||
}
|
||||
|
||||
existingField, err := r.GetFieldByID(ctx, deps.AccountID, f.ID)
|
||||
existingField, err := r.GetFieldByID(ctx, deps.AccountID, f.ID, deps.EntityType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -94,9 +94,10 @@ func (r *Repository) CheckFields(ctx context.Context, deps CheckFieldsDeps) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) GetFieldByID(ctx context.Context, accountID string, amoid int) (*models.Field, error) {
|
||||
// test +
|
||||
func (r *Repository) GetFieldByID(ctx context.Context, accountID string, amoid int, entity amo.EntityType) (*models.Field, error) {
|
||||
var field models.Field
|
||||
filter := bson.M{"id": accountID, "amoid": amoid}
|
||||
filter := bson.M{"id": accountID, "amoid": amoid, "entity": entity}
|
||||
err := r.fields.FindOne(ctx, filter).Decode(&field)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, nil
|
||||
@ -107,8 +108,9 @@ func (r *Repository) GetFieldByID(ctx context.Context, accountID string, amoid i
|
||||
return &field, nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) UpdateField(ctx context.Context, field *models.Field) error {
|
||||
filter := bson.M{"id": field.ID, "amoid": field.Amoid}
|
||||
filter := bson.M{"id": field.ID, "amoid": field.Amoid, "entity": field.Entity}
|
||||
update := bson.M{"$set": bson.M{
|
||||
"accountid": field.Accountid,
|
||||
"name": field.Name,
|
||||
@ -121,6 +123,7 @@ func (r *Repository) UpdateField(ctx context.Context, field *models.Field) error
|
||||
return err
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) InsertField(ctx context.Context, field *models.Field) error {
|
||||
_, err := r.fields.InsertOne(ctx, field)
|
||||
return err
|
||||
|
@ -17,6 +17,7 @@ func (r *Repository) UpdateListPipelines(ctx context.Context) error {
|
||||
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) GettingPipelinesFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListPipelinesResp, error) {
|
||||
offset := (req.Page - 1) * req.Size
|
||||
|
||||
@ -52,6 +53,7 @@ func (r *Repository) GettingPipelinesFromCash(ctx context.Context, req *models.P
|
||||
return pipelineListResp, nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) CheckPipelines(ctx context.Context, accountID string, pipelines []amo.Pipeline) error {
|
||||
for _, p := range pipelines {
|
||||
pipeline := models.Pipeline{
|
||||
@ -85,6 +87,7 @@ func (r *Repository) CheckPipelines(ctx context.Context, accountID string, pipel
|
||||
return nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) GetPipelineByID(ctx context.Context, accountID string, amoid int) (*models.Pipeline, error) {
|
||||
var pipeline models.Pipeline
|
||||
filter := bson.M{"id": accountID, "amoid": amoid}
|
||||
@ -98,6 +101,7 @@ func (r *Repository) GetPipelineByID(ctx context.Context, accountID string, amoi
|
||||
return &pipeline, nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) UpdatePipeline(ctx context.Context, pipeline *models.Pipeline) error {
|
||||
filter := bson.M{"id": pipeline.ID, "amoid": pipeline.Amoid}
|
||||
update := bson.M{"$set": bson.M{
|
||||
@ -110,6 +114,7 @@ func (r *Repository) UpdatePipeline(ctx context.Context, pipeline *models.Pipeli
|
||||
return err
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) InsertPipeline(ctx context.Context, pipeline *models.Pipeline) error {
|
||||
_, err := r.pipelines.InsertOne(ctx, pipeline)
|
||||
return err
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// test +
|
||||
func (r *Repository) GettingStepsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListStepsResp, error) {
|
||||
offset := (req.Page - 1) * req.Size
|
||||
|
||||
@ -52,6 +53,7 @@ func (r *Repository) UpdateListSteps(ctx context.Context) error {
|
||||
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) CheckSteps(ctx context.Context, accountID string, steps []amo.Statuses) error {
|
||||
for _, s := range steps {
|
||||
step := models.Step{
|
||||
@ -86,6 +88,7 @@ func (r *Repository) CheckSteps(ctx context.Context, accountID string, steps []a
|
||||
return nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) GetStepByID(ctx context.Context, accountID string, amoid int) (*models.Step, error) {
|
||||
var step models.Step
|
||||
filter := bson.M{"id": accountID, "amoid": amoid}
|
||||
@ -99,6 +102,7 @@ func (r *Repository) GetStepByID(ctx context.Context, accountID string, amoid in
|
||||
return &step, nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) UpdateStep(ctx context.Context, step *models.Step) error {
|
||||
filter := bson.M{"id": step.ID, "amoid": step.Amoid}
|
||||
update := bson.M{"$set": bson.M{
|
||||
@ -112,6 +116,7 @@ func (r *Repository) UpdateStep(ctx context.Context, step *models.Step) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) InsertStep(ctx context.Context, step *models.Step) error {
|
||||
_, err := r.steps.InsertOne(ctx, step)
|
||||
return err
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// test +
|
||||
func (r *Repository) GettingTagsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListTagsResp, error) {
|
||||
offset := (req.Page - 1) * req.Size
|
||||
|
||||
@ -59,6 +60,7 @@ type CheckTagsDeps struct {
|
||||
Tags []amo.Tag
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) CheckTags(ctx context.Context, deps CheckTagsDeps) error {
|
||||
for _, t := range deps.Tags {
|
||||
tag := models.Tag{
|
||||
@ -66,11 +68,11 @@ func (r *Repository) CheckTags(ctx context.Context, deps CheckTagsDeps) error {
|
||||
Accountid: deps.ID,
|
||||
Amoid: t.ID,
|
||||
Name: t.Name,
|
||||
Color: *t.Color,
|
||||
Color: t.Color,
|
||||
Entity: deps.EntityType,
|
||||
}
|
||||
|
||||
existingTag, err := r.GetTagByID(ctx, deps.AccountID, t.ID)
|
||||
existingTag, err := r.GetTagByID(ctx, deps.AccountID, t.ID, deps.EntityType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -93,9 +95,10 @@ func (r *Repository) CheckTags(ctx context.Context, deps CheckTagsDeps) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) GetTagByID(ctx context.Context, accountID string, amoid int) (*models.Tag, error) {
|
||||
// test +
|
||||
func (r *Repository) GetTagByID(ctx context.Context, accountID string, amoid int, entity amo.EntityType) (*models.Tag, error) {
|
||||
var tag models.Tag
|
||||
filter := bson.M{"id": accountID, "amoid": amoid}
|
||||
filter := bson.M{"id": accountID, "amoid": amoid, "entity": entity}
|
||||
err := r.tags.FindOne(ctx, filter).Decode(&tag)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, nil
|
||||
@ -106,8 +109,9 @@ func (r *Repository) GetTagByID(ctx context.Context, accountID string, amoid int
|
||||
return &tag, nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) UpdateTag(ctx context.Context, tag *models.Tag) error {
|
||||
filter := bson.M{"id": tag.ID, "amoid": tag.Amoid}
|
||||
filter := bson.M{"id": tag.ID, "amoid": tag.Amoid, "entity": tag.Entity}
|
||||
update := bson.M{"$set": bson.M{
|
||||
"accountid": tag.Accountid,
|
||||
"name": tag.Name,
|
||||
@ -119,6 +123,7 @@ func (r *Repository) UpdateTag(ctx context.Context, tag *models.Tag) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) InsertTag(ctx context.Context, tag *models.Tag) error {
|
||||
_, err := r.tags.InsertOne(ctx, tag)
|
||||
return err
|
||||
|
@ -16,6 +16,7 @@ func (r *Repository) UpdateListUsers(ctx context.Context) error {
|
||||
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) GettingUserFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListResp, error) {
|
||||
offset := (req.Page - 1) * req.Size
|
||||
|
||||
@ -73,6 +74,7 @@ func (r *Repository) GetCurrentAccount(ctx context.Context, accountID string) (*
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) CreateAccount(ctx context.Context, accountID string) error {
|
||||
userData := models.User{}
|
||||
userData.Createdat = time.Now().Unix()
|
||||
@ -84,6 +86,7 @@ func (r *Repository) CreateAccount(ctx context.Context, accountID string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) UpdateAccount(ctx context.Context, accountID string, userInfo models.User) error {
|
||||
filter := bson.M{"AccountID": accountID}
|
||||
update := bson.M{
|
||||
@ -107,6 +110,7 @@ func (r *Repository) UpdateAccount(ctx context.Context, accountID string, userIn
|
||||
return nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) CheckUsers(ctx context.Context, amouserid int, user models.User) error {
|
||||
filter := bson.M{"Amouserid": amouserid}
|
||||
update := bson.M{
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// test +
|
||||
func (r *Repository) WebhookCreate(ctx context.Context, tokens models.Token) error {
|
||||
filter := bson.M{"AccountID": tokens.AccountID}
|
||||
update := bson.M{
|
||||
@ -22,6 +23,7 @@ func (r *Repository) WebhookCreate(ctx context.Context, tokens models.Token) err
|
||||
return nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) WebhookUpdate(ctx context.Context, tokens models.Token) error {
|
||||
filter := bson.M{"AccountID": tokens.AccountID}
|
||||
// токены обновляются каждый раз при обновлении access токена
|
||||
@ -41,10 +43,10 @@ func (r *Repository) WebhookUpdate(ctx context.Context, tokens models.Token) err
|
||||
return nil
|
||||
}
|
||||
|
||||
// test +
|
||||
// воркер запускается каждые 5 минут, поэтомму ищем токены котторые исекают менее чем через 10 минут отдаем их на обноление
|
||||
func (r *Repository) CheckExpired(ctx context.Context) ([]models.Token, error) {
|
||||
tenMinutesAgo := time.Now().Add(10 * time.Minute).Unix()
|
||||
|
||||
tenMinutesAgo := time.Now().Add(-10 * time.Second).Unix()
|
||||
filter := bson.M{
|
||||
"Expiration": bson.M{
|
||||
"$lte": tenMinutesAgo,
|
||||
@ -65,6 +67,7 @@ func (r *Repository) CheckExpired(ctx context.Context) ([]models.Token, error) {
|
||||
return tokens, nil
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) GetAllTokens(ctx context.Context) ([]models.Token, error) {
|
||||
cursor, err := r.tokens.Find(ctx, bson.M{})
|
||||
if err != nil {
|
||||
|
@ -284,6 +284,8 @@ func (a *Amo) GetListTags(req amo.GetListTagsReq, accessToken string) (*amo.Resp
|
||||
}
|
||||
}
|
||||
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/account-info
|
||||
// GET /api/v4/account
|
||||
func (a *Amo) GetUserInfo(accessToken string) (*amo.AmocrmUserInformation, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
@ -317,6 +319,8 @@ func (a *Amo) GetUserInfo(accessToken string) (*amo.AmocrmUserInformation, error
|
||||
}
|
||||
|
||||
// токен должен быть с правами администратора
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/users-api#user-detail
|
||||
// GET /api/v4/users/{id
|
||||
func (a *Amo) GetUserByID(id int) (*amo.OneUserInfo, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
@ -350,6 +354,8 @@ func (a *Amo) GetUserByID(id int) (*amo.OneUserInfo, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA-%D0%B2%D0%BE%D1%80%D0%BE%D0%BD%D0%BE%D0%BA-%D1%81%D0%B4%D0%B5%D0%BB%D0%BE%D0%BA
|
||||
// GET /api/v4/leads/pipelines
|
||||
func (a *Amo) GetListPipelines(accessToken string) (*amo.PipelineResponse, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
|
651
tests/repository/repository_test.go
Normal file
651
tests/repository/repository_test.go
Normal file
@ -0,0 +1,651 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"amocrm/internal/initialize"
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/models/amo"
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/internal/tools"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pioz/faker"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_Repository(t *testing.T) {
|
||||
cfgLogger := zap.NewDevelopmentConfig()
|
||||
cfgLogger.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
cfgLogger.EncoderConfig.ConsoleSeparator = " "
|
||||
|
||||
logger, err := cfgLogger.Build()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
mdb, err := initialize.MongoDB(ctx, initialize.Config{
|
||||
MongoHost: "localhost",
|
||||
MongoPort: "27020",
|
||||
MongoDatabase: "admin",
|
||||
MongoAuth: "admin",
|
||||
MongoPassword: "test",
|
||||
MongoUser: "test",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("err init mongo")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
repo := repository.NewRepository(repository.Deps{
|
||||
MdbUser: mdb.Collection("amoUsers"),
|
||||
Tokens: mdb.Collection("tokens"),
|
||||
Pipelines: mdb.Collection("pipelines"),
|
||||
Steps: mdb.Collection("steps"),
|
||||
Tags: mdb.Collection("tags"),
|
||||
Fields: mdb.Collection("fields"),
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
err = webhookCreate(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = webhookUpdate(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
|
||||
count := 0
|
||||
for {
|
||||
if count == 8 {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
tokens, err := checkExpired(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
if len(tokens) > 0 {
|
||||
fmt.Println(tokens)
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
err = getAllTokens(ctx, t, repo)
|
||||
assert.NoError(t, err)
|
||||
err = createUser(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = updateUser(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = checkUsers(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = gettingUserFromCash(ctx, t, repo)
|
||||
assert.NoError(t, err)
|
||||
err = checkPipelines(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = gettingPipelinesFromCash(ctx, t, repo)
|
||||
assert.NoError(t, err)
|
||||
err = checkSteps(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = gettingStepsFromCash(ctx, t, repo)
|
||||
assert.NoError(t, err)
|
||||
err = checkTags(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = gettingTagsFromCash(ctx, t, repo)
|
||||
assert.NoError(t, err)
|
||||
err = checkFields(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = gettingFieldsFromCash(ctx, t, repo)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func createUser(ctx context.Context, repo *repository.Repository) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err := repo.CreateAccount(ctx, accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateUser(ctx context.Context, repo *repository.Repository) error {
|
||||
var testUserInfo amo.AmocrmUserInformation
|
||||
err := json.Unmarshal([]byte(jsonUserInfo), &testUserInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 1; i < 10; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
info := models.User{
|
||||
Name: faker.String(),
|
||||
Subdomain: "pena",
|
||||
Amocrmid: 666,
|
||||
Amouserid: i,
|
||||
Email: faker.Email(),
|
||||
Group: tools.ConvertUserGroups(&testUserInfo),
|
||||
Country: "Russia",
|
||||
}
|
||||
|
||||
if i%2 == 0 {
|
||||
role := faker.String()
|
||||
role2 := &role
|
||||
info.Role = *role2
|
||||
uuid := faker.UUID()
|
||||
uuid2 := &uuid
|
||||
info.ID = *uuid2
|
||||
}
|
||||
|
||||
err = repo.UpdateAccount(ctx, accID, info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkUsers(ctx context.Context, repo *repository.Repository) error {
|
||||
var testUserInfo amo.AmocrmUserInformation
|
||||
err := json.Unmarshal([]byte(jsonUserInfo), &testUserInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 1; i < 10; i++ {
|
||||
if i%2 != 0 {
|
||||
info := models.User{
|
||||
Name: faker.String(),
|
||||
Email: faker.Email(),
|
||||
Group: tools.ConvertUserGroups(&testUserInfo),
|
||||
}
|
||||
role := faker.String()
|
||||
role2 := &role
|
||||
info.Role = *role2
|
||||
|
||||
err = repo.CheckUsers(ctx, i, info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func gettingUserFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
req := models.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingUserFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assert.Equal(t, i, len(resp.Items))
|
||||
fmt.Println(len(resp.Items))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkPipelines(ctx context.Context, repo *repository.Repository) error {
|
||||
var testPipeline1 amo.PipelineResponse
|
||||
err := json.Unmarshal([]byte(jsonPipelines), &testPipeline1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testPipeline2 amo.PipelineResponse
|
||||
err = json.Unmarshal([]byte(jsonPipelines2), &testPipeline2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckPipelines(ctx, accID, testPipeline1.Embedded.Pipelines)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckPipelines(ctx, accID, testPipeline2.Embedded.Pipelines)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingPipelinesFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
for i := 1; i < 28; i++ {
|
||||
req := models.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingPipelinesFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assert.Equal(t, i, len(resp.Items))
|
||||
fmt.Println(resp.Items)
|
||||
fmt.Println(len(resp.Items))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkSteps(ctx context.Context, repo *repository.Repository) error {
|
||||
var testStep1 amo.ResponseGetListSteps
|
||||
err := json.Unmarshal([]byte(jsonStep1), &testStep1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testStep2 amo.ResponseGetListSteps
|
||||
err = json.Unmarshal([]byte(jsonStep2), &testStep2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckSteps(ctx, accID, testStep1.Embedded.Statuses)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckSteps(ctx, accID, testStep2.Embedded.Statuses)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingStepsFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
for i := 1; i < 46; i++ {
|
||||
req := models.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingStepsFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assert.Equal(t, i, len(resp.Items))
|
||||
fmt.Println(resp.Items)
|
||||
fmt.Println(len(resp.Items))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkTags(ctx context.Context, repo *repository.Repository) error {
|
||||
var testLeadsTags amo.ResponseGetListTags
|
||||
err := json.Unmarshal([]byte(jsonLeadsTags), &testLeadsTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testLeadsTags2 amo.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonLeadsTags2), &testLeadsTags2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testContactsTags amo.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonContactsTags), &testContactsTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testContactsTags2 amo.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonContactsTags2), &testContactsTags2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCompaniesTags amo.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonCompaniesTags), &testCompaniesTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCompaniesTags2 amo.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonCompaniesTags2), &testCompaniesTags2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCustomersTags amo.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonCustomersTags), &testCustomersTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCustomersTags2 amo.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonCustomersTags2), &testCustomersTags2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := 666666
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.LeadsTags,
|
||||
Tags: testLeadsTags.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CompaniesTags,
|
||||
Tags: testCompaniesTags.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CustomersTags,
|
||||
Tags: testCustomersTags.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.ContactsTags,
|
||||
Tags: testContactsTags.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.LeadsTags,
|
||||
Tags: testLeadsTags2.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CompaniesTags,
|
||||
Tags: testCompaniesTags2.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CustomersTags,
|
||||
Tags: testCustomersTags2.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.ContactsTags,
|
||||
Tags: testContactsTags2.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingTagsFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
for i := 1; i < 73; i++ {
|
||||
req := models.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingTagsFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assert.Equal(t, i, len(resp.Items))
|
||||
fmt.Println(resp.Items)
|
||||
fmt.Println(len(resp.Items))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkFields(ctx context.Context, repo *repository.Repository) error {
|
||||
var testLeadsFields amo.ResponseGetListFields
|
||||
err := json.Unmarshal([]byte(jsonLeadsFields), &testLeadsFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testLeadsFields2 amo.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonLeadsFields2), &testLeadsFields2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testContactsFields amo.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonContactsFields), &testContactsFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testContactsFields2 amo.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonContactsFields2), &testContactsFields2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCompaniesFields amo.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonCompaniesFields), &testCompaniesFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCompaniesFields2 amo.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonCompaniesFields2), &testCompaniesFields2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCustomersFields amo.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonCustomersFields), &testCustomersFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCustomersFields2 amo.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonCustomersFields2), &testCustomersFields2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
id := 666666
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.LeadsTags,
|
||||
Fields: testLeadsFields.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CompaniesTags,
|
||||
Fields: testCompaniesFields.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CustomersTags,
|
||||
Fields: testCustomersFields.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.ContactsTags,
|
||||
Fields: testContactsFields.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.LeadsTags,
|
||||
Fields: testLeadsFields2.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CompaniesTags,
|
||||
Fields: testCompaniesFields2.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CustomersTags,
|
||||
Fields: testCustomersFields2.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.ContactsTags,
|
||||
Fields: testContactsFields2.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingFieldsFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
for i := 1; i < 73; i++ {
|
||||
req := models.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingFieldsFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assert.Equal(t, i, len(resp.Items))
|
||||
fmt.Println(resp.Items)
|
||||
fmt.Println(len(resp.Items))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func webhookCreate(ctx context.Context, repo *repository.Repository) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err := repo.WebhookCreate(ctx, models.Token{
|
||||
RefreshToken: faker.UUID(),
|
||||
AccessToken: faker.UUID(),
|
||||
AccountID: accID,
|
||||
AuthCode: faker.String(),
|
||||
Expiration: time.Now().Unix() + 10,
|
||||
CreatedAt: time.Now().Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func webhookUpdate(ctx context.Context, repo *repository.Repository) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err := repo.WebhookUpdate(ctx, models.Token{
|
||||
RefreshToken: faker.UUID(),
|
||||
AccessToken: faker.UUID(),
|
||||
AccountID: accID,
|
||||
Expiration: time.Now().Unix() + int64(i),
|
||||
CreatedAt: time.Now().Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkExpired(ctx context.Context, repo *repository.Repository) ([]models.Token, error) {
|
||||
tokens, err := repo.CheckExpired(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return tokens, nil
|
||||
}
|
||||
|
||||
func getAllTokens(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
tokens, err := repo.GetAllTokens(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
assert.Equal(t, len(tokens), 9)
|
||||
|
||||
return nil
|
||||
}
|
1456
tests/repository/test_vars.go
Normal file
1456
tests/repository/test_vars.go
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user