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