1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
9 flushAndRunMultipleServers,
11 getJSONfeed, getMyUserInformation,
15 setAccessTokensToServers,
16 uploadVideo, userLogin
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'
23 chai.use(require('chai-xml'))
24 chai.use(require('chai-json-schema'))
25 chai.config.includeStack = true
26 const expect = chai.expect
28 describe('Test syndication feeds', () => {
29 let servers: ServerInfo[] = []
30 let userAccessToken: string
31 let rootAccountUUID: string
32 let rootChannelUUID: string
33 let userAccountUUID: string
34 let userChannelUUID: string
36 before(async function () {
40 servers = await flushAndRunMultipleServers(2)
42 await setAccessTokensToServers(servers)
43 await doubleFollow(servers[0], servers[1])
46 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
47 const user: User = res.body
48 rootAccountUUID = user.account.uuid
49 rootChannelUUID = user.videoChannels[0].uuid
53 const attr = { username: 'john', password: 'password' }
54 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: attr.username, password: attr.password })
55 userAccessToken = await userLogin(servers[0], attr)
57 const res = await getMyUserInformation(servers[0].url, userAccessToken)
58 const user: User = res.body
59 userAccountUUID = user.account.uuid
60 userChannelUUID = user.videoChannels[0].uuid
64 await uploadVideo(servers[ 0 ].url, userAccessToken, { name: 'user video' })
68 const videoAttributes = {
69 name: 'my super name for server 1',
70 description: 'my super description for server 1',
71 fixture: 'video_short.webm'
73 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
74 const videoId = res.body.video.id
76 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, 'super comment 1')
77 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, 'super comment 2')
80 await waitJobs(servers)
83 describe('All feed', function () {
85 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
86 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
87 const rss = await getXMLfeed(servers[ 0 ].url, feed)
88 expect(rss.text).xml.to.be.valid()
90 const atom = await getXMLfeed(servers[ 0 ].url, feed, 'atom')
91 expect(atom.text).xml.to.be.valid()
95 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
96 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
97 const json = await getJSONfeed(servers[ 0 ].url, feed)
98 expect(JSON.parse(json.text)).to.be.jsonSchema({ 'type': 'object' })
103 describe('Videos feed', function () {
104 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
105 for (const server of servers) {
106 const rss = await getXMLfeed(server.url, 'videos')
107 const xmlDoc = libxmljs.parseXmlString(rss.text)
108 const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure')
109 expect(xmlEnclosure).to.exist
110 expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent')
111 expect(xmlEnclosure.attr('length').value()).to.be.equal('218910')
112 expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent')
116 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
117 for (const server of servers) {
118 const json = await getJSONfeed(server.url, 'videos')
119 const jsonObj = JSON.parse(json.text)
120 expect(jsonObj.items.length).to.be.equal(2)
121 expect(jsonObj.items[ 0 ].attachments).to.exist
122 expect(jsonObj.items[ 0 ].attachments.length).to.be.eq(1)
123 expect(jsonObj.items[ 0 ].attachments[ 0 ].mime_type).to.be.eq('application/x-bittorrent')
124 expect(jsonObj.items[ 0 ].attachments[ 0 ].size_in_bytes).to.be.eq(218910)
125 expect(jsonObj.items[ 0 ].attachments[ 0 ].url).to.contain('720.torrent')
129 it('Should filter by account', async function () {
130 for (const server of servers) {
132 const json = await getJSONfeed(server.url, 'videos', { accountId: rootAccountUUID })
133 const jsonObj = JSON.parse(json.text)
134 expect(jsonObj.items.length).to.be.equal(1)
135 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
136 expect(jsonObj.items[ 0 ].author.name).to.equal('root')
140 const json = await getJSONfeed(server.url, 'videos', { accountId: userAccountUUID })
141 const jsonObj = JSON.parse(json.text)
142 expect(jsonObj.items.length).to.be.equal(1)
143 expect(jsonObj.items[ 0 ].title).to.equal('user video')
144 expect(jsonObj.items[ 0 ].author.name).to.equal('john')
149 const json = await getJSONfeed(servers[0].url, 'videos', { accountName: 'root' })
150 const jsonObj = JSON.parse(json.text)
151 expect(jsonObj.items.length).to.be.equal(1)
152 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
156 const json = await getJSONfeed(servers[0].url, 'videos', { accountName: 'john' })
157 const jsonObj = JSON.parse(json.text)
158 expect(jsonObj.items.length).to.be.equal(1)
159 expect(jsonObj.items[ 0 ].title).to.equal('user video')
163 it('Should filter by video channel', async function () {
164 for (const server of servers) {
166 const json = await getJSONfeed(server.url, 'videos', { videoChannelId: rootChannelUUID })
167 const jsonObj = JSON.parse(json.text)
168 expect(jsonObj.items.length).to.be.equal(1)
169 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
170 expect(jsonObj.items[ 0 ].author.name).to.equal('root')
174 const json = await getJSONfeed(server.url, 'videos', { videoChannelId: userChannelUUID })
175 const jsonObj = JSON.parse(json.text)
176 expect(jsonObj.items.length).to.be.equal(1)
177 expect(jsonObj.items[ 0 ].title).to.equal('user video')
178 expect(jsonObj.items[ 0 ].author.name).to.equal('john')
183 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelName: 'root_channel' })
184 const jsonObj = JSON.parse(json.text)
185 expect(jsonObj.items.length).to.be.equal(1)
186 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
190 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelName: 'john_channel' })
191 const jsonObj = JSON.parse(json.text)
192 expect(jsonObj.items.length).to.be.equal(1)
193 expect(jsonObj.items[ 0 ].title).to.equal('user video')
198 describe('Video comments feed', function () {
199 it('Should contain valid comments (covers JSON feed 1.0 endpoint)', async function () {
200 for (const server of servers) {
201 const json = await getJSONfeed(server.url, 'video-comments')
203 const jsonObj = JSON.parse(json.text)
204 expect(jsonObj.items.length).to.be.equal(2)
205 expect(jsonObj.items[ 0 ].html_content).to.equal('super comment 2')
206 expect(jsonObj.items[ 1 ].html_content).to.equal('super comment 1')
211 after(async function () {
212 await cleanupTests(servers)