Fix travis tests
[oweals/peertube.git] / server / tests / client.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import * as request from 'supertest'
6 const expect = chai.expect
7
8 import {
9   ServerInfo,
10   flushTests,
11   runServer,
12   serverLogin,
13   uploadVideo,
14   getVideosList, updateCustomConfig, getCustomConfig, killallServers, makeHTMLRequest
15 } from './utils'
16 import { CustomConfig } from '../../shared/models/server/custom-config.model'
17
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>')
22 }
23
24 describe('Test a client controllers', function () {
25   let server: ServerInfo
26
27   before(async function () {
28     this.timeout(120000)
29
30     await flushTests()
31
32     server = await runServer(1)
33     server.accessToken = await serverLogin(server)
34
35     const videoAttributes = {
36       name: 'my super name for server 1',
37       description: 'my super description for server 1'
38     }
39     await uploadVideo(server.url, server.accessToken, videoAttributes)
40
41     const res = await getVideosList(server.url)
42     const videos = res.body.data
43
44     expect(videos.length).to.equal(1)
45
46     server.video = videos[0]
47   })
48
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')
53       .expect(200)
54
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" />')
57   })
58
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')
63       .expect(200)
64
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" />')
67   })
68
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)
72       .get(path)
73       .set('Accept', 'text/html')
74       .expect(200)
75
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}" />`
79
80     expect(res.text).to.contain(expectedLink)
81   })
82
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')
87       .expect(200)
88
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" />')
91   })
92
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 = {
97       username: '@Kuja',
98       whitelisted: true
99     }
100     await updateCustomConfig(server.url, server.accessToken, config)
101
102     const res = await request(server.url)
103       .get('/videos/watch/' + server.video.uuid)
104       .set('Accept', 'text/html')
105       .expect(200)
106
107     expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
108     expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
109   })
110
111   it('Should have valid index html tags (title, description...)', async function () {
112     const res = await makeHTMLRequest(server.url, '/videos/trending')
113
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, '')
117   })
118
119   it('Should update the customized configuration and have the correct index html tags', async function () {
120     const newCustomConfig: CustomConfig = {
121       instance: {
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',
128         customizations: {
129           javascript: 'alert("coucou")',
130           css: 'body { background-color: red; }'
131         }
132       },
133       services: {
134         twitter: {
135           username: '@Kuja',
136           whitelisted: true
137         }
138       },
139       cache: {
140         previews: {
141           size: 2
142         },
143         captions: {
144           size: 3
145         }
146       },
147       signup: {
148         enabled: false,
149         limit: 5
150       },
151       admin: {
152         email: 'superadmin1@example.com'
153       },
154       user: {
155         videoQuota: 5242881
156       },
157       transcoding: {
158         enabled: true,
159         threads: 1,
160         resolutions: {
161           '240p': false,
162           '360p': true,
163           '480p': true,
164           '720p': false,
165           '1080p': false
166         }
167       }
168     }
169     await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
170
171     const res = await makeHTMLRequest(server.url, '/videos/trending')
172
173     checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
174   })
175
176   it('Should have valid index html updated tags (title, description...)', async function () {
177     const res = await makeHTMLRequest(server.url, '/videos/trending')
178
179     checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
180   })
181
182   after(async function () {
183     killallServers([ server ])
184   })
185 })