]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { | |
5 | cleanupTests, | |
6 | createSingleServer, | |
7 | PeerTubeServer, | |
8 | setAccessTokensToServers | |
9 | } from '../../../../shared/extra-utils' | |
10 | import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' | |
11 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
12 | ||
13 | describe('Test bulk API validators', function () { | |
14 | let server: PeerTubeServer | |
15 | let userAccessToken: string | |
16 | ||
17 | // --------------------------------------------------------------- | |
18 | ||
19 | before(async function () { | |
20 | this.timeout(120000) | |
21 | ||
22 | server = await createSingleServer(1) | |
23 | await setAccessTokensToServers([ server ]) | |
24 | ||
25 | const user = { username: 'user1', password: 'password' } | |
26 | await server.users.create({ username: user.username, password: user.password }) | |
27 | ||
28 | userAccessToken = await server.login.getAccessToken(user) | |
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' }, | |
39 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
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' }, | |
49 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
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' }, | |
59 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
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' }, | |
69 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
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' }, | |
79 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
80 | }) | |
81 | }) | |
82 | }) | |
83 | ||
84 | after(async function () { | |
85 | await cleanupTests([ server ]) | |
86 | }) | |
87 | }) |