1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import * as request from 'supertest'
16 updateCustomSubConfig,
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 () {
36 server = await runServer(1)
37 server.accessToken = await serverLogin(server)
39 const videoAttributes = {
40 name: 'my super name for server 1',
41 description: 'my super description for server 1'
43 await uploadVideo(server.url, server.accessToken, videoAttributes)
45 const res = await getVideosList(server.url)
46 const videos = res.body.data
48 expect(videos.length).to.equal(1)
50 server.video = videos[0]
53 it('Should have valid Open Graph tags on the watch page with video id', async function () {
54 const res = await request(server.url)
55 .get('/videos/watch/' + server.video.id)
56 .set('Accept', 'text/html')
59 expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
60 expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
63 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
64 const res = await request(server.url)
65 .get('/videos/watch/' + server.video.uuid)
66 .set('Accept', 'text/html')
69 expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
70 expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
73 it('Should have valid oEmbed discovery tags', async function () {
74 const path = '/videos/watch/' + server.video.uuid
75 const res = await request(server.url)
77 .set('Accept', 'text/html')
80 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:9001/services/oembed?' +
81 `url=http%3A%2F%2Flocalhost%3A9001%2Fvideos%2Fwatch%2F${server.video.uuid}" ` +
82 `title="${server.video.name}" />`
84 expect(res.text).to.contain(expectedLink)
87 it('Should have valid twitter card', async function () {
88 const res = await request(server.url)
89 .get('/videos/watch/' + server.video.uuid)
90 .set('Accept', 'text/html')
93 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
94 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
97 it('Should have valid twitter card if Twitter is whitelisted', async function () {
98 const res1 = await getCustomConfig(server.url, server.accessToken)
99 const config = res1.body
100 config.services.twitter = {
104 await updateCustomConfig(server.url, server.accessToken, config)
106 const res = await request(server.url)
107 .get('/videos/watch/' + server.video.uuid)
108 .set('Accept', 'text/html')
111 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
112 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
115 it('Should have valid index html tags (title, description...)', async function () {
116 const res = await makeHTMLRequest(server.url, '/videos/trending')
118 const description = 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
119 'with WebTorrent and Angular.'
120 checkIndexTags(res.text, 'PeerTube', description, '')
123 it('Should update the customized configuration and have the correct index html tags', async function () {
124 await updateCustomSubConfig(server.url, server.accessToken, {
126 name: 'PeerTube updated',
127 shortDescription: 'my short description',
128 description: 'my super description',
129 terms: 'my super terms',
130 defaultClientRoute: '/videos/recently-added',
131 defaultNSFWPolicy: 'blur',
133 javascript: 'alert("coucou")',
134 css: 'body { background-color: red; }'
139 const res = await makeHTMLRequest(server.url, '/videos/trending')
141 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
144 it('Should have valid index html updated tags (title, description...)', async function () {
145 const res = await makeHTMLRequest(server.url, '/videos/trending')
147 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
150 after(async function () {
151 killallServers([ server ])