]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/custom-pages.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / custom-pages.ts
CommitLineData
2539932e
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5import {
6 cleanupTests,
254d3579
C
7 createSingleServer,
8 PeerTubeServer,
41d1d075 9 setAccessTokensToServers
2539932e
C
10} from '../../../../shared/extra-utils'
11import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests'
12
13describe('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' },
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})