2023-07-10 12:39:25 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNotify(t *testing.T) {
|
|
|
|
th := SetupTestHelper(t)
|
|
|
|
defer th.TearDown()
|
|
|
|
t.Run("should correctly use the notification services to notify", func(t *testing.T) {
|
|
|
|
birthday := th.srv.birthdays[0]
|
|
|
|
th.mockNotificationService.
|
|
|
|
EXPECT().
|
2023-07-10 20:08:05 +01:00
|
|
|
Notify(birthday, nil).
|
2023-07-10 12:39:25 +01:00
|
|
|
Return(nil).
|
|
|
|
Times(1)
|
|
|
|
|
|
|
|
err := th.srv.Notify(birthday)
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("should return an error if a service fails", func(t *testing.T) {
|
|
|
|
mockErr := errors.New("failed to notify")
|
|
|
|
birthday := th.srv.birthdays[0]
|
|
|
|
th.mockNotificationService.
|
|
|
|
EXPECT().
|
2023-07-10 20:08:05 +01:00
|
|
|
Notify(birthday, nil).
|
2023-07-10 12:39:25 +01:00
|
|
|
Return(mockErr).
|
|
|
|
Times(1)
|
|
|
|
|
|
|
|
err := th.srv.Notify(birthday)
|
|
|
|
require.ErrorIs(t, err, mockErr)
|
|
|
|
})
|
|
|
|
}
|