1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushAndRunMultipleServers,
13 setAccessTokensToServers,
16 import * as libxmljs from 'libxmljs'
17 import { addVideoCommentThread } from '../utils/videos/video-comments'
18 import { waitJobs } from '../utils/server/jobs'
20 chai.use(require('chai-xml'))
21 chai.use(require('chai-json-schema'))
22 chai.config.includeStack = true
23 const expect = chai.expect
25 describe('Test syndication feeds', () => {
26 let servers: ServerInfo[] = []
28 before(async function () {
32 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers)
35 await doubleFollow(servers[0], servers[1])
37 const videoAttributes = {
38 name: 'my super name for server 1',
39 description: 'my super description for server 1',
40 fixture: 'video_short.webm'
42 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
43 const videoId = res.body.video.id
45 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1')
46 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
48 await waitJobs(servers)
51 describe('All feed', function () {
53 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
54 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
55 const rss = await getXMLfeed(servers[ 0 ].url, feed)
56 expect(rss.text).xml.to.be.valid()
58 const atom = await getXMLfeed(servers[ 0 ].url, feed, 'atom')
59 expect(atom.text).xml.to.be.valid()
63 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
64 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
65 const json = await getJSONfeed(servers[ 0 ].url, feed)
66 expect(JSON.parse(json.text)).to.be.jsonSchema({ 'type': 'object' })
71 describe('Videos feed', function () {
72 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
73 for (const server of servers) {
74 const rss = await getXMLfeed(server.url, 'videos')
75 const xmlDoc = libxmljs.parseXmlString(rss.text)
76 const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure')
77 expect(xmlEnclosure).to.exist
78 expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent')
79 expect(xmlEnclosure.attr('length').value()).to.be.equal('218910')
80 expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent')
84 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
85 for (const server of servers) {
86 const json = await getJSONfeed(server.url, 'videos')
87 const jsonObj = JSON.parse(json.text)
88 expect(jsonObj.items.length).to.be.equal(1)
89 expect(jsonObj.items[ 0 ].attachments).to.exist
90 expect(jsonObj.items[ 0 ].attachments.length).to.be.eq(1)
91 expect(jsonObj.items[ 0 ].attachments[ 0 ].mime_type).to.be.eq('application/x-bittorrent')
92 expect(jsonObj.items[ 0 ].attachments[ 0 ].size_in_bytes).to.be.eq(218910)
93 expect(jsonObj.items[ 0 ].attachments[ 0 ].url).to.contain('720.torrent')
98 describe('Video comments feed', function () {
99 it('Should contain valid comments (covers JSON feed 1.0 endpoint)', async function () {
100 for (const server of servers) {
101 const json = await getJSONfeed(server.url, 'video-comments')
103 const jsonObj = JSON.parse(json.text)
104 expect(jsonObj.items.length).to.be.equal(2)
105 expect(jsonObj.items[ 0 ].html_content).to.equal('super comment 2')
106 expect(jsonObj.items[ 1 ].html_content).to.equal('super comment 1')
111 after(async function () {
112 killallServers(servers)
114 // Keep the logs if the test failed