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