]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-channels.ts
Usernames are case insensitive now
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-channels.ts
CommitLineData
5f04dd2f
C
1/* tslint:disable:no-unused-expression */
2
3import * as request from 'supertest'
5f04dd2f
C
4import 'mocha'
5import * as chai from 'chai'
6const expect = chai.expect
7
8import {
9 ServerInfo,
10 flushTests,
11 runServer,
12 makePutBodyRequest,
13 setAccessTokensToServers,
14 killallServers,
15 getMyUserInformation,
16 makePostBodyRequest,
17 getVideoChannelsList,
18 createUser,
19 getUserAccessToken
20} from '../../utils'
21
22describe('Test videos API validator', function () {
23 const path = '/api/v1/videos/channels'
24 let server: ServerInfo
25 let channelId: number
26 let accessTokenUser: string
27
28 // ---------------------------------------------------------------
29
30 before(async function () {
31 this.timeout(20000)
32
33 await flushTests()
34
35 server = await runServer(1)
36
37 await setAccessTokensToServers([ server ])
38
39 const res = await getMyUserInformation(server.url, server.accessToken)
40 channelId = res.body.videoChannels[0].id
41
42 const user = {
43 username: 'fake',
44 password: 'fake_password'
45 }
46 await createUser(server.url, server.accessToken, user.username, user.password)
47
48 accessTokenUser = await getUserAccessToken(server, user)
49 })
50
51 describe('When listing a video channels', function () {
52 it('Should fail with a bad start pagination', async function () {
53 await request(server.url)
54 .get(path)
55 .query({ start: 'hello' })
56 .set('Accept', 'application/json')
57 .expect(400)
58 })
59
60 it('Should fail with a bad count pagination', async function () {
61 await request(server.url)
62 .get(path)
63 .query({ count: 'hello' })
64 .set('Accept', 'application/json')
65 .expect(400)
66 })
67
68 it('Should fail with an incorrect sort', async function () {
69 await request(server.url)
70 .get(path)
71 .query({ sort: 'hello' })
72 .set('Accept', 'application/json')
73 .expect(400)
74 })
75 })
76
77 describe('When listing author video channels', function () {
78 it('Should fail with bad author', async function () {
79 const path = '/api/v1/videos/authors/hello/channels'
80
81 await request(server.url)
82 .get(path)
83 .set('Accept', 'application/json')
84 .expect(400)
85 })
86
87 it('Should fail with a unknown author', async function () {
88 const path = '/api/v1/videos/authors/156/channels'
89
90 await request(server.url)
91 .get(path)
92 .set('Accept', 'application/json')
93 .expect(404)
94 })
95 })
96
97 describe('When adding a video channel', function () {
98
99 it('Should fail with a non authenticated user', async function () {
100 const fields = {
101 name: 'hello',
102 description: 'super description'
103 }
104 await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 })
105 })
106
107 it('Should fail with nothing', async function () {
108 const fields = {}
109 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
110 })
111
112 it('Should fail without name', async function () {
113 const fields = {
114 description: 'super description'
115 }
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 })
118
119 it('Should fail with a long name', async function () {
120 const fields = {
121 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
a265f7f3
C
122 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
123 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
124 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
5f04dd2f
C
125 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
126 description: 'super description'
127 }
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 })
130
131 it('Should fail with a long description', async function () {
132 const fields = {
133 name: 'hello',
134 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
135 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
136 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
137 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
138 }
139 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
140 })
141
142 it('Should succeed with the correct parameters', async function () {
143 const fields = {
144 name: 'hello',
145 description: 'super description'
146 }
147 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
148 })
149 })
150
151 describe('When updating a video channel', function () {
152 let videoChannelId
153
154 before(async function () {
155 const res = await getVideoChannelsList(server.url, 0, 1)
156 videoChannelId = res.body.data[0].id
157 })
158
159 it('Should fail with a non authenticated user', async function () {
160 const fields = {
161 name: 'hello',
162 description: 'super description'
163 }
164 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 })
165 })
166
167 it('Should fail with another authenticated user', async function () {
168 const fields = {
169 name: 'hello',
170 description: 'super description'
171 }
172 await makePutBodyRequest({
173 url: server.url,
174 path: path + '/' + videoChannelId,
175 token: accessTokenUser,
176 fields,
177 statusCodeExpected: 403
178 })
179 })
180
181 it('Should fail with a long name', async function () {
182 const fields = {
183 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
a265f7f3
C
184 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
185 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
186 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
5f04dd2f
C
187 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
188 description: 'super description'
189 }
190 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
191 })
192
193 it('Should fail with a long description', async function () {
194 const fields = {
195 name: 'hello',
196 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
197 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
198 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
199 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
200 }
201 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
202 })
203
204 it('Should succeed with the correct parameters', async function () {
205 const fields = {
206 name: 'hello 2',
207 description: 'super description 2'
208 }
209 await makePutBodyRequest({
210 url: server.url,
211 path: path + '/' + videoChannelId,
212 token: server.accessToken,
213 fields,
214 statusCodeExpected: 204
215 })
216 })
217 })
218
219 describe('When getting a video channel', function () {
220 let videoChannelId: number
221
222 before(async function () {
223 const res = await getVideoChannelsList(server.url, 0, 1)
224 videoChannelId = res.body.data[0].id
225 })
226
227 it('Should return the list of the video channels with nothing', async function () {
228 const res = await request(server.url)
229 .get(path)
230 .set('Accept', 'application/json')
231 .expect(200)
232 .expect('Content-Type', /json/)
233
234 expect(res.body.data).to.be.an('array')
235 })
236
237 it('Should fail without a correct uuid', async function () {
238 await request(server.url)
239 .get(path + '/coucou')
240 .set('Accept', 'application/json')
241 .expect(400)
242 })
243
244 it('Should return 404 with an incorrect video channel', async function () {
245 await request(server.url)
246 .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06')
247 .set('Accept', 'application/json')
248 .expect(404)
249 })
250
251 it('Should succeed with the correct parameters', async function () {
252 await request(server.url)
253 .get(path + '/' + videoChannelId)
254 .set('Accept', 'application/json')
255 .expect(200)
256 })
257 })
258
259 describe('When deleting a video channel', function () {
260 let videoChannelId: number
261
262 before(async function () {
263 const res = await getVideoChannelsList(server.url, 0, 1)
264 videoChannelId = res.body.data[0].id
265 })
266
267 it('Should fail with a non authenticated user', async function () {
268 await request(server.url)
269 .delete(path + '/' + videoChannelId)
270 .set('Authorization', 'Bearer coucou')
271 .expect(401)
272 })
273
274 it('Should fail with another authenticated user', async function () {
275 await request(server.url)
276 .delete(path + '/' + videoChannelId)
277 .set('Authorization', 'Bearer ' + accessTokenUser)
278 .expect(403)
279 })
280
281 it('Should fail with an unknown id', async function () {
282 await request(server.url)
283 .delete(path + '/454554')
284 .set('Authorization', 'Bearer ' + server.accessToken)
285 .expect(404)
286 })
287
288 it('Should succeed with the correct parameters', async function () {
289 await request(server.url)
290 .delete(path + '/' + videoChannelId)
291 .set('Authorization', 'Bearer ' + server.accessToken)
292 .expect(204)
293 })
294
295 it('Should fail to delete the last user video channel', async function () {
296 const res = await getVideoChannelsList(server.url, 0, 1)
297 videoChannelId = res.body.data[0].id
298
299 await request(server.url)
300 .delete(path + '/' + videoChannelId)
301 .set('Authorization', 'Bearer ' + server.accessToken)
302 .expect(409
303 )
304 })
305 })
306
307 after(async function () {
308 killallServers([ server ])
309
310 // Keep the logs if the test failed
311 if (this['ok']) {
312 await flushTests()
313 }
314 })
315})