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