]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/homepage.ts
Introduce CustomPage command
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / homepage.ts
CommitLineData
2539932e
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils'
e8bd7ce7 6import { ServerConfig } from '@shared/models'
2539932e
C
7import {
8 cleanupTests,
e8bd7ce7 9 CustomPagesCommand,
2539932e
C
10 flushAndRunServer,
11 getConfig,
2539932e
C
12 killallServers,
13 reRunServer,
14 ServerInfo,
e8bd7ce7 15 setAccessTokensToServers
2539932e
C
16} from '../../../../shared/extra-utils/index'
17
18const expect = chai.expect
19
20async function getHomepageState (server: ServerInfo) {
21 const res = await getConfig(server.url)
22
23 const config = res.body as ServerConfig
24 return config.homepage.enabled
25}
26
27describe('Test instance homepage actions', function () {
28 let server: ServerInfo
e8bd7ce7 29 let command: CustomPagesCommand
2539932e
C
30
31 before(async function () {
32 this.timeout(30000)
33
34 server = await flushAndRunServer(1)
35 await setAccessTokensToServers([ server ])
e8bd7ce7
C
36
37 command = server.customPageCommand
2539932e
C
38 })
39
40 it('Should not have a homepage', async function () {
41 const state = await getHomepageState(server)
42 expect(state).to.be.false
43
e8bd7ce7 44 await command.getInstanceHomepage({ expectedStatus: HttpStatusCode.NOT_FOUND_404 })
2539932e
C
45 })
46
47 it('Should set a homepage', async function () {
e8bd7ce7 48 await command.updateInstanceHomepage({ content: '<picsou-magazine></picsou-magazine>' })
2539932e 49
e8bd7ce7 50 const page = await command.getInstanceHomepage()
2539932e
C
51 expect(page.content).to.equal('<picsou-magazine></picsou-magazine>')
52
53 const state = await getHomepageState(server)
54 expect(state).to.be.true
55 })
56
57 it('Should have the same homepage after a restart', async function () {
58 this.timeout(30000)
59
60 killallServers([ server ])
61
62 await reRunServer(server)
63
e8bd7ce7 64 const page = await command.getInstanceHomepage()
2539932e
C
65 expect(page.content).to.equal('<picsou-magazine></picsou-magazine>')
66
67 const state = await getHomepageState(server)
68 expect(state).to.be.true
69 })
70
71 it('Should empty the homepage', async function () {
e8bd7ce7 72 await command.updateInstanceHomepage({ content: '' })
2539932e 73
e8bd7ce7 74 const page = await command.getInstanceHomepage()
2539932e
C
75 expect(page.content).to.be.empty
76
77 const state = await getHomepageState(server)
78 expect(state).to.be.false
79 })
80
81 after(async function () {
82 await cleanupTests([ server ])
83 })
84})