]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/bulk.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / bulk.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import {
5 cleanupTests,
6 createUser,
7 flushAndRunServer,
8 ServerInfo,
9 setAccessTokensToServers,
10 userLogin
11 } from '../../../../shared/extra-utils'
12 import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests'
13 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14
15 describe('Test bulk API validators', function () {
16 let server: ServerInfo
17 let userAccessToken: string
18
19 // ---------------------------------------------------------------
20
21 before(async function () {
22 this.timeout(120000)
23
24 server = await flushAndRunServer(1)
25 await setAccessTokensToServers([ server ])
26
27 const user = { username: 'user1', password: 'password' }
28 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
29
30 userAccessToken = await userLogin(server, user)
31 })
32
33 describe('When removing comments of', function () {
34 const path = '/api/v1/bulk/remove-comments-of'
35
36 it('Should fail with an unauthenticated user', async function () {
37 await makePostBodyRequest({
38 url: server.url,
39 path,
40 fields: { accountName: 'user1', scope: 'my-videos' },
41 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
42 })
43 })
44
45 it('Should fail with an unknown account', async function () {
46 await makePostBodyRequest({
47 url: server.url,
48 token: server.accessToken,
49 path,
50 fields: { accountName: 'user2', scope: 'my-videos' },
51 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
52 })
53 })
54
55 it('Should fail with an invalid scope', async function () {
56 await makePostBodyRequest({
57 url: server.url,
58 token: server.accessToken,
59 path,
60 fields: { accountName: 'user1', scope: 'my-videoss' },
61 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
62 })
63 })
64
65 it('Should fail to delete comments of the instance without the appropriate rights', async function () {
66 await makePostBodyRequest({
67 url: server.url,
68 token: userAccessToken,
69 path,
70 fields: { accountName: 'user1', scope: 'instance' },
71 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
72 })
73 })
74
75 it('Should succeed with the correct params', async function () {
76 await makePostBodyRequest({
77 url: server.url,
78 token: server.accessToken,
79 path,
80 fields: { accountName: 'user1', scope: 'instance' },
81 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
82 })
83 })
84 })
85
86 after(async function () {
87 await cleanupTests([ server ])
88 })
89 })