2024-04-22 15:59:07 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-11-29 07:38:24 +00:00
|
|
|
"gitea.pena/PenaSide/common/mongo"
|
2024-11-25 08:14:01 +00:00
|
|
|
"gitea.pena/PenaSide/notifier/internal/initialize"
|
|
|
|
"gitea.pena/PenaSide/notifier/internal/models"
|
|
|
|
"gitea.pena/PenaSide/notifier/internal/repository"
|
2024-04-22 15:59:07 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInsertAndGetMany(t *testing.T) {
|
|
|
|
crx := context.Background()
|
|
|
|
mdb, err := initialize.MongoInit(crx, initialize.Config{
|
2024-12-16 11:17:25 +00:00
|
|
|
External: initialize.External{
|
|
|
|
Database: mongo.Configuration{
|
|
|
|
URL: "mongodb://test:test@localhost:27020/",
|
|
|
|
DatabaseName: "admin",
|
|
|
|
},
|
2024-11-29 07:38:24 +00:00
|
|
|
},
|
2024-04-22 15:59:07 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
repo := repository.NewRepository(mdb.Collection("notify"))
|
|
|
|
ctx := context.Background()
|
|
|
|
testMessages := []models.Message{
|
|
|
|
{
|
|
|
|
AccountID: "1",
|
|
|
|
Email: "test",
|
|
|
|
ServiceKey: "1",
|
|
|
|
SendRegistration: false,
|
|
|
|
SendNoneCreated: false,
|
|
|
|
SendUnpublished: true,
|
|
|
|
SendPaid: false,
|
|
|
|
SendAt: time.Now().AddDate(0, 0, -12),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
AccountID: "2",
|
|
|
|
Email: "test2",
|
|
|
|
ServiceKey: "2",
|
|
|
|
SendRegistration: false,
|
|
|
|
SendNoneCreated: true,
|
|
|
|
SendUnpublished: false,
|
|
|
|
SendPaid: true,
|
|
|
|
SendAt: time.Now().AddDate(0, 0, -7),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
AccountID: "3",
|
|
|
|
Email: "test3",
|
|
|
|
ServiceKey: "3",
|
|
|
|
SendRegistration: false,
|
|
|
|
SendNoneCreated: false,
|
|
|
|
SendUnpublished: false,
|
|
|
|
SendPaid: false,
|
|
|
|
SendAt: time.Now().AddDate(0, 0, -14),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
AccountID: "4",
|
|
|
|
Email: "test4",
|
|
|
|
ServiceKey: "4",
|
|
|
|
SendRegistration: true,
|
|
|
|
SendNoneCreated: true,
|
|
|
|
SendUnpublished: true,
|
|
|
|
SendPaid: true,
|
|
|
|
SendAt: time.Now(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
AccountID: "5",
|
|
|
|
Email: "test5",
|
|
|
|
ServiceKey: "5",
|
|
|
|
SendRegistration: true,
|
|
|
|
SendNoneCreated: true,
|
|
|
|
SendUnpublished: true,
|
|
|
|
SendPaid: true,
|
|
|
|
SendAt: time.Now().AddDate(0, 0, -15),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, msg := range testMessages {
|
|
|
|
if err := repo.Insert(ctx, msg); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := repo.GetMany(ctx)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(result) != 3 {
|
|
|
|
t.Errorf("ожидал %d , получил %d", 3, len(result))
|
|
|
|
}
|
|
|
|
}
|