1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
8 flushAndRunMultipleServers,
10 getJSONfeed, getMyUserInformation,
14 setAccessTokensToServers,
15 uploadVideo, userLogin
17 import * as libxmljs from 'libxmljs'
18 import { addVideoCommentThread } from '../utils/videos/video-comments'
19 import { waitJobs } from '../utils/server/jobs'
20 import { User } from '../../../shared/models/users'
22 chai.use(require('chai-xml'))
23 chai.use(require('chai-json-schema'))
24 chai.config.includeStack = true
25 const expect = chai.expect
27 describe('Test syndication feeds', () => {
28 let servers: ServerInfo[] = []
29 let userAccessToken: string
30 let rootAccountUUID: string
31 let rootChannelUUID: string
32 let userAccountUUID: string
33 let userChannelUUID: string
35 before(async function () {
39 servers = await flushAndRunMultipleServers(2)
41 await setAccessTokensToServers(servers)
42 await doubleFollow(servers[0], servers[1])
45 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
46 const user: User = res.body
47 rootAccountUUID = user.account.uuid
48 rootChannelUUID = user.videoChannels[0].uuid
52 const attr = { username: 'john', password: 'password' }
53 await createUser(servers[0].url, servers[0].accessToken, attr.username, attr.password)
54 userAccessToken = await userLogin(servers[0], attr)
56 const res = await getMyUserInformation(servers[0].url, userAccessToken)
57 const user: User = res.body
58 userAccountUUID = user.account.uuid
59 userChannelUUID = user.videoChannels[0].uuid
63 await uploadVideo(servers[ 0 ].url, userAccessToken, { name: 'user video' })
67 const videoAttributes = {
68 name: 'my super name for server 1',
69 description: 'my super description for server 1',
70 fixture: 'video_short.webm'
72 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
73 const videoId = res.body.video.id
75 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, 'super comment 1')
76 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, 'super comment 2')
79 await waitJobs(servers)
82 describe('All feed', function () {
84 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
85 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
86 const rss = await getXMLfeed(servers[ 0 ].url, feed)
87 expect(rss.text).xml.to.be.valid()
89 const atom = await getXMLfeed(servers[ 0 ].url, feed, 'atom')
90 expect(atom.text).xml.to.be.valid()
94 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
95 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
96 const json = await getJSONfeed(servers[ 0 ].url, feed)
97 expect(JSON.parse(json.text)).to.be.jsonSchema({ 'type': 'object' })
102 describe('Videos feed', function () {
103 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
104 for (const server of servers) {
105 const rss = await getXMLfeed(server.url, 'videos')
106 const xmlDoc = libxmljs.parseXmlString(rss.text)
107 const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure')
108 expect(xmlEnclosure).to.exist
109 expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent')
110 expect(xmlEnclosure.attr('length').value()).to.be.equal('218910')
111 expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent')
115 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
116 for (const server of servers) {
117 const json = await getJSONfeed(server.url, 'videos')
118 const jsonObj = JSON.parse(json.text)
119 expect(jsonObj.items.length).to.be.equal(2)
120 expect(jsonObj.items[ 0 ].attachments).to.exist
121 expect(jsonObj.items[ 0 ].attachments.length).to.be.eq(1)
122 expect(jsonObj.items[ 0 ].attachments[ 0 ].mime_type).to.be.eq('application/x-bittorrent')
123 expect(jsonObj.items[ 0 ].attachments[ 0 ].size_in_bytes).to.be.eq(218910)
124 expect(jsonObj.items[ 0 ].attachments[ 0 ].url).to.contain('720.torrent')
128 it('Should filter by account', async function () {
129 for (const server of servers) {
131 const json = await getJSONfeed(server.url, 'videos', { accountId: rootAccountUUID })
132 const jsonObj = JSON.parse(json.text)
133 expect(jsonObj.items.length).to.be.equal(1)
134 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
135 expect(jsonObj.items[ 0 ].author.name).to.equal('root')
139 const json = await getJSONfeed(server.url, 'videos', { accountId: userAccountUUID })
140 const jsonObj = JSON.parse(json.text)
141 expect(jsonObj.items.length).to.be.equal(1)
142 expect(jsonObj.items[ 0 ].title).to.equal('user video')
143 expect(jsonObj.items[ 0 ].author.name).to.equal('john')
148 const json = await getJSONfeed(servers[0].url, 'videos', { accountName: 'root' })
149 const jsonObj = JSON.parse(json.text)
150 expect(jsonObj.items.length).to.be.equal(1)
151 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
155 const json = await getJSONfeed(servers[0].url, 'videos', { accountName: 'john' })
156 const jsonObj = JSON.parse(json.text)
157 expect(jsonObj.items.length).to.be.equal(1)
158 expect(jsonObj.items[ 0 ].title).to.equal('user video')
162 it('Should filter by video channel', async function () {
163 for (const server of servers) {
165 const json = await getJSONfeed(server.url, 'videos', { videoChannelId: rootChannelUUID })
166 const jsonObj = JSON.parse(json.text)
167 expect(jsonObj.items.length).to.be.equal(1)
168 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
169 expect(jsonObj.items[ 0 ].author.name).to.equal('root')
173 const json = await getJSONfeed(server.url, 'videos', { videoChannelId: userChannelUUID })
174 const jsonObj = JSON.parse(json.text)
175 expect(jsonObj.items.length).to.be.equal(1)
176 expect(jsonObj.items[ 0 ].title).to.equal('user video')
177 expect(jsonObj.items[ 0 ].author.name).to.equal('john')
182 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelName: 'root_channel' })
183 const jsonObj = JSON.parse(json.text)
184 expect(jsonObj.items.length).to.be.equal(1)
185 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
189 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelName: 'john_channel' })
190 const jsonObj = JSON.parse(json.text)
191 expect(jsonObj.items.length).to.be.equal(1)
192 expect(jsonObj.items[ 0 ].title).to.equal('user video')
197 describe('Video comments feed', function () {
198 it('Should contain valid comments (covers JSON feed 1.0 endpoint)', async function () {
199 for (const server of servers) {
200 const json = await getJSONfeed(server.url, 'video-comments')
202 const jsonObj = JSON.parse(json.text)
203 expect(jsonObj.items.length).to.be.equal(2)
204 expect(jsonObj.items[ 0 ].html_content).to.equal('super comment 2')
205 expect(jsonObj.items[ 1 ].html_content).to.equal('super comment 1')
210 after(async function () {
211 killallServers(servers)
213 // Keep the logs if the test failed