gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

favouritesget_test.go (2615B)


      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 favourites_test
     19 
     20 import (
     21 	"encoding/json"
     22 	"fmt"
     23 	"io/ioutil"
     24 	"net/http"
     25 	"net/http/httptest"
     26 	"testing"
     27 
     28 	"github.com/stretchr/testify/assert"
     29 	"github.com/stretchr/testify/suite"
     30 	"github.com/superseriousbusiness/gotosocial/internal/api/client/favourites"
     31 	"github.com/superseriousbusiness/gotosocial/internal/api/model"
     32 	"github.com/superseriousbusiness/gotosocial/internal/oauth"
     33 	"github.com/superseriousbusiness/gotosocial/testrig"
     34 )
     35 
     36 type FavouritesTestSuite struct {
     37 	FavouritesStandardTestSuite
     38 }
     39 
     40 func (suite *FavouritesTestSuite) TestGetFavourites() {
     41 	t := suite.testTokens["local_account_1"]
     42 	oauthToken := oauth.DBTokenToToken(t)
     43 
     44 	// setup
     45 	recorder := httptest.NewRecorder()
     46 	ctx, _ := testrig.CreateGinTestContext(recorder, nil)
     47 	ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_2"])
     48 	ctx.Set(oauth.SessionAuthorizedToken, oauthToken)
     49 	ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
     50 	ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
     51 	ctx.Request = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost:8080%s?limit=80", favourites.BasePath), nil)
     52 	ctx.Request.Header.Set("accept", "application/json")
     53 
     54 	suite.favModule.FavouritesGETHandler(ctx)
     55 
     56 	// check response
     57 	suite.EqualValues(http.StatusOK, recorder.Code)
     58 
     59 	result := recorder.Result()
     60 	defer result.Body.Close()
     61 	b, err := ioutil.ReadAll(result.Body)
     62 	assert.NoError(suite.T(), err)
     63 
     64 	favs := []model.Status{}
     65 	err = json.Unmarshal(b, &favs)
     66 
     67 	assert.NoError(suite.T(), err)
     68 
     69 	assert.Len(suite.T(), favs, 4)
     70 	assert.Equal(suite.T(), "01F8MHCP5P2NWYQ416SBA0XSEV", favs[0].ID)
     71 	assert.Equal(suite.T(), "01F8MH75CBF9JFX4ZAD54N0W0R", favs[len(favs)-1].ID)
     72 }
     73 
     74 func TestStatusGetTestSuite(t *testing.T) {
     75 	suite.Run(t, new(FavouritesTestSuite))
     76 }