1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
4 import { HttpStatusCode } from '@shared/models'
11 setAccessTokensToServers
12 } from '@shared/server-commands'
14 describe('Test jobs API validators', function () {
15 const path = '/api/v1/jobs/failed'
16 let server: PeerTubeServer
17 let userAccessToken = ''
19 // ---------------------------------------------------------------
21 before(async function () {
24 server = await createSingleServer(1)
26 await setAccessTokensToServers([ server ])
30 password: 'my super password'
32 await server.users.create({ username: user.username, password: user.password })
33 userAccessToken = await server.login.getAccessToken(user)
36 describe('When listing jobs', function () {
38 it('Should fail with a bad state', async function () {
39 await makeGetRequest({
41 token: server.accessToken,
46 it('Should fail with an incorrect job type', async function () {
47 await makeGetRequest({
49 token: server.accessToken,
57 it('Should fail with a bad start pagination', async function () {
58 await checkBadStartPagination(server.url, path, server.accessToken)
61 it('Should fail with a bad count pagination', async function () {
62 await checkBadCountPagination(server.url, path, server.accessToken)
65 it('Should fail with an incorrect sort', async function () {
66 await checkBadSortPagination(server.url, path, server.accessToken)
69 it('Should fail with a non authenticated user', async function () {
70 await makeGetRequest({
73 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
77 it('Should fail with a non admin user', async function () {
78 await makeGetRequest({
81 token: userAccessToken,
82 expectedStatus: HttpStatusCode.FORBIDDEN_403
87 describe('When pausing/resuming the job queue', async function () {
88 const commands = [ 'pause', 'resume' ]
90 it('Should fail with a non authenticated user', async function () {
91 for (const command of commands) {
92 await makePostBodyRequest({
94 path: '/api/v1/jobs/' + command,
95 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
100 it('Should fail with a non admin user', async function () {
101 for (const command of commands) {
102 await makePostBodyRequest({
104 path: '/api/v1/jobs/' + command,
105 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
110 it('Should succeed with the correct params', async function () {
111 for (const command of commands) {
112 await makePostBodyRequest({
114 path: '/api/v1/jobs/' + command,
115 token: server.accessToken,
116 expectedStatus: HttpStatusCode.NO_CONTENT_204
122 after(async function () {
123 await cleanupTests([ server ])