]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/custom-pages.ts
Introduce login command
[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 createUser,
8 flushAndRunServer,
9 ServerInfo,
10 setAccessTokensToServers
11 } from '../../../../shared/extra-utils'
12 import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests'
13
14 describe('Test custom pages validators', function () {
15 const path = '/api/v1/custom-pages/homepage/instance'
16
17 let server: ServerInfo
18 let userAccessToken: string
19
20 // ---------------------------------------------------------------
21
22 before(async function () {
23 this.timeout(120000)
24
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
27
28 const user = { username: 'user1', password: 'password' }
29 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
30
31 userAccessToken = await server.loginCommand.getAccessToken(user)
32 })
33
34 describe('When updating instance homepage', function () {
35
36 it('Should fail with an unauthenticated user', async function () {
37 await makePutBodyRequest({
38 url: server.url,
39 path,
40 fields: { content: 'super content' },
41 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
42 })
43 })
44
45 it('Should fail with a non admin user', async function () {
46 await makePutBodyRequest({
47 url: server.url,
48 path,
49 token: userAccessToken,
50 fields: { content: 'super content' },
51 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
52 })
53 })
54
55 it('Should succeed with the correct params', async function () {
56 await makePutBodyRequest({
57 url: server.url,
58 path,
59 token: server.accessToken,
60 fields: { content: 'super content' },
61 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
62 })
63 })
64 })
65
66 describe('When getting instance homapage', function () {
67
68 it('Should succeed with the correct params', async function () {
69 await makeGetRequest({
70 url: server.url,
71 path,
72 statusCodeExpected: HttpStatusCode.OK_200
73 })
74 })
75 })
76
77 after(async function () {
78 await cleanupTests([ server ])
79 })
80 })