| 
									
										
										
										
											2023-03-12 16:00:57 +01:00
										 |  |  | // GoToSocial | 
					
						
							|  |  |  | // Copyright (C) GoToSocial Authors admin@gotosocial.org | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // 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/>. | 
					
						
							| 
									
										
										
										
											2022-10-08 14:00:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | package account_test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/stretchr/testify/suite" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type GetRSSTestSuite struct { | 
					
						
							|  |  |  | 	AccountStandardTestSuite | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *GetRSSTestSuite) TestGetAccountRSSAdmin() { | 
					
						
							|  |  |  | 	getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(context.Background(), "admin") | 
					
						
							|  |  |  | 	suite.NoError(err) | 
					
						
							| 
									
										
										
										
											2024-04-16 13:10:13 +02:00
										 |  |  | 	suite.EqualValues(1634726497, lastModified.Unix()) | 
					
						
							| 
									
										
										
										
											2022-10-08 14:00:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	feed, err := getFeed() | 
					
						
							|  |  |  | 	suite.NoError(err) | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  | 	suite.Equal(`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> | 
					
						
							|  |  |  |   <channel> | 
					
						
							|  |  |  |     <title>Posts from @admin@localhost:8080</title> | 
					
						
							|  |  |  |     <link>http://localhost:8080/@admin</link> | 
					
						
							|  |  |  |     <description>Posts from @admin@localhost:8080</description> | 
					
						
							|  |  |  |     <pubDate>Wed, 20 Oct 2021 10:41:37 +0000</pubDate> | 
					
						
							|  |  |  |     <lastBuildDate>Wed, 20 Oct 2021 10:41:37 +0000</lastBuildDate> | 
					
						
							|  |  |  |     <item> | 
					
						
							| 
									
										
										
										
											2025-03-07 15:04:34 +01:00
										 |  |  |       <title>open to see some <strong>puppies</strong></title> | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  |       <link>http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37</link> | 
					
						
							|  |  |  |       <description>@admin@localhost:8080 made a new post: "🐕🐕🐕🐕🐕"</description> | 
					
						
							| 
									
										
										
										
											2025-03-07 15:04:34 +01:00
										 |  |  |       <content:encoded><![CDATA[<p>🐕🐕🐕🐕🐕</p>]]></content:encoded> | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  |       <author>@admin@localhost:8080</author> | 
					
						
							|  |  |  |       <guid isPermaLink="true">http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37</guid> | 
					
						
							|  |  |  |       <pubDate>Wed, 20 Oct 2021 12:36:45 +0000</pubDate> | 
					
						
							|  |  |  |       <source>http://localhost:8080/@admin/feed.rss</source> | 
					
						
							|  |  |  |     </item> | 
					
						
							|  |  |  |     <item> | 
					
						
							|  |  |  |       <title>hello world! #welcome ! first post on the instance :rainbow: !</title> | 
					
						
							|  |  |  |       <link>http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R</link> | 
					
						
							|  |  |  |       <description>@admin@localhost:8080 posted 1 attachment: "hello world! #welcome ! first post on the instance :rainbow: !"</description> | 
					
						
							| 
									
										
										
										
											2025-03-07 15:04:34 +01:00
										 |  |  |       <content:encoded><![CDATA[<p>hello world! <a href="http://localhost:8080/tags/welcome" class="mention hashtag" rel="tag nofollow noreferrer noopener" target="_blank">#<span>welcome</span></a> ! first post on the instance <img src="http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png" title=":rainbow:" alt=":rainbow:" width="25" height="25" /> !</p>]]></content:encoded> | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  |       <author>@admin@localhost:8080</author> | 
					
						
							|  |  |  |       <enclosure url="http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/original/01F8MH6NEM8D7527KZAECTCR76.jpg" length="62529" type="image/jpeg"></enclosure> | 
					
						
							|  |  |  |       <guid isPermaLink="true">http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R</guid> | 
					
						
							|  |  |  |       <pubDate>Wed, 20 Oct 2021 11:36:45 +0000</pubDate> | 
					
						
							|  |  |  |       <source>http://localhost:8080/@admin/feed.rss</source> | 
					
						
							|  |  |  |     </item> | 
					
						
							|  |  |  |   </channel> | 
					
						
							|  |  |  | </rss>`, feed) | 
					
						
							| 
									
										
										
										
											2022-10-08 14:00:39 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *GetRSSTestSuite) TestGetAccountRSSZork() { | 
					
						
							|  |  |  | 	getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(context.Background(), "the_mighty_zork") | 
					
						
							|  |  |  | 	suite.NoError(err) | 
					
						
							| 
									
										
										
										
											2024-12-05 13:35:07 +00:00
										 |  |  | 	suite.EqualValues(1730451600, lastModified.Unix()) | 
					
						
							| 
									
										
										
										
											2022-10-08 14:00:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	feed, err := getFeed() | 
					
						
							|  |  |  | 	suite.NoError(err) | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  | 	suite.Equal(`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> | 
					
						
							|  |  |  |   <channel> | 
					
						
							|  |  |  |     <title>Posts from @the_mighty_zork@localhost:8080</title> | 
					
						
							|  |  |  |     <link>http://localhost:8080/@the_mighty_zork</link> | 
					
						
							|  |  |  |     <description>Posts from @the_mighty_zork@localhost:8080</description> | 
					
						
							| 
									
										
										
										
											2024-12-05 13:35:07 +00:00
										 |  |  |     <pubDate>Fri, 01 Nov 2024 09:00:00 +0000</pubDate> | 
					
						
							|  |  |  |     <lastBuildDate>Fri, 01 Nov 2024 09:00:00 +0000</lastBuildDate> | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  |     <image> | 
					
						
							|  |  |  |       <url>http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.webp</url> | 
					
						
							|  |  |  |       <title>Avatar for @the_mighty_zork@localhost:8080</title> | 
					
						
							|  |  |  |       <link>http://localhost:8080/@the_mighty_zork</link> | 
					
						
							|  |  |  |     </image> | 
					
						
							| 
									
										
										
										
											2024-12-05 13:35:07 +00:00
										 |  |  |     <item> | 
					
						
							|  |  |  |       <title>edited status</title> | 
					
						
							|  |  |  |       <link>http://localhost:8080/@the_mighty_zork/statuses/01JDPZC707CKDN8N4QVWM4Z1NR</link> | 
					
						
							|  |  |  |       <description>@the_mighty_zork@localhost:8080 made a new post: "this is the latest revision of the status, with a content-warning"</description> | 
					
						
							|  |  |  |       <content:encoded><![CDATA[<p>this is the latest revision of the status, with a content-warning</p>]]></content:encoded> | 
					
						
							|  |  |  |       <author>@the_mighty_zork@localhost:8080</author> | 
					
						
							|  |  |  |       <guid isPermaLink="true">http://localhost:8080/@the_mighty_zork/statuses/01JDPZC707CKDN8N4QVWM4Z1NR</guid> | 
					
						
							|  |  |  |       <pubDate>Fri, 01 Nov 2024 09:00:00 +0000</pubDate> | 
					
						
							|  |  |  |       <source>http://localhost:8080/@the_mighty_zork/feed.rss</source> | 
					
						
							|  |  |  |     </item> | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  |     <item> | 
					
						
							|  |  |  |       <title>HTML in post</title> | 
					
						
							|  |  |  |       <link>http://localhost:8080/@the_mighty_zork/statuses/01HH9KYNQPA416TNJ53NSATP40</link> | 
					
						
							|  |  |  |       <description>@the_mighty_zork@localhost:8080 made a new post: "Here's a bunch of HTML, read it and weep, weep then!

`+"```"+`html
<section class="about-user">
 <div class="col-header">
 <h2>About</h2>
 </div> 
 <div class="fields">
 <h3 class="sr-only">Fields</h3>
 <dl>
...</description> | 
					
						
							|  |  |  |       <content:encoded><![CDATA[<p>Here's a bunch of HTML, read it and weep, weep then!</p><pre><code class="language-html"><section class="about-user"> | 
					
						
							|  |  |  |     <div class="col-header"> | 
					
						
							|  |  |  |         <h2>About</h2> | 
					
						
							|  |  |  |     </div>             | 
					
						
							|  |  |  |     <div class="fields"> | 
					
						
							|  |  |  |         <h3 class="sr-only">Fields</h3> | 
					
						
							|  |  |  |         <dl> | 
					
						
							|  |  |  |             <div class="field"> | 
					
						
							|  |  |  |                 <dt>should you follow me?</dt> | 
					
						
							|  |  |  |                 <dd>maybe!</dd> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |             <div class="field"> | 
					
						
							|  |  |  |                 <dt>age</dt> | 
					
						
							|  |  |  |                 <dd>120</dd> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |         </dl> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |     <div class="bio"> | 
					
						
							|  |  |  |         <h3 class="sr-only">Bio</h3> | 
					
						
							|  |  |  |         <p>i post about things that concern me</p> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |     <div class="sr-only" role="group"> | 
					
						
							|  |  |  |         <h3 class="sr-only">Stats</h3> | 
					
						
							|  |  |  |         <span>Joined in Jun, 2022.</span> | 
					
						
							|  |  |  |         <span>8 posts.</span> | 
					
						
							|  |  |  |         <span>Followed by 1.</span> | 
					
						
							|  |  |  |         <span>Following 1.</span> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |     <div class="accountstats" aria-hidden="true"> | 
					
						
							|  |  |  |         <b>Joined</b><time datetime="2022-06-04T13:12:00.000Z">Jun, 2022</time> | 
					
						
							|  |  |  |         <b>Posts</b><span>8</span> | 
					
						
							|  |  |  |         <b>Followed by</b><span>1</span> | 
					
						
							|  |  |  |         <b>Following</b><span>1</span> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  | </section> | 
					
						
							|  |  |  | </code></pre><p>There, hope you liked that!</p>]]></content:encoded> | 
					
						
							|  |  |  |       <author>@the_mighty_zork@localhost:8080</author> | 
					
						
							|  |  |  |       <guid isPermaLink="true">http://localhost:8080/@the_mighty_zork/statuses/01HH9KYNQPA416TNJ53NSATP40</guid> | 
					
						
							|  |  |  |       <pubDate>Sun, 10 Dec 2023 09:24:00 +0000</pubDate> | 
					
						
							|  |  |  |       <source>http://localhost:8080/@the_mighty_zork/feed.rss</source> | 
					
						
							|  |  |  |     </item> | 
					
						
							|  |  |  |     <item> | 
					
						
							|  |  |  |       <title>introduction post</title> | 
					
						
							|  |  |  |       <link>http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY</link> | 
					
						
							|  |  |  |       <description>@the_mighty_zork@localhost:8080 made a new post: "hello everyone!"</description> | 
					
						
							| 
									
										
										
										
											2025-03-07 15:04:34 +01:00
										 |  |  |       <content:encoded><![CDATA[<p>hello everyone!</p>]]></content:encoded> | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  |       <author>@the_mighty_zork@localhost:8080</author> | 
					
						
							|  |  |  |       <guid isPermaLink="true">http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY</guid> | 
					
						
							|  |  |  |       <pubDate>Wed, 20 Oct 2021 10:40:37 +0000</pubDate> | 
					
						
							|  |  |  |       <source>http://localhost:8080/@the_mighty_zork/feed.rss</source> | 
					
						
							|  |  |  |     </item> | 
					
						
							|  |  |  |   </channel> | 
					
						
							|  |  |  | </rss>`, feed) | 
					
						
							| 
									
										
										
										
											2022-10-08 14:00:39 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 17:05:59 +02:00
										 |  |  | func (suite *GetRSSTestSuite) TestGetAccountRSSZorkNoPosts() { | 
					
						
							|  |  |  | 	ctx := context.Background() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get all of zork's posts. | 
					
						
							|  |  |  | 	statuses, err := suite.db.GetAccountStatuses(ctx, suite.testAccounts["local_account_1"].ID, 0, false, false, "", "", false, false) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Now delete them! Hahaha! | 
					
						
							|  |  |  | 	for _, status := range statuses { | 
					
						
							|  |  |  | 		if err := suite.db.DeleteStatusByID(ctx, status.ID); err != nil { | 
					
						
							|  |  |  | 			suite.FailNow(err.Error()) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(ctx, "the_mighty_zork") | 
					
						
							|  |  |  | 	suite.NoError(err) | 
					
						
							|  |  |  | 	suite.Empty(lastModified) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	feed, err := getFeed() | 
					
						
							|  |  |  | 	suite.NoError(err) | 
					
						
							| 
									
										
										
										
											2024-07-21 14:22:08 +02:00
										 |  |  | 	suite.Equal(`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> | 
					
						
							|  |  |  |   <channel> | 
					
						
							|  |  |  |     <title>Posts from @the_mighty_zork@localhost:8080</title> | 
					
						
							|  |  |  |     <link>http://localhost:8080/@the_mighty_zork</link> | 
					
						
							|  |  |  |     <description>Posts from @the_mighty_zork@localhost:8080</description> | 
					
						
							|  |  |  |     <pubDate>Fri, 20 May 2022 11:09:18 +0000</pubDate> | 
					
						
							|  |  |  |     <lastBuildDate>Fri, 20 May 2022 11:09:18 +0000</lastBuildDate> | 
					
						
							|  |  |  |     <image> | 
					
						
							|  |  |  |       <url>http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.webp</url> | 
					
						
							|  |  |  |       <title>Avatar for @the_mighty_zork@localhost:8080</title> | 
					
						
							|  |  |  |       <link>http://localhost:8080/@the_mighty_zork</link> | 
					
						
							|  |  |  |     </image> | 
					
						
							|  |  |  |   </channel> | 
					
						
							|  |  |  | </rss>`, feed) | 
					
						
							| 
									
										
										
										
											2023-07-10 17:05:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 14:00:39 +02:00
										 |  |  | func TestGetRSSTestSuite(t *testing.T) { | 
					
						
							|  |  |  | 	suite.Run(t, new(GetRSSTestSuite)) | 
					
						
							|  |  |  | } |