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
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
e62afeace0
Коммит
ecb10ed62f
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user