Files
worker/spec/factories/notifications.go
Gleb Tv 2c884c5612
Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
refactor: adopt worker module path
2026-07-13 17:56:12 +03:00

54 строки
1.4 KiB
Go

package factories
import (
"github.com/icrowley/fake"
"rocketgit.ru/rsmon/worker/app/models"
)
// NotificationFactory provides functionality.
func NotificationFactory(account *models.Account, contactIDs, groupIDs []int64, alertDelay int64, notifyRestore bool) models.Notification {
BeforeExpiration := int64(3600)
notification := models.Notification{
Name: fake.Company(),
ContactIDs: contactIDs,
GroupIDs: groupIDs,
AlertDelay: &alertDelay,
NotifyDown: true,
NotifyRestore: notifyRestore,
BeforeExpiration: &BeforeExpiration,
}
if account == nil {
c := AccountFactory()
account = &c
}
notification.Account = account
notification.AccountID = account.ID
return notification
}
// PersistedNotification provides functionality.
func PersistedNotification(account *models.Account, contactIDs, groupIDs []int64, alertDelay int64, notifyRestore bool) models.Notification { //nolint:lll
notification := NotificationFactory(account, contactIDs, groupIDs, alertDelay, notifyRestore)
if notification.Account.ID == 0 {
err := models.DB().Save(&notification.Account).Error
if err != nil {
panic(err)
}
notification.AccountID = notification.Account.ID
}
err := models.DB().Save(&notification).Error
if err != nil {
panic(err)
}
err = notification.PersistRelations()
if err != nil {
panic(err)
}
return notification
}