| 
									
										
										
										
											2023-03-12 16:00:57 +01:00
										 |  |  | // GoToSocial | 
					
						
							|  |  |  | // Copyright (C) GoToSocial Authors admin@gotosocial.org | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | // (at your option) any later version. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | // GNU Affero General Public License for more details. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  | // along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | package search_test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 	"crypto/rand" | 
					
						
							|  |  |  | 	"crypto/rsa" | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	"io" | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	"net/http" | 
					
						
							|  |  |  | 	"net/http/httptest" | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	"net/url" | 
					
						
							|  |  |  | 	"strconv" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-26 15:34:10 +02:00
										 |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/api/client/search" | 
					
						
							|  |  |  | 	apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model" | 
					
						
							|  |  |  | 	apiutil "code.superseriousbusiness.org/gotosocial/internal/api/util" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/config" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/gtserror" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/gtsmodel" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/id" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/oauth" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/testrig" | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	"github.com/stretchr/testify/suite" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type SearchGetTestSuite struct { | 
					
						
							|  |  |  | 	SearchStandardTestSuite | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) getSearch( | 
					
						
							|  |  |  | 	requestingAccount *gtsmodel.Account, | 
					
						
							|  |  |  | 	token *gtsmodel.Token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 	apiVersion string, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	user *gtsmodel.User, | 
					
						
							|  |  |  | 	maxID *string, | 
					
						
							|  |  |  | 	minID *string, | 
					
						
							|  |  |  | 	limit *int, | 
					
						
							|  |  |  | 	offset *int, | 
					
						
							|  |  |  | 	query string, | 
					
						
							|  |  |  | 	queryType *string, | 
					
						
							|  |  |  | 	resolve *bool, | 
					
						
							|  |  |  | 	following *bool, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 	fromAccountID *string, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	expectedHTTPStatus int, | 
					
						
							|  |  |  | 	expectedBody string, | 
					
						
							|  |  |  | ) (*apimodel.SearchResult, error) { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		recorder   = httptest.NewRecorder() | 
					
						
							|  |  |  | 		ctx, _     = testrig.CreateGinTestContext(recorder, nil) | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		requestURL = testrig.URLMustParse("/api" + search.BasePath) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		queryParts []string | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Put the request together. | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 	ctx.AddParam(apiutil.APIVersionKey, apiVersion) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	if maxID != nil { | 
					
						
							|  |  |  | 		queryParts = append(queryParts, apiutil.MaxIDKey+"="+url.QueryEscape(*maxID)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if minID != nil { | 
					
						
							|  |  |  | 		queryParts = append(queryParts, apiutil.MinIDKey+"="+url.QueryEscape(*minID)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if limit != nil { | 
					
						
							|  |  |  | 		queryParts = append(queryParts, apiutil.LimitKey+"="+strconv.Itoa(*limit)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if offset != nil { | 
					
						
							|  |  |  | 		queryParts = append(queryParts, apiutil.SearchOffsetKey+"="+strconv.Itoa(*offset)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	queryParts = append(queryParts, apiutil.SearchQueryKey+"="+url.QueryEscape(query)) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	if queryType != nil { | 
					
						
							|  |  |  | 		queryParts = append(queryParts, apiutil.SearchTypeKey+"="+url.QueryEscape(*queryType)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if resolve != nil { | 
					
						
							|  |  |  | 		queryParts = append(queryParts, apiutil.SearchResolveKey+"="+strconv.FormatBool(*resolve)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if following != nil { | 
					
						
							|  |  |  | 		queryParts = append(queryParts, apiutil.SearchFollowingKey+"="+strconv.FormatBool(*following)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 	if fromAccountID != nil { | 
					
						
							| 
									
										
										
										
											2024-06-18 18:18:00 +02:00
										 |  |  | 		queryParts = append(queryParts, apiutil.AccountIDKey+"="+url.QueryEscape(*fromAccountID)) | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	requestURL.RawQuery = strings.Join(queryParts, "&") | 
					
						
							|  |  |  | 	ctx.Request = httptest.NewRequest(http.MethodGet, requestURL.String(), nil) | 
					
						
							|  |  |  | 	ctx.Set(oauth.SessionAuthorizedAccount, requestingAccount) | 
					
						
							|  |  |  | 	ctx.Set(oauth.SessionAuthorizedToken, oauth.DBTokenToToken(token)) | 
					
						
							|  |  |  | 	ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"]) | 
					
						
							|  |  |  | 	ctx.Set(oauth.SessionAuthorizedUser, user) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	// Trigger the function being tested. | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	suite.searchModule.SearchGETHandler(ctx) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	// Read the result. | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	result := recorder.Result() | 
					
						
							|  |  |  | 	defer result.Body.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	b, err := io.ReadAll(result.Body) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 17:21:46 +02:00
										 |  |  | 	errs := gtserror.NewMultiError(2) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Check expected code + body. | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if resultCode := recorder.Code; expectedHTTPStatus != resultCode { | 
					
						
							| 
									
										
										
										
											2023-08-02 17:21:46 +02:00
										 |  |  | 		errs.Appendf("expected %d got %d", expectedHTTPStatus, resultCode) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	// If we got an expected body, return early. | 
					
						
							|  |  |  | 	if expectedBody != "" && string(b) != expectedBody { | 
					
						
							| 
									
										
										
										
											2023-08-02 17:21:46 +02:00
										 |  |  | 		errs.Appendf("expected %s got %s", expectedBody, string(b)) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := errs.Combine(); err != nil { | 
					
						
							|  |  |  | 		suite.FailNow("", "%v (body %s)", err, string(b)) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult := &apimodel.SearchResult{} | 
					
						
							|  |  |  | 	if err := json.Unmarshal(b, searchResult); err != nil { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		suite.FailNow(err.Error()) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return searchResult, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) bodgeLocalInstance(domain string) { | 
					
						
							|  |  |  | 	// Set new host. | 
					
						
							|  |  |  | 	config.SetHost(domain) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	// Copy instance account to not mess up other tests. | 
					
						
							|  |  |  | 	instanceAccount := >smodel.Account{} | 
					
						
							|  |  |  | 	*instanceAccount = *suite.testAccounts["instance_account"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Set username of instance account to given domain. | 
					
						
							|  |  |  | 	instanceAccount.Username = domain | 
					
						
							|  |  |  | 	if err := suite.db.UpdateAccount(context.Background(), instanceAccount, "username"); err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchRemoteAccountByURI() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "https://unknown-instance.com/users/brand_new_person" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestring() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "@brand_new_person@unknown-instance.com" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-30 17:44:02 +01:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestringUppercase() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "@Some_User@example.org" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-30 17:44:02 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestringNoLeadingAt() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "brand_new_person@unknown-instance.com" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestringNoResolve() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "@brand_new_person@unknown-instance.com" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-07 19:53:21 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestringSpecialChars() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "@üser@ëxample.org" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2023-05-07 19:53:21 +02:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if l := len(searchResult.Accounts); l != 1 { | 
					
						
							|  |  |  | 		suite.FailNow("", "expected %d accounts, got %d", 1, l) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	suite.Equal("üser@ëxample.org", searchResult.Accounts[0].Acct) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestringSpecialCharsPunycode() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "@üser@xn--xample-ova.org" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2023-05-07 19:53:21 +02:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if l := len(searchResult.Accounts); l != 1 { | 
					
						
							|  |  |  | 		suite.FailNow("", "expected %d accounts, got %d", 1, l) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	suite.Equal("üser@ëxample.org", searchResult.Accounts[0].Acct) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchLocalAccountByNamestring() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "@the_mighty_zork" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchLocalAccountByNamestringWithDomain() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "@the_mighty_zork@localhost:8080" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchNonexistingLocalAccountByNamestringResolveTrue() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "@somone_made_up@localhost:8080" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchLocalAccountByURI() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "http://localhost:8080/users/the_mighty_zork" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-09 17:05:35 +02:00
										 |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchLocalAccountByURL() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "http://localhost:8080/@the_mighty_zork" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2023-05-09 17:05:35 +02:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchNonexistingLocalAccountByURL() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "http://localhost:8080/@the_shmighty_shmork" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchStatusByURL() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "https://turnip.farm/users/turniplover6969/statuses/70c53e54-3146-42d5-a630-83c8b6c7c042" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "statuses"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	if !suite.Len(searchResult.Statuses, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 status in search results but got 0") | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	gotStatus := searchResult.Statuses[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotStatus) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchBlockedDomainURL() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "https://replyguys.com/@someone" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchBlockedDomainNamestring() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "@someone@replyguys.com" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchAAny() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "a" | 
					
						
							|  |  |  | 		queryType          *string = nil // Return anything. | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-26 16:59:39 +01:00
										 |  |  | 	suite.Len(searchResult.Accounts, 6) | 
					
						
							| 
									
										
										
										
											2025-03-07 15:04:34 +01:00
										 |  |  | 	suite.Len(searchResult.Statuses, 9) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchAAnyFollowingOnly() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "a" | 
					
						
							|  |  |  | 		queryType          *string = nil // Return anything. | 
					
						
							|  |  |  | 		following          *bool   = func() *bool { i := true; return &i }() | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Accounts, 2) | 
					
						
							| 
									
										
										
										
											2025-03-07 15:04:34 +01:00
										 |  |  | 	suite.Len(searchResult.Statuses, 9) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchAStatuses() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "a" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "statuses"; return &i }() // Only statuses. | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							| 
									
										
										
										
											2025-03-07 15:04:34 +01:00
										 |  |  | 	suite.Len(searchResult.Statuses, 9) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchHiStatusesWithAccountIDInQueryParam() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "hi" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "statuses"; return &i }() // Only statuses. | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							|  |  |  | 		fromAccountID      *string = func() *string { i := suite.testAccounts["local_account_2"].ID; return &i }() | 
					
						
							|  |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							|  |  |  | 		fromAccountID, | 
					
						
							|  |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 1) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchHiStatusesWithAccountIDInQueryText() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "hi from:1happyturtle" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "statuses"; return &i }() // Only statuses. | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							|  |  |  | 		fromAccountID      *string = nil | 
					
						
							|  |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							|  |  |  | 		fromAccountID, | 
					
						
							|  |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 1) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchAAccounts() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "a" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() // Only accounts. | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-02-14 11:55:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-26 16:59:39 +01:00
										 |  |  | 	suite.Len(searchResult.Accounts, 6) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchAccountsLimit1() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = func() *int { i := 1; return &i }() | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "a" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() // Only accounts. | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 1) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchLocalInstanceAccountByURI() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "http://localhost:8080/users/localhost:8080" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2023-02-14 11:55:02 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 	// Should be able to get instance | 
					
						
							|  |  |  | 	// account by exact URI. | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 1) | 
					
						
							| 
									
										
										
										
											2023-02-14 11:55:02 +01:00
										 |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchLocalInstanceAccountFull() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	// Namestring excludes ':' in usernames, so we | 
					
						
							|  |  |  | 	// need to fiddle with the instance account a | 
					
						
							|  |  |  | 	// bit to get it to look like a different domain. | 
					
						
							|  |  |  | 	newDomain := "example.org" | 
					
						
							|  |  |  | 	suite.bodgeLocalInstance(newDomain) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "@" + newDomain + "@" + newDomain | 
					
						
							|  |  |  | 		queryType          *string = nil | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-02-14 11:55:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 	// Should be able to get instance | 
					
						
							|  |  |  | 	// account by full namestring. | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 1) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchLocalInstanceAccountPartial() { | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	// Namestring excludes ':' in usernames, so we | 
					
						
							|  |  |  | 	// need to fiddle with the instance account a | 
					
						
							|  |  |  | 	// bit to get it to look like a different domain. | 
					
						
							|  |  |  | 	newDomain := "example.org" | 
					
						
							|  |  |  | 	suite.bodgeLocalInstance(newDomain) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "@" + newDomain | 
					
						
							|  |  |  | 		queryType          *string = nil | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							| 
									
										
										
										
											2023-02-14 11:55:02 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 	// Query was a partial namestring from our | 
					
						
							| 
									
										
										
										
											2023-10-30 19:01:00 +01:00
										 |  |  | 	// instance, instance account should be | 
					
						
							|  |  |  | 	// excluded from results. | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchLocalInstanceAccountEvenMorePartial() { | 
					
						
							|  |  |  | 	// Namestring excludes ':' in usernames, so we | 
					
						
							|  |  |  | 	// need to fiddle with the instance account a | 
					
						
							|  |  |  | 	// bit to get it to look like a different domain. | 
					
						
							|  |  |  | 	newDomain := "example.org" | 
					
						
							|  |  |  | 	suite.bodgeLocalInstance(newDomain) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = newDomain | 
					
						
							|  |  |  | 		queryType          *string = nil | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Query was just 'example.org' which doesn't | 
					
						
							|  |  |  | 	// look like a namestring, so search should | 
					
						
							|  |  |  | 	// fall back to text search and therefore give | 
					
						
							|  |  |  | 	// 0 results back. | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchRemoteInstanceAccountPartial() { | 
					
						
							|  |  |  | 	// Insert an instance account that's not | 
					
						
							|  |  |  | 	// from our instance, and try to search | 
					
						
							|  |  |  | 	// for it with a partial namestring. | 
					
						
							|  |  |  | 	theirDomain := "example.org" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	key, err := rsa.GenerateKey(rand.Reader, 2048) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := suite.db.PutAccount(context.Background(), >smodel.Account{ | 
					
						
							|  |  |  | 		ID:                    "01H6RWPG8T6DNW6VNXPBCJBH5S", | 
					
						
							|  |  |  | 		Username:              theirDomain, | 
					
						
							|  |  |  | 		Domain:                theirDomain, | 
					
						
							|  |  |  | 		URI:                   "http://" + theirDomain + "/users/" + theirDomain, | 
					
						
							|  |  |  | 		URL:                   "http://" + theirDomain + "/@" + theirDomain, | 
					
						
							|  |  |  | 		PublicKeyURI:          "http://" + theirDomain + "/users/" + theirDomain + "#main-key", | 
					
						
							|  |  |  | 		InboxURI:              "http://" + theirDomain + "/users/" + theirDomain + "/inbox", | 
					
						
							|  |  |  | 		OutboxURI:             "http://" + theirDomain + "/users/" + theirDomain + "/outbox", | 
					
						
							|  |  |  | 		FollowersURI:          "http://" + theirDomain + "/users/" + theirDomain + "/followers", | 
					
						
							|  |  |  | 		FollowingURI:          "http://" + theirDomain + "/users/" + theirDomain + "/following", | 
					
						
							|  |  |  | 		FeaturedCollectionURI: "http://" + theirDomain + "/users/" + theirDomain + "/collections/featured", | 
					
						
							| 
									
										
										
										
											2025-04-06 14:39:40 +02:00
										 |  |  | 		ActorType:             gtsmodel.AccountActorTypePerson, | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 		PrivateKey:            key, | 
					
						
							|  |  |  | 		PublicKey:             &key.PublicKey, | 
					
						
							|  |  |  | 	}); err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "@" + theirDomain | 
					
						
							|  |  |  | 		queryType          *string = nil | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-08-02 09:31:09 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Search for instance account from | 
					
						
							|  |  |  | 	// another domain should return 0 results. | 
					
						
							| 
									
										
										
										
											2023-02-14 11:55:02 +01:00
										 |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchBadQueryType() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "whatever" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "aaaaaaaaaaa"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusBadRequest | 
					
						
							|  |  |  | 		expectedBody               = `{"error":"Bad Request: search query type aaaaaaaaaaa was not recognized, valid options are ['', 'accounts', 'statuses', 'hashtags']"}` | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchEmptyQuery() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "aaaaaaaaaaa"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusBadRequest | 
					
						
							|  |  |  | 		expectedBody               = `{"error":"Bad Request: required key q was not set or had empty value"}` | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchHashtagV1() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "#welcome" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "hashtags"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = `{"accounts":[],"statuses":[],"hashtags":[{"name":"welcome","url":"http://localhost:8080/tags/welcome","history":[]}]}` | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 1) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchHashtagV2() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "#welcome" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "hashtags"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = `{"accounts":[],"statuses":[],"hashtags":["welcome"]}` | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv1, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 1) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchHashtagButWithAccountSearch() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "#welcome" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = `` | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 0) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchNotHashtagButWithTypeHashtag() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = nil | 
					
						
							|  |  |  | 		query                      = "welco" | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "hashtags"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = `` | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-07-31 15:47:35 +02:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.Len(searchResult.Accounts, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Statuses, 0) | 
					
						
							|  |  |  | 	suite.Len(searchResult.Hashtags, 1) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 19:01:00 +01:00
										 |  |  | func (suite *SearchGetTestSuite) TestSearchBlockedAccountFullNamestring() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		targetAccount              = suite.testAccounts["remote_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "@" + targetAccount.Username + "@" + targetAccount.Domain | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-10-30 19:01:00 +01:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Block the account | 
					
						
							|  |  |  | 	// we're about to search. | 
					
						
							|  |  |  | 	if err := suite.db.PutBlock( | 
					
						
							|  |  |  | 		context.Background(), | 
					
						
							|  |  |  | 		>smodel.Block{ | 
					
						
							|  |  |  | 			ID:              id.NewULID(), | 
					
						
							|  |  |  | 			URI:             "https://example.org/nooooooo", | 
					
						
							|  |  |  | 			AccountID:       requestingAccount.ID, | 
					
						
							|  |  |  | 			TargetAccountID: targetAccount.ID, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	); err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-10-30 19:01:00 +01:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Search was for full namestring; | 
					
						
							|  |  |  | 	// we should still be able to see | 
					
						
							|  |  |  | 	// the account we've blocked. | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchBlockedAccountPartialNamestring() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		targetAccount              = suite.testAccounts["remote_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = "@" + targetAccount.Username | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-10-30 19:01:00 +01:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Block the account | 
					
						
							|  |  |  | 	// we're about to search. | 
					
						
							|  |  |  | 	if err := suite.db.PutBlock( | 
					
						
							|  |  |  | 		context.Background(), | 
					
						
							|  |  |  | 		>smodel.Block{ | 
					
						
							|  |  |  | 			ID:              id.NewULID(), | 
					
						
							|  |  |  | 			URI:             "https://example.org/nooooooo", | 
					
						
							|  |  |  | 			AccountID:       requestingAccount.ID, | 
					
						
							|  |  |  | 			TargetAccountID: targetAccount.ID, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	); err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-10-30 19:01:00 +01:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Search was for partial namestring; | 
					
						
							|  |  |  | 	// we should not be able to see | 
					
						
							|  |  |  | 	// the account we've blocked. | 
					
						
							|  |  |  | 	if !suite.Empty(searchResult.Accounts) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 0 accounts in search results") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *SearchGetTestSuite) TestSearchBlockedAccountURI() { | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		requestingAccount          = suite.testAccounts["local_account_1"] | 
					
						
							|  |  |  | 		targetAccount              = suite.testAccounts["remote_account_1"] | 
					
						
							|  |  |  | 		token                      = suite.testTokens["local_account_1"] | 
					
						
							|  |  |  | 		user                       = suite.testUsers["local_account_1"] | 
					
						
							|  |  |  | 		maxID              *string = nil | 
					
						
							|  |  |  | 		minID              *string = nil | 
					
						
							|  |  |  | 		limit              *int    = nil | 
					
						
							|  |  |  | 		offset             *int    = nil | 
					
						
							|  |  |  | 		resolve            *bool   = func() *bool { i := true; return &i }() | 
					
						
							|  |  |  | 		query                      = targetAccount.URI | 
					
						
							|  |  |  | 		queryType          *string = func() *string { i := "accounts"; return &i }() | 
					
						
							|  |  |  | 		following          *bool   = nil | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID      *string = nil | 
					
						
							| 
									
										
										
										
											2023-10-30 19:01:00 +01:00
										 |  |  | 		expectedHTTPStatus         = http.StatusOK | 
					
						
							|  |  |  | 		expectedBody               = "" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Block the account | 
					
						
							|  |  |  | 	// we're about to search. | 
					
						
							|  |  |  | 	if err := suite.db.PutBlock( | 
					
						
							|  |  |  | 		context.Background(), | 
					
						
							|  |  |  | 		>smodel.Block{ | 
					
						
							|  |  |  | 			ID:              id.NewULID(), | 
					
						
							|  |  |  | 			URI:             "https://example.org/nooooooo", | 
					
						
							|  |  |  | 			AccountID:       requestingAccount.ID, | 
					
						
							|  |  |  | 			TargetAccountID: targetAccount.ID, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	); err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	searchResult, err := suite.getSearch( | 
					
						
							|  |  |  | 		requestingAccount, | 
					
						
							|  |  |  | 		token, | 
					
						
							|  |  |  | 		apiutil.APIv2, | 
					
						
							|  |  |  | 		user, | 
					
						
							|  |  |  | 		maxID, | 
					
						
							|  |  |  | 		minID, | 
					
						
							|  |  |  | 		limit, | 
					
						
							|  |  |  | 		offset, | 
					
						
							|  |  |  | 		query, | 
					
						
							|  |  |  | 		queryType, | 
					
						
							|  |  |  | 		resolve, | 
					
						
							|  |  |  | 		following, | 
					
						
							| 
									
										
										
										
											2024-05-31 03:57:42 -07:00
										 |  |  | 		fromAccountID, | 
					
						
							| 
									
										
										
										
											2023-10-30 19:01:00 +01:00
										 |  |  | 		expectedHTTPStatus, | 
					
						
							|  |  |  | 		expectedBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Search was for precise URI; | 
					
						
							|  |  |  | 	// we should still be able to see | 
					
						
							|  |  |  | 	// the account we've blocked. | 
					
						
							|  |  |  | 	if !suite.Len(searchResult.Accounts, 1) { | 
					
						
							|  |  |  | 		suite.FailNow("expected 1 account in search results but got 0") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gotAccount := searchResult.Accounts[0] | 
					
						
							|  |  |  | 	suite.NotNil(gotAccount) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 10:24:55 +01:00
										 |  |  | func TestSearchGetTestSuite(t *testing.T) { | 
					
						
							|  |  |  | 	suite.Run(t, &SearchGetTestSuite{}) | 
					
						
							|  |  |  | } |