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