Fix Subreddit length

This commit is contained in:
Andre Medeiros 2022-05-13 10:27:56 -04:00
parent 1919b36f57
commit 69a9101499
2 changed files with 2 additions and 1 deletions

View file

@ -39,7 +39,7 @@ func validPrefix(value interface{}) error {
func (sr *Subreddit) Validate() error {
return validation.ValidateStruct(sr,
validation.Field(&sr.Name, validation.Required, validation.Length(2, 32), validation.By(validPrefix), validation.Match(regexp.MustCompile(`^[a-zA-Z0-9]\w{1,19}$`))),
validation.Field(&sr.Name, validation.Required, validation.Length(2, 21), validation.By(validPrefix), validation.Match(regexp.MustCompile(`^[a-zA-Z0-9]\w*$`))),
validation.Field(&sr.SubredditID, validation.Required, validation.Length(4, 9)),
)
}

View file

@ -22,6 +22,7 @@ func TestValidate(t *testing.T) {
"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},
"valid subreddit with 2 letters": {domain.Subreddit{Name: "de", SubredditID: "abcd"}, nil},
"valid subreddit with 21 letters": {domain.Subreddit{Name: "GamingLeaksAndRumours", SubredditID: "abcd"}, nil},
}
for scenario, tc := range tt {