1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import * as request from 'supertest'
15 updateCustomSubConfig,
17 } from '../../shared/extra-utils'
19 const expect = chai.expect
21 function checkIndexTags (html: string, title: string, description: string, css: string) {
22 expect(html).to.contain('<title>' + title + '</title>')
23 expect(html).to.contain('<meta name="description" content="' + description + '" />')
24 expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
27 describe('Test a client controllers', function () {
28 let server: ServerInfo
30 before(async function () {
33 server = await flushAndRunServer(1)
34 server.accessToken = await serverLogin(server)
36 const videoAttributes = {
37 name: 'my super name for server 1',
38 description: 'my super description for server 1'
40 await uploadVideo(server.url, server.accessToken, videoAttributes)
42 const res = await getVideosList(server.url)
43 const videos = res.body.data
45 expect(videos.length).to.equal(1)
47 server.video = videos[0]
50 it('Should have valid Open Graph tags on the watch page with video id', async function () {
51 const res = await request(server.url)
52 .get('/videos/watch/' + server.video.id)
53 .set('Accept', 'text/html')
56 expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
57 expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
60 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
61 const res = await request(server.url)
62 .get('/videos/watch/' + server.video.uuid)
63 .set('Accept', 'text/html')
66 expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
67 expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
70 it('Should have valid oEmbed discovery tags', async function () {
71 const path = '/videos/watch/' + server.video.uuid
72 const res = await request(server.url)
74 .set('Accept', 'text/html')
77 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:9001/services/oembed?' +
78 `url=http%3A%2F%2Flocalhost%3A9001%2Fvideos%2Fwatch%2F${server.video.uuid}" ` +
79 `title="${server.video.name}" />`
81 expect(res.text).to.contain(expectedLink)
84 it('Should have valid twitter card', async function () {
85 const res = await request(server.url)
86 .get('/videos/watch/' + server.video.uuid)
87 .set('Accept', 'text/html')
90 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
91 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
94 it('Should have valid twitter card if Twitter is whitelisted', async function () {
95 const res1 = await getCustomConfig(server.url, server.accessToken)
96 const config = res1.body
97 config.services.twitter = {
101 await updateCustomConfig(server.url, server.accessToken, config)
103 const res = await request(server.url)
104 .get('/videos/watch/' + server.video.uuid)
105 .set('Accept', 'text/html')
108 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
109 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
112 it('Should have valid index html tags (title, description...)', async function () {
113 const res = await makeHTMLRequest(server.url, '/videos/trending')
115 const description = 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
116 'with WebTorrent and Angular.'
117 checkIndexTags(res.text, 'PeerTube', description, '')
120 it('Should update the customized configuration and have the correct index html tags', async function () {
121 await updateCustomSubConfig(server.url, server.accessToken, {
123 name: 'PeerTube updated',
124 shortDescription: 'my short description',
125 description: 'my super description',
126 terms: 'my super terms',
127 defaultClientRoute: '/videos/recently-added',
128 defaultNSFWPolicy: 'blur',
130 javascript: 'alert("coucou")',
131 css: 'body { background-color: red; }'
136 const res = await makeHTMLRequest(server.url, '/videos/trending')
138 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
141 it('Should have valid index html updated tags (title, description...)', async function () {
142 const res = await makeHTMLRequest(server.url, '/videos/trending')
144 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
147 after(async function () {
148 await cleanupTests([ server ])