aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/follows.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/follows.ts')
-rw-r--r--server/tests/api/check-params/follows.ts112
1 files changed, 56 insertions, 56 deletions
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index c03dd5c9c..2bc9f6b96 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -1,33 +1,29 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import {
6 cleanupTests,
7 createUser,
8 flushAndRunServer,
9 makeDeleteRequest, makeGetRequest,
10 makePostBodyRequest,
11 ServerInfo,
12 setAccessTokensToServers,
13 userLogin
14} from '../../../../shared/extra-utils'
15import { 4import {
16 checkBadCountPagination, 5 checkBadCountPagination,
17 checkBadSortPagination, 6 checkBadSortPagination,
18 checkBadStartPagination 7 checkBadStartPagination,
19} from '../../../../shared/extra-utils/requests/check-api-params' 8 cleanupTests,
20import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 9 createSingleServer,
10 makeDeleteRequest,
11 makeGetRequest,
12 makePostBodyRequest,
13 PeerTubeServer,
14 setAccessTokensToServers
15} from '@shared/extra-utils'
16import { HttpStatusCode } from '@shared/models'
21 17
22describe('Test server follows API validators', function () { 18describe('Test server follows API validators', function () {
23 let server: ServerInfo 19 let server: PeerTubeServer
24 20
25 // --------------------------------------------------------------- 21 // ---------------------------------------------------------------
26 22
27 before(async function () { 23 before(async function () {
28 this.timeout(30000) 24 this.timeout(30000)
29 25
30 server = await flushAndRunServer(1) 26 server = await createSingleServer(1)
31 27
32 await setAccessTokensToServers([ server ]) 28 await setAccessTokensToServers([ server ])
33 }) 29 })
@@ -36,64 +32,68 @@ describe('Test server follows API validators', function () {
36 let userAccessToken = null 32 let userAccessToken = null
37 33
38 before(async function () { 34 before(async function () {
39 const user = { 35 userAccessToken = await server.users.generateUserAndToken('user1')
40 username: 'user1',
41 password: 'password'
42 }
43
44 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
45 userAccessToken = await userLogin(server, user)
46 }) 36 })
47 37
48 describe('When adding follows', function () { 38 describe('When adding follows', function () {
49 const path = '/api/v1/server/following' 39 const path = '/api/v1/server/following'
50 40
51 it('Should fail without hosts', async function () { 41 it('Should fail with nothing', async function () {
52 await makePostBodyRequest({ 42 await makePostBodyRequest({
53 url: server.url, 43 url: server.url,
54 path, 44 path,
55 token: server.accessToken, 45 token: server.accessToken,
56 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 46 expectedStatus: HttpStatusCode.BAD_REQUEST_400
57 }) 47 })
58 }) 48 })
59 49
60 it('Should fail if hosts is not an array', async function () { 50 it('Should fail if hosts is not composed by hosts', async function () {
61 await makePostBodyRequest({ 51 await makePostBodyRequest({
62 url: server.url, 52 url: server.url,
63 path, 53 path,
54 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
64 token: server.accessToken, 55 token: server.accessToken,
65 fields: { hosts: 'localhost:9002' }, 56 expectedStatus: HttpStatusCode.BAD_REQUEST_400
66 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
67 }) 57 })
68 }) 58 })
69 59
70 it('Should fail if the array is not composed by hosts', async function () { 60 it('Should fail if hosts is composed with http schemes', async function () {
71 await makePostBodyRequest({ 61 await makePostBodyRequest({
72 url: server.url, 62 url: server.url,
73 path, 63 path,
74 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, 64 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
65 token: server.accessToken,
66 expectedStatus: HttpStatusCode.BAD_REQUEST_400
67 })
68 })
69
70 it('Should fail if hosts are not unique', async function () {
71 await makePostBodyRequest({
72 url: server.url,
73 path,
74 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
75 token: server.accessToken, 75 token: server.accessToken,
76 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 76 expectedStatus: HttpStatusCode.BAD_REQUEST_400
77 }) 77 })
78 }) 78 })
79 79
80 it('Should fail if the array is composed with http schemes', async function () { 80 it('Should fail if handles is not composed by handles', async function () {
81 await makePostBodyRequest({ 81 await makePostBodyRequest({
82 url: server.url, 82 url: server.url,
83 path, 83 path,
84 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, 84 fields: { handles: [ 'hello@example.com', 'localhost:9001' ] },
85 token: server.accessToken, 85 token: server.accessToken,
86 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 86 expectedStatus: HttpStatusCode.BAD_REQUEST_400
87 }) 87 })
88 }) 88 })
89 89
90 it('Should fail if hosts are not unique', async function () { 90 it('Should fail if handles are not unique', async function () {
91 await makePostBodyRequest({ 91 await makePostBodyRequest({
92 url: server.url, 92 url: server.url,
93 path, 93 path,
94 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, 94 fields: { urls: [ 'hello@example.com', 'hello@example.com' ] },
95 token: server.accessToken, 95 token: server.accessToken,
96 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 96 expectedStatus: HttpStatusCode.BAD_REQUEST_400
97 }) 97 })
98 }) 98 })
99 99
@@ -103,7 +103,7 @@ describe('Test server follows API validators', function () {
103 path, 103 path,
104 fields: { hosts: [ 'localhost:9002' ] }, 104 fields: { hosts: [ 'localhost:9002' ] },
105 token: 'fake_token', 105 token: 'fake_token',
106 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 106 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
107 }) 107 })
108 }) 108 })
109 109
@@ -113,7 +113,7 @@ describe('Test server follows API validators', function () {
113 path, 113 path,
114 fields: { hosts: [ 'localhost:9002' ] }, 114 fields: { hosts: [ 'localhost:9002' ] },
115 token: userAccessToken, 115 token: userAccessToken,
116 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 116 expectedStatus: HttpStatusCode.FORBIDDEN_403
117 }) 117 })
118 }) 118 })
119 }) 119 })
@@ -157,7 +157,7 @@ describe('Test server follows API validators', function () {
157 await makeGetRequest({ 157 await makeGetRequest({
158 url: server.url, 158 url: server.url,
159 path, 159 path,
160 statusCodeExpected: HttpStatusCode.OK_200, 160 expectedStatus: HttpStatusCode.OK_200,
161 query: { 161 query: {
162 state: 'accepted', 162 state: 'accepted',
163 actorType: 'Application' 163 actorType: 'Application'
@@ -206,7 +206,7 @@ describe('Test server follows API validators', function () {
206 await makeGetRequest({ 206 await makeGetRequest({
207 url: server.url, 207 url: server.url,
208 path, 208 path,
209 statusCodeExpected: HttpStatusCode.OK_200, 209 expectedStatus: HttpStatusCode.OK_200,
210 query: { 210 query: {
211 state: 'accepted' 211 state: 'accepted'
212 } 212 }
@@ -222,7 +222,7 @@ describe('Test server follows API validators', function () {
222 url: server.url, 222 url: server.url,
223 path: path + '/toto@localhost:9002', 223 path: path + '/toto@localhost:9002',
224 token: 'fake_token', 224 token: 'fake_token',
225 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 225 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
226 }) 226 })
227 }) 227 })
228 228
@@ -231,7 +231,7 @@ describe('Test server follows API validators', function () {
231 url: server.url, 231 url: server.url,
232 path: path + '/toto@localhost:9002', 232 path: path + '/toto@localhost:9002',
233 token: userAccessToken, 233 token: userAccessToken,
234 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 234 expectedStatus: HttpStatusCode.FORBIDDEN_403
235 }) 235 })
236 }) 236 })
237 237
@@ -240,7 +240,7 @@ describe('Test server follows API validators', function () {
240 url: server.url, 240 url: server.url,
241 path: path + '/toto', 241 path: path + '/toto',
242 token: server.accessToken, 242 token: server.accessToken,
243 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 243 expectedStatus: HttpStatusCode.BAD_REQUEST_400
244 }) 244 })
245 }) 245 })
246 246
@@ -249,7 +249,7 @@ describe('Test server follows API validators', function () {
249 url: server.url, 249 url: server.url,
250 path: path + '/toto@localhost:9003', 250 path: path + '/toto@localhost:9003',
251 token: server.accessToken, 251 token: server.accessToken,
252 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 252 expectedStatus: HttpStatusCode.NOT_FOUND_404
253 }) 253 })
254 }) 254 })
255 }) 255 })
@@ -262,7 +262,7 @@ describe('Test server follows API validators', function () {
262 url: server.url, 262 url: server.url,
263 path: path + '/toto@localhost:9002/accept', 263 path: path + '/toto@localhost:9002/accept',
264 token: 'fake_token', 264 token: 'fake_token',
265 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 265 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
266 }) 266 })
267 }) 267 })
268 268
@@ -271,7 +271,7 @@ describe('Test server follows API validators', function () {
271 url: server.url, 271 url: server.url,
272 path: path + '/toto@localhost:9002/accept', 272 path: path + '/toto@localhost:9002/accept',
273 token: userAccessToken, 273 token: userAccessToken,
274 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 274 expectedStatus: HttpStatusCode.FORBIDDEN_403
275 }) 275 })
276 }) 276 })
277 277
@@ -280,7 +280,7 @@ describe('Test server follows API validators', function () {
280 url: server.url, 280 url: server.url,
281 path: path + '/toto/accept', 281 path: path + '/toto/accept',
282 token: server.accessToken, 282 token: server.accessToken,
283 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 283 expectedStatus: HttpStatusCode.BAD_REQUEST_400
284 }) 284 })
285 }) 285 })
286 286
@@ -289,7 +289,7 @@ describe('Test server follows API validators', function () {
289 url: server.url, 289 url: server.url,
290 path: path + '/toto@localhost:9003/accept', 290 path: path + '/toto@localhost:9003/accept',
291 token: server.accessToken, 291 token: server.accessToken,
292 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 292 expectedStatus: HttpStatusCode.NOT_FOUND_404
293 }) 293 })
294 }) 294 })
295 }) 295 })
@@ -302,7 +302,7 @@ describe('Test server follows API validators', function () {
302 url: server.url, 302 url: server.url,
303 path: path + '/toto@localhost:9002/reject', 303 path: path + '/toto@localhost:9002/reject',
304 token: 'fake_token', 304 token: 'fake_token',
305 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 305 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
306 }) 306 })
307 }) 307 })
308 308
@@ -311,7 +311,7 @@ describe('Test server follows API validators', function () {
311 url: server.url, 311 url: server.url,
312 path: path + '/toto@localhost:9002/reject', 312 path: path + '/toto@localhost:9002/reject',
313 token: userAccessToken, 313 token: userAccessToken,
314 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 314 expectedStatus: HttpStatusCode.FORBIDDEN_403
315 }) 315 })
316 }) 316 })
317 317
@@ -320,7 +320,7 @@ describe('Test server follows API validators', function () {
320 url: server.url, 320 url: server.url,
321 path: path + '/toto/reject', 321 path: path + '/toto/reject',
322 token: server.accessToken, 322 token: server.accessToken,
323 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 323 expectedStatus: HttpStatusCode.BAD_REQUEST_400
324 }) 324 })
325 }) 325 })
326 326
@@ -329,7 +329,7 @@ describe('Test server follows API validators', function () {
329 url: server.url, 329 url: server.url,
330 path: path + '/toto@localhost:9003/reject', 330 path: path + '/toto@localhost:9003/reject',
331 token: server.accessToken, 331 token: server.accessToken,
332 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 332 expectedStatus: HttpStatusCode.NOT_FOUND_404
333 }) 333 })
334 }) 334 })
335 }) 335 })
@@ -342,7 +342,7 @@ describe('Test server follows API validators', function () {
342 url: server.url, 342 url: server.url,
343 path: path + '/localhost:9002', 343 path: path + '/localhost:9002',
344 token: 'fake_token', 344 token: 'fake_token',
345 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 345 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
346 }) 346 })
347 }) 347 })
348 348
@@ -351,7 +351,7 @@ describe('Test server follows API validators', function () {
351 url: server.url, 351 url: server.url,
352 path: path + '/localhost:9002', 352 path: path + '/localhost:9002',
353 token: userAccessToken, 353 token: userAccessToken,
354 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 354 expectedStatus: HttpStatusCode.FORBIDDEN_403
355 }) 355 })
356 }) 356 })
357 357
@@ -360,7 +360,7 @@ describe('Test server follows API validators', function () {
360 url: server.url, 360 url: server.url,
361 path: path + '/example.com', 361 path: path + '/example.com',
362 token: server.accessToken, 362 token: server.accessToken,
363 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 363 expectedStatus: HttpStatusCode.NOT_FOUND_404
364 }) 364 })
365 }) 365 })
366 }) 366 })