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