1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
4 import { HttpStatusCode } from '@shared/models'
6 describe('Test bulk API validators', function () {
7 let server: PeerTubeServer
8 let userAccessToken: string
10 // ---------------------------------------------------------------
12 before(async function () {
15 server = await createSingleServer(1)
16 await setAccessTokensToServers([ server ])
18 const user = { username: 'user1', password: 'password' }
19 await server.users.create({ username: user.username, password: user.password })
21 userAccessToken = await server.login.getAccessToken(user)
24 describe('When removing comments of', function () {
25 const path = '/api/v1/bulk/remove-comments-of'
27 it('Should fail with an unauthenticated user', async function () {
28 await makePostBodyRequest({
31 fields: { accountName: 'user1', scope: 'my-videos' },
32 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
36 it('Should fail with an unknown account', async function () {
37 await makePostBodyRequest({
39 token: server.accessToken,
41 fields: { accountName: 'user2', scope: 'my-videos' },
42 expectedStatus: HttpStatusCode.NOT_FOUND_404
46 it('Should fail with an invalid scope', async function () {
47 await makePostBodyRequest({
49 token: server.accessToken,
51 fields: { accountName: 'user1', scope: 'my-videoss' },
52 expectedStatus: HttpStatusCode.BAD_REQUEST_400
56 it('Should fail to delete comments of the instance without the appropriate rights', async function () {
57 await makePostBodyRequest({
59 token: userAccessToken,
61 fields: { accountName: 'user1', scope: 'instance' },
62 expectedStatus: HttpStatusCode.FORBIDDEN_403
66 it('Should succeed with the correct params', async function () {
67 await makePostBodyRequest({
69 token: server.accessToken,
71 fields: { accountName: 'user1', scope: 'instance' },
72 expectedStatus: HttpStatusCode.NO_CONTENT_204
77 after(async function () {
78 await cleanupTests([ server ])