notification_test.go (2911B)
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 stream_test 19 20 import ( 21 "bytes" 22 "context" 23 "encoding/json" 24 "testing" 25 26 "github.com/stretchr/testify/suite" 27 apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" 28 "github.com/superseriousbusiness/gotosocial/testrig" 29 ) 30 31 type NotificationTestSuite struct { 32 StreamTestSuite 33 } 34 35 func (suite *NotificationTestSuite) TestStreamNotification() { 36 account := suite.testAccounts["local_account_1"] 37 38 openStream, errWithCode := suite.streamProcessor.Open(context.Background(), account, "user") 39 suite.NoError(errWithCode) 40 41 followAccount := suite.testAccounts["remote_account_1"] 42 followAccountAPIModel, err := testrig.NewTestTypeConverter(suite.db).AccountToAPIAccountPublic(context.Background(), followAccount) 43 suite.NoError(err) 44 45 notification := &apimodel.Notification{ 46 ID: "01FH57SJCMDWQGEAJ0X08CE3WV", 47 Type: "follow", 48 CreatedAt: "2021-10-04T08:52:36.000Z", 49 Account: followAccountAPIModel, 50 } 51 52 err = suite.streamProcessor.Notify(notification, account) 53 suite.NoError(err) 54 55 msg := <-openStream.Messages 56 dst := new(bytes.Buffer) 57 err = json.Indent(dst, []byte(msg.Payload), "", " ") 58 suite.NoError(err) 59 suite.Equal(`{ 60 "id": "01FH57SJCMDWQGEAJ0X08CE3WV", 61 "type": "follow", 62 "created_at": "2021-10-04T08:52:36.000Z", 63 "account": { 64 "id": "01F8MH5ZK5VRH73AKHQM6Y9VNX", 65 "username": "foss_satan", 66 "acct": "foss_satan@fossbros-anonymous.io", 67 "display_name": "big gerald", 68 "locked": false, 69 "discoverable": true, 70 "bot": false, 71 "created_at": "2021-09-26T10:52:36.000Z", 72 "note": "i post about like, i dunno, stuff, or whatever!!!!", 73 "url": "http://fossbros-anonymous.io/@foss_satan", 74 "avatar": "", 75 "avatar_static": "", 76 "header": "http://localhost:8080/assets/default_header.png", 77 "header_static": "http://localhost:8080/assets/default_header.png", 78 "followers_count": 0, 79 "following_count": 0, 80 "statuses_count": 1, 81 "last_status_at": "2021-09-20T10:40:37.000Z", 82 "emojis": [], 83 "fields": [] 84 } 85 }`, dst.String()) 86 } 87 88 func TestNotificationTestSuite(t *testing.T) { 89 suite.Run(t, &NotificationTestSuite{}) 90 }