accountverify_test.go (3699B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package accounts_test 19 20 import ( 21 "encoding/json" 22 "io/ioutil" 23 "net/http" 24 "net/http/httptest" 25 "testing" 26 "time" 27 28 "github.com/stretchr/testify/assert" 29 "github.com/stretchr/testify/suite" 30 "github.com/superseriousbusiness/gotosocial/internal/api/client/accounts" 31 apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" 32 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 33 ) 34 35 type AccountVerifyTestSuite struct { 36 AccountStandardTestSuite 37 } 38 39 func (suite *AccountVerifyTestSuite) TestAccountVerifyGet() { 40 testAccount := suite.testAccounts["local_account_1"] 41 42 // set up the request 43 recorder := httptest.NewRecorder() 44 ctx := suite.newContext(recorder, http.MethodGet, nil, accounts.VerifyPath, "") 45 46 // call the handler 47 suite.accountsModule.AccountVerifyGETHandler(ctx) 48 49 // 1. we should have OK because our request was valid 50 suite.Equal(http.StatusOK, recorder.Code) 51 52 // 2. we should have no error message in the result body 53 result := recorder.Result() 54 defer result.Body.Close() 55 56 // check the response 57 b, err := ioutil.ReadAll(result.Body) 58 assert.NoError(suite.T(), err) 59 60 // unmarshal the returned account 61 apimodelAccount := &apimodel.Account{} 62 err = json.Unmarshal(b, apimodelAccount) 63 suite.NoError(err) 64 65 createdAt, err := time.Parse(time.RFC3339, apimodelAccount.CreatedAt) 66 suite.NoError(err) 67 68 suite.Equal(testAccount.ID, apimodelAccount.ID) 69 suite.Equal(testAccount.Username, apimodelAccount.Username) 70 suite.Equal(testAccount.Username, apimodelAccount.Acct) 71 suite.Equal(testAccount.DisplayName, apimodelAccount.DisplayName) 72 suite.Equal(*testAccount.Locked, apimodelAccount.Locked) 73 suite.Equal(*testAccount.Bot, apimodelAccount.Bot) 74 suite.WithinDuration(testAccount.CreatedAt, createdAt, 30*time.Second) // we lose a bit of accuracy serializing so fuzz this a bit 75 suite.Equal(testAccount.URL, apimodelAccount.URL) 76 suite.Equal("http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg", apimodelAccount.Avatar) 77 suite.Equal("http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.jpg", apimodelAccount.AvatarStatic) 78 suite.Equal("http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg", apimodelAccount.Header) 79 suite.Equal("http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/small/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg", apimodelAccount.HeaderStatic) 80 suite.Equal(2, apimodelAccount.FollowersCount) 81 suite.Equal(2, apimodelAccount.FollowingCount) 82 suite.Equal(5, apimodelAccount.StatusesCount) 83 suite.EqualValues(gtsmodel.VisibilityPublic, apimodelAccount.Source.Privacy) 84 suite.Equal(testAccount.Language, apimodelAccount.Source.Language) 85 suite.Equal(testAccount.NoteRaw, apimodelAccount.Source.Note) 86 } 87 88 func TestAccountVerifyTestSuite(t *testing.T) { 89 suite.Run(t, new(AccountVerifyTestSuite)) 90 }