]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as request from 'supertest' | |
4 | import 'mocha' | |
5 | import * as chai from 'chai' | |
6 | const expect = chai.expect | |
7 | ||
8 | import { | |
9 | ServerInfo, | |
10 | flushTests, | |
11 | runServer, | |
12 | makePutBodyRequest, | |
13 | setAccessTokensToServers, | |
14 | killallServers, | |
15 | getMyUserInformation, | |
16 | makePostBodyRequest, | |
17 | getVideoChannelsList, | |
18 | createUser, | |
19 | getUserAccessToken | |
20 | } from '../../utils' | |
21 | ||
22 | describe('Test videos API validator', function () { | |
23 | const path = '/api/v1/videos/channels' | |
24 | let server: ServerInfo | |
25 | let channelId: number | |
26 | let accessTokenUser: string | |
27 | ||
28 | // --------------------------------------------------------------- | |
29 | ||
30 | before(async function () { | |
31 | this.timeout(20000) | |
32 | ||
33 | await flushTests() | |
34 | ||
35 | server = await runServer(1) | |
36 | ||
37 | await setAccessTokensToServers([ server ]) | |
38 | ||
39 | const res = await getMyUserInformation(server.url, server.accessToken) | |
40 | channelId = res.body.videoChannels[0].id | |
41 | ||
42 | const user = { | |
43 | username: 'fake', | |
44 | password: 'fake_password' | |
45 | } | |
46 | await createUser(server.url, server.accessToken, user.username, user.password) | |
47 | ||
48 | accessTokenUser = await getUserAccessToken(server, user) | |
49 | }) | |
50 | ||
51 | describe('When listing a video channels', function () { | |
52 | it('Should fail with a bad start pagination', async function () { | |
53 | await request(server.url) | |
54 | .get(path) | |
55 | .query({ start: 'hello' }) | |
56 | .set('Accept', 'application/json') | |
57 | .expect(400) | |
58 | }) | |
59 | ||
60 | it('Should fail with a bad count pagination', async function () { | |
61 | await request(server.url) | |
62 | .get(path) | |
63 | .query({ count: 'hello' }) | |
64 | .set('Accept', 'application/json') | |
65 | .expect(400) | |
66 | }) | |
67 | ||
68 | it('Should fail with an incorrect sort', async function () { | |
69 | await request(server.url) | |
70 | .get(path) | |
71 | .query({ sort: 'hello' }) | |
72 | .set('Accept', 'application/json') | |
73 | .expect(400) | |
74 | }) | |
75 | }) | |
76 | ||
77 | describe('When listing author video channels', function () { | |
78 | it('Should fail with bad author', async function () { | |
79 | const path = '/api/v1/videos/authors/hello/channels' | |
80 | ||
81 | await request(server.url) | |
82 | .get(path) | |
83 | .set('Accept', 'application/json') | |
84 | .expect(400) | |
85 | }) | |
86 | ||
87 | it('Should fail with a unknown author', async function () { | |
88 | const path = '/api/v1/videos/authors/156/channels' | |
89 | ||
90 | await request(server.url) | |
91 | .get(path) | |
92 | .set('Accept', 'application/json') | |
93 | .expect(404) | |
94 | }) | |
95 | }) | |
96 | ||
97 | describe('When adding a video channel', function () { | |
98 | ||
99 | it('Should fail with a non authenticated user', async function () { | |
100 | const fields = { | |
101 | name: 'hello', | |
102 | description: 'super description' | |
103 | } | |
104 | await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 }) | |
105 | }) | |
106 | ||
107 | it('Should fail with nothing', async function () { | |
108 | const fields = {} | |
109 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
110 | }) | |
111 | ||
112 | it('Should fail without name', async function () { | |
113 | const fields = { | |
114 | description: 'super description' | |
115 | } | |
116 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
117 | }) | |
118 | ||
119 | it('Should fail with a long name', async function () { | |
120 | const fields = { | |
121 | name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + | |
122 | 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long', | |
123 | description: 'super description' | |
124 | } | |
125 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
126 | }) | |
127 | ||
128 | it('Should fail with a long description', async function () { | |
129 | const fields = { | |
130 | name: 'hello', | |
131 | description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + | |
132 | 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' + | |
133 | 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + | |
134 | 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description' | |
135 | } | |
136 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
137 | }) | |
138 | ||
139 | it('Should succeed with the correct parameters', async function () { | |
140 | const fields = { | |
141 | name: 'hello', | |
142 | description: 'super description' | |
143 | } | |
144 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
145 | }) | |
146 | }) | |
147 | ||
148 | describe('When updating a video channel', function () { | |
149 | let videoChannelId | |
150 | ||
151 | before(async function () { | |
152 | const res = await getVideoChannelsList(server.url, 0, 1) | |
153 | videoChannelId = res.body.data[0].id | |
154 | }) | |
155 | ||
156 | it('Should fail with a non authenticated user', async function () { | |
157 | const fields = { | |
158 | name: 'hello', | |
159 | description: 'super description' | |
160 | } | |
161 | await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 }) | |
162 | }) | |
163 | ||
164 | it('Should fail with another authenticated user', async function () { | |
165 | const fields = { | |
166 | name: 'hello', | |
167 | description: 'super description' | |
168 | } | |
169 | await makePutBodyRequest({ | |
170 | url: server.url, | |
171 | path: path + '/' + videoChannelId, | |
172 | token: accessTokenUser, | |
173 | fields, | |
174 | statusCodeExpected: 403 | |
175 | }) | |
176 | }) | |
177 | ||
178 | it('Should fail with a long name', async function () { | |
179 | const fields = { | |
180 | name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + | |
181 | 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long', | |
182 | description: 'super description' | |
183 | } | |
184 | await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) | |
185 | }) | |
186 | ||
187 | it('Should fail with a long description', async function () { | |
188 | const fields = { | |
189 | name: 'hello', | |
190 | description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + | |
191 | 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' + | |
192 | 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + | |
193 | 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description' | |
194 | } | |
195 | await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) | |
196 | }) | |
197 | ||
198 | it('Should succeed with the correct parameters', async function () { | |
199 | const fields = { | |
200 | name: 'hello 2', | |
201 | description: 'super description 2' | |
202 | } | |
203 | await makePutBodyRequest({ | |
204 | url: server.url, | |
205 | path: path + '/' + videoChannelId, | |
206 | token: server.accessToken, | |
207 | fields, | |
208 | statusCodeExpected: 204 | |
209 | }) | |
210 | }) | |
211 | }) | |
212 | ||
213 | describe('When getting a video channel', function () { | |
214 | let videoChannelId: number | |
215 | ||
216 | before(async function () { | |
217 | const res = await getVideoChannelsList(server.url, 0, 1) | |
218 | videoChannelId = res.body.data[0].id | |
219 | }) | |
220 | ||
221 | it('Should return the list of the video channels with nothing', async function () { | |
222 | const res = await request(server.url) | |
223 | .get(path) | |
224 | .set('Accept', 'application/json') | |
225 | .expect(200) | |
226 | .expect('Content-Type', /json/) | |
227 | ||
228 | expect(res.body.data).to.be.an('array') | |
229 | }) | |
230 | ||
231 | it('Should fail without a correct uuid', async function () { | |
232 | await request(server.url) | |
233 | .get(path + '/coucou') | |
234 | .set('Accept', 'application/json') | |
235 | .expect(400) | |
236 | }) | |
237 | ||
238 | it('Should return 404 with an incorrect video channel', async function () { | |
239 | await request(server.url) | |
240 | .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06') | |
241 | .set('Accept', 'application/json') | |
242 | .expect(404) | |
243 | }) | |
244 | ||
245 | it('Should succeed with the correct parameters', async function () { | |
246 | await request(server.url) | |
247 | .get(path + '/' + videoChannelId) | |
248 | .set('Accept', 'application/json') | |
249 | .expect(200) | |
250 | }) | |
251 | }) | |
252 | ||
253 | describe('When deleting a video channel', function () { | |
254 | let videoChannelId: number | |
255 | ||
256 | before(async function () { | |
257 | const res = await getVideoChannelsList(server.url, 0, 1) | |
258 | videoChannelId = res.body.data[0].id | |
259 | }) | |
260 | ||
261 | it('Should fail with a non authenticated user', async function () { | |
262 | await request(server.url) | |
263 | .delete(path + '/' + videoChannelId) | |
264 | .set('Authorization', 'Bearer coucou') | |
265 | .expect(401) | |
266 | }) | |
267 | ||
268 | it('Should fail with another authenticated user', async function () { | |
269 | await request(server.url) | |
270 | .delete(path + '/' + videoChannelId) | |
271 | .set('Authorization', 'Bearer ' + accessTokenUser) | |
272 | .expect(403) | |
273 | }) | |
274 | ||
275 | it('Should fail with an unknown id', async function () { | |
276 | await request(server.url) | |
277 | .delete(path + '/454554') | |
278 | .set('Authorization', 'Bearer ' + server.accessToken) | |
279 | .expect(404) | |
280 | }) | |
281 | ||
282 | it('Should succeed with the correct parameters', async function () { | |
283 | await request(server.url) | |
284 | .delete(path + '/' + videoChannelId) | |
285 | .set('Authorization', 'Bearer ' + server.accessToken) | |
286 | .expect(204) | |
287 | }) | |
288 | ||
289 | it('Should fail to delete the last user video channel', async function () { | |
290 | const res = await getVideoChannelsList(server.url, 0, 1) | |
291 | videoChannelId = res.body.data[0].id | |
292 | ||
293 | await request(server.url) | |
294 | .delete(path + '/' + videoChannelId) | |
295 | .set('Authorization', 'Bearer ' + server.accessToken) | |
296 | .expect(409 | |
297 | ) | |
298 | }) | |
299 | }) | |
300 | ||
301 | after(async function () { | |
302 | killallServers([ server ]) | |
303 | ||
304 | // Keep the logs if the test failed | |
305 | if (this['ok']) { | |
306 | await flushTests() | |
307 | } | |
308 | }) | |
309 | }) |