2021-05-08 14:25:55 +02:00
/ *
GoToSocial
2023-01-05 12:43:00 +01:00
Copyright ( C ) 2021 - 2023 GoToSocial Authors admin @ gotosocial . org
2021-05-08 14:25:55 +02:00
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Affero General Public License for more details .
You should have received a copy of the GNU Affero General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
package typeutils_test
import (
2021-08-25 15:34:33 +02:00
"context"
2021-05-08 14:25:55 +02:00
"encoding/json"
2022-05-23 17:40:03 +02:00
"strings"
2021-05-08 14:25:55 +02:00
"testing"
"github.com/stretchr/testify/suite"
2021-11-13 17:29:43 +01:00
"github.com/superseriousbusiness/activity/streams"
2022-09-26 11:56:01 +02:00
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
2022-07-04 15:41:20 +02:00
"github.com/superseriousbusiness/gotosocial/testrig"
2021-05-08 14:25:55 +02:00
)
type InternalToASTestSuite struct {
2021-09-14 12:23:56 +02:00
TypeUtilsTestSuite
2021-05-08 14:25:55 +02:00
}
func ( suite * InternalToASTestSuite ) TestAccountToAS ( ) {
2022-09-26 11:56:01 +02:00
testAccount := & gtsmodel . Account { }
* testAccount = * suite . testAccounts [ "local_account_1" ] // take zork for this test
2021-05-08 14:25:55 +02:00
2021-08-25 15:34:33 +02:00
asPerson , err := suite . typeconverter . AccountToAS ( context . Background ( ) , testAccount )
2021-10-24 11:57:39 +02:00
suite . NoError ( err )
2021-05-08 14:25:55 +02:00
ser , err := streams . Serialize ( asPerson )
2021-10-24 11:57:39 +02:00
suite . NoError ( err )
2021-05-08 14:25:55 +02:00
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
2021-10-24 11:57:39 +02:00
suite . NoError ( err )
2021-05-08 14:25:55 +02:00
2022-05-23 17:40:03 +02:00
// trim off everything up to 'discoverable';
// this is necessary because the order of multiple 'context' entries is not determinate
trimmed := strings . Split ( string ( bytes ) , "\"discoverable\"" ) [ 1 ]
2023-01-13 17:02:45 +01:00
suite . Equal ( ` : true ,
"featured" : "http://localhost:8080/users/the_mighty_zork/collections/featured" ,
"followers" : "http://localhost:8080/users/the_mighty_zork/followers" ,
"following" : "http://localhost:8080/users/the_mighty_zork/following" ,
"icon" : {
"mediaType" : "image/jpeg" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg"
} ,
"id" : "http://localhost:8080/users/the_mighty_zork" ,
"image" : {
"mediaType" : "image/jpeg" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg"
} ,
"inbox" : "http://localhost:8080/users/the_mighty_zork/inbox" ,
"manuallyApprovesFollowers" : false ,
"name" : "original zork (he/they)" ,
"outbox" : "http://localhost:8080/users/the_mighty_zork/outbox" ,
"preferredUsername" : "the_mighty_zork" ,
"publicKey" : {
"id" : "http://localhost:8080/users/the_mighty_zork/main-key" ,
"owner" : "http://localhost:8080/users/the_mighty_zork" ,
"publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwXTcOAvM1Jiw5Ffpk0qn\nr0cwbNvFe/5zQ+Tp7tumK/ZnT37o7X0FUEXrxNi+dkhmeJ0gsaiN+JQGNUewvpSk\nPIAXKvi908aSfCGjs7bGlJCJCuDuL5d6m7hZnP9rt9fJc70GElPpG0jc9fXwlz7T\nlsPb2ecatmG05Y4jPwdC+oN4MNCv9yQzEvCVMzl76EJaM602kIHC1CISn0rDFmYd\n9rSN7XPlNJw1F6PbpJ/BWQ+pXHKw3OEwNTETAUNYiVGnZU+B7a7bZC9f6/aPbJuV\nt8Qmg+UnDvW1Y8gmfHnxaWG2f5TDBvCHmcYtucIZPLQD4trAozC4ryqlmCWQNKbt\n0wIDAQAB\n-----END PUBLIC KEY-----\n"
} ,
"summary" : "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e" ,
"tag" : [ ] ,
"type" : "Person" ,
"url" : "http://localhost:8080/@the_mighty_zork"
} ` , trimmed )
2022-09-26 11:56:01 +02:00
}
func ( suite * InternalToASTestSuite ) TestAccountToASWithEmoji ( ) {
testAccount := & gtsmodel . Account { }
* testAccount = * suite . testAccounts [ "local_account_1" ] // take zork for this test
testAccount . Emojis = [ ] * gtsmodel . Emoji { suite . testEmojis [ "rainbow" ] }
asPerson , err := suite . typeconverter . AccountToAS ( context . Background ( ) , testAccount )
suite . NoError ( err )
ser , err := streams . Serialize ( asPerson )
suite . NoError ( err )
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
2022-09-26 11:56:01 +02:00
suite . NoError ( err )
// trim off everything up to 'discoverable';
// this is necessary because the order of multiple 'context' entries is not determinate
trimmed := strings . Split ( string ( bytes ) , "\"discoverable\"" ) [ 1 ]
2023-01-13 17:02:45 +01:00
suite . Equal ( ` : true ,
"featured" : "http://localhost:8080/users/the_mighty_zork/collections/featured" ,
"followers" : "http://localhost:8080/users/the_mighty_zork/followers" ,
"following" : "http://localhost:8080/users/the_mighty_zork/following" ,
"icon" : {
"mediaType" : "image/jpeg" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg"
} ,
"id" : "http://localhost:8080/users/the_mighty_zork" ,
"image" : {
"mediaType" : "image/jpeg" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg"
} ,
"inbox" : "http://localhost:8080/users/the_mighty_zork/inbox" ,
"manuallyApprovesFollowers" : false ,
"name" : "original zork (he/they)" ,
"outbox" : "http://localhost:8080/users/the_mighty_zork/outbox" ,
"preferredUsername" : "the_mighty_zork" ,
"publicKey" : {
"id" : "http://localhost:8080/users/the_mighty_zork/main-key" ,
"owner" : "http://localhost:8080/users/the_mighty_zork" ,
"publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwXTcOAvM1Jiw5Ffpk0qn\nr0cwbNvFe/5zQ+Tp7tumK/ZnT37o7X0FUEXrxNi+dkhmeJ0gsaiN+JQGNUewvpSk\nPIAXKvi908aSfCGjs7bGlJCJCuDuL5d6m7hZnP9rt9fJc70GElPpG0jc9fXwlz7T\nlsPb2ecatmG05Y4jPwdC+oN4MNCv9yQzEvCVMzl76EJaM602kIHC1CISn0rDFmYd\n9rSN7XPlNJw1F6PbpJ/BWQ+pXHKw3OEwNTETAUNYiVGnZU+B7a7bZC9f6/aPbJuV\nt8Qmg+UnDvW1Y8gmfHnxaWG2f5TDBvCHmcYtucIZPLQD4trAozC4ryqlmCWQNKbt\n0wIDAQAB\n-----END PUBLIC KEY-----\n"
} ,
"summary" : "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e" ,
"tag" : {
"icon" : {
"mediaType" : "image/png" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png"
} ,
"id" : "http://localhost:8080/emoji/01F8MH9H8E4VG3KDYJR9EGPXCQ" ,
"name" : ":rainbow:" ,
"type" : "Emoji" ,
"updated" : "2021-09-20T12:40:37+02:00"
} ,
"type" : "Person" ,
"url" : "http://localhost:8080/@the_mighty_zork"
} ` , trimmed )
2022-09-23 21:27:35 +02:00
}
func ( suite * InternalToASTestSuite ) TestAccountToASWithSharedInbox ( ) {
2022-09-26 11:56:01 +02:00
testAccount := & gtsmodel . Account { }
* testAccount = * suite . testAccounts [ "local_account_1" ] // take zork for this test
2022-09-23 21:27:35 +02:00
sharedInbox := "http://localhost:8080/sharedInbox"
testAccount . SharedInboxURI = & sharedInbox
asPerson , err := suite . typeconverter . AccountToAS ( context . Background ( ) , testAccount )
suite . NoError ( err )
ser , err := streams . Serialize ( asPerson )
suite . NoError ( err )
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
2022-09-23 21:27:35 +02:00
suite . NoError ( err )
// trim off everything up to 'discoverable';
// this is necessary because the order of multiple 'context' entries is not determinate
trimmed := strings . Split ( string ( bytes ) , "\"discoverable\"" ) [ 1 ]
2023-01-13 17:02:45 +01:00
suite . Equal ( ` : true ,
"endpoints" : {
"sharedInbox" : "http://localhost:8080/sharedInbox"
} ,
"featured" : "http://localhost:8080/users/the_mighty_zork/collections/featured" ,
"followers" : "http://localhost:8080/users/the_mighty_zork/followers" ,
"following" : "http://localhost:8080/users/the_mighty_zork/following" ,
"icon" : {
"mediaType" : "image/jpeg" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg"
} ,
"id" : "http://localhost:8080/users/the_mighty_zork" ,
"image" : {
"mediaType" : "image/jpeg" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg"
} ,
"inbox" : "http://localhost:8080/users/the_mighty_zork/inbox" ,
"manuallyApprovesFollowers" : false ,
"name" : "original zork (he/they)" ,
"outbox" : "http://localhost:8080/users/the_mighty_zork/outbox" ,
"preferredUsername" : "the_mighty_zork" ,
"publicKey" : {
"id" : "http://localhost:8080/users/the_mighty_zork/main-key" ,
"owner" : "http://localhost:8080/users/the_mighty_zork" ,
"publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwXTcOAvM1Jiw5Ffpk0qn\nr0cwbNvFe/5zQ+Tp7tumK/ZnT37o7X0FUEXrxNi+dkhmeJ0gsaiN+JQGNUewvpSk\nPIAXKvi908aSfCGjs7bGlJCJCuDuL5d6m7hZnP9rt9fJc70GElPpG0jc9fXwlz7T\nlsPb2ecatmG05Y4jPwdC+oN4MNCv9yQzEvCVMzl76EJaM602kIHC1CISn0rDFmYd\n9rSN7XPlNJw1F6PbpJ/BWQ+pXHKw3OEwNTETAUNYiVGnZU+B7a7bZC9f6/aPbJuV\nt8Qmg+UnDvW1Y8gmfHnxaWG2f5TDBvCHmcYtucIZPLQD4trAozC4ryqlmCWQNKbt\n0wIDAQAB\n-----END PUBLIC KEY-----\n"
} ,
"summary" : "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e" ,
"tag" : [ ] ,
"type" : "Person" ,
"url" : "http://localhost:8080/@the_mighty_zork"
} ` , trimmed )
2021-05-08 14:25:55 +02:00
}
2021-10-24 11:57:39 +02:00
func ( suite * InternalToASTestSuite ) TestOutboxToASCollection ( ) {
testAccount := suite . testAccounts [ "admin_account" ]
ctx := context . Background ( )
collection , err := suite . typeconverter . OutboxToASCollection ( ctx , testAccount . OutboxURI )
suite . NoError ( err )
ser , err := streams . Serialize ( collection )
2022-07-04 15:41:20 +02:00
suite . NoError ( err )
2021-10-24 11:57:39 +02:00
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
2021-10-24 11:57:39 +02:00
suite . NoError ( err )
2023-01-13 17:02:45 +01:00
suite . Equal ( ` {
"@context" : "https://www.w3.org/ns/activitystreams" ,
"first" : "http://localhost:8080/users/admin/outbox?page=true" ,
"id" : "http://localhost:8080/users/admin/outbox" ,
"type" : "OrderedCollection"
} ` , string ( bytes ) )
2021-10-24 11:57:39 +02:00
}
2021-11-13 17:29:43 +01:00
func ( suite * InternalToASTestSuite ) TestStatusToAS ( ) {
testStatus := suite . testStatuses [ "local_account_1_status_1" ]
ctx := context . Background ( )
asStatus , err := suite . typeconverter . StatusToAS ( ctx , testStatus )
suite . NoError ( err )
ser , err := streams . Serialize ( asStatus )
2022-07-04 15:41:20 +02:00
suite . NoError ( err )
2021-11-13 17:29:43 +01:00
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
suite . NoError ( err )
suite . Equal ( ` {
"@context" : "https://www.w3.org/ns/activitystreams" ,
"attachment" : [ ] ,
"attributedTo" : "http://localhost:8080/users/the_mighty_zork" ,
"cc" : "http://localhost:8080/users/the_mighty_zork/followers" ,
"content" : "hello everyone!" ,
"id" : "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY" ,
"published" : "2021-10-20T12:40:37+02:00" ,
"replies" : {
"first" : {
"id" : "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies?page=true" ,
"next" : "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies?only_other_accounts=false\u0026page=true" ,
"partOf" : "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies" ,
"type" : "CollectionPage"
} ,
"id" : "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies" ,
"type" : "Collection"
} ,
"sensitive" : true ,
"summary" : "introduction post" ,
"tag" : [ ] ,
"to" : "https://www.w3.org/ns/activitystreams#Public" ,
"type" : "Note" ,
"url" : "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY"
} ` , string ( bytes ) )
2021-11-13 17:29:43 +01:00
}
2022-09-15 11:29:05 +02:00
func ( suite * InternalToASTestSuite ) TestStatusWithTagsToASWithIDs ( ) {
// use the status with just IDs of attachments and emojis pinned on it
testStatus := suite . testStatuses [ "admin_account_status_1" ]
2022-09-02 12:11:43 +02:00
ctx := context . Background ( )
asStatus , err := suite . typeconverter . StatusToAS ( ctx , testStatus )
suite . NoError ( err )
ser , err := streams . Serialize ( asStatus )
suite . NoError ( err )
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
2022-09-02 12:11:43 +02:00
suite . NoError ( err )
2022-09-02 17:00:11 +02:00
// we can't be sure in what order the two context entries --
// http://joinmastodon.org/ns, https://www.w3.org/ns/activitystreams --
// will appear, so trim them out of the string for consistency
trimmed := strings . SplitAfter ( string ( bytes ) , ` "attachment": ` ) [ 1 ]
2023-01-13 17:02:45 +01:00
suite . Equal ( ` {
"blurhash" : "LNJRdVM{00Rj%Mayt7j[4nWBofRj" ,
"mediaType" : "image/jpeg" ,
"name" : "Black and white image of some 50's style text saying: Welcome On Board" ,
"type" : "Document" ,
"url" : "http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/original/01F8MH6NEM8D7527KZAECTCR76.jpg"
} ,
"attributedTo" : "http://localhost:8080/users/admin" ,
"cc" : "http://localhost:8080/users/admin/followers" ,
"content" : "hello world! #welcome ! first post on the instance :rainbow: !" ,
"id" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R" ,
"published" : "2021-10-20T11:36:45Z" ,
"replies" : {
"first" : {
"id" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/replies?page=true" ,
"next" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/replies?only_other_accounts=false\u0026page=true" ,
"partOf" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/replies" ,
"type" : "CollectionPage"
} ,
"id" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/replies" ,
"type" : "Collection"
} ,
"sensitive" : false ,
"summary" : "" ,
"tag" : {
"icon" : {
"mediaType" : "image/png" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png"
} ,
"id" : "http://localhost:8080/emoji/01F8MH9H8E4VG3KDYJR9EGPXCQ" ,
"name" : ":rainbow:" ,
"type" : "Emoji" ,
"updated" : "2021-09-20T10:40:37Z"
} ,
"to" : "https://www.w3.org/ns/activitystreams#Public" ,
"type" : "Note" ,
"url" : "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R"
} ` , trimmed )
2022-09-02 12:11:43 +02:00
}
2022-09-15 11:29:05 +02:00
func ( suite * InternalToASTestSuite ) TestStatusWithTagsToASFromDB ( ) {
2021-11-22 12:48:46 +01:00
ctx := context . Background ( )
2022-09-15 11:29:05 +02:00
// get the entire status with all tags
testStatus , err := suite . db . GetStatusByID ( ctx , suite . testStatuses [ "admin_account_status_1" ] . ID )
2021-11-22 12:48:46 +01:00
suite . NoError ( err )
asStatus , err := suite . typeconverter . StatusToAS ( ctx , testStatus )
suite . NoError ( err )
ser , err := streams . Serialize ( asStatus )
2022-07-04 15:41:20 +02:00
suite . NoError ( err )
2021-11-22 12:48:46 +01:00
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
2021-11-22 12:48:46 +01:00
suite . NoError ( err )
2022-09-15 11:29:05 +02:00
// we can't be sure in what order the two context entries --
// http://joinmastodon.org/ns, https://www.w3.org/ns/activitystreams --
// will appear, so trim them out of the string for consistency
trimmed := strings . SplitAfter ( string ( bytes ) , ` "attachment": ` ) [ 1 ]
2023-01-13 17:02:45 +01:00
suite . Equal ( ` {
"blurhash" : "LNJRdVM{00Rj%Mayt7j[4nWBofRj" ,
"mediaType" : "image/jpeg" ,
"name" : "Black and white image of some 50's style text saying: Welcome On Board" ,
"type" : "Document" ,
"url" : "http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/original/01F8MH6NEM8D7527KZAECTCR76.jpg"
} ,
"attributedTo" : "http://localhost:8080/users/admin" ,
"cc" : "http://localhost:8080/users/admin/followers" ,
"content" : "hello world! #welcome ! first post on the instance :rainbow: !" ,
"id" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R" ,
"published" : "2021-10-20T11:36:45Z" ,
"replies" : {
"first" : {
"id" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/replies?page=true" ,
"next" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/replies?only_other_accounts=false\u0026page=true" ,
"partOf" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/replies" ,
"type" : "CollectionPage"
} ,
"id" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/replies" ,
"type" : "Collection"
} ,
"sensitive" : false ,
"summary" : "" ,
"tag" : {
"icon" : {
"mediaType" : "image/png" ,
"type" : "Image" ,
"url" : "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png"
} ,
"id" : "http://localhost:8080/emoji/01F8MH9H8E4VG3KDYJR9EGPXCQ" ,
"name" : ":rainbow:" ,
"type" : "Emoji" ,
"updated" : "2021-09-20T10:40:37Z"
} ,
"to" : "https://www.w3.org/ns/activitystreams#Public" ,
"type" : "Note" ,
"url" : "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R"
} ` , trimmed )
2021-11-22 12:48:46 +01:00
}
2022-09-15 11:29:05 +02:00
func ( suite * InternalToASTestSuite ) TestStatusToASWithMentions ( ) {
testStatusID := suite . testStatuses [ "admin_account_status_3" ] . ID
2021-11-13 17:29:43 +01:00
ctx := context . Background ( )
2022-09-15 11:29:05 +02:00
testStatus , err := suite . db . GetStatusByID ( ctx , testStatusID )
suite . NoError ( err )
2021-11-13 17:29:43 +01:00
asStatus , err := suite . typeconverter . StatusToAS ( ctx , testStatus )
suite . NoError ( err )
ser , err := streams . Serialize ( asStatus )
2022-07-04 15:41:20 +02:00
suite . NoError ( err )
2021-11-13 17:29:43 +01:00
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
suite . NoError ( err )
suite . Equal ( ` {
"@context" : "https://www.w3.org/ns/activitystreams" ,
"attachment" : [ ] ,
"attributedTo" : "http://localhost:8080/users/admin" ,
"cc" : [
"http://localhost:8080/users/admin/followers" ,
"http://localhost:8080/users/the_mighty_zork"
] ,
"content" : "hi @the_mighty_zork welcome to the instance!" ,
"id" : "http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0" ,
"inReplyTo" : "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY" ,
"published" : "2021-11-20T13:32:16Z" ,
"replies" : {
"first" : {
"id" : "http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0/replies?page=true" ,
"next" : "http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0/replies?only_other_accounts=false\u0026page=true" ,
"partOf" : "http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0/replies" ,
"type" : "CollectionPage"
} ,
"id" : "http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0/replies" ,
"type" : "Collection"
} ,
"sensitive" : false ,
"summary" : "" ,
"tag" : {
"href" : "http://localhost:8080/users/the_mighty_zork" ,
"name" : "@the_mighty_zork@localhost:8080" ,
"type" : "Mention"
} ,
"to" : "https://www.w3.org/ns/activitystreams#Public" ,
"type" : "Note" ,
"url" : "http://localhost:8080/@admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0"
} ` , string ( bytes ) )
2021-11-13 17:29:43 +01:00
}
2021-10-24 11:57:39 +02:00
func ( suite * InternalToASTestSuite ) TestStatusesToASOutboxPage ( ) {
testAccount := suite . testAccounts [ "admin_account" ]
ctx := context . Background ( )
// get public statuses from testaccount
2022-04-15 14:33:01 +02:00
statuses , err := suite . db . GetAccountStatuses ( ctx , testAccount . ID , 30 , true , true , "" , "" , false , false , true )
2021-10-24 11:57:39 +02:00
suite . NoError ( err )
page , err := suite . typeconverter . StatusesToASOutboxPage ( ctx , testAccount . OutboxURI , "" , "" , statuses )
suite . NoError ( err )
ser , err := streams . Serialize ( page )
2022-07-04 15:41:20 +02:00
suite . NoError ( err )
2021-10-24 11:57:39 +02:00
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
suite . NoError ( err )
suite . Equal ( ` {
"@context" : "https://www.w3.org/ns/activitystreams" ,
"id" : "http://localhost:8080/users/admin/outbox?page=true" ,
"next" : "http://localhost:8080/users/admin/outbox?page=true\u0026max_id=01F8MH75CBF9JFX4ZAD54N0W0R" ,
"orderedItems" : [
{
"actor" : "http://localhost:8080/users/admin" ,
"cc" : "http://localhost:8080/users/admin/followers" ,
"id" : "http://localhost:8080/users/admin/statuses/01F8MHAAY43M6RJ473VQFCVH37/activity" ,
"object" : "http://localhost:8080/users/admin/statuses/01F8MHAAY43M6RJ473VQFCVH37" ,
"published" : "2021-10-20T12:36:45Z" ,
"to" : "https://www.w3.org/ns/activitystreams#Public" ,
"type" : "Create"
} ,
{
"actor" : "http://localhost:8080/users/admin" ,
"cc" : "http://localhost:8080/users/admin/followers" ,
"id" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R/activity" ,
"object" : "http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R" ,
"published" : "2021-10-20T11:36:45Z" ,
"to" : "https://www.w3.org/ns/activitystreams#Public" ,
"type" : "Create"
}
] ,
"partOf" : "http://localhost:8080/users/admin/outbox" ,
"prev" : "http://localhost:8080/users/admin/outbox?page=true\u0026min_id=01F8MHAAY43M6RJ473VQFCVH37" ,
"type" : "OrderedCollectionPage"
} ` , string ( bytes ) )
2021-10-24 11:57:39 +02:00
}
2022-07-04 15:41:20 +02:00
func ( suite * InternalToASTestSuite ) TestSelfBoostFollowersOnlyToAS ( ) {
ctx := context . Background ( )
testStatus := suite . testStatuses [ "local_account_1_status_5" ]
testAccount := suite . testAccounts [ "local_account_1" ]
boostWrapperStatus , err := suite . typeconverter . StatusToBoost ( ctx , testStatus , testAccount )
suite . NoError ( err )
suite . NotNil ( boostWrapperStatus )
boostWrapperStatus . ID = "01G74JJ1KS331G2JXHRMZCE0ER"
boostWrapperStatus . URI = "http://localhost:8080/users/the_mighty_zork/statuses/01G74JJ1KS331G2JXHRMZCE0ER"
boostWrapperStatus . CreatedAt = testrig . TimeMustParse ( "2022-06-09T13:12:00Z" )
asBoost , err := suite . typeconverter . BoostToAS ( ctx , boostWrapperStatus , testAccount , testAccount )
suite . NoError ( err )
ser , err := streams . Serialize ( asBoost )
suite . NoError ( err )
2023-01-13 17:02:45 +01:00
bytes , err := json . MarshalIndent ( ser , "" , " " )
2022-07-04 15:41:20 +02:00
suite . NoError ( err )
2023-01-13 17:02:45 +01:00
suite . Equal ( ` {
"@context" : "https://www.w3.org/ns/activitystreams" ,
"actor" : "http://localhost:8080/users/the_mighty_zork" ,
"cc" : "http://localhost:8080/users/the_mighty_zork" ,
"id" : "http://localhost:8080/users/the_mighty_zork/statuses/01G74JJ1KS331G2JXHRMZCE0ER" ,
"object" : "http://localhost:8080/users/the_mighty_zork/statuses/01FCTA44PW9H1TB328S9AQXKDS" ,
"published" : "2022-06-09T13:12:00Z" ,
"to" : "http://localhost:8080/users/the_mighty_zork/followers" ,
"type" : "Announce"
} ` , string ( bytes ) )
2022-07-04 15:41:20 +02:00
}
2021-05-08 14:25:55 +02:00
func TestInternalToASTestSuite ( t * testing . T ) {
suite . Run ( t , new ( InternalToASTestSuite ) )
}