]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import * as request from 'supertest' | |
0e1dc3e7 | 6 | import { |
0e1dc3e7 | 7 | flushTests, |
590fb506 C |
8 | getCustomConfig, |
9 | getVideosList, | |
10 | killallServers, | |
11 | makeHTMLRequest, | |
0e1dc3e7 | 12 | runServer, |
590fb506 | 13 | ServerInfo, |
eec63bbc | 14 | serverLogin, |
590fb506 C |
15 | updateCustomConfig, |
16 | updateCustomSubConfig, | |
17 | uploadVideo | |
0e1dc3e7 | 18 | } from './utils' |
590fb506 C |
19 | |
20 | const expect = chai.expect | |
5bcfd029 C |
21 | |
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>') | |
26 | } | |
0e1dc3e7 C |
27 | |
28 | describe('Test a client controllers', function () { | |
29 | let server: ServerInfo | |
30 | ||
31 | before(async function () { | |
32 | this.timeout(120000) | |
33 | ||
34 | await flushTests() | |
35 | ||
36 | server = await runServer(1) | |
eec63bbc | 37 | server.accessToken = await serverLogin(server) |
0e1dc3e7 C |
38 | |
39 | const videoAttributes = { | |
9a27cdc2 C |
40 | name: 'my super name for server 1', |
41 | description: 'my super description for server 1' | |
0e1dc3e7 C |
42 | } |
43 | await uploadVideo(server.url, server.accessToken, videoAttributes) | |
44 | ||
45 | const res = await getVideosList(server.url) | |
46 | const videos = res.body.data | |
47 | ||
48 | expect(videos.length).to.equal(1) | |
49 | ||
50 | server.video = videos[0] | |
51 | }) | |
52 | ||
d8755eed | 53 | it('Should have valid Open Graph tags on the watch page with video id', async function () { |
0e1dc3e7 | 54 | const res = await request(server.url) |
98ec8b8e C |
55 | .get('/videos/watch/' + server.video.id) |
56 | .set('Accept', 'text/html') | |
57 | .expect(200) | |
0e1dc3e7 | 58 | |
9a27cdc2 C |
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" />') | |
0e1dc3e7 C |
61 | }) |
62 | ||
d8755eed | 63 | it('Should have valid Open Graph tags on the watch page with video uuid', async function () { |
0e1dc3e7 | 64 | const res = await request(server.url) |
98ec8b8e C |
65 | .get('/videos/watch/' + server.video.uuid) |
66 | .set('Accept', 'text/html') | |
67 | .expect(200) | |
0e1dc3e7 | 68 | |
9a27cdc2 C |
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" />') | |
0e1dc3e7 C |
71 | }) |
72 | ||
d8755eed C |
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) | |
76 | .get(path) | |
98ec8b8e | 77 | .set('Accept', 'text/html') |
d8755eed C |
78 | .expect(200) |
79 | ||
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}" />` | |
83 | ||
84 | expect(res.text).to.contain(expectedLink) | |
85 | }) | |
86 | ||
8be1afa1 C |
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') | |
91 | .expect(200) | |
92 | ||
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" />') | |
95 | }) | |
96 | ||
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 = { | |
101 | username: '@Kuja', | |
102 | whitelisted: true | |
103 | } | |
104 | await updateCustomConfig(server.url, server.accessToken, config) | |
105 | ||
106 | const res = await request(server.url) | |
107 | .get('/videos/watch/' + server.video.uuid) | |
108 | .set('Accept', 'text/html') | |
109 | .expect(200) | |
110 | ||
111 | expect(res.text).to.contain('<meta property="twitter:card" content="player" />') | |
112 | expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
113 | }) | |
114 | ||
5bcfd029 C |
115 | it('Should have valid index html tags (title, description...)', async function () { |
116 | const res = await makeHTMLRequest(server.url, '/videos/trending') | |
117 | ||
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, '') | |
121 | }) | |
122 | ||
123 | it('Should update the customized configuration and have the correct index html tags', async function () { | |
590fb506 | 124 | await updateCustomSubConfig(server.url, server.accessToken, { |
5bcfd029 | 125 | instance: { |
60979b07 C |
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', | |
5bcfd029 C |
132 | customizations: { |
133 | javascript: 'alert("coucou")', | |
134 | css: 'body { background-color: red; }' | |
135 | } | |
5bcfd029 | 136 | } |
590fb506 | 137 | }) |
5bcfd029 C |
138 | |
139 | const res = await makeHTMLRequest(server.url, '/videos/trending') | |
140 | ||
141 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') | |
142 | }) | |
143 | ||
144 | it('Should have valid index html updated tags (title, description...)', async function () { | |
145 | const res = await makeHTMLRequest(server.url, '/videos/trending') | |
146 | ||
147 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') | |
148 | }) | |
149 | ||
0e1dc3e7 | 150 | after(async function () { |
3cd0734f | 151 | killallServers([ server ]) |
0e1dc3e7 C |
152 | }) |
153 | }) |