]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/feeds/feeds.ts
Use largest avatar in RSS feeds, unique guid for liveItems (#5817)
[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
1ed1994f
AG
180 const itemGuid = xmlDoc.rss.channel.item.guid
181 expect(itemGuid).to.exist
182 expect(itemGuid['@_isPermaLink']).to.equal(true)
183
cb0eda56 184 const enclosure = xmlDoc.rss.channel.item.enclosure
b70025bf 185 expect(enclosure).to.exist
cb0eda56
AG
186 const alternateEnclosure = xmlDoc.rss.channel.item['podcast:alternateEnclosure']
187 expect(alternateEnclosure).to.exist
188
189 expect(alternateEnclosure['@_type']).to.equal('video/webm')
190 expect(alternateEnclosure['@_length']).to.equal(218910)
191 expect(alternateEnclosure['@_lang']).to.equal('zh')
192 expect(alternateEnclosure['@_title']).to.equal('720p')
193 expect(alternateEnclosure['@_default']).to.equal(true)
194
195 expect(alternateEnclosure['podcast:source'][0]['@_uri']).to.contain('-720.webm')
196 expect(alternateEnclosure['podcast:source'][0]['@_uri']).to.equal(enclosure['@_url'])
197 expect(alternateEnclosure['podcast:source'][1]['@_uri']).to.contain('-720.torrent')
198 expect(alternateEnclosure['podcast:source'][1]['@_contentType']).to.equal('application/x-bittorrent')
199 expect(alternateEnclosure['podcast:source'][2]['@_uri']).to.contain('magnet:?')
200 })
4393b255 201
cb0eda56
AG
202 it('Should contain a valid podcast:alternateEnclosure with HLS only', async function () {
203 const rss = await serverHLSOnly.feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId })
204 expect(XMLValidator.validate(rss)).to.be.true
fe3a55b0 205
cb0eda56
AG
206 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
207 const xmlDoc = parser.parse(rss)
208
1ed1994f
AG
209 const itemGuid = xmlDoc.rss.channel.item.guid
210 expect(itemGuid).to.exist
211 expect(itemGuid['@_isPermaLink']).to.equal(true)
212
cb0eda56
AG
213 const enclosure = xmlDoc.rss.channel.item.enclosure
214 const alternateEnclosure = xmlDoc.rss.channel.item['podcast:alternateEnclosure']
215 expect(alternateEnclosure).to.exist
216
217 expect(alternateEnclosure['@_type']).to.equal('application/x-mpegURL')
218 expect(alternateEnclosure['@_lang']).to.equal('zh')
219 expect(alternateEnclosure['@_title']).to.equal('HLS')
220 expect(alternateEnclosure['@_default']).to.equal(true)
221
222 expect(alternateEnclosure['podcast:source']['@_uri']).to.contain('-master.m3u8')
223 expect(alternateEnclosure['podcast:source']['@_uri']).to.equal(enclosure['@_url'])
224 })
225
226 it('Should contain a valid podcast:socialInteract', async function () {
227 const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId })
228 expect(XMLValidator.validate(rss)).to.be.true
229
230 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
231 const xmlDoc = parser.parse(rss)
232
233 const item = xmlDoc.rss.channel.item
234 const socialInteract = item['podcast:socialInteract']
235 expect(socialInteract).to.exist
236 expect(socialInteract['@_protocol']).to.equal('activitypub')
237 expect(socialInteract['@_uri']).to.exist
238 expect(socialInteract['@_accountUrl']).to.exist
239 })
240
241 it('Should contain a valid support custom tags for plugins', async function () {
242 const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: userChannelId })
243 expect(XMLValidator.validate(rss)).to.be.true
244
245 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
246 const xmlDoc = parser.parse(rss)
247
248 const fooTag = xmlDoc.rss.channel.fooTag
249 expect(fooTag).to.exist
250 expect(fooTag['@_bar']).to.equal('baz')
251 expect(fooTag['#text']).to.equal(42)
252
253 const bizzBuzzItem = xmlDoc.rss.channel['biz:buzzItem']
254 expect(bizzBuzzItem).to.exist
255
256 let nestedTag = bizzBuzzItem.nestedTag
257 expect(nestedTag).to.exist
258 expect(nestedTag).to.equal('example nested tag')
259
260 const item = xmlDoc.rss.channel.item
261 const fizzTag = item.fizzTag
262 expect(fizzTag).to.exist
263 expect(fizzTag['@_bar']).to.equal('baz')
264 expect(fizzTag['#text']).to.equal(21)
265
266 const bizzBuzz = item['biz:buzz']
267 expect(bizzBuzz).to.exist
268
269 nestedTag = bizzBuzz.nestedTag
270 expect(nestedTag).to.exist
271 expect(nestedTag).to.equal('example nested tag')
272 })
273
274 it('Should contain a valid podcast:liveItem for live streams', async function () {
275 this.timeout(120000)
276
277 const { uuid } = await servers[0].live.create({
278 fields: {
279 name: 'live-0',
280 privacy: VideoPrivacy.PUBLIC,
281 channelId: rootChannelId,
282 permanentLive: false
283 }
284 })
285 liveId = uuid
286
287 const ffmpeg = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveId, copyCodecs: true, fixtureName: 'video_short.mp4' })
288 await servers[0].live.waitUntilPublished({ videoId: liveId })
289
290 const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId })
291 expect(XMLValidator.validate(rss)).to.be.true
292
293 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
294 const xmlDoc = parser.parse(rss)
295 const liveItem = xmlDoc.rss.channel['podcast:liveItem']
296 expect(liveItem.title).to.equal('live-0')
1ed1994f
AG
297 expect(liveItem.guid['@_isPermaLink']).to.equal(false)
298 expect(liveItem.guid['#text']).to.contain(`${uuid}_`)
cb0eda56
AG
299 expect(liveItem['@_status']).to.equal('live')
300
301 const enclosure = liveItem.enclosure
302 const alternateEnclosure = liveItem['podcast:alternateEnclosure']
303 expect(alternateEnclosure).to.exist
304 expect(alternateEnclosure['@_type']).to.equal('application/x-mpegURL')
305 expect(alternateEnclosure['@_title']).to.equal('HLS live stream')
306 expect(alternateEnclosure['@_default']).to.equal(true)
307
308 expect(alternateEnclosure['podcast:source']['@_uri']).to.contain('/master.m3u8')
309 expect(alternateEnclosure['podcast:source']['@_uri']).to.equal(enclosure['@_url'])
310
311 await stopFfmpeg(ffmpeg)
312
313 await servers[0].live.waitUntilEnded({ videoId: liveId })
314
315 await waitJobs(servers)
316 })
fe3a55b0 317 })
662fb3ab 318
cb0eda56 319 describe('JSON feed', function () {
57cfff78 320
cb0eda56
AG
321 it('Should contain a valid \'attachments\' object', async function () {
322 for (const server of servers) {
323 const json = await server.feed.getJSON({ feed: 'videos', ignoreCache: true })
324 const jsonObj = JSON.parse(json)
325 expect(jsonObj.items.length).to.be.equal(2)
326 expect(jsonObj.items[0].attachments).to.exist
327 expect(jsonObj.items[0].attachments.length).to.be.eq(1)
328 expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent')
329 expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910)
330 expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent')
331 }
332 })
57cfff78 333
cb0eda56 334 it('Should filter by account', async function () {
662fb3ab 335 {
cb0eda56 336 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: rootAccountId }, ignoreCache: true })
c1bc8ee4 337 const jsonObj = JSON.parse(json)
662fb3ab 338 expect(jsonObj.items.length).to.be.equal(1)
a1587156 339 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
cb0eda56 340 expect(jsonObj.items[0].author.name).to.equal('Main root channel')
662fb3ab
C
341 }
342
343 {
cb0eda56 344 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: userAccountId }, ignoreCache: true })
c1bc8ee4 345 const jsonObj = JSON.parse(json)
662fb3ab 346 expect(jsonObj.items.length).to.be.equal(1)
a1587156 347 expect(jsonObj.items[0].title).to.equal('user video')
cb0eda56 348 expect(jsonObj.items[0].author.name).to.equal('Main john channel')
662fb3ab 349 }
662fb3ab 350
cb0eda56
AG
351 for (const server of servers) {
352 {
353 const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'root@' + servers[0].host }, ignoreCache: true })
354 const jsonObj = JSON.parse(json)
355 expect(jsonObj.items.length).to.be.equal(1)
356 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
357 }
358
359 {
360 const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'john@' + servers[0].host }, ignoreCache: true })
361 const jsonObj = JSON.parse(json)
362 expect(jsonObj.items.length).to.be.equal(1)
363 expect(jsonObj.items[0].title).to.equal('user video')
364 }
365 }
366 })
662fb3ab 367
cb0eda56 368 it('Should filter by video channel', async function () {
662fb3ab 369 {
cb0eda56 370 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId }, ignoreCache: true })
c1bc8ee4 371 const jsonObj = JSON.parse(json)
662fb3ab 372 expect(jsonObj.items.length).to.be.equal(1)
a1587156 373 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
cb0eda56 374 expect(jsonObj.items[0].author.name).to.equal('Main root channel')
662fb3ab
C
375 }
376
377 {
cb0eda56 378 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: userChannelId }, ignoreCache: true })
c1bc8ee4 379 const jsonObj = JSON.parse(json)
662fb3ab 380 expect(jsonObj.items.length).to.be.equal(1)
a1587156 381 expect(jsonObj.items[0].title).to.equal('user video')
cb0eda56 382 expect(jsonObj.items[0].author.name).to.equal('Main john channel')
662fb3ab 383 }
97816649 384
cb0eda56
AG
385 for (const server of servers) {
386 {
387 const query = { videoChannelName: 'root_channel@' + servers[0].host }
388 const json = await server.feed.getJSON({ feed: 'videos', query, ignoreCache: true })
389 const jsonObj = JSON.parse(json)
390 expect(jsonObj.items.length).to.be.equal(1)
391 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
392 }
393
394 {
395 const query = { videoChannelName: 'john_channel@' + servers[0].host }
396 const json = await server.feed.getJSON({ feed: 'videos', query, ignoreCache: true })
397 const jsonObj = JSON.parse(json)
398 expect(jsonObj.items.length).to.be.equal(1)
399 expect(jsonObj.items[0].title).to.equal('user video')
400 }
401 }
402 })
97816649 403
cb0eda56
AG
404 it('Should correctly have videos feed with HLS only', async function () {
405 this.timeout(120000)
97816649 406
cb0eda56
AG
407 const json = await serverHLSOnly.feed.getJSON({ feed: 'videos', ignoreCache: true })
408 const jsonObj = JSON.parse(json)
409 expect(jsonObj.items.length).to.be.equal(1)
410 expect(jsonObj.items[0].attachments).to.exist
411 expect(jsonObj.items[0].attachments.length).to.be.eq(4)
7a5c3d77 412
cb0eda56
AG
413 for (let i = 0; i < 4; i++) {
414 expect(jsonObj.items[0].attachments[i].mime_type).to.be.eq('application/x-bittorrent')
415 expect(jsonObj.items[0].attachments[i].size_in_bytes).to.be.greaterThan(0)
416 expect(jsonObj.items[0].attachments[i].url).to.exist
7a5c3d77
C
417 }
418 })
7a5c3d77 419
cb0eda56
AG
420 it('Should not display waiting live videos', async function () {
421 const { uuid } = await servers[0].live.create({
422 fields: {
423 name: 'live',
424 privacy: VideoPrivacy.PUBLIC,
425 channelId: rootChannelId
426 }
427 })
428 liveId = uuid
7a5c3d77 429
cb0eda56
AG
430 const json = await servers[0].feed.getJSON({ feed: 'videos', ignoreCache: true })
431
432 const jsonObj = JSON.parse(json)
433 expect(jsonObj.items.length).to.be.equal(2)
434 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
435 expect(jsonObj.items[1].title).to.equal('user video')
436 })
7a5c3d77 437
cb0eda56
AG
438 it('Should display published live videos', async function () {
439 this.timeout(120000)
7a5c3d77 440
cb0eda56
AG
441 const ffmpeg = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveId, copyCodecs: true, fixtureName: 'video_short.mp4' })
442 await servers[0].live.waitUntilPublished({ videoId: liveId })
7a5c3d77 443
cb0eda56 444 const json = await servers[0].feed.getJSON({ feed: 'videos', ignoreCache: true })
7a5c3d77 445
cb0eda56
AG
446 const jsonObj = JSON.parse(json)
447 expect(jsonObj.items.length).to.be.equal(3)
448 expect(jsonObj.items[0].title).to.equal('live')
449 expect(jsonObj.items[1].title).to.equal('my super name for server 1')
450 expect(jsonObj.items[2].title).to.equal('user video')
7a5c3d77 451
cb0eda56
AG
452 await stopFfmpeg(ffmpeg)
453 })
5e1bd869 454
cb0eda56
AG
455 it('Should have the channel avatar as feed icon', async function () {
456 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId }, ignoreCache: true })
5e1bd869 457
cb0eda56
AG
458 const jsonObj = JSON.parse(json)
459 const imageUrl = jsonObj.icon
460 expect(imageUrl).to.include('/lazy-static/avatars/')
461 await makeRawRequest({ url: imageUrl, expectedStatus: HttpStatusCode.OK_200 })
462 })
5e1bd869 463 })
fe3a55b0
C
464 })
465
466 describe('Video comments feed', function () {
68b6fd21
C
467
468 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
fe3a55b0 469 for (const server of servers) {
41e74ec9 470 const json = await server.feed.getJSON({ feed: 'video-comments', ignoreCache: true })
fe3a55b0 471
c1bc8ee4 472 const jsonObj = JSON.parse(json)
fe3a55b0 473 expect(jsonObj.items.length).to.be.equal(2)
4393b255
C
474 expect(jsonObj.items[0].content_html).to.contain('<p>super comment 2</p>')
475 expect(jsonObj.items[1].content_html).to.contain('<p>super comment 1</p>')
fe3a55b0
C
476 }
477 })
1df8a4d7
C
478
479 it('Should not list comments from muted accounts or instances', async function () {
696d83fd
C
480 this.timeout(30000)
481
41e74ec9 482 const remoteHandle = 'root@' + servers[0].host
696d83fd 483
89d241a7 484 await servers[1].blocklist.addToServerBlocklist({ account: remoteHandle })
1df8a4d7
C
485
486 {
41e74ec9 487 const json = await servers[1].feed.getJSON({ feed: 'video-comments', ignoreCache: true })
c1bc8ee4 488 const jsonObj = JSON.parse(json)
1df8a4d7
C
489 expect(jsonObj.items.length).to.be.equal(0)
490 }
491
89d241a7 492 await servers[1].blocklist.removeFromServerBlocklist({ account: remoteHandle })
696d83fd
C
493
494 {
89d241a7 495 const videoUUID = (await servers[1].videos.quickUpload({ name: 'server 2' })).uuid
696d83fd 496 await waitJobs(servers)
89d241a7 497 await servers[0].comments.createThread({ videoId: videoUUID, text: 'super comment' })
696d83fd
C
498 await waitJobs(servers)
499
41e74ec9 500 const json = await servers[1].feed.getJSON({ feed: 'video-comments', ignoreCache: true })
c1bc8ee4 501 const jsonObj = JSON.parse(json)
696d83fd
C
502 expect(jsonObj.items.length).to.be.equal(3)
503 }
504
89d241a7 505 await servers[1].blocklist.addToMyBlocklist({ account: remoteHandle })
696d83fd
C
506
507 {
41e74ec9 508 const json = await servers[1].feed.getJSON({ feed: 'video-comments', ignoreCache: true })
c1bc8ee4 509 const jsonObj = JSON.parse(json)
696d83fd
C
510 expect(jsonObj.items.length).to.be.equal(2)
511 }
1df8a4d7 512 })
fe3a55b0
C
513 })
514
afff310e 515 describe('Video feed from my subscriptions', function () {
18490b07
C
516 let feeduserAccountId: number
517 let feeduserFeedToken: string
afff310e
RK
518
519 it('Should list no videos for a user with no videos and no subscriptions', async function () {
afff310e 520 const attr = { username: 'feeduser', password: 'password' }
89d241a7
C
521 await servers[0].users.create({ username: attr.username, password: attr.password })
522 const feeduserAccessToken = await servers[0].login.getAccessToken(attr)
afff310e
RK
523
524 {
89d241a7 525 const user = await servers[0].users.getMyInfo({ token: feeduserAccessToken })
afff310e
RK
526 feeduserAccountId = user.account.id
527 }
528
529 {
89d241a7 530 const token = await servers[0].users.getMyScopedTokens({ token: feeduserAccessToken })
afff310e
RK
531 feeduserFeedToken = token.feedToken
532 }
533
534 {
692ae8c3 535 const body = await servers[0].videos.listMySubscriptionVideos({ token: feeduserAccessToken })
2c27e704 536 expect(body.total).to.equal(0)
afff310e 537
c1bc8ee4 538 const query = { accountId: feeduserAccountId, token: feeduserFeedToken }
41e74ec9 539 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
c1bc8ee4 540 const jsonObj = JSON.parse(json)
afff310e
RK
541 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
542 }
543 })
544
18490b07 545 it('Should fail with an invalid token', async function () {
c1bc8ee4 546 const query = { accountId: feeduserAccountId, token: 'toto' }
41e74ec9 547 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403, ignoreCache: true })
18490b07
C
548 })
549
550 it('Should fail with a token of another user', async function () {
c1bc8ee4 551 const query = { accountId: feeduserAccountId, token: userFeedToken }
41e74ec9 552 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403, ignoreCache: true })
18490b07
C
553 })
554
afff310e 555 it('Should list no videos for a user with videos but no subscriptions', async function () {
692ae8c3 556 const body = await servers[0].videos.listMySubscriptionVideos({ token: userAccessToken })
2c27e704 557 expect(body.total).to.equal(0)
afff310e 558
c1bc8ee4 559 const query = { accountId: userAccountId, token: userFeedToken }
41e74ec9 560 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
c1bc8ee4 561 const jsonObj = JSON.parse(json)
18490b07 562 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
afff310e
RK
563 })
564
565 it('Should list self videos for a user with a subscription to themselves', async function () {
566 this.timeout(30000)
567
41e74ec9 568 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'john_channel@' + servers[0].host })
afff310e
RK
569 await waitJobs(servers)
570
571 {
692ae8c3 572 const body = await servers[0].videos.listMySubscriptionVideos({ token: userAccessToken })
2c27e704
C
573 expect(body.total).to.equal(1)
574 expect(body.data[0].name).to.equal('user video')
afff310e 575
41e74ec9
C
576 const query = { accountId: userAccountId, token: userFeedToken }
577 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
c1bc8ee4 578 const jsonObj = JSON.parse(json)
afff310e
RK
579 expect(jsonObj.items.length).to.be.equal(1) // subscribed to self, it should not list the instance's videos but list john's
580 }
581 })
582
583 it('Should list videos of a user\'s subscription', async function () {
584 this.timeout(30000)
585
41e74ec9 586 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@' + servers[0].host })
afff310e
RK
587 await waitJobs(servers)
588
589 {
692ae8c3 590 const body = await servers[0].videos.listMySubscriptionVideos({ token: userAccessToken })
7e0f50d6 591 expect(body.total).to.equal(2, 'there should be 2 videos part of the subscription')
afff310e 592
41e74ec9
C
593 const query = { accountId: userAccountId, token: userFeedToken }
594 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
c1bc8ee4 595 const jsonObj = JSON.parse(json)
afff310e
RK
596 expect(jsonObj.items.length).to.be.equal(2) // subscribed to root, it should not list the instance's videos but list root/john's
597 }
598 })
599
18490b07 600 it('Should renew the token, and so have an invalid old token', async function () {
89d241a7 601 await servers[0].users.renewMyScopedTokens({ token: userAccessToken })
18490b07 602
41e74ec9
C
603 const query = { accountId: userAccountId, token: userFeedToken }
604 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403, ignoreCache: true })
18490b07
C
605 })
606
607 it('Should succeed with the new token', async function () {
89d241a7 608 const token = await servers[0].users.getMyScopedTokens({ token: userAccessToken })
18490b07
C
609 userFeedToken = token.feedToken
610
41e74ec9
C
611 const query = { accountId: userAccountId, token: userFeedToken }
612 await servers[0].feed.getJSON({ feed: 'subscriptions', query, ignoreCache: true })
18490b07
C
613 })
614
afff310e
RK
615 })
616
7c3b7976 617 after(async function () {
cb0eda56
AG
618 await servers[0].plugins.uninstall({ npmName: 'peertube-plugin-test-podcast-custom-tags' })
619
97816649 620 await cleanupTests([ ...servers, serverHLSOnly ])
fe3a55b0
C
621 })
622})