]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-channels.ts
Fix real world script
[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 () {
22 this.timeout(20000)
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',
65 description: 'super description'
66 }
5f04dd2f
C
67
68 it('Should fail with a non authenticated user', async function () {
11ba2ab3 69 await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
5f04dd2f
C
70 })
71
72 it('Should fail with nothing', async function () {
73 const fields = {}
74 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
75 })
76
77 it('Should fail without name', async function () {
11ba2ab3 78 const fields = omit(baseCorrectParams, 'name')
5f04dd2f
C
79 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
80 })
81
82 it('Should fail with a long name', async function () {
11ba2ab3 83 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
5f04dd2f
C
84 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
85 })
86
87 it('Should fail with a long description', async function () {
11ba2ab3 88 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
5f04dd2f
C
89 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
90 })
91
92 it('Should succeed with the correct parameters', async function () {
11ba2ab3
C
93 await makePostBodyRequest({
94 url: server.url,
95 path,
96 token: server.accessToken,
97 fields: baseCorrectParams,
98 statusCodeExpected: 204
99 })
5f04dd2f
C
100 })
101 })
102
103 describe('When updating a video channel', function () {
11ba2ab3
C
104 const baseCorrectParams = {
105 name: 'hello',
106 description: 'super description'
107 }
108
5f04dd2f
C
109 let videoChannelId
110
111 before(async function () {
112 const res = await getVideoChannelsList(server.url, 0, 1)
113 videoChannelId = res.body.data[0].id
114 })
115
116 it('Should fail with a non authenticated user', async function () {
11ba2ab3
C
117 await makePutBodyRequest({
118 url: server.url,
119 path: path + '/' + videoChannelId,
120 token: 'hi',
121 fields: baseCorrectParams,
122 statusCodeExpected: 401
123 })
5f04dd2f
C
124 })
125
126 it('Should fail with another authenticated user', async function () {
5f04dd2f
C
127 await makePutBodyRequest({
128 url: server.url,
129 path: path + '/' + videoChannelId,
130 token: accessTokenUser,
11ba2ab3 131 fields: baseCorrectParams,
5f04dd2f
C
132 statusCodeExpected: 403
133 })
134 })
135
136 it('Should fail with a long name', async function () {
11ba2ab3 137 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
5f04dd2f
C
138 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
139 })
140
141 it('Should fail with a long description', async function () {
11ba2ab3 142 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
5f04dd2f
C
143 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
144 })
145
146 it('Should succeed with the correct parameters', async function () {
5f04dd2f
C
147 await makePutBodyRequest({
148 url: server.url,
149 path: path + '/' + videoChannelId,
150 token: server.accessToken,
11ba2ab3 151 fields: baseCorrectParams,
5f04dd2f
C
152 statusCodeExpected: 204
153 })
154 })
155 })
156
157 describe('When getting a video channel', function () {
158 let videoChannelId: number
159
160 before(async function () {
161 const res = await getVideoChannelsList(server.url, 0, 1)
162 videoChannelId = res.body.data[0].id
163 })
164
165 it('Should return the list of the video channels with nothing', async function () {
11ba2ab3
C
166 const res = await makeGetRequest({
167 url: server.url,
168 path,
169 statusCodeExpected: 200
170 })
5f04dd2f
C
171
172 expect(res.body.data).to.be.an('array')
173 })
174
175 it('Should fail without a correct uuid', async function () {
11ba2ab3
C
176 await makeGetRequest({
177 url: server.url,
178 path: path + '/coucou',
179 statusCodeExpected: 400
180 })
5f04dd2f
C
181 })
182
183 it('Should return 404 with an incorrect video channel', async function () {
11ba2ab3
C
184 await makeGetRequest({
185 url: server.url,
186 path: path + '/4da6fde3-88f7-4d16-b119-108df5630b06',
187 statusCodeExpected: 404
188 })
5f04dd2f
C
189 })
190
191 it('Should succeed with the correct parameters', async function () {
11ba2ab3
C
192 await makeGetRequest({
193 url: server.url,
194 path: path + '/' + videoChannelId,
195 statusCodeExpected: 200
196 })
5f04dd2f
C
197 })
198 })
199
200 describe('When deleting a video channel', function () {
201 let videoChannelId: number
202
203 before(async function () {
204 const res = await getVideoChannelsList(server.url, 0, 1)
205 videoChannelId = res.body.data[0].id
206 })
207
208 it('Should fail with a non authenticated user', async function () {
11ba2ab3 209 await deleteVideoChannel(server.url, 'coucou', videoChannelId, 401)
5f04dd2f
C
210 })
211
212 it('Should fail with another authenticated user', async function () {
11ba2ab3 213 await deleteVideoChannel(server.url, accessTokenUser, videoChannelId, 403)
5f04dd2f
C
214 })
215
216 it('Should fail with an unknown id', async function () {
11ba2ab3 217 await deleteVideoChannel(server.url, server.accessToken, 454554, 404)
5f04dd2f
C
218 })
219
220 it('Should succeed with the correct parameters', async function () {
11ba2ab3 221 await deleteVideoChannel(server.url, server.accessToken, videoChannelId)
5f04dd2f
C
222 })
223
224 it('Should fail to delete the last user video channel', async function () {
225 const res = await getVideoChannelsList(server.url, 0, 1)
226 videoChannelId = res.body.data[0].id
227
11ba2ab3 228 await deleteVideoChannel(server.url, server.accessToken, videoChannelId, 409)
5f04dd2f
C
229 })
230 })
231
232 after(async function () {
233 killallServers([ server ])
234
235 // Keep the logs if the test failed
236 if (this['ok']) {
237 await flushTests()
238 }
239 })
240})