gtsocial-umbx

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

mention_test.go (3355B)


      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 validate_test
     19 
     20 import (
     21 	"testing"
     22 	"time"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     26 	"github.com/superseriousbusiness/gotosocial/internal/validate"
     27 )
     28 
     29 func happyMention() *gtsmodel.Mention {
     30 	return &gtsmodel.Mention{
     31 		ID:               "01FE91RJR88PSEEE30EV35QR8N",
     32 		CreatedAt:        time.Now(),
     33 		UpdatedAt:        time.Now(),
     34 		OriginAccountID:  "01FE96MAE58MXCE5C4SSMEMCEK",
     35 		OriginAccountURI: "https://some-instance/accounts/bleepbloop",
     36 		OriginAccount:    nil,
     37 		TargetAccountID:  "01FE96MXRHWZHKC0WH5FT82H1A",
     38 		TargetAccount:    nil,
     39 		StatusID:         "01FE96NBPNJNY26730FT6GZTFE",
     40 		Status:           nil,
     41 	}
     42 }
     43 
     44 type MentionValidateTestSuite struct {
     45 	suite.Suite
     46 }
     47 
     48 func (suite *MentionValidateTestSuite) TestValidateMentionHappyPath() {
     49 	// no problem here
     50 	m := happyMention()
     51 	err := validate.Struct(m)
     52 	suite.NoError(err)
     53 }
     54 
     55 func (suite *MentionValidateTestSuite) TestValidateMentionBadID() {
     56 	m := happyMention()
     57 
     58 	m.ID = ""
     59 	err := validate.Struct(m)
     60 	suite.EqualError(err, "Key: 'Mention.ID' Error:Field validation for 'ID' failed on the 'required' tag")
     61 
     62 	m.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB"
     63 	err = validate.Struct(m)
     64 	suite.EqualError(err, "Key: 'Mention.ID' Error:Field validation for 'ID' failed on the 'ulid' tag")
     65 }
     66 
     67 func (suite *MentionValidateTestSuite) TestValidateMentionAccountURI() {
     68 	m := happyMention()
     69 
     70 	m.OriginAccountURI = ""
     71 	err := validate.Struct(m)
     72 	suite.EqualError(err, "Key: 'Mention.OriginAccountURI' Error:Field validation for 'OriginAccountURI' failed on the 'url' tag")
     73 
     74 	m.OriginAccountURI = "---------------------------"
     75 	err = validate.Struct(m)
     76 	suite.EqualError(err, "Key: 'Mention.OriginAccountURI' Error:Field validation for 'OriginAccountURI' failed on the 'url' tag")
     77 }
     78 
     79 func (suite *MentionValidateTestSuite) TestValidateMentionDodgyStatusID() {
     80 	m := happyMention()
     81 
     82 	m.StatusID = "9HZJ76B6VXSKF"
     83 	err := validate.Struct(m)
     84 	suite.EqualError(err, "Key: 'Mention.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
     85 
     86 	m.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!"
     87 	err = validate.Struct(m)
     88 	suite.EqualError(err, "Key: 'Mention.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag")
     89 }
     90 
     91 func (suite *MentionValidateTestSuite) TestValidateMentionNoCreatedAt() {
     92 	m := happyMention()
     93 
     94 	m.CreatedAt = time.Time{}
     95 	err := validate.Struct(m)
     96 	suite.NoError(err)
     97 }
     98 
     99 func TestMentionValidateTestSuite(t *testing.T) {
    100 	suite.Run(t, new(MentionValidateTestSuite))
    101 }