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