]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/feeds/feeds.ts
Add Podcast RSS feeds (#5487)
[github/Chocobozzz/PeerTube.git] / server / tests / feeds / feeds.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fe3a55b0 2
479b2696 3import * as chai from 'chai'
2d28b0c2 4import { XMLParser, XMLValidator } from 'fast-xml-parser'
d0800f76 5import { HttpStatusCode, VideoPrivacy } from '@shared/models'
696d83fd 6import {
7c3b7976 7 cleanupTests,
254d3579
C
8 createMultipleServers,
9 createSingleServer,
4c7e60bc 10 doubleFollow,
20bafcb6 11 makeGetRequest,
5e1bd869 12 makeRawRequest,
254d3579 13 PeerTubeServer,
cb0eda56 14 PluginsCommand,
fe3a55b0 15 setAccessTokensToServers,
d0800f76 16 setDefaultChannelAvatar,
7a5c3d77 17 stopFfmpeg,
5f8bd4cb 18 waitJobs
bf54587a 19} from '@shared/server-commands'
fe3a55b0
C
20
21chai.use(require('chai-xml'))
22chai.use(require('chai-json-schema'))
23chai.config.includeStack = true
479b2696 24
e5d771a3
C
25const expect = chai.expect
26
fe3a55b0 27describe('Test syndication feeds', () => {
254d3579
C
28 let servers: PeerTubeServer[] = []
29 let serverHLSOnly: PeerTubeServer
cb0eda56 30
662fb3ab 31 let userAccessToken: string
57cfff78
C
32 let rootAccountId: number
33 let rootChannelId: number
cb0eda56 34
57cfff78
C
35 let userAccountId: number
36 let userChannelId: number
afff310e 37 let userFeedToken: string
cb0eda56 38
7a5c3d77 39 let liveId: string
fe3a55b0
C
40
41 before(async function () {
42 this.timeout(120000)
43
44 // Run servers
254d3579
C
45 servers = await createMultipleServers(2)
46 serverHLSOnly = await createSingleServer(3, {
97816649
C
47 transcoding: {
48 enabled: true,
49 webtorrent: { enabled: false },
50 hls: { enabled: true }
51 }
52 })
fe3a55b0 53
97816649 54 await setAccessTokensToServers([ ...servers, serverHLSOnly ])
d0800f76 55 await setDefaultChannelAvatar(servers[0])
fe3a55b0
C
56 await doubleFollow(servers[0], servers[1])
57
7a5c3d77
C
58 await servers[0].config.enableLive({ allowReplay: false, transcoding: false })
59
662fb3ab 60 {
89d241a7 61 const user = await servers[0].users.getMyInfo()
57cfff78
C
62 rootAccountId = user.account.id
63 rootChannelId = user.videoChannels[0].id
fe3a55b0 64 }
fe3a55b0 65
662fb3ab 66 {
20bafcb6 67 userAccessToken = await servers[0].users.generateUserAndToken('john')
662fb3ab 68
89d241a7 69 const user = await servers[0].users.getMyInfo({ token: userAccessToken })
57cfff78
C
70 userAccountId = user.account.id
71 userChannelId = user.videoChannels[0].id
afff310e 72
89d241a7 73 const token = await servers[0].users.getMyScopedTokens({ token: userAccessToken })
afff310e 74 userFeedToken = token.feedToken
662fb3ab
C
75 }
76
77 {
89d241a7 78 await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'user video' } })
662fb3ab
C
79 }
80
81 {
d23dd9fb 82 const attributes = {
662fb3ab
C
83 name: 'my super name for server 1',
84 description: 'my super description for server 1',
85 fixture: 'video_short.webm'
86 }
89d241a7 87 const { id } = await servers[0].videos.upload({ attributes })
662fb3ab 88
89d241a7
C
89 await servers[0].comments.createThread({ videoId: id, text: 'super comment 1' })
90 await servers[0].comments.createThread({ videoId: id, text: 'super comment 2' })
662fb3ab 91 }
fe3a55b0 92
68b6fd21 93 {
d23dd9fb 94 const attributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
89d241a7 95 const { id } = await servers[0].videos.upload({ attributes })
68b6fd21 96
89d241a7 97 await servers[0].comments.createThread({ videoId: id, text: 'comment on unlisted video' })
68b6fd21
C
98 }
99
cb0eda56
AG
100 await serverHLSOnly.videos.upload({ attributes: { name: 'hls only video' } })
101
102 await waitJobs([ ...servers, serverHLSOnly ])
103
104 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-podcast-custom-tags') })
fe3a55b0
C
105 })
106
107 describe('All feed', function () {
108
109 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
110 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
41e74ec9 111 const rss = await servers[0].feed.getXML({ feed, ignoreCache: true })
c1bc8ee4 112 expect(rss).xml.to.be.valid()
fe3a55b0 113
41e74ec9 114 const atom = await servers[0].feed.getXML({ feed, format: 'atom', ignoreCache: true })
c1bc8ee4 115 expect(atom).xml.to.be.valid()
fe3a55b0
C
116 }
117 })
118
cb0eda56
AG
119 it('Should be well formed XML (covers Podcast endpoint)', async function () {
120 const podcast = await servers[0].feed.getPodcastXML({ ignoreCache: true, channelId: rootChannelId })
121 expect(podcast).xml.to.be.valid()
122 })
123
fe3a55b0
C
124 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
125 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
41e74ec9 126 const jsonText = await servers[0].feed.getJSON({ feed, ignoreCache: true })
c1bc8ee4 127 expect(JSON.parse(jsonText)).to.be.jsonSchema({ type: 'object' })
fe3a55b0
C
128 }
129 })
20bafcb6
C
130
131 it('Should serve the endpoint with a classic request', async function () {
132 await makeGetRequest({
133 url: servers[0].url,
134 path: '/feeds/videos.xml',
135 accept: 'application/xml',
136 expectedStatus: HttpStatusCode.OK_200
137 })
138 })
139
140 it('Should serve the endpoint as a cached request', async function () {
141 const res = await makeGetRequest({
142 url: servers[0].url,
143 path: '/feeds/videos.xml',
144 accept: 'application/xml',
145 expectedStatus: HttpStatusCode.OK_200
146 })
147
148 expect(res.headers['x-api-cache-cached']).to.equal('true')
149 })
150
151 it('Should not serve the endpoint as a cached request', async function () {
152 const res = await makeGetRequest({
153 url: servers[0].url,
154 path: '/feeds/videos.xml?v=186',
155 accept: 'application/xml',
156 expectedStatus: HttpStatusCode.OK_200
157 })
158
159 expect(res.headers['x-api-cache-cached']).to.not.exist
160 })
161
162 it('Should refuse to serve the endpoint without accept header', async function () {
163 await makeGetRequest({ url: servers[0].url, path: '/feeds/videos.xml', expectedStatus: HttpStatusCode.NOT_ACCEPTABLE_406 })
164 })
fe3a55b0
C
165 })
166
167 describe('Videos feed', function () {
97816649 168
cb0eda56
AG
169 describe('Podcast feed', function () {
170
171 it('Should contain a valid podcast:alternateEnclosure', async function () {
172 // Since podcast feeds should only work on the server they originate on,
173 // only test the first server where the videos reside
174 const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId })
2d28b0c2 175 expect(XMLValidator.validate(rss)).to.be.true
b70025bf 176
2d28b0c2
C
177 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
178 const xmlDoc = parser.parse(rss)
b70025bf 179
cb0eda56 180 const enclosure = xmlDoc.rss.channel.item.enclosure
b70025bf 181 expect(enclosure).to.exist
cb0eda56
AG
182 const alternateEnclosure = xmlDoc.rss.channel.item['podcast:alternateEnclosure']
183 expect(alternateEnclosure).to.exist
184
185 expect(alternateEnclosure['@_type']).to.equal('video/webm')
186 expect(alternateEnclosure['@_length']).to.equal(218910)
187 expect(alternateEnclosure['@_lang']).to.equal('zh')
188 expect(alternateEnclosure['@_title']).to.equal('720p')
189 expect(alternateEnclosure['@_default']).to.equal(true)
190
191 expect(alternateEnclosure['podcast:source'][0]['@_uri']).to.contain('-720.webm')
192 expect(alternateEnclosure['podcast:source'][0]['@_uri']).to.equal(enclosure['@_url'])
193 expect(alternateEnclosure['podcast:source'][1]['@_uri']).to.contain('-720.torrent')
194 expect(alternateEnclosure['podcast:source'][1]['@_contentType']).to.equal('application/x-bittorrent')
195 expect(alternateEnclosure['podcast:source'][2]['@_uri']).to.contain('magnet:?')
196 })
4393b255 197
cb0eda56
AG
198 it('Should contain a valid podcast:alternateEnclosure with HLS only', async function () {
199 const rss = await serverHLSOnly.feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId })
200 expect(XMLValidator.validate(rss)).to.be.true
fe3a55b0 201
cb0eda56
AG
202 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
203 const xmlDoc = parser.parse(rss)
204
205 const enclosure = xmlDoc.rss.channel.item.enclosure
206 const alternateEnclosure = xmlDoc.rss.channel.item['podcast:alternateEnclosure']
207 expect(alternateEnclosure).to.exist
208
209 expect(alternateEnclosure['@_type']).to.equal('application/x-mpegURL')
210 expect(alternateEnclosure['@_lang']).to.equal('zh')
211 expect(alternateEnclosure['@_title']).to.equal('HLS')
212 expect(alternateEnclosure['@_default']).to.equal(true)
213
214 expect(alternateEnclosure['podcast:source']['@_uri']).to.contain('-master.m3u8')
215 expect(alternateEnclosure['podcast:source']['@_uri']).to.equal(enclosure['@_url'])
216 })
217
218 it('Should contain a valid podcast:socialInteract', async function () {
219 const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId })
220 expect(XMLValidator.validate(rss)).to.be.true
221
222 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
223 const xmlDoc = parser.parse(rss)
224
225 const item = xmlDoc.rss.channel.item
226 const socialInteract = item['podcast:socialInteract']
227 expect(socialInteract).to.exist
228 expect(socialInteract['@_protocol']).to.equal('activitypub')
229 expect(socialInteract['@_uri']).to.exist
230 expect(socialInteract['@_accountUrl']).to.exist
231 })
232
233 it('Should contain a valid support custom tags for plugins', async function () {
234 const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: userChannelId })
235 expect(XMLValidator.validate(rss)).to.be.true
236
237 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
238 const xmlDoc = parser.parse(rss)
239
240 const fooTag = xmlDoc.rss.channel.fooTag
241 expect(fooTag).to.exist
242 expect(fooTag['@_bar']).to.equal('baz')
243 expect(fooTag['#text']).to.equal(42)
244
245 const bizzBuzzItem = xmlDoc.rss.channel['biz:buzzItem']
246 expect(bizzBuzzItem).to.exist
247
248 let nestedTag = bizzBuzzItem.nestedTag
249 expect(nestedTag).to.exist
250 expect(nestedTag).to.equal('example nested tag')
251
252 const item = xmlDoc.rss.channel.item
253 const fizzTag = item.fizzTag
254 expect(fizzTag).to.exist
255 expect(fizzTag['@_bar']).to.equal('baz')
256 expect(fizzTag['#text']).to.equal(21)
257
258 const bizzBuzz = item['biz:buzz']
259 expect(bizzBuzz).to.exist
260
261 nestedTag = bizzBuzz.nestedTag
262 expect(nestedTag).to.exist
263 expect(nestedTag).to.equal('example nested tag')
264 })
265
266 it('Should contain a valid podcast:liveItem for live streams', async function () {
267 this.timeout(120000)
268
269 const { uuid } = await servers[0].live.create({
270 fields: {
271 name: 'live-0',
272 privacy: VideoPrivacy.PUBLIC,
273 channelId: rootChannelId,
274 permanentLive: false
275 }
276 })
277 liveId = uuid
278
279 const ffmpeg = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveId, copyCodecs: true, fixtureName: 'video_short.mp4' })
280 await servers[0].live.waitUntilPublished({ videoId: liveId })
281
282 const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId })
283 expect(XMLValidator.validate(rss)).to.be.true
284
285 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
286 const xmlDoc = parser.parse(rss)
287 const liveItem = xmlDoc.rss.channel['podcast:liveItem']
288 expect(liveItem.title).to.equal('live-0')
289 expect(liveItem['@_status']).to.equal('live')
290
291 const enclosure = liveItem.enclosure
292 const alternateEnclosure = liveItem['podcast:alternateEnclosure']
293 expect(alternateEnclosure).to.exist
294 expect(alternateEnclosure['@_type']).to.equal('application/x-mpegURL')
295 expect(alternateEnclosure['@_title']).to.equal('HLS live stream')
296 expect(alternateEnclosure['@_default']).to.equal(true)
297
298 expect(alternateEnclosure['podcast:source']['@_uri']).to.contain('/master.m3u8')
299 expect(alternateEnclosure['podcast:source']['@_uri']).to.equal(enclosure['@_url'])
300
301 await stopFfmpeg(ffmpeg)
302
303 await servers[0].live.waitUntilEnded({ videoId: liveId })
304
305 await waitJobs(servers)
306 })
fe3a55b0 307 })
662fb3ab 308
cb0eda56 309 describe('JSON feed', function () {
57cfff78 310
cb0eda56
AG
311 it('Should contain a valid \'attachments\' object', async function () {
312 for (const server of servers) {
313 const json = await server.feed.getJSON({ feed: 'videos', ignoreCache: true })
314 const jsonObj = JSON.parse(json)
315 expect(jsonObj.items.length).to.be.equal(2)
316 expect(jsonObj.items[0].attachments).to.exist
317 expect(jsonObj.items[0].attachments.length).to.be.eq(1)
318 expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent')
319 expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910)
320 expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent')
321 }
322 })
57cfff78 323
cb0eda56 324 it('Should filter by account', async function () {
662fb3ab 325 {
cb0eda56 326 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: rootAccountId }, ignoreCache: true })
c1bc8ee4 327 const jsonObj = JSON.parse(json)
662fb3ab 328 expect(jsonObj.items.length).to.be.equal(1)
a1587156 329 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
cb0eda56 330 expect(jsonObj.items[0].author.name).to.equal('Main root channel')
662fb3ab
C
331 }
332
333 {
cb0eda56 334 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: userAccountId }, ignoreCache: true })
c1bc8ee4 335 const jsonObj = JSON.parse(json)
662fb3ab 336 expect(jsonObj.items.length).to.be.equal(1)
a1587156 337 expect(jsonObj.items[0].title).to.equal('user video')
cb0eda56 338 expect(jsonObj.items[0].author.name).to.equal('Main john channel')
662fb3ab 339 }
662fb3ab 340
cb0eda56
AG
341 for (const server of servers) {
342 {
343 const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'root@' + servers[0].host }, ignoreCache: true })
344 const jsonObj = JSON.parse(json)
345 expect(jsonObj.items.length).to.be.equal(1)
346 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
347 }
348
349 {
350 const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'john@' + servers[0].host }, ignoreCache: true })
351 const jsonObj = JSON.parse(json)
352 expect(jsonObj.items.length).to.be.equal(1)
353 expect(jsonObj.items[0].title).to.equal('user video')
354 }
355 }
356 })
662fb3ab 357
cb0eda56 358 it('Should filter by video channel', async function () {
662fb3ab 359 {
cb0eda56 360 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId }, ignoreCache: true })
c1bc8ee4 361 const jsonObj = JSON.parse(json)
662fb3ab 362 expect(jsonObj.items.length).to.be.equal(1)
a1587156 363 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
cb0eda56 364 expect(jsonObj.items[0].author.name).to.equal('Main root channel')
662fb3ab
C
365 }
366
367 {
cb0eda56 368 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: userChannelId }, ignoreCache: true })
c1bc8ee4 369 const jsonObj = JSON.parse(json)
662fb3ab 370 expect(jsonObj.items.length).to.be.equal(1)
a1587156 371 expect(jsonObj.items[0].title).to.equal('user video')
cb0eda56 372 expect(jsonObj.items[0].author.name).to.equal('Main john channel')
662fb3ab 373 }
97816649 374
cb0eda56
AG
375 for (const server of servers) {
376 {
377 const query = { videoChannelName: 'root_channel@' + servers[0].host }
378 const json = await server.feed.getJSON({ feed: 'videos', query, ignoreCache: true })
379 const jsonObj = JSON.parse(json)
380 expect(jsonObj.items.length).to.be.equal(1)
381 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
382 }
383
384 {
385 const query = { videoChannelName: 'john_channel@' + servers[0].host }
386 const json = await server.feed.getJSON({ feed: 'videos', query, ignoreCache: true })
387 const jsonObj = JSON.parse(json)
388 expect(jsonObj.items.length).to.be.equal(1)
389 expect(jsonObj.items[0].title).to.equal('user video')
390 }
391 }
392 })
97816649 393
cb0eda56
AG
394 it('Should correctly have videos feed with HLS only', async function () {
395 this.timeout(120000)
97816649 396
cb0eda56
AG
397 const json = await serverHLSOnly.feed.getJSON({ feed: 'videos', ignoreCache: true })
398 const jsonObj = JSON.parse(json)
399 expect(jsonObj.items.length).to.be.equal(1)
400 expect(jsonObj.items[0].attachments).to.exist
401 expect(jsonObj.items[0].attachments.length).to.be.eq(4)
7a5c3d77 402
cb0eda56
AG
403 for (let i = 0; i < 4; i++) {
404 expect(jsonObj.items[0].attachments[i].mime_type).to.be.eq('application/x-bittorrent')
405 expect(jsonObj.items[0].attachments[i].size_in_bytes).to.be.greaterThan(0)
406 expect(jsonObj.items[0].attachments[i].url).to.exist
7a5c3d77
C
407 }
408 })
7a5c3d77 409
cb0eda56
AG
410 it('Should not display waiting live videos', async function () {
411 const { uuid } = await servers[0].live.create({
412 fields: {
413 name: 'live',
414 privacy: VideoPrivacy.PUBLIC,
415 channelId: rootChannelId
416 }
417 })
418 liveId = uuid
7a5c3d77 419
cb0eda56
AG
420 const json = await servers[0].feed.getJSON({ feed: 'videos', ignoreCache: true })
421
422 const jsonObj = JSON.parse(json)
423 expect(jsonObj.items.length).to.be.equal(2)
424 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
425 expect(jsonObj.items[1].title).to.equal('user video')
426 })
7a5c3d77 427
cb0eda56
AG
428 it('Should display published live videos', async function () {
429 this.timeout(120000)
7a5c3d77 430
cb0eda56
AG
431 const ffmpeg = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveId, copyCodecs: true, fixtureName: 'video_short.mp4' })
432 await servers[0].live.waitUntilPublished({ videoId: liveId })
7a5c3d77 433
cb0eda56 434 const json = await servers[0].feed.getJSON({ feed: 'videos', ignoreCache: true })
7a5c3d77 435
cb0eda56
AG
436 const jsonObj = JSON.parse(json)
437 expect(jsonObj.items.length).to.be.equal(3)
438 expect(jsonObj.items[0].title).to.equal('live')
439 expect(jsonObj.items[1].title).to.equal('my super name for server 1')
440 expect(jsonObj.items[2].title).to.equal('user video')
7a5c3d77 441
cb0eda56
AG
442 await stopFfmpeg(ffmpeg)
443 })
5e1bd869 444
cb0eda56
AG
445 it('Should have the channel avatar as feed icon', async function () {
446 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId }, ignoreCache: true })
5e1bd869 447
cb0eda56
AG
448 const jsonObj = JSON.parse(json)
449 const imageUrl = jsonObj.icon
450 expect(imageUrl).to.include('/lazy-static/avatars/')
451 await makeRawRequest({ url: imageUrl, expectedStatus: HttpStatusCode.OK_200 })
452 })
5e1bd869 453 })
fe3a55b0
C
454 })
455
456 describe('Video comments feed', function () {
68b6fd21
C
457
458 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
fe3a55b0 459 for (const server of servers) {
41e74ec9 460 const json = await server.feed.getJSON({ feed: 'video-comments', ignoreCache: true })
fe3a55b0 461
c1bc8ee4 462 const jsonObj = JSON.parse(json)
fe3a55b0 463 expect(jsonObj.items.length).to.be.equal(2)
4393b255
C
464 expect(jsonObj.items[0].content_html).to.contain('<p>super comment 2</p>')
465 expect(jsonObj.items[1].content_html).to.contain('<p>super comment 1</p>')
fe3a55b0
C
466 }
467 })
1df8a4d7
C
468
469 it('Should not list comments from muted accounts or instances', async function () {
696d83fd
C
470 this.timeout(30000)
471
41e74ec9 472 const remoteHandle = 'root@' + servers[0].host
696d83fd 473
89d241a7 474 await servers[1].blocklist.addToServerBlocklist({ account: remoteHandle })
1df8a4d7
C
475
476 {
41e74ec9 477 const json = await servers[1].feed.getJSON({ feed: 'video-comments', ignoreCache: true })
c1bc8ee4 478 const jsonObj = JSON.parse(json)
1df8a4d7
C
479 expect(jsonObj.items.length).to.be.equal(0)
480 }
481
89d241a7 482 await servers[1].blocklist.removeFromServerBlocklist({ account: remoteHandle })
696d83fd
C
483
484 {
89d241a7 485 const videoUUID = (await servers[1].videos.quickUpload({ name: 'server 2' })).uuid
696d83fd 486 await waitJobs(servers)
89d241a7 487 await servers[0].comments.createThread({ videoId: videoUUID, text: 'super comment' })
696d83fd
C
488 await waitJobs(servers)
489
41e74ec9 490 const json = await servers[1].feed.getJSON({ feed: 'video-comments', ignoreCache: true })
c1bc8ee4 491 const jsonObj = JSON.parse(json)
696d83fd
C
492 expect(jsonObj.items.length).to.be.equal(3)
493 }
494
89d241a7 495 await servers[1].blocklist.addToMyBlocklist({ account: remoteHandle })
696d83fd
C
496
497 {
41e74ec9 498 const json = await servers[1].feed.getJSON({ feed: 'video-comments', ignoreCache: true })
c1bc8ee4 499 const jsonObj = JSON.parse(json)
696d83fd
C
500 expect(jsonObj.items.length).to.be.equal(2)
501 }
1df8a4d7 502 })
fe3a55b0
C
503 })
504
afff310e 505 describe('Video feed from my subscriptions', function () {
18490b07
C
506 let feeduserAccountId: number
507 let feeduserFeedToken: string
afff310e
RK
508
509 it('Should list no videos for a user with no videos and no subscriptions', async function () {
afff310e 510 const attr = { username: 'feeduser', password: 'password' }
89d241a7
C
511 await servers[0].users.create({ username: attr.username, password: attr.password })
512 const feeduserAccessToken = await servers[0].login.getAccessToken(attr)
afff310e
RK
513
514 {
89d241a7 515 const user = await servers[0].users.getMyInfo({ token: feeduserAccessToken })
afff310e
RK
516 feeduserAccountId = user.account.id
517 }
518
519 {
89d241a7 520 const token = await servers[0].users.getMyScopedTokens({ token: feeduserAccessToken })
afff310e
RK
521 feeduserFeedToken = token.feedToken
522 }
523
524 {
692ae8c3 525 const body = await servers[0].videos.listMySubscriptionVideos({ token: feeduserAccessToken })
2c27e704 526 expect(body.total).to.equal(0)
afff310e 527
c1bc8ee4 528 const query = { accountId: feeduserAccountId, token: feeduserFeedToken }
41e74ec9 529 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
c1bc8ee4 530 const jsonObj = JSON.parse(json)
afff310e
RK
531 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
532 }
533 })
534
18490b07 535 it('Should fail with an invalid token', async function () {
c1bc8ee4 536 const query = { accountId: feeduserAccountId, token: 'toto' }
41e74ec9 537 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403, ignoreCache: true })
18490b07
C
538 })
539
540 it('Should fail with a token of another user', async function () {
c1bc8ee4 541 const query = { accountId: feeduserAccountId, token: userFeedToken }
41e74ec9 542 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403, ignoreCache: true })
18490b07
C
543 })
544
afff310e 545 it('Should list no videos for a user with videos but no subscriptions', async function () {
692ae8c3 546 const body = await servers[0].videos.listMySubscriptionVideos({ token: userAccessToken })
2c27e704 547 expect(body.total).to.equal(0)
afff310e 548
c1bc8ee4 549 const query = { accountId: userAccountId, token: userFeedToken }
41e74ec9 550 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
c1bc8ee4 551 const jsonObj = JSON.parse(json)
18490b07 552 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
afff310e
RK
553 })
554
555 it('Should list self videos for a user with a subscription to themselves', async function () {
556 this.timeout(30000)
557
41e74ec9 558 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'john_channel@' + servers[0].host })
afff310e
RK
559 await waitJobs(servers)
560
561 {
692ae8c3 562 const body = await servers[0].videos.listMySubscriptionVideos({ token: userAccessToken })
2c27e704
C
563 expect(body.total).to.equal(1)
564 expect(body.data[0].name).to.equal('user video')
afff310e 565
41e74ec9
C
566 const query = { accountId: userAccountId, token: userFeedToken }
567 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
c1bc8ee4 568 const jsonObj = JSON.parse(json)
afff310e
RK
569 expect(jsonObj.items.length).to.be.equal(1) // subscribed to self, it should not list the instance's videos but list john's
570 }
571 })
572
573 it('Should list videos of a user\'s subscription', async function () {
574 this.timeout(30000)
575
41e74ec9 576 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@' + servers[0].host })
afff310e
RK
577 await waitJobs(servers)
578
579 {
692ae8c3 580 const body = await servers[0].videos.listMySubscriptionVideos({ token: userAccessToken })
7e0f50d6 581 expect(body.total).to.equal(2, 'there should be 2 videos part of the subscription')
afff310e 582
41e74ec9
C
583 const query = { accountId: userAccountId, token: userFeedToken }
584 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
c1bc8ee4 585 const jsonObj = JSON.parse(json)
afff310e
RK
586 expect(jsonObj.items.length).to.be.equal(2) // subscribed to root, it should not list the instance's videos but list root/john's
587 }
588 })
589
18490b07 590 it('Should renew the token, and so have an invalid old token', async function () {
89d241a7 591 await servers[0].users.renewMyScopedTokens({ token: userAccessToken })
18490b07 592
41e74ec9
C
593 const query = { accountId: userAccountId, token: userFeedToken }
594 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403, ignoreCache: true })
18490b07
C
595 })
596
597 it('Should succeed with the new token', async function () {
89d241a7 598 const token = await servers[0].users.getMyScopedTokens({ token: userAccessToken })
18490b07
C
599 userFeedToken = token.feedToken
600
41e74ec9
C
601 const query = { accountId: userAccountId, token: userFeedToken }
602 await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
18490b07
C
603 })
604
afff310e
RK
605 })
606
7c3b7976 607 after(async function () {
cb0eda56
AG
608 await servers[0].plugins.uninstall({ npmName: 'peertube-plugin-test-podcast-custom-tags' })
609
97816649 610 await cleanupTests([ ...servers, serverHLSOnly ])
fe3a55b0
C
611 })
612})