package test import ( "context" "fmt" "gitea.pena/PenaSide/common/mongo" "gitea.pena/PenaSide/notifier/internal/initialize" "gitea.pena/PenaSide/notifier/internal/models" "gitea.pena/PenaSide/notifier/internal/repository" "testing" "time" ) func TestInsertAndGetMany(t *testing.T) { crx := context.Background() mdb, err := initialize.MongoInit(crx, initialize.Config{ External: initialize.External{ Database: mongo.Configuration{ URL: "mongodb://test:test@localhost:27020/", DatabaseName: "admin", }, }, }) 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)) } }