Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
66 строки
1.6 KiB
Go
66 строки
1.6 KiB
Go
package models_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"rocketgit.ru/rsmon/worker/app/models"
|
|
)
|
|
|
|
// TestSystemContacts verifies that SystemContacts returns only contacts with
|
|
// is_system=true and ignores contacts with is_system=false or nil.
|
|
func TestSystemContacts(t *testing.T) {
|
|
models.Drop()
|
|
models.Migrate()
|
|
|
|
account := &models.Account{Name: "test-account"}
|
|
require.NoError(t, models.DB().Create(account).Error)
|
|
accountID := account.ID
|
|
|
|
trueVal, falseVal := true, false
|
|
|
|
systemContact := &models.Contact{
|
|
AccountID: &accountID,
|
|
Name: "system-admin",
|
|
Kind: "email",
|
|
Value: "ops@example.com",
|
|
IsSystem: &trueVal,
|
|
}
|
|
regularContact := &models.Contact{
|
|
AccountID: &accountID,
|
|
Name: "regular",
|
|
Kind: "email",
|
|
Value: "user@example.com",
|
|
IsSystem: &falseVal,
|
|
}
|
|
nilSystemContact := &models.Contact{
|
|
AccountID: &accountID,
|
|
Name: "nil-system",
|
|
Kind: "email",
|
|
Value: "nil@example.com",
|
|
}
|
|
|
|
require.NoError(t, models.DB().Create(systemContact).Error)
|
|
require.NoError(t, models.DB().Create(regularContact).Error)
|
|
require.NoError(t, models.DB().Create(nilSystemContact).Error)
|
|
|
|
got, err := models.SystemContacts()
|
|
require.NoError(t, err)
|
|
|
|
var ids []int64
|
|
var names []string
|
|
for _, c := range got {
|
|
ids = append(ids, c.ID)
|
|
names = append(names, c.Name)
|
|
}
|
|
|
|
assert.Contains(t, names, "system-admin")
|
|
assert.NotContains(t, names, "regular")
|
|
assert.NotContains(t, names, "nil-system")
|
|
assert.Contains(t, ids, systemContact.ID)
|
|
assert.NotContains(t, ids, regularContact.ID)
|
|
assert.NotContains(t, ids, nilSystemContact.ID)
|
|
}
|