]>
Commit | Line | Data |
---|---|---|
fe3a55b0 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | doubleFollow, | |
7 | flushAndRunMultipleServers, | |
8 | flushTests, | |
9 | getJSONfeed, | |
10 | getXMLfeed, | |
11 | killallServers, | |
12 | ServerInfo, | |
13 | setAccessTokensToServers, | |
3cd0734f | 14 | uploadVideo |
fe3a55b0 | 15 | } from '../utils' |
fe3a55b0 C |
16 | import * as libxmljs from 'libxmljs' |
17 | import { addVideoCommentThread } from '../utils/videos/video-comments' | |
3cd0734f | 18 | import { waitJobs } from '../utils/server/jobs' |
fe3a55b0 C |
19 | |
20 | chai.use(require('chai-xml')) | |
21 | chai.use(require('chai-json-schema')) | |
22 | chai.config.includeStack = true | |
23 | const expect = chai.expect | |
24 | ||
25 | describe('Test syndication feeds', () => { | |
26 | let servers: ServerInfo[] = [] | |
27 | ||
28 | before(async function () { | |
29 | this.timeout(120000) | |
30 | ||
31 | // Run servers | |
32 | servers = await flushAndRunMultipleServers(2) | |
33 | ||
34 | await setAccessTokensToServers(servers) | |
35 | await doubleFollow(servers[0], servers[1]) | |
36 | ||
37 | const videoAttributes = { | |
38 | name: 'my super name for server 1', | |
39 | description: 'my super description for server 1', | |
40 | fixture: 'video_short.webm' | |
41 | } | |
42 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
43 | const videoId = res.body.video.id | |
44 | ||
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') | |
47 | ||
3cd0734f | 48 | await waitJobs(servers) |
fe3a55b0 C |
49 | }) |
50 | ||
51 | describe('All feed', function () { | |
52 | ||
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() | |
57 | ||
58 | const atom = await getXMLfeed(servers[ 0 ].url, feed, 'atom') | |
59 | expect(atom.text).xml.to.be.valid() | |
60 | } | |
61 | }) | |
62 | ||
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' }) | |
67 | } | |
68 | }) | |
69 | }) | |
70 | ||
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') | |
81 | } | |
82 | }) | |
83 | ||
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') | |
94 | } | |
95 | }) | |
96 | }) | |
97 | ||
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') | |
102 | ||
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') | |
107 | } | |
108 | }) | |
109 | }) | |
110 | ||
111 | after(async function () { | |
112 | killallServers(servers) | |
113 | ||
114 | // Keep the logs if the test failed | |
115 | if (this['ok']) { | |
116 | await flushTests() | |
117 | } | |
118 | }) | |
119 | }) |