birthdaybot/model/birthdays_test.go
2023-07-10 22:44:48 +02:00

57 lines
1.5 KiB
Go

package model
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNewBirthdayFromRecord(t *testing.T) {
t.Run("should correctly parse different records", func(t *testing.T) {
testCases := []struct {
Record []string
ExpectedName string
ExpectedEmail string
ExpectedPhone string
ExpectedYearOfBirth int
ExpectedMonthOfBirth int
ExpectedDayOfBirth int
}{
{
Record: []string{"John Doe ", "john@doe.com", " 123456789", "17/04/2192"},
ExpectedName: "John Doe",
ExpectedEmail: "john@doe.com",
ExpectedPhone: "123456789",
ExpectedYearOfBirth: 2192,
ExpectedMonthOfBirth: 4,
ExpectedDayOfBirth: 17,
},
}
for _, tc := range testCases {
t.Run(tc.ExpectedName, func(t *testing.T) {
b, err := NewBirthdayFromRecord(tc.Record)
require.NoError(t, err)
require.Equal(t, tc.ExpectedName, b.Name)
require.Equal(t, tc.ExpectedEmail, b.Email)
require.Equal(t, tc.ExpectedPhone, b.Phone)
require.Equal(t, tc.ExpectedYearOfBirth, b.YearOfBirth)
require.Equal(t, tc.ExpectedMonthOfBirth, b.MonthOfBirth)
require.Equal(t, tc.ExpectedDayOfBirth, b.DayOfBirth)
})
}
})
}
func TestFilename(t *testing.T) {
birthday := &Birthday{
Name: "John Doe",
Email: "john@doe.com",
Phone: "123456789",
YearOfBirth: 2022,
MonthOfBirth: 4,
DayOfBirth: 6,
}
require.Equal(t, "2022_4_6_123456789.png", birthday.Filename())
}