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