]>
Commit | Line | Data |
---|---|---|
2539932e C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
5 | import { | |
6 | cleanupTests, | |
7 | createUser, | |
8 | flushAndRunServer, | |
9 | ServerInfo, | |
10 | setAccessTokensToServers, | |
11 | userLogin | |
12 | } from '../../../../shared/extra-utils' | |
13 | import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests' | |
14 | ||
15 | describe('Test custom pages validators', function () { | |
16 | const path = '/api/v1/custom-pages/homepage/instance' | |
17 | ||
18 | let server: ServerInfo | |
19 | let userAccessToken: string | |
20 | ||
21 | // --------------------------------------------------------------- | |
22 | ||
23 | before(async function () { | |
24 | this.timeout(120000) | |
25 | ||
26 | server = await flushAndRunServer(1) | |
27 | await setAccessTokensToServers([ server ]) | |
28 | ||
29 | const user = { username: 'user1', password: 'password' } | |
30 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
31 | ||
32 | userAccessToken = await userLogin(server, user) | |
33 | }) | |
34 | ||
35 | describe('When updating instance homepage', function () { | |
36 | ||
37 | it('Should fail with an unauthenticated user', async function () { | |
38 | await makePutBodyRequest({ | |
39 | url: server.url, | |
40 | path, | |
41 | fields: { content: 'super content' }, | |
42 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
43 | }) | |
44 | }) | |
45 | ||
46 | it('Should fail with a non admin user', async function () { | |
47 | await makePutBodyRequest({ | |
48 | url: server.url, | |
49 | path, | |
50 | token: userAccessToken, | |
51 | fields: { content: 'super content' }, | |
52 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
53 | }) | |
54 | }) | |
55 | ||
56 | it('Should succeed with the correct params', async function () { | |
57 | await makePutBodyRequest({ | |
58 | url: server.url, | |
59 | path, | |
60 | token: server.accessToken, | |
61 | fields: { content: 'super content' }, | |
62 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
63 | }) | |
64 | }) | |
65 | }) | |
66 | ||
67 | describe('When getting instance homapage', function () { | |
68 | ||
69 | it('Should succeed with the correct params', async function () { | |
70 | await makeGetRequest({ | |
71 | url: server.url, | |
72 | path, | |
73 | statusCodeExpected: HttpStatusCode.OK_200 | |
74 | }) | |
75 | }) | |
76 | }) | |
77 | ||
78 | after(async function () { | |
79 | await cleanupTests([ server ]) | |
80 | }) | |
81 | }) |