diff options
Diffstat (limited to 'packages/tests/src/api/check-params/jobs.ts')
-rw-r--r-- | packages/tests/src/api/check-params/jobs.ts | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/packages/tests/src/api/check-params/jobs.ts b/packages/tests/src/api/check-params/jobs.ts new file mode 100644 index 000000000..331d58c6a --- /dev/null +++ b/packages/tests/src/api/check-params/jobs.ts | |||
@@ -0,0 +1,125 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@tests/shared/checks.js' | ||
4 | import { HttpStatusCode } from '@peertube/peertube-models' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createSingleServer, | ||
8 | makeGetRequest, | ||
9 | makePostBodyRequest, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers | ||
12 | } from '@peertube/peertube-server-commands' | ||
13 | |||
14 | describe('Test jobs API validators', function () { | ||
15 | const path = '/api/v1/jobs/failed' | ||
16 | let server: PeerTubeServer | ||
17 | let userAccessToken = '' | ||
18 | |||
19 | // --------------------------------------------------------------- | ||
20 | |||
21 | before(async function () { | ||
22 | this.timeout(120000) | ||
23 | |||
24 | server = await createSingleServer(1) | ||
25 | |||
26 | await setAccessTokensToServers([ server ]) | ||
27 | |||
28 | const user = { | ||
29 | username: 'user1', | ||
30 | password: 'my super password' | ||
31 | } | ||
32 | await server.users.create({ username: user.username, password: user.password }) | ||
33 | userAccessToken = await server.login.getAccessToken(user) | ||
34 | }) | ||
35 | |||
36 | describe('When listing jobs', function () { | ||
37 | |||
38 | it('Should fail with a bad state', async function () { | ||
39 | await makeGetRequest({ | ||
40 | url: server.url, | ||
41 | token: server.accessToken, | ||
42 | path: path + 'ade' | ||
43 | }) | ||
44 | }) | ||
45 | |||
46 | it('Should fail with an incorrect job type', async function () { | ||
47 | await makeGetRequest({ | ||
48 | url: server.url, | ||
49 | token: server.accessToken, | ||
50 | path, | ||
51 | query: { | ||
52 | jobType: 'toto' | ||
53 | } | ||
54 | }) | ||
55 | }) | ||
56 | |||
57 | it('Should fail with a bad start pagination', async function () { | ||
58 | await checkBadStartPagination(server.url, path, server.accessToken) | ||
59 | }) | ||
60 | |||
61 | it('Should fail with a bad count pagination', async function () { | ||
62 | await checkBadCountPagination(server.url, path, server.accessToken) | ||
63 | }) | ||
64 | |||
65 | it('Should fail with an incorrect sort', async function () { | ||
66 | await checkBadSortPagination(server.url, path, server.accessToken) | ||
67 | }) | ||
68 | |||
69 | it('Should fail with a non authenticated user', async function () { | ||
70 | await makeGetRequest({ | ||
71 | url: server.url, | ||
72 | path, | ||
73 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
74 | }) | ||
75 | }) | ||
76 | |||
77 | it('Should fail with a non admin user', async function () { | ||
78 | await makeGetRequest({ | ||
79 | url: server.url, | ||
80 | path, | ||
81 | token: userAccessToken, | ||
82 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
83 | }) | ||
84 | }) | ||
85 | }) | ||
86 | |||
87 | describe('When pausing/resuming the job queue', async function () { | ||
88 | const commands = [ 'pause', 'resume' ] | ||
89 | |||
90 | it('Should fail with a non authenticated user', async function () { | ||
91 | for (const command of commands) { | ||
92 | await makePostBodyRequest({ | ||
93 | url: server.url, | ||
94 | path: '/api/v1/jobs/' + command, | ||
95 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
96 | }) | ||
97 | } | ||
98 | }) | ||
99 | |||
100 | it('Should fail with a non admin user', async function () { | ||
101 | for (const command of commands) { | ||
102 | await makePostBodyRequest({ | ||
103 | url: server.url, | ||
104 | path: '/api/v1/jobs/' + command, | ||
105 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
106 | }) | ||
107 | } | ||
108 | }) | ||
109 | |||
110 | it('Should succeed with the correct params', async function () { | ||
111 | for (const command of commands) { | ||
112 | await makePostBodyRequest({ | ||
113 | url: server.url, | ||
114 | path: '/api/v1/jobs/' + command, | ||
115 | token: server.accessToken, | ||
116 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
117 | }) | ||
118 | } | ||
119 | }) | ||
120 | }) | ||
121 | |||
122 | after(async function () { | ||
123 | await cleanupTests([ server ]) | ||
124 | }) | ||
125 | }) | ||