1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 import { HttpStatusCode } from '@shared/models'
7 describe('Test bulk API validators', function () {
8 let server: PeerTubeServer
9 let userAccessToken: string
11 // ---------------------------------------------------------------
13 before(async function () {
16 server = await createSingleServer(1)
17 await setAccessTokensToServers([ server ])
19 const user = { username: 'user1', password: 'password' }
20 await server.users.create({ username: user.username, password: user.password })
22 userAccessToken = await server.login.getAccessToken(user)
25 describe('When removing comments of', function () {
26 const path = '/api/v1/bulk/remove-comments-of'
28 it('Should fail with an unauthenticated user', async function () {
29 await makePostBodyRequest({
32 fields: { accountName: 'user1', scope: 'my-videos' },
33 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
37 it('Should fail with an unknown account', async function () {
38 await makePostBodyRequest({
40 token: server.accessToken,
42 fields: { accountName: 'user2', scope: 'my-videos' },
43 expectedStatus: HttpStatusCode.NOT_FOUND_404
47 it('Should fail with an invalid scope', async function () {
48 await makePostBodyRequest({
50 token: server.accessToken,
52 fields: { accountName: 'user1', scope: 'my-videoss' },
53 expectedStatus: HttpStatusCode.BAD_REQUEST_400
57 it('Should fail to delete comments of the instance without the appropriate rights', async function () {
58 await makePostBodyRequest({
60 token: userAccessToken,
62 fields: { accountName: 'user1', scope: 'instance' },
63 expectedStatus: HttpStatusCode.FORBIDDEN_403
67 it('Should succeed with the correct params', async function () {
68 await makePostBodyRequest({
70 token: server.accessToken,
72 fields: { accountName: 'user1', scope: 'instance' },
73 expectedStatus: HttpStatusCode.NO_CONTENT_204
78 after(async function () {
79 await cleanupTests([ server ])