gtsocial-umbx

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

block_test.go (2415B)


      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 	"fmt"
     22 	"io/ioutil"
     23 	"net/http"
     24 	"net/http/httptest"
     25 	"strings"
     26 	"testing"
     27 
     28 	"github.com/gin-gonic/gin"
     29 	"github.com/stretchr/testify/assert"
     30 	"github.com/stretchr/testify/suite"
     31 	"github.com/superseriousbusiness/gotosocial/internal/api/client/accounts"
     32 	"github.com/superseriousbusiness/gotosocial/internal/oauth"
     33 	"github.com/superseriousbusiness/gotosocial/testrig"
     34 )
     35 
     36 type BlockTestSuite struct {
     37 	AccountStandardTestSuite
     38 }
     39 
     40 func (suite *BlockTestSuite) TestBlockSelf() {
     41 	testAcct := suite.testAccounts["local_account_1"]
     42 	recorder := httptest.NewRecorder()
     43 	ctx, _ := testrig.CreateGinTestContext(recorder, nil)
     44 	ctx.Set(oauth.SessionAuthorizedAccount, testAcct)
     45 	ctx.Set(oauth.SessionAuthorizedToken, oauth.DBTokenToToken(suite.testTokens["local_account_1"]))
     46 	ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
     47 	ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
     48 	ctx.Request = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost:8080%s", strings.Replace(accounts.BlockPath, ":id", testAcct.ID, 1)), nil)
     49 
     50 	ctx.Params = gin.Params{
     51 		gin.Param{
     52 			Key:   accounts.IDKey,
     53 			Value: testAcct.ID,
     54 		},
     55 	}
     56 
     57 	suite.accountsModule.AccountBlockPOSTHandler(ctx)
     58 
     59 	// 1. status should be Not Acceptable due to attempted self-block
     60 	suite.Equal(http.StatusNotAcceptable, recorder.Code)
     61 
     62 	result := recorder.Result()
     63 	defer result.Body.Close()
     64 
     65 	// check the response
     66 	b, err := ioutil.ReadAll(result.Body)
     67 	_ = b
     68 	assert.NoError(suite.T(), err)
     69 }
     70 
     71 func TestBlockTestSuite(t *testing.T) {
     72 	suite.Run(t, new(BlockTestSuite))
     73 }