summaryrefslogtreecommitdiffstats
path: root/model/utils_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-04-22 21:52:03 +0900
committerHarrison Healey <harrisonmhealey@gmail.com>2017-04-22 08:52:03 -0400
commitecb10ed62fdff179e34f82b0ff2569da8390f4ad (patch)
treee2405ed87a31cca42275b98a76e1312c0a1867eb /model/utils_test.go
parente62afeace04e2abd23fa78a0a54e0a5d2e17e0b7 (diff)
downloadchat-ecb10ed62fdff179e34f82b0ff2569da8390f4ad.tar.gz
chat-ecb10ed62fdff179e34f82b0ff2569da8390f4ad.tar.bz2
chat-ecb10ed62fdff179e34f82b0ff2569da8390f4ad.zip
APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name (#6117)
* APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name * updated v3 deleteReaction endpoint * update parameter of app.DeleteReactionForPost() * update utils.IsValidAlphaNum, add utils.IsValidAlphaNumHyphenUnderscore, and add related tests
Diffstat (limited to 'model/utils_test.go')
-rw-r--r--model/utils_test.go188
1 files changed, 188 insertions, 0 deletions
diff --git a/model/utils_test.go b/model/utils_test.go
index e77ce80fb..94ee55aa9 100644
--- a/model/utils_test.go
+++ b/model/utils_test.go
@@ -137,3 +137,191 @@ func TestParseHashtags(t *testing.T) {
}
}
}
+
+func TestIsValidAlphaNum(t *testing.T) {
+ cases := []struct {
+ Input string
+ Result bool
+ }{
+ {
+ Input: "test",
+ Result: true,
+ },
+ {
+ Input: "test-name",
+ Result: true,
+ },
+ {
+ Input: "test--name",
+ Result: true,
+ },
+ {
+ Input: "test__name",
+ Result: true,
+ },
+ {
+ Input: "-",
+ Result: false,
+ },
+ {
+ Input: "__",
+ Result: false,
+ },
+ {
+ Input: "test-",
+ Result: false,
+ },
+ {
+ Input: "test--",
+ Result: false,
+ },
+ {
+ Input: "test__",
+ Result: false,
+ },
+ {
+ Input: "test:name",
+ Result: false,
+ },
+ }
+
+ for _, tc := range cases {
+ actual := IsValidAlphaNum(tc.Input)
+ if actual != tc.Result {
+ t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result)
+ }
+ }
+}
+
+func TestIsValidAlphaNumHyphenUnderscore(t *testing.T) {
+ casesWithFormat := []struct {
+ Input string
+ Result bool
+ }{
+ {
+ Input: "test",
+ Result: true,
+ },
+ {
+ Input: "test-name",
+ Result: true,
+ },
+ {
+ Input: "test--name",
+ Result: true,
+ },
+ {
+ Input: "test__name",
+ Result: true,
+ },
+ {
+ Input: "test_name",
+ Result: true,
+ },
+ {
+ Input: "test_-name",
+ Result: true,
+ },
+ {
+ Input: "-",
+ Result: false,
+ },
+ {
+ Input: "__",
+ Result: false,
+ },
+ {
+ Input: "test-",
+ Result: false,
+ },
+ {
+ Input: "test--",
+ Result: false,
+ },
+ {
+ Input: "test__",
+ Result: false,
+ },
+ {
+ Input: "test:name",
+ Result: false,
+ },
+ }
+
+ for _, tc := range casesWithFormat {
+ actual := IsValidAlphaNumHyphenUnderscore(tc.Input, true)
+ if actual != tc.Result {
+ t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result)
+ }
+ }
+
+ casesWithoutFormat := []struct {
+ Input string
+ Result bool
+ }{
+ {
+ Input: "test",
+ Result: true,
+ },
+ {
+ Input: "test-name",
+ Result: true,
+ },
+ {
+ Input: "test--name",
+ Result: true,
+ },
+ {
+ Input: "test__name",
+ Result: true,
+ },
+ {
+ Input: "test_name",
+ Result: true,
+ },
+ {
+ Input: "test_-name",
+ Result: true,
+ },
+ {
+ Input: "-",
+ Result: true,
+ },
+ {
+ Input: "_",
+ Result: true,
+ },
+ {
+ Input: "test-",
+ Result: true,
+ },
+ {
+ Input: "test--",
+ Result: true,
+ },
+ {
+ Input: "test__",
+ Result: true,
+ },
+ {
+ Input: ".",
+ Result: false,
+ },
+
+ {
+ Input: "test,",
+ Result: false,
+ },
+ {
+ Input: "test:name",
+ Result: false,
+ },
+ }
+
+ for _, tc := range casesWithoutFormat {
+ actual := IsValidAlphaNumHyphenUnderscore(tc.Input, false)
+ if actual != tc.Result {
+ t.Fatalf("case: '%v'\tshould returned: %#v", tc.Input, tc.Result)
+ }
+ }
+}