]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/feeds/feeds.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / feeds / feeds.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fe3a55b0
C
2
3import * as chai from 'chai'
4import 'mocha'
5import {
7c3b7976 6 cleanupTests,
662fb3ab 7 createUser,
fe3a55b0
C
8 doubleFollow,
9 flushAndRunMultipleServers,
57cfff78
C
10 getJSONfeed,
11 getMyUserInformation,
fe3a55b0 12 getXMLfeed,
fe3a55b0
C
13 ServerInfo,
14 setAccessTokensToServers,
57cfff78
C
15 uploadVideo,
16 userLogin
94565d52 17} from '../../../shared/extra-utils'
fe3a55b0 18import * as libxmljs from 'libxmljs'
94565d52
C
19import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
20import { waitJobs } from '../../../shared/extra-utils/server/jobs'
662fb3ab 21import { User } from '../../../shared/models/users'
68b6fd21 22import { VideoPrivacy } from '@shared/models'
1df8a4d7 23import { addAccountToServerBlocklist } from '@shared/extra-utils/users/blocklist'
fe3a55b0
C
24
25chai.use(require('chai-xml'))
26chai.use(require('chai-json-schema'))
27chai.config.includeStack = true
28const expect = chai.expect
29
30describe('Test syndication feeds', () => {
31 let servers: ServerInfo[] = []
662fb3ab 32 let userAccessToken: string
57cfff78
C
33 let rootAccountId: number
34 let rootChannelId: number
35 let userAccountId: number
36 let userChannelId: number
fe3a55b0
C
37
38 before(async function () {
39 this.timeout(120000)
40
41 // Run servers
42 servers = await flushAndRunMultipleServers(2)
43
44 await setAccessTokensToServers(servers)
45 await doubleFollow(servers[0], servers[1])
46
662fb3ab
C
47 {
48 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
49 const user: User = res.body
57cfff78
C
50 rootAccountId = user.account.id
51 rootChannelId = user.videoChannels[0].id
fe3a55b0 52 }
fe3a55b0 53
662fb3ab
C
54 {
55 const attr = { username: 'john', password: 'password' }
a1587156 56 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
662fb3ab
C
57 userAccessToken = await userLogin(servers[0], attr)
58
59 const res = await getMyUserInformation(servers[0].url, userAccessToken)
60 const user: User = res.body
57cfff78
C
61 userAccountId = user.account.id
62 userChannelId = user.videoChannels[0].id
662fb3ab
C
63 }
64
65 {
a1587156 66 await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' })
662fb3ab
C
67 }
68
69 {
70 const videoAttributes = {
71 name: 'my super name for server 1',
72 description: 'my super description for server 1',
73 fixture: 'video_short.webm'
74 }
a1587156 75 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
662fb3ab
C
76 const videoId = res.body.video.id
77
a1587156
C
78 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1')
79 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
662fb3ab 80 }
fe3a55b0 81
68b6fd21
C
82 {
83 const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
84 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
85 const videoId = res.body.video.id
86
87 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video')
88 }
89
3cd0734f 90 await waitJobs(servers)
fe3a55b0
C
91 })
92
93 describe('All feed', function () {
94
95 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
96 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
a1587156 97 const rss = await getXMLfeed(servers[0].url, feed)
fe3a55b0
C
98 expect(rss.text).xml.to.be.valid()
99
a1587156 100 const atom = await getXMLfeed(servers[0].url, feed, 'atom')
fe3a55b0
C
101 expect(atom.text).xml.to.be.valid()
102 }
103 })
104
105 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
106 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
a1587156
C
107 const json = await getJSONfeed(servers[0].url, feed)
108 expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' })
fe3a55b0
C
109 }
110 })
111 })
112
113 describe('Videos feed', function () {
114 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
115 for (const server of servers) {
116 const rss = await getXMLfeed(server.url, 'videos')
117 const xmlDoc = libxmljs.parseXmlString(rss.text)
118 const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure')
119 expect(xmlEnclosure).to.exist
120 expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent')
121 expect(xmlEnclosure.attr('length').value()).to.be.equal('218910')
122 expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent')
123 }
124 })
125
126 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
127 for (const server of servers) {
128 const json = await getJSONfeed(server.url, 'videos')
129 const jsonObj = JSON.parse(json.text)
662fb3ab 130 expect(jsonObj.items.length).to.be.equal(2)
a1587156
C
131 expect(jsonObj.items[0].attachments).to.exist
132 expect(jsonObj.items[0].attachments.length).to.be.eq(1)
133 expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent')
134 expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910)
135 expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent')
fe3a55b0
C
136 }
137 })
662fb3ab
C
138
139 it('Should filter by account', async function () {
57cfff78
C
140 {
141 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: rootAccountId })
142 const jsonObj = JSON.parse(json.text)
143 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
144 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
145 expect(jsonObj.items[0].author.name).to.equal('root')
57cfff78
C
146 }
147
148 {
149 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId })
150 const jsonObj = JSON.parse(json.text)
151 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
152 expect(jsonObj.items[0].title).to.equal('user video')
153 expect(jsonObj.items[0].author.name).to.equal('john')
57cfff78
C
154 }
155
662fb3ab
C
156 for (const server of servers) {
157 {
57cfff78 158 const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port })
662fb3ab
C
159 const jsonObj = JSON.parse(json.text)
160 expect(jsonObj.items.length).to.be.equal(1)
a1587156 161 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
662fb3ab
C
162 }
163
164 {
57cfff78 165 const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port })
662fb3ab
C
166 const jsonObj = JSON.parse(json.text)
167 expect(jsonObj.items.length).to.be.equal(1)
a1587156 168 expect(jsonObj.items[0].title).to.equal('user video')
662fb3ab
C
169 }
170 }
57cfff78 171 })
662fb3ab 172
57cfff78 173 it('Should filter by video channel', async function () {
662fb3ab 174 {
57cfff78 175 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId })
662fb3ab
C
176 const jsonObj = JSON.parse(json.text)
177 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
178 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
179 expect(jsonObj.items[0].author.name).to.equal('root')
662fb3ab
C
180 }
181
182 {
57cfff78 183 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId })
662fb3ab
C
184 const jsonObj = JSON.parse(json.text)
185 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
186 expect(jsonObj.items[0].title).to.equal('user video')
187 expect(jsonObj.items[0].author.name).to.equal('john')
662fb3ab 188 }
662fb3ab 189
662fb3ab
C
190 for (const server of servers) {
191 {
57cfff78 192 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port })
662fb3ab
C
193 const jsonObj = JSON.parse(json.text)
194 expect(jsonObj.items.length).to.be.equal(1)
a1587156 195 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
662fb3ab
C
196 }
197
198 {
57cfff78 199 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port })
662fb3ab
C
200 const jsonObj = JSON.parse(json.text)
201 expect(jsonObj.items.length).to.be.equal(1)
a1587156 202 expect(jsonObj.items[0].title).to.equal('user video')
662fb3ab
C
203 }
204 }
662fb3ab 205 })
fe3a55b0
C
206 })
207
208 describe('Video comments feed', function () {
68b6fd21
C
209
210 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
fe3a55b0
C
211 for (const server of servers) {
212 const json = await getJSONfeed(server.url, 'video-comments')
213
214 const jsonObj = JSON.parse(json.text)
215 expect(jsonObj.items.length).to.be.equal(2)
a1587156
C
216 expect(jsonObj.items[0].html_content).to.equal('super comment 2')
217 expect(jsonObj.items[1].html_content).to.equal('super comment 1')
fe3a55b0
C
218 }
219 })
1df8a4d7
C
220
221 it('Should not list comments from muted accounts or instances', async function () {
222 await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, 'root@localhost:' + servers[0].port)
223
224 {
225 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 2 })
226 const jsonObj = JSON.parse(json.text)
227 expect(jsonObj.items.length).to.be.equal(0)
228 }
229
230 })
fe3a55b0
C
231 })
232
7c3b7976
C
233 after(async function () {
234 await cleanupTests(servers)
fe3a55b0
C
235 })
236})