]>
Commit | Line | Data |
---|---|---|
fe3a55b0 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
662fb3ab | 6 | createUser, |
fe3a55b0 C |
7 | doubleFollow, |
8 | flushAndRunMultipleServers, | |
9 | flushTests, | |
662fb3ab | 10 | getJSONfeed, getMyUserInformation, |
fe3a55b0 C |
11 | getXMLfeed, |
12 | killallServers, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
662fb3ab | 15 | uploadVideo, userLogin |
9639bd17 | 16 | } from '../../../shared/utils' |
fe3a55b0 | 17 | import * as libxmljs from 'libxmljs' |
9639bd17 | 18 | import { addVideoCommentThread } from '../../../shared/utils/videos/video-comments' |
19 | import { waitJobs } from '../../../shared/utils/server/jobs' | |
662fb3ab | 20 | import { User } from '../../../shared/models/users' |
fe3a55b0 C |
21 | |
22 | chai.use(require('chai-xml')) | |
23 | chai.use(require('chai-json-schema')) | |
24 | chai.config.includeStack = true | |
25 | const expect = chai.expect | |
26 | ||
27 | describe('Test syndication feeds', () => { | |
28 | let servers: ServerInfo[] = [] | |
662fb3ab C |
29 | let userAccessToken: string |
30 | let rootAccountUUID: string | |
31 | let rootChannelUUID: string | |
32 | let userAccountUUID: string | |
33 | let userChannelUUID: string | |
fe3a55b0 C |
34 | |
35 | before(async function () { | |
36 | this.timeout(120000) | |
37 | ||
38 | // Run servers | |
39 | servers = await flushAndRunMultipleServers(2) | |
40 | ||
41 | await setAccessTokensToServers(servers) | |
42 | await doubleFollow(servers[0], servers[1]) | |
43 | ||
662fb3ab C |
44 | { |
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 | |
fe3a55b0 | 49 | } |
fe3a55b0 | 50 | |
662fb3ab C |
51 | { |
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) | |
55 | ||
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 | |
60 | } | |
61 | ||
62 | { | |
63 | await uploadVideo(servers[ 0 ].url, userAccessToken, { name: 'user video' }) | |
64 | } | |
65 | ||
66 | { | |
67 | const videoAttributes = { | |
68 | name: 'my super name for server 1', | |
69 | description: 'my super description for server 1', | |
70 | fixture: 'video_short.webm' | |
71 | } | |
72 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) | |
73 | const videoId = res.body.video.id | |
74 | ||
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') | |
77 | } | |
fe3a55b0 | 78 | |
3cd0734f | 79 | await waitJobs(servers) |
fe3a55b0 C |
80 | }) |
81 | ||
82 | describe('All feed', function () { | |
83 | ||
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() | |
88 | ||
89 | const atom = await getXMLfeed(servers[ 0 ].url, feed, 'atom') | |
90 | expect(atom.text).xml.to.be.valid() | |
91 | } | |
92 | }) | |
93 | ||
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' }) | |
98 | } | |
99 | }) | |
100 | }) | |
101 | ||
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') | |
112 | } | |
113 | }) | |
114 | ||
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) | |
662fb3ab | 119 | expect(jsonObj.items.length).to.be.equal(2) |
fe3a55b0 C |
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') | |
125 | } | |
126 | }) | |
662fb3ab C |
127 | |
128 | it('Should filter by account', async function () { | |
129 | for (const server of servers) { | |
130 | { | |
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') | |
136 | } | |
137 | ||
138 | { | |
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') | |
144 | } | |
145 | } | |
146 | ||
147 | { | |
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') | |
152 | } | |
153 | ||
154 | { | |
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') | |
159 | } | |
160 | }) | |
161 | ||
162 | it('Should filter by video channel', async function () { | |
163 | for (const server of servers) { | |
164 | { | |
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') | |
170 | } | |
171 | ||
172 | { | |
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') | |
178 | } | |
179 | } | |
180 | ||
181 | { | |
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') | |
186 | } | |
187 | ||
188 | { | |
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') | |
193 | } | |
194 | }) | |
fe3a55b0 C |
195 | }) |
196 | ||
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') | |
201 | ||
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') | |
206 | } | |
207 | }) | |
208 | }) | |
209 | ||
210 | after(async function () { | |
211 | killallServers(servers) | |
212 | ||
213 | // Keep the logs if the test failed | |
214 | if (this['ok']) { | |
215 | await flushTests() | |
216 | } | |
217 | }) | |
218 | }) |