]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/client.ts
Upgrade server dep
[github/Chocobozzz/PeerTube.git] / server / tests / client.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
5import * as request from 'supertest'
0e1dc3e7 6import {
7c3b7976
C
7 cleanupTests,
8 flushAndRunServer,
590fb506
C
9 getCustomConfig,
10 getVideosList,
590fb506 11 makeHTMLRequest,
590fb506 12 ServerInfo,
eec63bbc 13 serverLogin,
590fb506
C
14 updateCustomConfig,
15 updateCustomSubConfig,
16 uploadVideo
94565d52 17} from '../../shared/extra-utils'
590fb506
C
18
19const expect = chai.expect
5bcfd029
C
20
21function 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>')
25}
0e1dc3e7
C
26
27describe('Test a client controllers', function () {
28 let server: ServerInfo
29
30 before(async function () {
31 this.timeout(120000)
32
210feb6c 33 server = await flushAndRunServer(1)
eec63bbc 34 server.accessToken = await serverLogin(server)
0e1dc3e7
C
35
36 const videoAttributes = {
9a27cdc2
C
37 name: 'my super name for server 1',
38 description: 'my super description for server 1'
0e1dc3e7
C
39 }
40 await uploadVideo(server.url, server.accessToken, videoAttributes)
41
42 const res = await getVideosList(server.url)
43 const videos = res.body.data
44
45 expect(videos.length).to.equal(1)
46
47 server.video = videos[0]
48 })
49
d8755eed 50 it('Should have valid Open Graph tags on the watch page with video id', async function () {
0e1dc3e7 51 const res = await request(server.url)
98ec8b8e
C
52 .get('/videos/watch/' + server.video.id)
53 .set('Accept', 'text/html')
54 .expect(200)
0e1dc3e7 55
9a27cdc2
C
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" />')
0e1dc3e7
C
58 })
59
d8755eed 60 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
0e1dc3e7 61 const res = await request(server.url)
98ec8b8e
C
62 .get('/videos/watch/' + server.video.uuid)
63 .set('Accept', 'text/html')
64 .expect(200)
0e1dc3e7 65
9a27cdc2
C
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" />')
0e1dc3e7
C
68 })
69
d8755eed
C
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)
73 .get(path)
98ec8b8e 74 .set('Accept', 'text/html')
d8755eed
C
75 .expect(200)
76
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}" />`
80
81 expect(res.text).to.contain(expectedLink)
82 })
83
8be1afa1
C
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')
88 .expect(200)
89
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" />')
92 })
93
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 = {
98 username: '@Kuja',
99 whitelisted: true
100 }
101 await updateCustomConfig(server.url, server.accessToken, config)
102
103 const res = await request(server.url)
104 .get('/videos/watch/' + server.video.uuid)
105 .set('Accept', 'text/html')
106 .expect(200)
107
108 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
109 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
110 })
111
5bcfd029
C
112 it('Should have valid index html tags (title, description...)', async function () {
113 const res = await makeHTMLRequest(server.url, '/videos/trending')
114
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, '')
118 })
119
120 it('Should update the customized configuration and have the correct index html tags', async function () {
590fb506 121 await updateCustomSubConfig(server.url, server.accessToken, {
5bcfd029 122 instance: {
60979b07
C
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',
5bcfd029
C
129 customizations: {
130 javascript: 'alert("coucou")',
131 css: 'body { background-color: red; }'
132 }
5bcfd029 133 }
590fb506 134 })
5bcfd029
C
135
136 const res = await makeHTMLRequest(server.url, '/videos/trending')
137
138 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
139 })
140
141 it('Should have valid index html updated tags (title, description...)', async function () {
142 const res = await makeHTMLRequest(server.url, '/videos/trending')
143
144 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
145 })
146
7c3b7976
C
147 after(async function () {
148 await cleanupTests([ server ])
0e1dc3e7
C
149 })
150})