2022-05-07 16:37:21 +00:00
|
|
|
package domain_test
|
2022-05-07 15:21:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-05-07 16:37:21 +00:00
|
|
|
|
|
|
|
"github.com/christianselig/apollo-backend/internal/domain"
|
2022-05-07 15:21:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidate(t *testing.T) {
|
2022-05-07 16:37:21 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-05-07 17:22:06 +00:00
|
|
|
tt := map[string]struct {
|
2022-05-07 16:37:21 +00:00
|
|
|
subreddit domain.Subreddit
|
2022-05-07 15:21:01 +00:00
|
|
|
err error
|
|
|
|
}{
|
2022-05-07 16:37:21 +00:00
|
|
|
"invalid subreddit prefix": {domain.Subreddit{Name: "u_iamthatis"}, errors.New("invalid subreddit format")},
|
|
|
|
"valid subreddit": {domain.Subreddit{Name: "pics", SubredditID: "abcd"}, nil},
|
|
|
|
"valid subreddit starting with u": {domain.Subreddit{Name: "urcool", SubredditID: "abcd"}, nil},
|
|
|
|
"valid subreddit with _": {domain.Subreddit{Name: "p_i_x_a_r", SubredditID: "abcd"}, nil},
|
2022-05-12 20:23:16 +00:00
|
|
|
"valid subreddit with 2 letters": {domain.Subreddit{Name: "de", SubredditID: "abcd"}, nil},
|
2022-05-13 14:27:56 +00:00
|
|
|
"valid subreddit with 21 letters": {domain.Subreddit{Name: "GamingLeaksAndRumours", SubredditID: "abcd"}, nil},
|
2022-05-07 15:21:01 +00:00
|
|
|
}
|
|
|
|
|
2022-05-07 17:22:06 +00:00
|
|
|
for scenario, tc := range tt {
|
2022-05-07 15:21:01 +00:00
|
|
|
t.Run(scenario, func(t *testing.T) {
|
2022-05-07 16:37:21 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-05-07 15:21:01 +00:00
|
|
|
err := tc.subreddit.Validate()
|
|
|
|
|
|
|
|
if tc.err == nil {
|
|
|
|
require.NoError(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|