mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-28 22:52:47 +00:00
Regression tests for #3497 (v1 API)
This commit is contained in:
parent
8209564ec2
commit
c407b9b779
|
@ -41,6 +41,7 @@ func (suite *FiltersTestSuite) postFilter(
|
||||||
irreversible *bool,
|
irreversible *bool,
|
||||||
wholeWord *bool,
|
wholeWord *bool,
|
||||||
expiresIn *int,
|
expiresIn *int,
|
||||||
|
expiresInStr *string,
|
||||||
requestJson *string,
|
requestJson *string,
|
||||||
expectedHTTPStatus int,
|
expectedHTTPStatus int,
|
||||||
expectedBody string,
|
expectedBody string,
|
||||||
|
@ -75,6 +76,8 @@ func (suite *FiltersTestSuite) postFilter(
|
||||||
}
|
}
|
||||||
if expiresIn != nil {
|
if expiresIn != nil {
|
||||||
ctx.Request.Form["expires_in"] = []string{strconv.Itoa(*expiresIn)}
|
ctx.Request.Form["expires_in"] = []string{strconv.Itoa(*expiresIn)}
|
||||||
|
} else if expiresInStr != nil {
|
||||||
|
ctx.Request.Form["expires_in"] = []string{*expiresInStr}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +127,7 @@ func (suite *FiltersTestSuite) TestPostFilterFull() {
|
||||||
irreversible := false
|
irreversible := false
|
||||||
wholeWord := true
|
wholeWord := true
|
||||||
expiresIn := 86400
|
expiresIn := 86400
|
||||||
filter, err := suite.postFilter(&phrase, &context, &irreversible, &wholeWord, &expiresIn, nil, http.StatusOK, "")
|
filter, err := suite.postFilter(&phrase, &context, &irreversible, &wholeWord, &expiresIn, nil, nil, http.StatusOK, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -155,7 +158,7 @@ func (suite *FiltersTestSuite) TestPostFilterFullJSON() {
|
||||||
"whole_word": true,
|
"whole_word": true,
|
||||||
"expires_in": 86400.1
|
"expires_in": 86400.1
|
||||||
}`
|
}`
|
||||||
filter, err := suite.postFilter(nil, nil, nil, nil, nil, &requestJson, http.StatusOK, "")
|
filter, err := suite.postFilter(nil, nil, nil, nil, nil, nil, &requestJson, http.StatusOK, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -182,7 +185,7 @@ func (suite *FiltersTestSuite) TestPostFilterMinimal() {
|
||||||
|
|
||||||
phrase := "GNU/Linux"
|
phrase := "GNU/Linux"
|
||||||
context := []string{"home"}
|
context := []string{"home"}
|
||||||
filter, err := suite.postFilter(&phrase, &context, nil, nil, nil, nil, http.StatusOK, "")
|
filter, err := suite.postFilter(&phrase, &context, nil, nil, nil, nil, nil, http.StatusOK, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -203,7 +206,7 @@ func (suite *FiltersTestSuite) TestPostFilterMinimal() {
|
||||||
func (suite *FiltersTestSuite) TestPostFilterEmptyPhrase() {
|
func (suite *FiltersTestSuite) TestPostFilterEmptyPhrase() {
|
||||||
phrase := ""
|
phrase := ""
|
||||||
context := []string{"home"}
|
context := []string{"home"}
|
||||||
_, err := suite.postFilter(&phrase, &context, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.postFilter(&phrase, &context, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -211,7 +214,7 @@ func (suite *FiltersTestSuite) TestPostFilterEmptyPhrase() {
|
||||||
|
|
||||||
func (suite *FiltersTestSuite) TestPostFilterMissingPhrase() {
|
func (suite *FiltersTestSuite) TestPostFilterMissingPhrase() {
|
||||||
context := []string{"home"}
|
context := []string{"home"}
|
||||||
_, err := suite.postFilter(nil, &context, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.postFilter(nil, &context, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -220,7 +223,7 @@ func (suite *FiltersTestSuite) TestPostFilterMissingPhrase() {
|
||||||
func (suite *FiltersTestSuite) TestPostFilterEmptyContext() {
|
func (suite *FiltersTestSuite) TestPostFilterEmptyContext() {
|
||||||
phrase := "GNU/Linux"
|
phrase := "GNU/Linux"
|
||||||
context := []string{}
|
context := []string{}
|
||||||
_, err := suite.postFilter(&phrase, &context, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.postFilter(&phrase, &context, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -228,7 +231,7 @@ func (suite *FiltersTestSuite) TestPostFilterEmptyContext() {
|
||||||
|
|
||||||
func (suite *FiltersTestSuite) TestPostFilterMissingContext() {
|
func (suite *FiltersTestSuite) TestPostFilterMissingContext() {
|
||||||
phrase := "GNU/Linux"
|
phrase := "GNU/Linux"
|
||||||
_, err := suite.postFilter(&phrase, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.postFilter(&phrase, nil, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -237,8 +240,37 @@ func (suite *FiltersTestSuite) TestPostFilterMissingContext() {
|
||||||
// There should be a filter with this phrase as its title in our test fixtures. Creating another should fail.
|
// There should be a filter with this phrase as its title in our test fixtures. Creating another should fail.
|
||||||
func (suite *FiltersTestSuite) TestPostFilterTitleConflict() {
|
func (suite *FiltersTestSuite) TestPostFilterTitleConflict() {
|
||||||
phrase := "fnord"
|
phrase := "fnord"
|
||||||
_, err := suite.postFilter(&phrase, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.postFilter(&phrase, nil, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// postFilterWithExpiration creates a filter with optional expiration.
|
||||||
|
func (suite *FiltersTestSuite) postFilterWithExpiration(phrase *string, expiresIn *int, expiresInStr *string, requestJson *string) *apimodel.FilterV1 {
|
||||||
|
context := []string{"home"}
|
||||||
|
filter, err := suite.postFilter(phrase, &context, nil, nil, expiresIn, expiresInStr, requestJson, http.StatusOK, "")
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
return filter
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regression test for https://github.com/superseriousbusiness/gotosocial/issues/3497
|
||||||
|
func (suite *FiltersTestSuite) TestPostFilterWithEmptyStringExpiration() {
|
||||||
|
title := "Form Sins"
|
||||||
|
expiresInStr := ""
|
||||||
|
filter := suite.postFilterWithExpiration(&title, nil, &expiresInStr, nil)
|
||||||
|
suite.Nil(filter.ExpiresAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regression test related to https://github.com/superseriousbusiness/gotosocial/issues/3497
|
||||||
|
func (suite *FiltersTestSuite) TestPostFilterWithNullExpirationJSON() {
|
||||||
|
requestJson := `{
|
||||||
|
"phrase": "JSON Sins",
|
||||||
|
"context": ["home"],
|
||||||
|
"expires_in": null
|
||||||
|
}`
|
||||||
|
filter := suite.postFilterWithExpiration(nil, nil, nil, &requestJson)
|
||||||
|
suite.Nil(filter.ExpiresAt)
|
||||||
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ func (suite *FiltersTestSuite) putFilter(
|
||||||
irreversible *bool,
|
irreversible *bool,
|
||||||
wholeWord *bool,
|
wholeWord *bool,
|
||||||
expiresIn *int,
|
expiresIn *int,
|
||||||
|
expiresInStr *string,
|
||||||
requestJson *string,
|
requestJson *string,
|
||||||
expectedHTTPStatus int,
|
expectedHTTPStatus int,
|
||||||
expectedBody string,
|
expectedBody string,
|
||||||
|
@ -76,6 +77,8 @@ func (suite *FiltersTestSuite) putFilter(
|
||||||
}
|
}
|
||||||
if expiresIn != nil {
|
if expiresIn != nil {
|
||||||
ctx.Request.Form["expires_in"] = []string{strconv.Itoa(*expiresIn)}
|
ctx.Request.Form["expires_in"] = []string{strconv.Itoa(*expiresIn)}
|
||||||
|
} else if expiresInStr != nil {
|
||||||
|
ctx.Request.Form["expires_in"] = []string{*expiresInStr}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +131,7 @@ func (suite *FiltersTestSuite) TestPutFilterFull() {
|
||||||
irreversible := false
|
irreversible := false
|
||||||
wholeWord := true
|
wholeWord := true
|
||||||
expiresIn := 86400
|
expiresIn := 86400
|
||||||
filter, err := suite.putFilter(id, &phrase, &context, &irreversible, &wholeWord, &expiresIn, nil, http.StatusOK, "")
|
filter, err := suite.putFilter(id, &phrase, &context, &irreversible, &wholeWord, &expiresIn, nil, nil, http.StatusOK, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -160,7 +163,7 @@ func (suite *FiltersTestSuite) TestPutFilterFullJSON() {
|
||||||
"whole_word": true,
|
"whole_word": true,
|
||||||
"expires_in": 86400.1
|
"expires_in": 86400.1
|
||||||
}`
|
}`
|
||||||
filter, err := suite.putFilter(id, nil, nil, nil, nil, nil, &requestJson, http.StatusOK, "")
|
filter, err := suite.putFilter(id, nil, nil, nil, nil, nil, nil, &requestJson, http.StatusOK, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -188,7 +191,7 @@ func (suite *FiltersTestSuite) TestPutFilterMinimal() {
|
||||||
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
||||||
phrase := "GNU/Linux"
|
phrase := "GNU/Linux"
|
||||||
context := []string{"home"}
|
context := []string{"home"}
|
||||||
filter, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, http.StatusOK, "")
|
filter, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, nil, http.StatusOK, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -210,7 +213,7 @@ func (suite *FiltersTestSuite) TestPutFilterEmptyPhrase() {
|
||||||
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
||||||
phrase := ""
|
phrase := ""
|
||||||
context := []string{"home"}
|
context := []string{"home"}
|
||||||
_, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -219,7 +222,7 @@ func (suite *FiltersTestSuite) TestPutFilterEmptyPhrase() {
|
||||||
func (suite *FiltersTestSuite) TestPutFilterMissingPhrase() {
|
func (suite *FiltersTestSuite) TestPutFilterMissingPhrase() {
|
||||||
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
||||||
context := []string{"home"}
|
context := []string{"home"}
|
||||||
_, err := suite.putFilter(id, nil, &context, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.putFilter(id, nil, &context, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -229,7 +232,7 @@ func (suite *FiltersTestSuite) TestPutFilterEmptyContext() {
|
||||||
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
||||||
phrase := "GNU/Linux"
|
phrase := "GNU/Linux"
|
||||||
context := []string{}
|
context := []string{}
|
||||||
_, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -238,7 +241,7 @@ func (suite *FiltersTestSuite) TestPutFilterEmptyContext() {
|
||||||
func (suite *FiltersTestSuite) TestPutFilterMissingContext() {
|
func (suite *FiltersTestSuite) TestPutFilterMissingContext() {
|
||||||
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
||||||
phrase := "GNU/Linux"
|
phrase := "GNU/Linux"
|
||||||
_, err := suite.putFilter(id, &phrase, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.putFilter(id, &phrase, nil, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -248,7 +251,7 @@ func (suite *FiltersTestSuite) TestPutFilterMissingContext() {
|
||||||
func (suite *FiltersTestSuite) TestPutFilterTitleConflict() {
|
func (suite *FiltersTestSuite) TestPutFilterTitleConflict() {
|
||||||
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
id := suite.testFilterKeywords["local_account_1_filter_1_keyword_1"].ID
|
||||||
phrase := "metasyntactic variables"
|
phrase := "metasyntactic variables"
|
||||||
_, err := suite.putFilter(id, &phrase, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
_, err := suite.putFilter(id, &phrase, nil, nil, nil, nil, nil, nil, http.StatusUnprocessableEntity, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -258,7 +261,7 @@ func (suite *FiltersTestSuite) TestPutAnotherAccountsFilter() {
|
||||||
id := suite.testFilterKeywords["local_account_2_filter_1_keyword_1"].ID
|
id := suite.testFilterKeywords["local_account_2_filter_1_keyword_1"].ID
|
||||||
phrase := "GNU/Linux"
|
phrase := "GNU/Linux"
|
||||||
context := []string{"home"}
|
context := []string{"home"}
|
||||||
_, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, http.StatusNotFound, `{"error":"Not Found"}`)
|
_, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, nil, http.StatusNotFound, `{"error":"Not Found"}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -268,8 +271,53 @@ func (suite *FiltersTestSuite) TestPutNonexistentFilter() {
|
||||||
id := "not_even_a_real_ULID"
|
id := "not_even_a_real_ULID"
|
||||||
phrase := "GNU/Linux"
|
phrase := "GNU/Linux"
|
||||||
context := []string{"home"}
|
context := []string{"home"}
|
||||||
_, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, http.StatusNotFound, `{"error":"Not Found"}`)
|
_, err := suite.putFilter(id, &phrase, &context, nil, nil, nil, nil, nil, http.StatusNotFound, `{"error":"Not Found"}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setFilterExpiration sets filter expiration.
|
||||||
|
func (suite *FiltersTestSuite) setFilterExpiration(id string, expiresIn *int, expiresInStr *string, requestJson *string) *apimodel.FilterV1 {
|
||||||
|
filter, err := suite.putFilter(id, nil, nil, nil, nil, expiresIn, expiresInStr, requestJson, http.StatusOK, "")
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
return filter
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regression test for https://github.com/superseriousbusiness/gotosocial/issues/3497
|
||||||
|
func (suite *FiltersTestSuite) TestPutFilterUnsetExpirationDateEmptyString() {
|
||||||
|
id := suite.testFilters["local_account_1_filter_2"].ID
|
||||||
|
|
||||||
|
// Setup: set an expiration date for the filter.
|
||||||
|
expiresIn := 86400
|
||||||
|
filter := suite.setFilterExpiration(id, &expiresIn, nil, nil)
|
||||||
|
if !suite.NotNil(filter.ExpiresAt) {
|
||||||
|
suite.FailNow("Test precondition failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unset the filter's expiration date by setting it to an empty string.
|
||||||
|
expiresInStr := ""
|
||||||
|
filter = suite.setFilterExpiration(id, nil, &expiresInStr, nil)
|
||||||
|
suite.Nil(filter.ExpiresAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regression test related to https://github.com/superseriousbusiness/gotosocial/issues/3497
|
||||||
|
func (suite *FiltersTestSuite) TestPutFilterUnsetExpirationDateNullJSON() {
|
||||||
|
id := suite.testFilters["local_account_1_filter_3"].ID
|
||||||
|
|
||||||
|
// Setup: set an expiration date for the filter.
|
||||||
|
expiresIn := 86400
|
||||||
|
filter := suite.setFilterExpiration(id, &expiresIn, nil, nil)
|
||||||
|
if !suite.NotNil(filter.ExpiresAt) {
|
||||||
|
suite.FailNow("Test precondition failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unset the filter's expiration date by setting it to a null literal.
|
||||||
|
requestJson := `{
|
||||||
|
"expires_in": null
|
||||||
|
}`
|
||||||
|
filter = suite.setFilterExpiration(id, nil, nil, &requestJson)
|
||||||
|
suite.Nil(filter.ExpiresAt)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue