1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
9 flushAndRunMultipleServers,
14 setAccessTokensToServers,
17 } from '../../../shared/extra-utils'
18 import * as libxmljs from 'libxmljs'
19 import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
20 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
21 import { User } from '../../../shared/models/users'
22 import { VideoPrivacy } from '@shared/models'
23 import { addAccountToServerBlocklist } from '@shared/extra-utils/users/blocklist'
25 chai.use(require('chai-xml'))
26 chai.use(require('chai-json-schema'))
27 chai.config.includeStack = true
28 const expect = chai.expect
30 describe('Test syndication feeds', () => {
31 let servers: ServerInfo[] = []
32 let userAccessToken: string
33 let rootAccountId: number
34 let rootChannelId: number
35 let userAccountId: number
36 let userChannelId: number
38 before(async function () {
42 servers = await flushAndRunMultipleServers(2)
44 await setAccessTokensToServers(servers)
45 await doubleFollow(servers[0], servers[1])
48 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
49 const user: User = res.body
50 rootAccountId = user.account.id
51 rootChannelId = user.videoChannels[0].id
55 const attr = { username: 'john', password: 'password' }
56 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
57 userAccessToken = await userLogin(servers[0], attr)
59 const res = await getMyUserInformation(servers[0].url, userAccessToken)
60 const user: User = res.body
61 userAccountId = user.account.id
62 userChannelId = user.videoChannels[0].id
66 await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' })
70 const videoAttributes = {
71 name: 'my super name for server 1',
72 description: 'my super description for server 1',
73 fixture: 'video_short.webm'
75 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
76 const videoId = res.body.video.id
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')
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
87 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video')
90 await waitJobs(servers)
93 describe('All feed', function () {
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' ]) {
97 const rss = await getXMLfeed(servers[0].url, feed)
98 expect(rss.text).xml.to.be.valid()
100 const atom = await getXMLfeed(servers[0].url, feed, 'atom')
101 expect(atom.text).xml.to.be.valid()
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' ]) {
107 const json = await getJSONfeed(servers[0].url, feed)
108 expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' })
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')
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)
130 expect(jsonObj.items.length).to.be.equal(2)
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')
139 it('Should filter by account', async function () {
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)
144 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
145 expect(jsonObj.items[0].author.name).to.equal('root')
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)
152 expect(jsonObj.items[0].title).to.equal('user video')
153 expect(jsonObj.items[0].author.name).to.equal('john')
156 for (const server of servers) {
158 const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port })
159 const jsonObj = JSON.parse(json.text)
160 expect(jsonObj.items.length).to.be.equal(1)
161 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
165 const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port })
166 const jsonObj = JSON.parse(json.text)
167 expect(jsonObj.items.length).to.be.equal(1)
168 expect(jsonObj.items[0].title).to.equal('user video')
173 it('Should filter by video channel', async function () {
175 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId })
176 const jsonObj = JSON.parse(json.text)
177 expect(jsonObj.items.length).to.be.equal(1)
178 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
179 expect(jsonObj.items[0].author.name).to.equal('root')
183 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId })
184 const jsonObj = JSON.parse(json.text)
185 expect(jsonObj.items.length).to.be.equal(1)
186 expect(jsonObj.items[0].title).to.equal('user video')
187 expect(jsonObj.items[0].author.name).to.equal('john')
190 for (const server of servers) {
192 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port })
193 const jsonObj = JSON.parse(json.text)
194 expect(jsonObj.items.length).to.be.equal(1)
195 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
199 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port })
200 const jsonObj = JSON.parse(json.text)
201 expect(jsonObj.items.length).to.be.equal(1)
202 expect(jsonObj.items[0].title).to.equal('user video')
208 describe('Video comments feed', function () {
210 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
211 for (const server of servers) {
212 const json = await getJSONfeed(server.url, 'video-comments')
214 const jsonObj = JSON.parse(json.text)
215 expect(jsonObj.items.length).to.be.equal(2)
216 expect(jsonObj.items[0].html_content).to.equal('super comment 2')
217 expect(jsonObj.items[1].html_content).to.equal('super comment 1')
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)
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)
233 after(async function () {
234 await cleanupTests(servers)