birthdaybot/server/web_test.go

40 lines
875 B
Go
Raw Normal View History

package server
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestPort(t *testing.T) {
th := SetupTestHelper(t)
defer th.TearDown()
port := th.srv.WebServer.Port()
require.NotEmpty(t, port)
}
func TestHealthHandler(t *testing.T) {
th := SetupTestHelper(t)
defer th.TearDown()
t.Run("should return ok if the server is up and running", func(t *testing.T) {
health, err := th.client.Health(context.Background())
require.NoError(t, err)
require.True(t, health)
})
}
func TestNextBirthdaysHandler(t *testing.T) {
th := SetupTestHelper(t)
defer th.TearDown()
t.Run("should return a list if the server is up and running", func(t *testing.T) {
birthdays, err := th.client.NextBirthdays(context.Background())
require.NoError(t, err)
require.Len(t, birthdays, 1)
require.Equal(t, "john@doe.com", birthdays[0].Email)
})
}