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