1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5 import { HttpStatusCode } from '@shared/models'
12 setAccessTokensToServers
13 } from '@shared/server-commands'
15 describe('Test jobs API validators', function () {
16 const path = '/api/v1/jobs/failed'
17 let server: PeerTubeServer
18 let userAccessToken = ''
20 // ---------------------------------------------------------------
22 before(async function () {
25 server = await createSingleServer(1)
27 await setAccessTokensToServers([ server ])
31 password: 'my super password'
33 await server.users.create({ username: user.username, password: user.password })
34 userAccessToken = await server.login.getAccessToken(user)
37 describe('When listing jobs', function () {
39 it('Should fail with a bad state', async function () {
40 await makeGetRequest({
42 token: server.accessToken,
47 it('Should fail with an incorrect job type', async function () {
48 await makeGetRequest({
50 token: server.accessToken,
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, path, server.accessToken)
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, path, server.accessToken)
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, path, server.accessToken)
70 it('Should fail with a non authenticated user', async function () {
71 await makeGetRequest({
74 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
78 it('Should fail with a non admin user', async function () {
79 await makeGetRequest({
82 token: userAccessToken,
83 expectedStatus: HttpStatusCode.FORBIDDEN_403
88 describe('When pausing/resuming the job queue', async function () {
89 const commands = [ 'pause', 'resume' ]
91 it('Should fail with a non authenticated user', async function () {
92 for (const command of commands) {
93 await makePostBodyRequest({
95 path: '/api/v1/jobs/' + command,
96 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
101 it('Should fail with a non admin user', async function () {
102 for (const command of commands) {
103 await makePostBodyRequest({
105 path: '/api/v1/jobs/' + command,
106 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
111 it('Should succeed with the correct params', async function () {
112 for (const command of commands) {
113 await makePostBodyRequest({
115 path: '/api/v1/jobs/' + command,
116 token: server.accessToken,
117 expectedStatus: HttpStatusCode.NO_CONTENT_204
123 after(async function () {
124 await cleanupTests([ server ])