]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/custom-pages.ts
3d84fb3e67977867526f36c2bc95b9fab43b0a74
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / custom-pages.ts
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 flushAndRunServer,
8 ServerInfo,
9 setAccessTokensToServers
10 } from '../../../../shared/extra-utils'
11 import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests'
12
13 describe('Test custom pages validators', function () {
14 const path = '/api/v1/custom-pages/homepage/instance'
15
16 let server: ServerInfo
17 let userAccessToken: string
18
19 // ---------------------------------------------------------------
20
21 before(async function () {
22 this.timeout(120000)
23
24 server = await flushAndRunServer(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 statusCodeExpected: 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 statusCodeExpected: 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 statusCodeExpected: 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 statusCodeExpected: HttpStatusCode.OK_200
72 })
73 })
74 })
75
76 after(async function () {
77 await cleanupTests([ server ])
78 })
79 })