diff options
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/bulk.ts | 88 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 |
2 files changed, 89 insertions, 0 deletions
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts new file mode 100644 index 000000000..432858b33 --- /dev/null +++ b/server/tests/api/check-params/bulk.ts | |||
@@ -0,0 +1,88 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { | ||
5 | cleanupTests, | ||
6 | createUser, | ||
7 | flushAndRunServer, | ||
8 | ServerInfo, | ||
9 | setAccessTokensToServers, | ||
10 | userLogin | ||
11 | } from '../../../../shared/extra-utils' | ||
12 | import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' | ||
13 | |||
14 | describe('Test bulk API validators', function () { | ||
15 | let server: ServerInfo | ||
16 | let userAccessToken: string | ||
17 | |||
18 | // --------------------------------------------------------------- | ||
19 | |||
20 | before(async function () { | ||
21 | this.timeout(120000) | ||
22 | |||
23 | server = await flushAndRunServer(1) | ||
24 | await setAccessTokensToServers([ server ]) | ||
25 | |||
26 | const user = { username: 'user1', password: 'password' } | ||
27 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | ||
28 | |||
29 | userAccessToken = await userLogin(server, user) | ||
30 | }) | ||
31 | |||
32 | describe('When removing comments of', function () { | ||
33 | const path = '/api/v1/bulk/remove-comments-of' | ||
34 | |||
35 | it('Should fail with an unauthenticated user', async function () { | ||
36 | await makePostBodyRequest({ | ||
37 | url: server.url, | ||
38 | path, | ||
39 | fields: { accountName: 'user1', scope: 'my-videos' }, | ||
40 | statusCodeExpected: 401 | ||
41 | }) | ||
42 | }) | ||
43 | |||
44 | it('Should fail with an unknown account', async function () { | ||
45 | await makePostBodyRequest({ | ||
46 | url: server.url, | ||
47 | token: server.accessToken, | ||
48 | path, | ||
49 | fields: { accountName: 'user2', scope: 'my-videos' }, | ||
50 | statusCodeExpected: 404 | ||
51 | }) | ||
52 | }) | ||
53 | |||
54 | it('Should fail with an invalid scope', async function () { | ||
55 | await makePostBodyRequest({ | ||
56 | url: server.url, | ||
57 | token: server.accessToken, | ||
58 | path, | ||
59 | fields: { accountName: 'user1', scope: 'my-videoss' }, | ||
60 | statusCodeExpected: 400 | ||
61 | }) | ||
62 | }) | ||
63 | |||
64 | it('Should fail to delete comments of the instance without the appropriate rights', async function () { | ||
65 | await makePostBodyRequest({ | ||
66 | url: server.url, | ||
67 | token: userAccessToken, | ||
68 | path, | ||
69 | fields: { accountName: 'user1', scope: 'instance' }, | ||
70 | statusCodeExpected: 403 | ||
71 | }) | ||
72 | }) | ||
73 | |||
74 | it('Should succeed with the correct params', async function () { | ||
75 | await makePostBodyRequest({ | ||
76 | url: server.url, | ||
77 | token: server.accessToken, | ||
78 | path, | ||
79 | fields: { accountName: 'user1', scope: 'instance' }, | ||
80 | statusCodeExpected: 204 | ||
81 | }) | ||
82 | }) | ||
83 | }) | ||
84 | |||
85 | after(async function () { | ||
86 | await cleanupTests([ server ]) | ||
87 | }) | ||
88 | }) | ||
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index ef152f55c..93ffd98b1 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import './accounts' | 1 | import './accounts' |
2 | import './blocklist' | 2 | import './blocklist' |
3 | import './bulk' | ||
3 | import './config' | 4 | import './config' |
4 | import './contact-form' | 5 | import './contact-form' |
5 | import './debug' | 6 | import './debug' |