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