]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/feeds/feeds.ts
Use test wrapper exit function
[github/Chocobozzz/PeerTube.git] / server / tests / feeds / feeds.ts
CommitLineData
fe3a55b0
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
7c3b7976 6 cleanupTests,
662fb3ab 7 createUser,
fe3a55b0
C
8 doubleFollow,
9 flushAndRunMultipleServers,
10 flushTests,
662fb3ab 11 getJSONfeed, getMyUserInformation,
fe3a55b0
C
12 getXMLfeed,
13 killallServers,
14 ServerInfo,
15 setAccessTokensToServers,
662fb3ab 16 uploadVideo, userLogin
94565d52 17} from '../../../shared/extra-utils'
fe3a55b0 18import * as libxmljs from 'libxmljs'
94565d52
C
19import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
20import { waitJobs } from '../../../shared/extra-utils/server/jobs'
662fb3ab 21import { User } from '../../../shared/models/users'
fe3a55b0
C
22
23chai.use(require('chai-xml'))
24chai.use(require('chai-json-schema'))
25chai.config.includeStack = true
26const expect = chai.expect
27
28describe('Test syndication feeds', () => {
29 let servers: ServerInfo[] = []
662fb3ab
C
30 let userAccessToken: string
31 let rootAccountUUID: string
32 let rootChannelUUID: string
33 let userAccountUUID: string
34 let userChannelUUID: string
fe3a55b0
C
35
36 before(async function () {
37 this.timeout(120000)
38
39 // Run servers
40 servers = await flushAndRunMultipleServers(2)
41
42 await setAccessTokensToServers(servers)
43 await doubleFollow(servers[0], servers[1])
44
662fb3ab
C
45 {
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
fe3a55b0 50 }
fe3a55b0 51
662fb3ab
C
52 {
53 const attr = { username: 'john', password: 'password' }
1eddc9a7 54 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: attr.username, password: attr.password })
662fb3ab
C
55 userAccessToken = await userLogin(servers[0], attr)
56
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
61 }
62
63 {
64 await uploadVideo(servers[ 0 ].url, userAccessToken, { name: 'user video' })
65 }
66
67 {
68 const videoAttributes = {
69 name: 'my super name for server 1',
70 description: 'my super description for server 1',
71 fixture: 'video_short.webm'
72 }
73 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
74 const videoId = res.body.video.id
75
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')
78 }
fe3a55b0 79
3cd0734f 80 await waitJobs(servers)
fe3a55b0
C
81 })
82
83 describe('All feed', function () {
84
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()
89
90 const atom = await getXMLfeed(servers[ 0 ].url, feed, 'atom')
91 expect(atom.text).xml.to.be.valid()
92 }
93 })
94
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' })
99 }
100 })
101 })
102
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')
113 }
114 })
115
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)
662fb3ab 120 expect(jsonObj.items.length).to.be.equal(2)
fe3a55b0
C
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')
126 }
127 })
662fb3ab
C
128
129 it('Should filter by account', async function () {
130 for (const server of servers) {
131 {
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')
137 }
138
139 {
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')
145 }
146 }
147
148 {
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')
153 }
154
155 {
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')
160 }
161 })
162
163 it('Should filter by video channel', async function () {
164 for (const server of servers) {
165 {
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')
171 }
172
173 {
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')
179 }
180 }
181
182 {
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')
187 }
188
189 {
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')
194 }
195 })
fe3a55b0
C
196 })
197
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')
202
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')
207 }
208 })
209 })
210
7c3b7976
C
211 after(async function () {
212 await cleanupTests(servers)
fe3a55b0
C
213 })
214})