aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-channels.ts')
-rw-r--r--server/tests/api/check-params/video-channels.ts88
1 files changed, 42 insertions, 46 deletions
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 5c02afd31..2e63916d4 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -3,43 +3,37 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 6import {
8 buildAbsoluteFixturePath, 7 buildAbsoluteFixturePath,
8 ChannelsCommand,
9 checkBadCountPagination,
10 checkBadSortPagination,
11 checkBadStartPagination,
9 cleanupTests, 12 cleanupTests,
10 createUser, 13 createSingleServer,
11 deleteVideoChannel,
12 flushAndRunServer,
13 getAccountVideoChannelsList,
14 immutableAssign,
15 makeGetRequest, 14 makeGetRequest,
16 makePostBodyRequest, 15 makePostBodyRequest,
17 makePutBodyRequest, 16 makePutBodyRequest,
18 makeUploadRequest, 17 makeUploadRequest,
19 ServerInfo, 18 PeerTubeServer,
20 setAccessTokensToServers, 19 setAccessTokensToServers
21 userLogin 20} from '@shared/extra-utils'
22} from '../../../../shared/extra-utils' 21import { HttpStatusCode, VideoChannelUpdate } from '@shared/models'
23import {
24 checkBadCountPagination,
25 checkBadSortPagination,
26 checkBadStartPagination
27} from '../../../../shared/extra-utils/requests/check-api-params'
28import { VideoChannelUpdate } from '../../../../shared/models/videos'
29 22
30const expect = chai.expect 23const expect = chai.expect
31 24
32describe('Test video channels API validator', function () { 25describe('Test video channels API validator', function () {
33 const videoChannelPath = '/api/v1/video-channels' 26 const videoChannelPath = '/api/v1/video-channels'
34 let server: ServerInfo 27 let server: PeerTubeServer
35 let accessTokenUser: string 28 let accessTokenUser: string
29 let command: ChannelsCommand
36 30
37 // --------------------------------------------------------------- 31 // ---------------------------------------------------------------
38 32
39 before(async function () { 33 before(async function () {
40 this.timeout(30000) 34 this.timeout(30000)
41 35
42 server = await flushAndRunServer(1) 36 server = await createSingleServer(1)
43 37
44 await setAccessTokensToServers([ server ]) 38 await setAccessTokensToServers([ server ])
45 39
@@ -49,9 +43,11 @@ describe('Test video channels API validator', function () {
49 } 43 }
50 44
51 { 45 {
52 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 46 await server.users.create({ username: user.username, password: user.password })
53 accessTokenUser = await userLogin(server, user) 47 accessTokenUser = await server.login.getAccessToken(user)
54 } 48 }
49
50 command = server.channels
55 }) 51 })
56 52
57 describe('When listing a video channels', function () { 53 describe('When listing a video channels', function () {
@@ -84,14 +80,14 @@ describe('Test video channels API validator', function () {
84 }) 80 })
85 81
86 it('Should fail with a unknown account', async function () { 82 it('Should fail with a unknown account', async function () {
87 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: HttpStatusCode.NOT_FOUND_404 }) 83 await server.channels.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
88 }) 84 })
89 85
90 it('Should succeed with the correct parameters', async function () { 86 it('Should succeed with the correct parameters', async function () {
91 await makeGetRequest({ 87 await makeGetRequest({
92 url: server.url, 88 url: server.url,
93 path: accountChannelPath, 89 path: accountChannelPath,
94 statusCodeExpected: HttpStatusCode.OK_200 90 expectedStatus: HttpStatusCode.OK_200
95 }) 91 })
96 }) 92 })
97 }) 93 })
@@ -110,7 +106,7 @@ describe('Test video channels API validator', function () {
110 path: videoChannelPath, 106 path: videoChannelPath,
111 token: 'none', 107 token: 'none',
112 fields: baseCorrectParams, 108 fields: baseCorrectParams,
113 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 109 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
114 }) 110 })
115 }) 111 })
116 112
@@ -125,7 +121,7 @@ describe('Test video channels API validator', function () {
125 }) 121 })
126 122
127 it('Should fail with a bad name', async function () { 123 it('Should fail with a bad name', async function () {
128 const fields = immutableAssign(baseCorrectParams, { name: 'super name' }) 124 const fields = { ...baseCorrectParams, name: 'super name' }
129 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 125 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
130 }) 126 })
131 127
@@ -135,17 +131,17 @@ describe('Test video channels API validator', function () {
135 }) 131 })
136 132
137 it('Should fail with a long name', async function () { 133 it('Should fail with a long name', async function () {
138 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) 134 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
139 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 135 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
140 }) 136 })
141 137
142 it('Should fail with a long description', async function () { 138 it('Should fail with a long description', async function () {
143 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) 139 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
144 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 140 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
145 }) 141 })
146 142
147 it('Should fail with a long support text', async function () { 143 it('Should fail with a long support text', async function () {
148 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 144 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
149 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 145 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
150 }) 146 })
151 147
@@ -155,7 +151,7 @@ describe('Test video channels API validator', function () {
155 path: videoChannelPath, 151 path: videoChannelPath,
156 token: server.accessToken, 152 token: server.accessToken,
157 fields: baseCorrectParams, 153 fields: baseCorrectParams,
158 statusCodeExpected: HttpStatusCode.OK_200 154 expectedStatus: HttpStatusCode.OK_200
159 }) 155 })
160 }) 156 })
161 157
@@ -165,7 +161,7 @@ describe('Test video channels API validator', function () {
165 path: videoChannelPath, 161 path: videoChannelPath,
166 token: server.accessToken, 162 token: server.accessToken,
167 fields: baseCorrectParams, 163 fields: baseCorrectParams,
168 statusCodeExpected: HttpStatusCode.CONFLICT_409 164 expectedStatus: HttpStatusCode.CONFLICT_409
169 }) 165 })
170 }) 166 })
171 }) 167 })
@@ -189,7 +185,7 @@ describe('Test video channels API validator', function () {
189 path, 185 path,
190 token: 'hi', 186 token: 'hi',
191 fields: baseCorrectParams, 187 fields: baseCorrectParams,
192 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 188 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
193 }) 189 })
194 }) 190 })
195 191
@@ -199,27 +195,27 @@ describe('Test video channels API validator', function () {
199 path, 195 path,
200 token: accessTokenUser, 196 token: accessTokenUser,
201 fields: baseCorrectParams, 197 fields: baseCorrectParams,
202 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 198 expectedStatus: HttpStatusCode.FORBIDDEN_403
203 }) 199 })
204 }) 200 })
205 201
206 it('Should fail with a long name', async function () { 202 it('Should fail with a long name', async function () {
207 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) 203 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
208 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 204 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
209 }) 205 })
210 206
211 it('Should fail with a long description', async function () { 207 it('Should fail with a long description', async function () {
212 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) 208 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
213 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 209 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
214 }) 210 })
215 211
216 it('Should fail with a long support text', async function () { 212 it('Should fail with a long support text', async function () {
217 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 213 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
218 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 214 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
219 }) 215 })
220 216
221 it('Should fail with a bad bulkVideosSupportUpdate field', async function () { 217 it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
222 const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' }) 218 const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' }
223 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 219 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
224 }) 220 })
225 221
@@ -229,7 +225,7 @@ describe('Test video channels API validator', function () {
229 path, 225 path,
230 token: server.accessToken, 226 token: server.accessToken,
231 fields: baseCorrectParams, 227 fields: baseCorrectParams,
232 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 228 expectedStatus: HttpStatusCode.NO_CONTENT_204
233 }) 229 })
234 }) 230 })
235 }) 231 })
@@ -274,7 +270,7 @@ describe('Test video channels API validator', function () {
274 path: `${path}/${type}/pick`, 270 path: `${path}/${type}/pick`,
275 fields, 271 fields,
276 attaches, 272 attaches,
277 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 273 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
278 }) 274 })
279 } 275 }
280 }) 276 })
@@ -291,7 +287,7 @@ describe('Test video channels API validator', function () {
291 token: server.accessToken, 287 token: server.accessToken,
292 fields, 288 fields,
293 attaches, 289 attaches,
294 statusCodeExpected: HttpStatusCode.OK_200 290 expectedStatus: HttpStatusCode.OK_200
295 }) 291 })
296 } 292 }
297 }) 293 })
@@ -302,7 +298,7 @@ describe('Test video channels API validator', function () {
302 const res = await makeGetRequest({ 298 const res = await makeGetRequest({
303 url: server.url, 299 url: server.url,
304 path: videoChannelPath, 300 path: videoChannelPath,
305 statusCodeExpected: HttpStatusCode.OK_200 301 expectedStatus: HttpStatusCode.OK_200
306 }) 302 })
307 303
308 expect(res.body.data).to.be.an('array') 304 expect(res.body.data).to.be.an('array')
@@ -312,7 +308,7 @@ describe('Test video channels API validator', function () {
312 await makeGetRequest({ 308 await makeGetRequest({
313 url: server.url, 309 url: server.url,
314 path: videoChannelPath + '/super_channel2', 310 path: videoChannelPath + '/super_channel2',
315 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 311 expectedStatus: HttpStatusCode.NOT_FOUND_404
316 }) 312 })
317 }) 313 })
318 314
@@ -320,30 +316,30 @@ describe('Test video channels API validator', function () {
320 await makeGetRequest({ 316 await makeGetRequest({
321 url: server.url, 317 url: server.url,
322 path: videoChannelPath + '/super_channel', 318 path: videoChannelPath + '/super_channel',
323 statusCodeExpected: HttpStatusCode.OK_200 319 expectedStatus: HttpStatusCode.OK_200
324 }) 320 })
325 }) 321 })
326 }) 322 })
327 323
328 describe('When deleting a video channel', function () { 324 describe('When deleting a video channel', function () {
329 it('Should fail with a non authenticated user', async function () { 325 it('Should fail with a non authenticated user', async function () {
330 await deleteVideoChannel(server.url, 'coucou', 'super_channel', HttpStatusCode.UNAUTHORIZED_401) 326 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
331 }) 327 })
332 328
333 it('Should fail with another authenticated user', async function () { 329 it('Should fail with another authenticated user', async function () {
334 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', HttpStatusCode.FORBIDDEN_403) 330 await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
335 }) 331 })
336 332
337 it('Should fail with an unknown video channel id', async function () { 333 it('Should fail with an unknown video channel id', async function () {
338 await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', HttpStatusCode.NOT_FOUND_404) 334 await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
339 }) 335 })
340 336
341 it('Should succeed with the correct parameters', async function () { 337 it('Should succeed with the correct parameters', async function () {
342 await deleteVideoChannel(server.url, server.accessToken, 'super_channel') 338 await command.delete({ channelName: 'super_channel' })
343 }) 339 })
344 340
345 it('Should fail to delete the last user video channel', async function () { 341 it('Should fail to delete the last user video channel', async function () {
346 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', HttpStatusCode.CONFLICT_409) 342 await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 })
347 }) 343 })
348 }) 344 })
349 345