aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/server/homepage.ts
blob: c291037f22fd24ca49f3a29205929632fb576bf1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import {
  cleanupTests,
  CustomPagesCommand,
  createSingleServer,
  killallServers,
  PeerTubeServer,
  setAccessTokensToServers
} from '../../../../shared/extra-utils/index'

const expect = chai.expect

async function getHomepageState (server: PeerTubeServer) {
  const config = await server.config.getConfig()

  return config.homepage.enabled
}

describe('Test instance homepage actions', function () {
  let server: PeerTubeServer
  let command: CustomPagesCommand

  before(async function () {
    this.timeout(30000)

    server = await createSingleServer(1)
    await setAccessTokensToServers([ server ])

    command = server.customPage
  })

  it('Should not have a homepage', async function () {
    const state = await getHomepageState(server)
    expect(state).to.be.false

    await command.getInstanceHomepage({ expectedStatus: HttpStatusCode.NOT_FOUND_404 })
  })

  it('Should set a homepage', async function () {
    await command.updateInstanceHomepage({ content: '<picsou-magazine></picsou-magazine>' })

    const page = await command.getInstanceHomepage()
    expect(page.content).to.equal('<picsou-magazine></picsou-magazine>')

    const state = await getHomepageState(server)
    expect(state).to.be.true
  })

  it('Should have the same homepage after a restart', async function () {
    this.timeout(30000)

    await killallServers([ server ])

    await server.run()

    const page = await command.getInstanceHomepage()
    expect(page.content).to.equal('<picsou-magazine></picsou-magazine>')

    const state = await getHomepageState(server)
    expect(state).to.be.true
  })

  it('Should empty the homepage', async function () {
    await command.updateInstanceHomepage({ content: '' })

    const page = await command.getInstanceHomepage()
    expect(page.content).to.be.empty

    const state = await getHomepageState(server)
    expect(state).to.be.false
  })

  after(async function () {
    await cleanupTests([ server ])
  })
})