]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { HttpStatusCode } from '@shared/core-utils' | |
6 | import { ServerConfig } from '@shared/models' | |
7 | import { | |
8 | cleanupTests, | |
9 | CustomPagesCommand, | |
10 | flushAndRunServer, | |
11 | getConfig, | |
12 | killallServers, | |
13 | reRunServer, | |
14 | ServerInfo, | |
15 | setAccessTokensToServers | |
16 | } from '../../../../shared/extra-utils/index' | |
17 | ||
18 | const expect = chai.expect | |
19 | ||
20 | async 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 | ||
27 | describe('Test instance homepage actions', function () { | |
28 | let server: ServerInfo | |
29 | let command: CustomPagesCommand | |
30 | ||
31 | before(async function () { | |
32 | this.timeout(30000) | |
33 | ||
34 | server = await flushAndRunServer(1) | |
35 | await setAccessTokensToServers([ server ]) | |
36 | ||
37 | command = server.customPageCommand | |
38 | }) | |
39 | ||
40 | it('Should not have a homepage', async function () { | |
41 | const state = await getHomepageState(server) | |
42 | expect(state).to.be.false | |
43 | ||
44 | await command.getInstanceHomepage({ expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
45 | }) | |
46 | ||
47 | it('Should set a homepage', async function () { | |
48 | await command.updateInstanceHomepage({ content: '<picsou-magazine></picsou-magazine>' }) | |
49 | ||
50 | const page = await command.getInstanceHomepage() | |
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 | ||
64 | const page = await command.getInstanceHomepage() | |
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 () { | |
72 | await command.updateInstanceHomepage({ content: '' }) | |
73 | ||
74 | const page = await command.getInstanceHomepage() | |
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 | }) |