]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/bulk.ts
shared/ typescript types dir server-commands
[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 { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 import { HttpStatusCode } from '@shared/models'
6
7 describe('Test bulk API validators', function () {
8 let server: PeerTubeServer
9 let userAccessToken: string
10
11 // ---------------------------------------------------------------
12
13 before(async function () {
14 this.timeout(120000)
15
16 server = await createSingleServer(1)
17 await setAccessTokensToServers([ server ])
18
19 const user = { username: 'user1', password: 'password' }
20 await server.users.create({ username: user.username, password: user.password })
21
22 userAccessToken = await server.login.getAccessToken(user)
23 })
24
25 describe('When removing comments of', function () {
26 const path = '/api/v1/bulk/remove-comments-of'
27
28 it('Should fail with an unauthenticated user', async function () {
29 await makePostBodyRequest({
30 url: server.url,
31 path,
32 fields: { accountName: 'user1', scope: 'my-videos' },
33 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
34 })
35 })
36
37 it('Should fail with an unknown account', async function () {
38 await makePostBodyRequest({
39 url: server.url,
40 token: server.accessToken,
41 path,
42 fields: { accountName: 'user2', scope: 'my-videos' },
43 expectedStatus: HttpStatusCode.NOT_FOUND_404
44 })
45 })
46
47 it('Should fail with an invalid scope', async function () {
48 await makePostBodyRequest({
49 url: server.url,
50 token: server.accessToken,
51 path,
52 fields: { accountName: 'user1', scope: 'my-videoss' },
53 expectedStatus: HttpStatusCode.BAD_REQUEST_400
54 })
55 })
56
57 it('Should fail to delete comments of the instance without the appropriate rights', async function () {
58 await makePostBodyRequest({
59 url: server.url,
60 token: userAccessToken,
61 path,
62 fields: { accountName: 'user1', scope: 'instance' },
63 expectedStatus: HttpStatusCode.FORBIDDEN_403
64 })
65 })
66
67 it('Should succeed with the correct params', async function () {
68 await makePostBodyRequest({
69 url: server.url,
70 token: server.accessToken,
71 path,
72 fields: { accountName: 'user1', scope: 'instance' },
73 expectedStatus: HttpStatusCode.NO_CONTENT_204
74 })
75 })
76 })
77
78 after(async function () {
79 await cleanupTests([ server ])
80 })
81 })