]>
Commit | Line | Data |
---|---|---|
5f04dd2f C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
5f04dd2f | 3 | import * as chai from 'chai' |
11ba2ab3 C |
4 | import { omit } from 'lodash' |
5 | import 'mocha' | |
5f04dd2f | 6 | import { |
48dce1c9 C |
7 | createUser, |
8 | deleteVideoChannel, | |
9 | flushTests, | |
ad9e39fb C |
10 | getAccountVideoChannelsList, |
11 | getMyUserInformation, | |
48dce1c9 C |
12 | getVideoChannelsList, |
13 | immutableAssign, | |
14 | killallServers, | |
15 | makeGetRequest, | |
16 | makePostBodyRequest, | |
52d9f792 C |
17 | makePutBodyRequest, |
18 | makeUploadRequest, | |
48dce1c9 C |
19 | runServer, |
20 | ServerInfo, | |
21 | setAccessTokensToServers, | |
22 | userLogin | |
5f04dd2f | 23 | } from '../../utils' |
11ba2ab3 | 24 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
6b738c7a | 25 | import { User } from '../../../../shared/models/users' |
52d9f792 | 26 | import { join } from 'path' |
11ba2ab3 C |
27 | |
28 | const expect = chai.expect | |
5f04dd2f | 29 | |
08c1efbe | 30 | describe('Test video channels API validator', function () { |
48dce1c9 | 31 | const videoChannelPath = '/api/v1/video-channels' |
5f04dd2f | 32 | let server: ServerInfo |
5f04dd2f C |
33 | let accessTokenUser: string |
34 | ||
35 | // --------------------------------------------------------------- | |
36 | ||
37 | before(async function () { | |
e212f887 | 38 | this.timeout(30000) |
5f04dd2f C |
39 | |
40 | await flushTests() | |
41 | ||
42 | server = await runServer(1) | |
43 | ||
44 | await setAccessTokensToServers([ server ]) | |
45 | ||
5f04dd2f C |
46 | const user = { |
47 | username: 'fake', | |
48 | password: 'fake_password' | |
49 | } | |
6b738c7a C |
50 | |
51 | { | |
52 | await createUser(server.url, server.accessToken, user.username, user.password) | |
53 | accessTokenUser = await userLogin(server, user) | |
54 | } | |
5f04dd2f C |
55 | }) |
56 | ||
57 | describe('When listing a video channels', function () { | |
58 | it('Should fail with a bad start pagination', async function () { | |
48dce1c9 | 59 | await checkBadStartPagination(server.url, videoChannelPath, server.accessToken) |
5f04dd2f C |
60 | }) |
61 | ||
62 | it('Should fail with a bad count pagination', async function () { | |
48dce1c9 | 63 | await checkBadCountPagination(server.url, videoChannelPath, server.accessToken) |
5f04dd2f C |
64 | }) |
65 | ||
66 | it('Should fail with an incorrect sort', async function () { | |
48dce1c9 | 67 | await checkBadSortPagination(server.url, videoChannelPath, server.accessToken) |
5f04dd2f C |
68 | }) |
69 | }) | |
70 | ||
d50acfab | 71 | describe('When listing account video channels', function () { |
d50acfab | 72 | it('Should fail with a unknown account', async function () { |
ad9e39fb | 73 | await getAccountVideoChannelsList(server.url, 'unknown', 404) |
5f04dd2f C |
74 | }) |
75 | }) | |
76 | ||
77 | describe('When adding a video channel', function () { | |
11ba2ab3 | 78 | const baseCorrectParams = { |
8a19bee1 | 79 | name: 'super_channel', |
08c1efbe | 80 | displayName: 'hello', |
2422c46b C |
81 | description: 'super description', |
82 | support: 'super support text' | |
11ba2ab3 | 83 | } |
48dce1c9 | 84 | |
5f04dd2f | 85 | it('Should fail with a non authenticated user', async function () { |
cc918ac3 C |
86 | await makePostBodyRequest({ |
87 | url: server.url, | |
88 | path: videoChannelPath, | |
89 | token: 'none', | |
90 | fields: baseCorrectParams, | |
91 | statusCodeExpected: 401 | |
92 | }) | |
5f04dd2f C |
93 | }) |
94 | ||
95 | it('Should fail with nothing', async function () { | |
96 | const fields = {} | |
cc918ac3 | 97 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
5f04dd2f C |
98 | }) |
99 | ||
8a19bee1 C |
100 | it('Should fail without a name', async function () { |
101 | const fields = omit(baseCorrectParams, 'name') | |
102 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
103 | }) | |
104 | ||
105 | it('Should fail with a bad name', async function () { | |
106 | const fields = immutableAssign(baseCorrectParams, { name: 'super name' }) | |
107 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
108 | }) | |
109 | ||
08c1efbe C |
110 | it('Should fail without a name', async function () { |
111 | const fields = omit(baseCorrectParams, 'displayName') | |
cc918ac3 | 112 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
5f04dd2f C |
113 | }) |
114 | ||
115 | it('Should fail with a long name', async function () { | |
08c1efbe | 116 | const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) |
cc918ac3 | 117 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
5f04dd2f C |
118 | }) |
119 | ||
120 | it('Should fail with a long description', async function () { | |
9419b013 | 121 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) }) |
cc918ac3 | 122 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
5f04dd2f C |
123 | }) |
124 | ||
2422c46b | 125 | it('Should fail with a long support text', async function () { |
9419b013 | 126 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) }) |
cc918ac3 | 127 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
2422c46b C |
128 | }) |
129 | ||
5f04dd2f | 130 | it('Should succeed with the correct parameters', async function () { |
11ba2ab3 C |
131 | await makePostBodyRequest({ |
132 | url: server.url, | |
cc918ac3 | 133 | path: videoChannelPath, |
11ba2ab3 C |
134 | token: server.accessToken, |
135 | fields: baseCorrectParams, | |
2422c46b | 136 | statusCodeExpected: 200 |
11ba2ab3 | 137 | }) |
5f04dd2f C |
138 | }) |
139 | }) | |
140 | ||
141 | describe('When updating a video channel', function () { | |
11ba2ab3 | 142 | const baseCorrectParams = { |
08c1efbe | 143 | displayName: 'hello', |
11ba2ab3 C |
144 | description: 'super description' |
145 | } | |
6b738c7a | 146 | let path: string |
11ba2ab3 | 147 | |
5f04dd2f | 148 | before(async function () { |
8a19bee1 | 149 | path = videoChannelPath + '/super_channel' |
5f04dd2f C |
150 | }) |
151 | ||
152 | it('Should fail with a non authenticated user', async function () { | |
11ba2ab3 C |
153 | await makePutBodyRequest({ |
154 | url: server.url, | |
48dce1c9 | 155 | path, |
11ba2ab3 C |
156 | token: 'hi', |
157 | fields: baseCorrectParams, | |
158 | statusCodeExpected: 401 | |
159 | }) | |
5f04dd2f C |
160 | }) |
161 | ||
162 | it('Should fail with another authenticated user', async function () { | |
5f04dd2f C |
163 | await makePutBodyRequest({ |
164 | url: server.url, | |
48dce1c9 | 165 | path, |
5f04dd2f | 166 | token: accessTokenUser, |
11ba2ab3 | 167 | fields: baseCorrectParams, |
5f04dd2f C |
168 | statusCodeExpected: 403 |
169 | }) | |
170 | }) | |
171 | ||
172 | it('Should fail with a long name', async function () { | |
08c1efbe | 173 | const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) |
48dce1c9 | 174 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
5f04dd2f C |
175 | }) |
176 | ||
177 | it('Should fail with a long description', async function () { | |
9419b013 | 178 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) }) |
48dce1c9 | 179 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
5f04dd2f C |
180 | }) |
181 | ||
2422c46b | 182 | it('Should fail with a long support text', async function () { |
9419b013 | 183 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) }) |
48dce1c9 | 184 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
2422c46b C |
185 | }) |
186 | ||
5f04dd2f | 187 | it('Should succeed with the correct parameters', async function () { |
5f04dd2f C |
188 | await makePutBodyRequest({ |
189 | url: server.url, | |
48dce1c9 | 190 | path, |
5f04dd2f | 191 | token: server.accessToken, |
11ba2ab3 | 192 | fields: baseCorrectParams, |
5f04dd2f C |
193 | statusCodeExpected: 204 |
194 | }) | |
195 | }) | |
196 | }) | |
197 | ||
4bbfc6c6 C |
198 | describe('When updating video channel avatar', function () { |
199 | let path: string | |
200 | ||
201 | before(async function () { | |
8a19bee1 | 202 | path = videoChannelPath + '/super_channel' |
4bbfc6c6 C |
203 | }) |
204 | ||
205 | it('Should fail with an incorrect input file', async function () { | |
206 | const fields = {} | |
207 | const attaches = { | |
208 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') | |
209 | } | |
210 | await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches }) | |
211 | }) | |
212 | ||
213 | it('Should fail with a big file', async function () { | |
214 | const fields = {} | |
215 | const attaches = { | |
216 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') | |
217 | } | |
218 | await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches }) | |
219 | }) | |
220 | ||
221 | it('Should fail with an unauthenticated user', async function () { | |
222 | const fields = {} | |
223 | const attaches = { | |
224 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
225 | } | |
226 | await makeUploadRequest({ | |
227 | url: server.url, | |
228 | path: path + '/avatar/pick', | |
229 | fields, | |
230 | attaches, | |
231 | statusCodeExpected: 401 | |
232 | }) | |
233 | }) | |
234 | ||
235 | it('Should succeed with the correct params', async function () { | |
236 | const fields = {} | |
237 | const attaches = { | |
238 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
239 | } | |
240 | await makeUploadRequest({ | |
241 | url: server.url, | |
242 | path: path + '/avatar/pick', | |
243 | token: server.accessToken, | |
244 | fields, | |
245 | attaches, | |
246 | statusCodeExpected: 200 | |
247 | }) | |
248 | }) | |
249 | }) | |
250 | ||
5f04dd2f | 251 | describe('When getting a video channel', function () { |
5f04dd2f | 252 | it('Should return the list of the video channels with nothing', async function () { |
11ba2ab3 C |
253 | const res = await makeGetRequest({ |
254 | url: server.url, | |
cc918ac3 | 255 | path: videoChannelPath, |
11ba2ab3 C |
256 | statusCodeExpected: 200 |
257 | }) | |
5f04dd2f C |
258 | |
259 | expect(res.body.data).to.be.an('array') | |
260 | }) | |
261 | ||
5f04dd2f | 262 | it('Should return 404 with an incorrect video channel', async function () { |
11ba2ab3 C |
263 | await makeGetRequest({ |
264 | url: server.url, | |
8a19bee1 | 265 | path: videoChannelPath + '/super_channel2', |
11ba2ab3 C |
266 | statusCodeExpected: 404 |
267 | }) | |
5f04dd2f C |
268 | }) |
269 | ||
270 | it('Should succeed with the correct parameters', async function () { | |
11ba2ab3 C |
271 | await makeGetRequest({ |
272 | url: server.url, | |
8a19bee1 | 273 | path: videoChannelPath + '/super_channel', |
11ba2ab3 C |
274 | statusCodeExpected: 200 |
275 | }) | |
5f04dd2f C |
276 | }) |
277 | }) | |
278 | ||
279 | describe('When deleting a video channel', function () { | |
5f04dd2f | 280 | it('Should fail with a non authenticated user', async function () { |
8a19bee1 | 281 | await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401) |
5f04dd2f C |
282 | }) |
283 | ||
284 | it('Should fail with another authenticated user', async function () { | |
8a19bee1 | 285 | await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403) |
5f04dd2f C |
286 | }) |
287 | ||
48dce1c9 | 288 | it('Should fail with an unknown video channel id', async function () { |
8a19bee1 | 289 | await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404) |
5f04dd2f C |
290 | }) |
291 | ||
292 | it('Should succeed with the correct parameters', async function () { | |
8a19bee1 | 293 | await deleteVideoChannel(server.url, server.accessToken, 'super_channel') |
5f04dd2f C |
294 | }) |
295 | ||
296 | it('Should fail to delete the last user video channel', async function () { | |
8a19bee1 | 297 | await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409) |
5f04dd2f C |
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 | }) |