]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-channels.ts
Do not enable cors twice on /api in test mode
[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,
ad9e39fb
C
10 getAccountVideoChannelsList,
11 getMyUserInformation,
48dce1c9
C
12 getVideoChannelsList,
13 immutableAssign,
14 killallServers,
15 makeGetRequest,
16 makePostBodyRequest,
17 makePutBodyRequest,
18 runServer,
19 ServerInfo,
20 setAccessTokensToServers,
21 userLogin
5f04dd2f 22} from '../../utils'
11ba2ab3 23import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
6b738c7a 24import { User } from '../../../../shared/models/users'
11ba2ab3
C
25
26const expect = chai.expect
5f04dd2f 27
08c1efbe 28describe('Test video channels 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 76 describe('When listing account video channels', function () {
d50acfab 77 it('Should fail with a unknown account', async function () {
ad9e39fb 78 await getAccountVideoChannelsList(server.url, 'unknown', 404)
5f04dd2f
C
79 })
80 })
81
82 describe('When adding a video channel', function () {
11ba2ab3 83 const baseCorrectParams = {
08c1efbe 84 displayName: 'hello',
2422c46b
C
85 description: 'super description',
86 support: 'super support text'
11ba2ab3 87 }
48dce1c9 88
5f04dd2f 89 it('Should fail with a non authenticated user', async function () {
cc918ac3
C
90 await makePostBodyRequest({
91 url: server.url,
92 path: videoChannelPath,
93 token: 'none',
94 fields: baseCorrectParams,
95 statusCodeExpected: 401
96 })
5f04dd2f
C
97 })
98
99 it('Should fail with nothing', async function () {
100 const fields = {}
cc918ac3 101 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
102 })
103
08c1efbe
C
104 it('Should fail without a name', async function () {
105 const fields = omit(baseCorrectParams, 'displayName')
cc918ac3 106 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
107 })
108
109 it('Should fail with a long name', async function () {
08c1efbe 110 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
cc918ac3 111 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
112 })
113
114 it('Should fail with a long description', async function () {
9419b013 115 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
cc918ac3 116 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
117 })
118
2422c46b 119 it('Should fail with a long support text', async function () {
9419b013 120 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
cc918ac3 121 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
2422c46b
C
122 })
123
5f04dd2f 124 it('Should succeed with the correct parameters', async function () {
11ba2ab3
C
125 await makePostBodyRequest({
126 url: server.url,
cc918ac3 127 path: videoChannelPath,
11ba2ab3
C
128 token: server.accessToken,
129 fields: baseCorrectParams,
2422c46b 130 statusCodeExpected: 200
11ba2ab3 131 })
5f04dd2f
C
132 })
133 })
134
135 describe('When updating a video channel', function () {
11ba2ab3 136 const baseCorrectParams = {
08c1efbe 137 displayName: 'hello',
11ba2ab3
C
138 description: 'super description'
139 }
6b738c7a 140 let path: string
11ba2ab3 141
5f04dd2f 142 before(async function () {
cc918ac3 143 path = videoChannelPath + '/' + videoChannelUUID
5f04dd2f
C
144 })
145
146 it('Should fail with a non authenticated user', async function () {
11ba2ab3
C
147 await makePutBodyRequest({
148 url: server.url,
48dce1c9 149 path,
11ba2ab3
C
150 token: 'hi',
151 fields: baseCorrectParams,
152 statusCodeExpected: 401
153 })
5f04dd2f
C
154 })
155
156 it('Should fail with another authenticated user', async function () {
5f04dd2f
C
157 await makePutBodyRequest({
158 url: server.url,
48dce1c9 159 path,
5f04dd2f 160 token: accessTokenUser,
11ba2ab3 161 fields: baseCorrectParams,
5f04dd2f
C
162 statusCodeExpected: 403
163 })
164 })
165
166 it('Should fail with a long name', async function () {
08c1efbe 167 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
48dce1c9 168 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
5f04dd2f
C
169 })
170
171 it('Should fail with a long description', async function () {
9419b013 172 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
48dce1c9 173 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
5f04dd2f
C
174 })
175
2422c46b 176 it('Should fail with a long support text', async function () {
9419b013 177 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
48dce1c9 178 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
2422c46b
C
179 })
180
5f04dd2f 181 it('Should succeed with the correct parameters', async function () {
5f04dd2f
C
182 await makePutBodyRequest({
183 url: server.url,
48dce1c9 184 path,
5f04dd2f 185 token: server.accessToken,
11ba2ab3 186 fields: baseCorrectParams,
5f04dd2f
C
187 statusCodeExpected: 204
188 })
189 })
190 })
191
192 describe('When getting a video channel', function () {
5f04dd2f 193 it('Should return the list of the video channels with nothing', async function () {
11ba2ab3
C
194 const res = await makeGetRequest({
195 url: server.url,
cc918ac3 196 path: videoChannelPath,
11ba2ab3
C
197 statusCodeExpected: 200
198 })
5f04dd2f
C
199
200 expect(res.body.data).to.be.an('array')
201 })
202
203 it('Should fail without a correct uuid', async function () {
11ba2ab3
C
204 await makeGetRequest({
205 url: server.url,
cc918ac3 206 path: videoChannelPath + '/coucou',
11ba2ab3
C
207 statusCodeExpected: 400
208 })
5f04dd2f
C
209 })
210
211 it('Should return 404 with an incorrect video channel', async function () {
11ba2ab3
C
212 await makeGetRequest({
213 url: server.url,
cc918ac3 214 path: videoChannelPath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
11ba2ab3
C
215 statusCodeExpected: 404
216 })
5f04dd2f
C
217 })
218
219 it('Should succeed with the correct parameters', async function () {
11ba2ab3
C
220 await makeGetRequest({
221 url: server.url,
cc918ac3 222 path: videoChannelPath + '/' + videoChannelUUID,
11ba2ab3
C
223 statusCodeExpected: 200
224 })
5f04dd2f
C
225 })
226 })
227
228 describe('When deleting a video channel', function () {
5f04dd2f 229 it('Should fail with a non authenticated user', async function () {
cc918ac3 230 await deleteVideoChannel(server.url, 'coucou', videoChannelUUID, 401)
5f04dd2f
C
231 })
232
233 it('Should fail with another authenticated user', async function () {
cc918ac3 234 await deleteVideoChannel(server.url, accessTokenUser, videoChannelUUID, 403)
5f04dd2f
C
235 })
236
48dce1c9 237 it('Should fail with an unknown video channel id', async function () {
cc918ac3 238 await deleteVideoChannel(server.url, server.accessToken,454554, 404)
5f04dd2f
C
239 })
240
241 it('Should succeed with the correct parameters', async function () {
cc918ac3 242 await deleteVideoChannel(server.url, server.accessToken, videoChannelUUID)
5f04dd2f
C
243 })
244
245 it('Should fail to delete the last user video channel', async function () {
246 const res = await getVideoChannelsList(server.url, 0, 1)
6b738c7a 247 const lastVideoChannelUUID = res.body.data[0].uuid
5f04dd2f 248
cc918ac3 249 await deleteVideoChannel(server.url, server.accessToken, lastVideoChannelUUID, 409)
5f04dd2f
C
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})