]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-channels.ts
Update video-channel routes (again)
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-channels.ts
CommitLineData
5f04dd2f
C
1/* tslint:disable:no-unused-expression */
2
5f04dd2f 3import * as chai from 'chai'
11ba2ab3
C
4import { omit } from 'lodash'
5import 'mocha'
5f04dd2f 6import {
48dce1c9
C
7 createUser,
8 deleteVideoChannel,
9 flushTests,
6b738c7a 10 getAccountVideoChannelsList, getMyUserInformation,
48dce1c9
C
11 getVideoChannelsList,
12 immutableAssign,
13 killallServers,
14 makeGetRequest,
15 makePostBodyRequest,
16 makePutBodyRequest,
17 runServer,
18 ServerInfo,
19 setAccessTokensToServers,
20 userLogin
5f04dd2f 21} from '../../utils'
11ba2ab3 22import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
48dce1c9 23import { getAccountsList } from '../../utils/users/accounts'
6b738c7a 24import { User } from '../../../../shared/models/users'
11ba2ab3
C
25
26const expect = chai.expect
5f04dd2f
C
27
28describe('Test videos API validator', function () {
48dce1c9 29 const videoChannelPath = '/api/v1/video-channels'
5f04dd2f 30 let server: ServerInfo
5f04dd2f 31 let accessTokenUser: string
6b738c7a 32 let videoChannelUUID: string
5f04dd2f
C
33
34 // ---------------------------------------------------------------
35
36 before(async function () {
e212f887 37 this.timeout(30000)
5f04dd2f
C
38
39 await flushTests()
40
41 server = await runServer(1)
42
43 await setAccessTokensToServers([ server ])
44
5f04dd2f
C
45 const user = {
46 username: 'fake',
47 password: 'fake_password'
48 }
6b738c7a
C
49
50 {
51 await createUser(server.url, server.accessToken, user.username, user.password)
52 accessTokenUser = await userLogin(server, user)
53 }
54
55 {
56 const res = await getMyUserInformation(server.url, server.accessToken)
57 const user: User = res.body
6b738c7a
C
58 videoChannelUUID = user.videoChannels[0].uuid
59 }
5f04dd2f
C
60 })
61
62 describe('When listing a video channels', function () {
63 it('Should fail with a bad start pagination', async function () {
48dce1c9 64 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
5f04dd2f
C
65 })
66
67 it('Should fail with a bad count pagination', async function () {
48dce1c9 68 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
5f04dd2f
C
69 })
70
71 it('Should fail with an incorrect sort', async function () {
48dce1c9 72 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
5f04dd2f
C
73 })
74 })
75
d50acfab
C
76 describe('When listing account video channels', function () {
77 it('Should fail with bad account', async function () {
11ba2ab3 78 await getAccountVideoChannelsList(server.url, 'hello', 400)
5f04dd2f
C
79 })
80
d50acfab 81 it('Should fail with a unknown account', async function () {
11ba2ab3 82 await getAccountVideoChannelsList(server.url, 154, 404)
5f04dd2f
C
83 })
84 })
85
86 describe('When adding a video channel', function () {
11ba2ab3
C
87 const baseCorrectParams = {
88 name: 'hello',
2422c46b
C
89 description: 'super description',
90 support: 'super support text'
11ba2ab3 91 }
48dce1c9 92
5f04dd2f 93 it('Should fail with a non authenticated user', async function () {
cc918ac3
C
94 await makePostBodyRequest({
95 url: server.url,
96 path: videoChannelPath,
97 token: 'none',
98 fields: baseCorrectParams,
99 statusCodeExpected: 401
100 })
5f04dd2f
C
101 })
102
103 it('Should fail with nothing', async function () {
104 const fields = {}
cc918ac3 105 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
106 })
107
108 it('Should fail without name', async function () {
11ba2ab3 109 const fields = omit(baseCorrectParams, 'name')
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 () {
11ba2ab3 114 const fields = immutableAssign(baseCorrectParams, { name: '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 () {
11ba2ab3 119 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
cc918ac3 120 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
121 })
122
2422c46b
C
123 it('Should fail with a long support text', async function () {
124 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
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
C
136 })
137 })
138
139 describe('When updating a video channel', function () {
11ba2ab3
C
140 const baseCorrectParams = {
141 name: 'hello',
142 description: 'super description'
143 }
6b738c7a 144 let path: string
11ba2ab3 145
5f04dd2f 146 before(async function () {
cc918ac3 147 path = videoChannelPath + '/' + videoChannelUUID
5f04dd2f
C
148 })
149
150 it('Should fail with a non authenticated user', async function () {
11ba2ab3
C
151 await makePutBodyRequest({
152 url: server.url,
48dce1c9 153 path,
11ba2ab3
C
154 token: 'hi',
155 fields: baseCorrectParams,
156 statusCodeExpected: 401
157 })
5f04dd2f
C
158 })
159
160 it('Should fail with another authenticated user', async function () {
5f04dd2f
C
161 await makePutBodyRequest({
162 url: server.url,
48dce1c9 163 path,
5f04dd2f 164 token: accessTokenUser,
11ba2ab3 165 fields: baseCorrectParams,
5f04dd2f
C
166 statusCodeExpected: 403
167 })
168 })
169
170 it('Should fail with a long name', async function () {
11ba2ab3 171 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
48dce1c9 172 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
5f04dd2f
C
173 })
174
175 it('Should fail with a long description', async function () {
11ba2ab3 176 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
48dce1c9 177 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
5f04dd2f
C
178 })
179
2422c46b
C
180 it('Should fail with a long support text', async function () {
181 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
48dce1c9 182 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
2422c46b
C
183 })
184
5f04dd2f 185 it('Should succeed with the correct parameters', async function () {
5f04dd2f
C
186 await makePutBodyRequest({
187 url: server.url,
48dce1c9 188 path,
5f04dd2f 189 token: server.accessToken,
11ba2ab3 190 fields: baseCorrectParams,
5f04dd2f
C
191 statusCodeExpected: 204
192 })
193 })
194 })
195
196 describe('When getting a video channel', function () {
5f04dd2f 197 it('Should return the list of the video channels with nothing', async function () {
11ba2ab3
C
198 const res = await makeGetRequest({
199 url: server.url,
cc918ac3 200 path: videoChannelPath,
11ba2ab3
C
201 statusCodeExpected: 200
202 })
5f04dd2f
C
203
204 expect(res.body.data).to.be.an('array')
205 })
206
207 it('Should fail without a correct uuid', async function () {
11ba2ab3
C
208 await makeGetRequest({
209 url: server.url,
cc918ac3 210 path: videoChannelPath + '/coucou',
11ba2ab3
C
211 statusCodeExpected: 400
212 })
5f04dd2f
C
213 })
214
215 it('Should return 404 with an incorrect video channel', async function () {
11ba2ab3
C
216 await makeGetRequest({
217 url: server.url,
cc918ac3 218 path: videoChannelPath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
11ba2ab3
C
219 statusCodeExpected: 404
220 })
5f04dd2f
C
221 })
222
223 it('Should succeed with the correct parameters', async function () {
11ba2ab3
C
224 await makeGetRequest({
225 url: server.url,
cc918ac3 226 path: videoChannelPath + '/' + videoChannelUUID,
11ba2ab3
C
227 statusCodeExpected: 200
228 })
5f04dd2f
C
229 })
230 })
231
232 describe('When deleting a video channel', function () {
5f04dd2f 233 it('Should fail with a non authenticated user', async function () {
cc918ac3 234 await deleteVideoChannel(server.url, 'coucou', videoChannelUUID, 401)
5f04dd2f
C
235 })
236
237 it('Should fail with another authenticated user', async function () {
cc918ac3 238 await deleteVideoChannel(server.url, accessTokenUser, videoChannelUUID, 403)
5f04dd2f
C
239 })
240
48dce1c9 241 it('Should fail with an unknown video channel id', async function () {
cc918ac3 242 await deleteVideoChannel(server.url, server.accessToken,454554, 404)
5f04dd2f
C
243 })
244
245 it('Should succeed with the correct parameters', async function () {
cc918ac3 246 await deleteVideoChannel(server.url, server.accessToken, videoChannelUUID)
5f04dd2f
C
247 })
248
249 it('Should fail to delete the last user video channel', async function () {
250 const res = await getVideoChannelsList(server.url, 0, 1)
6b738c7a 251 const lastVideoChannelUUID = res.body.data[0].uuid
5f04dd2f 252
cc918ac3 253 await deleteVideoChannel(server.url, server.accessToken, lastVideoChannelUUID, 409)
5f04dd2f
C
254 })
255 })
256
257 after(async function () {
258 killallServers([ server ])
259
260 // Keep the logs if the test failed
261 if (this['ok']) {
262 await flushTests()
263 }
264 })
265})