44 lines
1.2 KiB
Go
44 lines
1.2 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)
|
|
})
|
|
}
|
|
})
|
|
}
|