statusbookmark_test.go (2919B)
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 happyStatusBookmark() *gtsmodel.StatusBookmark { 30 return >smodel.StatusBookmark{ 31 ID: "01FE91RJR88PSEEE30EV35QR8N", 32 CreatedAt: time.Now(), 33 AccountID: "01FE96MAE58MXCE5C4SSMEMCEK", 34 Account: nil, 35 TargetAccountID: "01FE96MXRHWZHKC0WH5FT82H1A", 36 TargetAccount: nil, 37 StatusID: "01FE96NBPNJNY26730FT6GZTFE", 38 Status: nil, 39 } 40 } 41 42 type StatusBookmarkValidateTestSuite struct { 43 suite.Suite 44 } 45 46 func (suite *StatusBookmarkValidateTestSuite) TestValidateStatusBookmarkHappyPath() { 47 // no problem here 48 s := happyStatusBookmark() 49 err := validate.Struct(s) 50 suite.NoError(err) 51 } 52 53 func (suite *StatusBookmarkValidateTestSuite) TestValidateStatusBookmarkBadID() { 54 s := happyStatusBookmark() 55 56 s.ID = "" 57 err := validate.Struct(s) 58 suite.EqualError(err, "Key: 'StatusBookmark.ID' Error:Field validation for 'ID' failed on the 'required' tag") 59 60 s.ID = "01FE96W293ZPRG9FQQP48HK8N001FE96W32AT24VYBGM12WN3GKB" 61 err = validate.Struct(s) 62 suite.EqualError(err, "Key: 'StatusBookmark.ID' Error:Field validation for 'ID' failed on the 'ulid' tag") 63 } 64 65 func (suite *StatusBookmarkValidateTestSuite) TestValidateStatusBookmarkDodgyStatusID() { 66 s := happyStatusBookmark() 67 68 s.StatusID = "9HZJ76B6VXSKF" 69 err := validate.Struct(s) 70 suite.EqualError(err, "Key: 'StatusBookmark.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag") 71 72 s.StatusID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!" 73 err = validate.Struct(s) 74 suite.EqualError(err, "Key: 'StatusBookmark.StatusID' Error:Field validation for 'StatusID' failed on the 'ulid' tag") 75 } 76 77 func (suite *StatusBookmarkValidateTestSuite) TestValidateStatusBookmarkNoCreatedAt() { 78 s := happyStatusBookmark() 79 80 s.CreatedAt = time.Time{} 81 err := validate.Struct(s) 82 suite.NoError(err) 83 } 84 85 func TestStatusBookmarkValidateTestSuite(t *testing.T) { 86 suite.Run(t, new(StatusBookmarkValidateTestSuite)) 87 }