birthdaybot/server/server_test.go

37 lines
779 B
Go

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().
Notify(birthday, nil).
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().
Notify(birthday, nil).
Return(mockErr).
Times(1)
err := th.srv.Notify(birthday)
require.ErrorIs(t, err, mockErr)
})
}