package repository_test import ( "context" "testing" "time" "git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository" ) func TestAlertDiscordCreate(t *testing.T) { t.Log(time.Time{}) db, err := setupInMemoryDb() if err != nil { t.Log(err) t.FailNow() } defer db.Close() r := repository.NewAlertDiscordRepository(db) created, err := r.Create(context.Background(), 1, 1, 1) if err != nil { t.Log(err) t.FailNow() } if created != 1 { t.Log("failed to create the record") t.FailNow() } } func TestAlertDiscordCreateAndValidate(t *testing.T) { t.Log(time.Time{}) db, err := setupInMemoryDb() if err != nil { t.Log(err) t.FailNow() } defer db.Close() source := repository.NewSourceRepository(db) source.Create(context.Background(), domain.SourceCollectorRss, "Unit Testing", "www.fake.com", "testing,units", true) sourceRecord, _ := source.GetBySourceAndName(context.Background(), domain.SourceCollectorRss, "Unit Testing") webhookRepo := repository.NewDiscordWebHookRepository(db) webhookRepo.Create(context.Background(), 999, "discord.com", "Unit Testing", "memes", true) webhook, _ := webhookRepo.GetByUrl(context.Background(), "discord.com") r := repository.NewAlertDiscordRepository(db) r.Create(context.Background(), 999, sourceRecord.ID, webhook.ID) alert, err := r.ListByUser(context.Background(), 0, 10, 999) if err != nil { t.Error(err) t.FailNow() } if len(alert) != 1 { t.Error("got the incorrect number of rows back") t.FailNow() } }