aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-channels.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-28 16:26:28 +0100
committerChocobozzz <me@florianbigard.com>2017-12-28 16:30:58 +0100
commit11ba2ab3f1e3ec29b3765fa0c1ff4ed410c851a9 (patch)
tree2adb1d78aaf42dfd817d628abff12a618a6ae8f0 /server/tests/api/check-params/video-channels.ts
parent26d21b7867c225d99e0625af51da4643e351d86d (diff)
downloadPeerTube-11ba2ab3f1e3ec29b3765fa0c1ff4ed410c851a9.tar.gz
PeerTube-11ba2ab3f1e3ec29b3765fa0c1ff4ed410c851a9.tar.zst
PeerTube-11ba2ab3f1e3ec29b3765fa0c1ff4ed410c851a9.zip
Improve check videos parameters tests
Diffstat (limited to 'server/tests/api/check-params/video-channels.ts')
-rw-r--r--server/tests/api/check-params/video-channels.ts206
1 files changed, 68 insertions, 138 deletions
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index bf464152b..22e98d110 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -1,22 +1,15 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as request from 'supertest'
4import 'mocha'
5import * as chai from 'chai' 3import * as chai from 'chai'
6const expect = chai.expect 4import { omit } from 'lodash'
7 5import 'mocha'
8import { 6import {
9 ServerInfo, 7 createUser, deleteVideoChannel, flushTests, getAccountVideoChannelsList, getVideoChannelsList, immutableAssign, killallServers,
10 flushTests, 8 makeGetRequest, makePostBodyRequest, makePutBodyRequest, runServer, ServerInfo, setAccessTokensToServers, userLogin
11 runServer,
12 makePutBodyRequest,
13 setAccessTokensToServers,
14 killallServers,
15 makePostBodyRequest,
16 getVideoChannelsList,
17 createUser,
18 userLogin
19} from '../../utils' 9} from '../../utils'
10import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
11
12const expect = chai.expect
20 13
21describe('Test videos API validator', function () { 14describe('Test videos API validator', function () {
22 const path = '/api/v1/videos/channels' 15 const path = '/api/v1/videos/channels'
@@ -39,64 +32,41 @@ describe('Test videos API validator', function () {
39 password: 'fake_password' 32 password: 'fake_password'
40 } 33 }
41 await createUser(server.url, server.accessToken, user.username, user.password) 34 await createUser(server.url, server.accessToken, user.username, user.password)
42
43 accessTokenUser = await userLogin(server, user) 35 accessTokenUser = await userLogin(server, user)
44 }) 36 })
45 37
46 describe('When listing a video channels', function () { 38 describe('When listing a video channels', function () {
47 it('Should fail with a bad start pagination', async function () { 39 it('Should fail with a bad start pagination', async function () {
48 await request(server.url) 40 await checkBadStartPagination(server.url, path, server.accessToken)
49 .get(path)
50 .query({ start: 'hello' })
51 .set('Accept', 'application/json')
52 .expect(400)
53 }) 41 })
54 42
55 it('Should fail with a bad count pagination', async function () { 43 it('Should fail with a bad count pagination', async function () {
56 await request(server.url) 44 await checkBadCountPagination(server.url, path, server.accessToken)
57 .get(path)
58 .query({ count: 'hello' })
59 .set('Accept', 'application/json')
60 .expect(400)
61 }) 45 })
62 46
63 it('Should fail with an incorrect sort', async function () { 47 it('Should fail with an incorrect sort', async function () {
64 await request(server.url) 48 await checkBadSortPagination(server.url, path, server.accessToken)
65 .get(path)
66 .query({ sort: 'hello' })
67 .set('Accept', 'application/json')
68 .expect(400)
69 }) 49 })
70 }) 50 })
71 51
72 describe('When listing account video channels', function () { 52 describe('When listing account video channels', function () {
73 it('Should fail with bad account', async function () { 53 it('Should fail with bad account', async function () {
74 const path = '/api/v1/videos/accounts/hello/channels' 54 await getAccountVideoChannelsList(server.url, 'hello', 400)
75
76 await request(server.url)
77 .get(path)
78 .set('Accept', 'application/json')
79 .expect(400)
80 }) 55 })
81 56
82 it('Should fail with a unknown account', async function () { 57 it('Should fail with a unknown account', async function () {
83 const path = '/api/v1/videos/accounts/156/channels' 58 await getAccountVideoChannelsList(server.url, 154, 404)
84
85 await request(server.url)
86 .get(path)
87 .set('Accept', 'application/json')
88 .expect(404)
89 }) 59 })
90 }) 60 })
91 61
92 describe('When adding a video channel', function () { 62 describe('When adding a video channel', function () {
63 const baseCorrectParams = {
64 name: 'hello',
65 description: 'super description'
66 }
93 67
94 it('Should fail with a non authenticated user', async function () { 68 it('Should fail with a non authenticated user', async function () {
95 const fields = { 69 await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
96 name: 'hello',
97 description: 'super description'
98 }
99 await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 })
100 }) 70 })
101 71
102 it('Should fail with nothing', async function () { 72 it('Should fail with nothing', async function () {
@@ -105,45 +75,37 @@ describe('Test videos API validator', function () {
105 }) 75 })
106 76
107 it('Should fail without name', async function () { 77 it('Should fail without name', async function () {
108 const fields = { 78 const fields = omit(baseCorrectParams, 'name')
109 description: 'super description'
110 }
111 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 79 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
112 }) 80 })
113 81
114 it('Should fail with a long name', async function () { 82 it('Should fail with a long name', async function () {
115 const fields = { 83 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
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 }) 84 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
124 }) 85 })
125 86
126 it('Should fail with a long description', async function () { 87 it('Should fail with a long description', async function () {
127 const fields = { 88 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
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 }) 89 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 }) 90 })
136 91
137 it('Should succeed with the correct parameters', async function () { 92 it('Should succeed with the correct parameters', async function () {
138 const fields = { 93 await makePostBodyRequest({
139 name: 'hello', 94 url: server.url,
140 description: 'super description' 95 path,
141 } 96 token: server.accessToken,
142 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) 97 fields: baseCorrectParams,
98 statusCodeExpected: 204
99 })
143 }) 100 })
144 }) 101 })
145 102
146 describe('When updating a video channel', function () { 103 describe('When updating a video channel', function () {
104 const baseCorrectParams = {
105 name: 'hello',
106 description: 'super description'
107 }
108
147 let videoChannelId 109 let videoChannelId
148 110
149 before(async function () { 111 before(async function () {
@@ -152,60 +114,41 @@ describe('Test videos API validator', function () {
152 }) 114 })
153 115
154 it('Should fail with a non authenticated user', async function () { 116 it('Should fail with a non authenticated user', async function () {
155 const fields = { 117 await makePutBodyRequest({
156 name: 'hello', 118 url: server.url,
157 description: 'super description' 119 path: path + '/' + videoChannelId,
158 } 120 token: 'hi',
159 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 }) 121 fields: baseCorrectParams,
122 statusCodeExpected: 401
123 })
160 }) 124 })
161 125
162 it('Should fail with another authenticated user', async function () { 126 it('Should fail with another authenticated user', async function () {
163 const fields = {
164 name: 'hello',
165 description: 'super description'
166 }
167 await makePutBodyRequest({ 127 await makePutBodyRequest({
168 url: server.url, 128 url: server.url,
169 path: path + '/' + videoChannelId, 129 path: path + '/' + videoChannelId,
170 token: accessTokenUser, 130 token: accessTokenUser,
171 fields, 131 fields: baseCorrectParams,
172 statusCodeExpected: 403 132 statusCodeExpected: 403
173 }) 133 })
174 }) 134 })
175 135
176 it('Should fail with a long name', async function () { 136 it('Should fail with a long name', async function () {
177 const fields = { 137 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
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 }) 138 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
186 }) 139 })
187 140
188 it('Should fail with a long description', async function () { 141 it('Should fail with a long description', async function () {
189 const fields = { 142 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
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 }) 143 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
197 }) 144 })
198 145
199 it('Should succeed with the correct parameters', async function () { 146 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({ 147 await makePutBodyRequest({
205 url: server.url, 148 url: server.url,
206 path: path + '/' + videoChannelId, 149 path: path + '/' + videoChannelId,
207 token: server.accessToken, 150 token: server.accessToken,
208 fields, 151 fields: baseCorrectParams,
209 statusCodeExpected: 204 152 statusCodeExpected: 204
210 }) 153 })
211 }) 154 })
@@ -220,34 +163,37 @@ describe('Test videos API validator', function () {
220 }) 163 })
221 164
222 it('Should return the list of the video channels with nothing', async function () { 165 it('Should return the list of the video channels with nothing', async function () {
223 const res = await request(server.url) 166 const res = await makeGetRequest({
224 .get(path) 167 url: server.url,
225 .set('Accept', 'application/json') 168 path,
226 .expect(200) 169 statusCodeExpected: 200
227 .expect('Content-Type', /json/) 170 })
228 171
229 expect(res.body.data).to.be.an('array') 172 expect(res.body.data).to.be.an('array')
230 }) 173 })
231 174
232 it('Should fail without a correct uuid', async function () { 175 it('Should fail without a correct uuid', async function () {
233 await request(server.url) 176 await makeGetRequest({
234 .get(path + '/coucou') 177 url: server.url,
235 .set('Accept', 'application/json') 178 path: path + '/coucou',
236 .expect(400) 179 statusCodeExpected: 400
180 })
237 }) 181 })
238 182
239 it('Should return 404 with an incorrect video channel', async function () { 183 it('Should return 404 with an incorrect video channel', async function () {
240 await request(server.url) 184 await makeGetRequest({
241 .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06') 185 url: server.url,
242 .set('Accept', 'application/json') 186 path: path + '/4da6fde3-88f7-4d16-b119-108df5630b06',
243 .expect(404) 187 statusCodeExpected: 404
188 })
244 }) 189 })
245 190
246 it('Should succeed with the correct parameters', async function () { 191 it('Should succeed with the correct parameters', async function () {
247 await request(server.url) 192 await makeGetRequest({
248 .get(path + '/' + videoChannelId) 193 url: server.url,
249 .set('Accept', 'application/json') 194 path: path + '/' + videoChannelId,
250 .expect(200) 195 statusCodeExpected: 200
196 })
251 }) 197 })
252 }) 198 })
253 199
@@ -260,42 +206,26 @@ describe('Test videos API validator', function () {
260 }) 206 })
261 207
262 it('Should fail with a non authenticated user', async function () { 208 it('Should fail with a non authenticated user', async function () {
263 await request(server.url) 209 await deleteVideoChannel(server.url, 'coucou', videoChannelId, 401)
264 .delete(path + '/' + videoChannelId)
265 .set('Authorization', 'Bearer coucou')
266 .expect(401)
267 }) 210 })
268 211
269 it('Should fail with another authenticated user', async function () { 212 it('Should fail with another authenticated user', async function () {
270 await request(server.url) 213 await deleteVideoChannel(server.url, accessTokenUser, videoChannelId, 403)
271 .delete(path + '/' + videoChannelId)
272 .set('Authorization', 'Bearer ' + accessTokenUser)
273 .expect(403)
274 }) 214 })
275 215
276 it('Should fail with an unknown id', async function () { 216 it('Should fail with an unknown id', async function () {
277 await request(server.url) 217 await deleteVideoChannel(server.url, server.accessToken, 454554, 404)
278 .delete(path + '/454554')
279 .set('Authorization', 'Bearer ' + server.accessToken)
280 .expect(404)
281 }) 218 })
282 219
283 it('Should succeed with the correct parameters', async function () { 220 it('Should succeed with the correct parameters', async function () {
284 await request(server.url) 221 await deleteVideoChannel(server.url, server.accessToken, videoChannelId)
285 .delete(path + '/' + videoChannelId)
286 .set('Authorization', 'Bearer ' + server.accessToken)
287 .expect(204)
288 }) 222 })
289 223
290 it('Should fail to delete the last user video channel', async function () { 224 it('Should fail to delete the last user video channel', async function () {
291 const res = await getVideoChannelsList(server.url, 0, 1) 225 const res = await getVideoChannelsList(server.url, 0, 1)
292 videoChannelId = res.body.data[0].id 226 videoChannelId = res.body.data[0].id
293 227
294 await request(server.url) 228 await deleteVideoChannel(server.url, server.accessToken, videoChannelId, 409)
295 .delete(path + '/' + videoChannelId)
296 .set('Authorization', 'Bearer ' + server.accessToken)
297 .expect(409
298 )
299 }) 229 })
300 }) 230 })
301 231