aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/jobs.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/api/check-params/jobs.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/api/check-params/jobs.ts')
-rw-r--r--server/tests/api/check-params/jobs.ts125
1 files changed, 0 insertions, 125 deletions
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
deleted file mode 100644
index 873da3955..000000000
--- a/server/tests/api/check-params/jobs.ts
+++ /dev/null
@@ -1,125 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
4import { HttpStatusCode } from '@shared/models'
5import {
6 cleanupTests,
7 createSingleServer,
8 makeGetRequest,
9 makePostBodyRequest,
10 PeerTubeServer,
11 setAccessTokensToServers
12} from '@shared/server-commands'
13
14describe('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})