1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import * as request from 'supertest'
16 updateCustomSubConfig,
18 } from '../../shared/extra-utils'
20 const expect = chai.expect
22 function checkIndexTags (html: string, title: string, description: string, css: string) {
23 expect(html).to.contain('<title>' + title + '</title>')
24 expect(html).to.contain('<meta name="description" content="' + description + '" />')
25 expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
28 describe('Test a client controllers', function () {
29 let server: ServerInfo
31 before(async function () {
34 server = await flushAndRunServer(1)
35 server.accessToken = await serverLogin(server)
37 const videoAttributes = {
38 name: 'my super name for server 1',
39 description: 'my super description for server 1'
41 await uploadVideo(server.url, server.accessToken, videoAttributes)
43 const res = await getVideosList(server.url)
44 const videos = res.body.data
46 expect(videos.length).to.equal(1)
48 server.video = videos[0]
51 it('Should have valid Open Graph tags on the watch page with video id', async function () {
52 const res = await request(server.url)
53 .get('/videos/watch/' + server.video.id)
54 .set('Accept', 'text/html')
57 expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
58 expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
61 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
62 const res = await request(server.url)
63 .get('/videos/watch/' + server.video.uuid)
64 .set('Accept', 'text/html')
67 expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
68 expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
71 it('Should have valid oEmbed discovery tags', async function () {
72 const path = '/videos/watch/' + server.video.uuid
73 const res = await request(server.url)
75 .set('Accept', 'text/html')
78 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:9001/services/oembed?' +
79 `url=http%3A%2F%2Flocalhost%3A9001%2Fvideos%2Fwatch%2F${server.video.uuid}" ` +
80 `title="${server.video.name}" />`
82 expect(res.text).to.contain(expectedLink)
85 it('Should have valid twitter card', async function () {
86 const res = await request(server.url)
87 .get('/videos/watch/' + server.video.uuid)
88 .set('Accept', 'text/html')
91 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
92 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
95 it('Should have valid twitter card if Twitter is whitelisted', async function () {
96 const res1 = await getCustomConfig(server.url, server.accessToken)
97 const config = res1.body
98 config.services.twitter = {
102 await updateCustomConfig(server.url, server.accessToken, config)
104 const res = await request(server.url)
105 .get('/videos/watch/' + server.video.uuid)
106 .set('Accept', 'text/html')
109 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
110 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
113 it('Should have valid index html tags (title, description...)', async function () {
114 const res = await makeHTMLRequest(server.url, '/videos/trending')
116 const description = 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
117 'with WebTorrent and Angular.'
118 checkIndexTags(res.text, 'PeerTube', description, '')
121 it('Should update the customized configuration and have the correct index html tags', async function () {
122 await updateCustomSubConfig(server.url, server.accessToken, {
124 name: 'PeerTube updated',
125 shortDescription: 'my short description',
126 description: 'my super description',
127 terms: 'my super terms',
128 defaultClientRoute: '/videos/recently-added',
129 defaultNSFWPolicy: 'blur',
131 javascript: 'alert("coucou")',
132 css: 'body { background-color: red; }'
137 const res = await makeHTMLRequest(server.url, '/videos/trending')
139 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
142 it('Should have valid index html updated tags (title, description...)', async function () {
143 const res = await makeHTMLRequest(server.url, '/videos/trending')
145 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
149 killallServers([ server ])