1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import * as request from 'supertest'
6 const expect = chai.expect
14 getVideosList, updateCustomConfig, getCustomConfig, killallServers, makeHTMLRequest
16 import { CustomConfig } from '../../shared/models/server/custom-config.model'
18 function checkIndexTags (html: string, title: string, description: string, css: string) {
19 expect(html).to.contain('<title>' + title + '</title>')
20 expect(html).to.contain('<meta name="description" content="' + description + '" />')
21 expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
24 describe('Test a client controllers', function () {
25 let server: ServerInfo
27 before(async function () {
32 server = await runServer(1)
33 server.accessToken = await serverLogin(server)
35 const videoAttributes = {
36 name: 'my super name for server 1',
37 description: 'my super description for server 1'
39 await uploadVideo(server.url, server.accessToken, videoAttributes)
41 const res = await getVideosList(server.url)
42 const videos = res.body.data
44 expect(videos.length).to.equal(1)
46 server.video = videos[0]
49 it('Should have valid Open Graph tags on the watch page with video id', async function () {
50 const res = await request(server.url)
51 .get('/videos/watch/' + server.video.id)
52 .set('Accept', 'text/html')
55 expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
56 expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
59 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
60 const res = await request(server.url)
61 .get('/videos/watch/' + server.video.uuid)
62 .set('Accept', 'text/html')
65 expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
66 expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
69 it('Should have valid oEmbed discovery tags', async function () {
70 const path = '/videos/watch/' + server.video.uuid
71 const res = await request(server.url)
73 .set('Accept', 'text/html')
76 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:9001/services/oembed?' +
77 `url=http%3A%2F%2Flocalhost%3A9001%2Fvideos%2Fwatch%2F${server.video.uuid}" ` +
78 `title="${server.video.name}" />`
80 expect(res.text).to.contain(expectedLink)
83 it('Should have valid twitter card', async function () {
84 const res = await request(server.url)
85 .get('/videos/watch/' + server.video.uuid)
86 .set('Accept', 'text/html')
89 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
90 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
93 it('Should have valid twitter card if Twitter is whitelisted', async function () {
94 const res1 = await getCustomConfig(server.url, server.accessToken)
95 const config = res1.body
96 config.services.twitter = {
100 await updateCustomConfig(server.url, server.accessToken, config)
102 const res = await request(server.url)
103 .get('/videos/watch/' + server.video.uuid)
104 .set('Accept', 'text/html')
107 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
108 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
111 it('Should have valid index html tags (title, description...)', async function () {
112 const res = await makeHTMLRequest(server.url, '/videos/trending')
114 const description = 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
115 'with WebTorrent and Angular.'
116 checkIndexTags(res.text, 'PeerTube', description, '')
119 it('Should update the customized configuration and have the correct index html tags', async function () {
120 const newCustomConfig: CustomConfig = {
122 name: 'PeerTube updated',
123 shortDescription: 'my short description',
124 description: 'my super description',
125 terms: 'my super terms',
126 defaultClientRoute: '/videos/recently-added',
127 defaultNSFWPolicy: 'blur' as 'blur',
129 javascript: 'alert("coucou")',
130 css: 'body { background-color: red; }'
152 email: 'superadmin1@example.com'
169 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
171 const res = await makeHTMLRequest(server.url, '/videos/trending')
173 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
176 it('Should have valid index html updated tags (title, description...)', async function () {
177 const res = await makeHTMLRequest(server.url, '/videos/trending')
179 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
182 after(async function () {
183 killallServers([ server ])