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