1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
12 setAccessTokensToServers,
14 flushAndRunMultipleServers,
17 import { runServer } from '../../utils/server/servers'
18 import { join } from 'path'
19 import * as libxmljs from 'libxmljs'
21 chai.use(require('chai-xml'))
22 chai.use(require('chai-json-schema'))
23 chai.config.includeStack = true
24 const expect = chai.expect
26 describe('Test instance-wide syndication feeds', () => {
27 let servers: ServerInfo[] = []
29 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
35 await setAccessTokensToServers(servers)
39 const videoAttributes = {
40 name: 'my super name for server 1',
41 description: 'my super description for server 1',
42 fixture: 'video_short.webm'
44 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
49 it('should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
50 const rss = await getXMLfeed(servers[0].url)
51 expect(rss.text).xml.to.be.valid()
53 const atom = await getXMLfeed(servers[0].url, 'atom')
54 expect(atom.text).xml.to.be.valid()
57 it('should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
58 const json = await getJSONfeed(servers[0].url)
59 expect(JSON.parse(json.text)).to.be.jsonSchema({ 'type': 'object' })
62 it('should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
63 const rss = await getXMLfeed(servers[0].url)
64 const xmlDoc = libxmljs.parseXmlString(rss.text)
65 const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure')
66 expect(xmlEnclosure).to.exist
67 expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent')
68 expect(xmlEnclosure.attr('length').value()).to.be.equal('218910')
69 expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent')
72 it('should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
73 const json = await getJSONfeed(servers[0].url)
74 const jsonObj = JSON.parse(json.text)
75 expect(jsonObj.items.length).to.be.equal(1)
76 expect(jsonObj.items[0].attachments).to.exist
77 expect(jsonObj.items[0].attachments.length).to.be.eq(1)
78 expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent')
79 expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910)
80 expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent')
83 after(async function () {
84 killallServers(servers)
86 // Keep the logs if the test failed