fix subreddit watchers for 2 letter subreddits

This commit is contained in:
Andre Medeiros 2022-05-12 16:23:16 -04:00
parent 132374fb6b
commit 1919b36f57
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(3, 32), validation.By(validPrefix), validation.Match(regexp.MustCompile(`^[a-zA-Z0-9]\w{1,19}$`))),
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.SubredditID, validation.Required, validation.Length(4, 9)),
)
}

View file

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