gtsocial-umbx

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

statusunbookmark_test.go (2607B)


      1 /*
      2    GoToSocial
      3    Copyright (C) GoToSocial Authors admin@gotosocial.org
      4    This program is free software: you can redistribute it and/or modify
      5    it under the terms of the GNU Affero General Public License as published by
      6    the Free Software Foundation, either version 3 of the License, or
      7    (at your option) any later version.
      8    This program is distributed in the hope that it will be useful,
      9    but WITHOUT ANY WARRANTY; without even the implied warranty of
     10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11    GNU Affero General Public License for more details.
     12    You should have received a copy of the GNU Affero General Public License
     13    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     14 */
     15 
     16 package statuses_test
     17 
     18 import (
     19 	"encoding/json"
     20 	"fmt"
     21 	"io/ioutil"
     22 	"net/http"
     23 	"net/http/httptest"
     24 	"strings"
     25 	"testing"
     26 
     27 	"github.com/gin-gonic/gin"
     28 	"github.com/stretchr/testify/suite"
     29 	"github.com/superseriousbusiness/gotosocial/internal/api/client/statuses"
     30 	"github.com/superseriousbusiness/gotosocial/internal/api/model"
     31 	"github.com/superseriousbusiness/gotosocial/internal/oauth"
     32 	"github.com/superseriousbusiness/gotosocial/testrig"
     33 )
     34 
     35 type StatusUnbookmarkTestSuite struct {
     36 	StatusStandardTestSuite
     37 }
     38 
     39 func (suite *StatusUnbookmarkTestSuite) TestPostUnbookmark() {
     40 	t := suite.testTokens["local_account_1"]
     41 	oauthToken := oauth.DBTokenToToken(t)
     42 
     43 	targetStatus := suite.testStatuses["admin_account_status_1"]
     44 
     45 	// setup
     46 	recorder := httptest.NewRecorder()
     47 	ctx, _ := testrig.CreateGinTestContext(recorder, nil)
     48 	ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
     49 	ctx.Set(oauth.SessionAuthorizedToken, oauthToken)
     50 	ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
     51 	ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
     52 	ctx.Request = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost:8080%s", strings.Replace(statuses.UnbookmarkPath, ":id", targetStatus.ID, 1)), nil) // the endpoint we're hitting
     53 	ctx.Request.Header.Set("accept", "application/json")
     54 
     55 	ctx.Params = gin.Params{
     56 		gin.Param{
     57 			Key:   statuses.IDKey,
     58 			Value: targetStatus.ID,
     59 		},
     60 	}
     61 
     62 	suite.statusModule.StatusUnbookmarkPOSTHandler(ctx)
     63 
     64 	result := recorder.Result()
     65 	defer result.Body.Close()
     66 	b, err := ioutil.ReadAll(result.Body)
     67 	suite.NoError(err)
     68 
     69 	statusReply := &model.Status{}
     70 	err = json.Unmarshal(b, statusReply)
     71 	suite.NoError(err)
     72 
     73 	suite.False(statusReply.Bookmarked)
     74 }
     75 
     76 func TestStatusUnbookmarkTestSuite(t *testing.T) {
     77 	suite.Run(t, new(StatusUnbookmarkTestSuite))
     78 }