]>
Commit | Line | Data |
---|---|---|
2539932e C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
e0faa8ad | 3 | import { HttpStatusCode } from '@shared/models' |
2539932e C |
4 | import { |
5 | cleanupTests, | |
254d3579 | 6 | createSingleServer, |
c0e8b12e C |
7 | makeGetRequest, |
8 | makePutBodyRequest, | |
254d3579 | 9 | PeerTubeServer, |
41d1d075 | 10 | setAccessTokensToServers |
bf54587a | 11 | } from '@shared/server-commands' |
2539932e C |
12 | |
13 | describe('Test custom pages validators', function () { | |
14 | const path = '/api/v1/custom-pages/homepage/instance' | |
15 | ||
254d3579 | 16 | let server: PeerTubeServer |
2539932e C |
17 | let userAccessToken: string |
18 | ||
19 | // --------------------------------------------------------------- | |
20 | ||
21 | before(async function () { | |
22 | this.timeout(120000) | |
23 | ||
254d3579 | 24 | server = await createSingleServer(1) |
2539932e C |
25 | await setAccessTokensToServers([ server ]) |
26 | ||
27 | const user = { username: 'user1', password: 'password' } | |
89d241a7 | 28 | await server.users.create({ username: user.username, password: user.password }) |
2539932e | 29 | |
89d241a7 | 30 | userAccessToken = await server.login.getAccessToken(user) |
2539932e C |
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' }, | |
c0e8b12e | 40 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
2539932e C |
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' }, | |
c0e8b12e | 50 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
2539932e C |
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' }, | |
c0e8b12e | 60 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
2539932e C |
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, | |
c0e8b12e | 71 | expectedStatus: HttpStatusCode.OK_200 |
2539932e C |
72 | }) |
73 | }) | |
74 | }) | |
75 | ||
76 | after(async function () { | |
77 | await cleanupTests([ server ]) | |
78 | }) | |
79 | }) |