]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import * as request from 'supertest' | |
6 | import { | |
7 | cleanupTests, | |
8 | flushAndRunServer, | |
9 | getCustomConfig, | |
10 | getVideosList, | |
11 | makeHTMLRequest, | |
12 | ServerInfo, | |
13 | serverLogin, | |
14 | updateCustomConfig, | |
15 | updateCustomSubConfig, | |
16 | uploadVideo | |
17 | } from '../../shared/extra-utils' | |
18 | ||
19 | const expect = chai.expect | |
20 | ||
21 | function 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 | } | |
26 | ||
27 | describe('Test a client controllers', function () { | |
28 | let server: ServerInfo | |
29 | ||
30 | before(async function () { | |
31 | this.timeout(120000) | |
32 | ||
33 | server = await flushAndRunServer(1) | |
34 | server.accessToken = await serverLogin(server) | |
35 | ||
36 | const videoAttributes = { | |
37 | name: 'my super name for server 1', | |
38 | description: 'my super description for server 1' | |
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 | ||
50 | it('Should have valid Open Graph tags on the watch page with video id', async function () { | |
51 | const res = await request(server.url) | |
52 | .get('/videos/watch/' + server.video.id) | |
53 | .set('Accept', 'text/html') | |
54 | .expect(200) | |
55 | ||
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" />') | |
58 | }) | |
59 | ||
60 | it('Should have valid Open Graph tags on the watch page with video uuid', async function () { | |
61 | const res = await request(server.url) | |
62 | .get('/videos/watch/' + server.video.uuid) | |
63 | .set('Accept', 'text/html') | |
64 | .expect(200) | |
65 | ||
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" />') | |
68 | }) | |
69 | ||
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) | |
74 | .set('Accept', 'text/html') | |
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 | ||
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 | ||
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 () { | |
121 | await updateCustomSubConfig(server.url, server.accessToken, { | |
122 | instance: { | |
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', | |
129 | customizations: { | |
130 | javascript: 'alert("coucou")', | |
131 | css: 'body { background-color: red; }' | |
132 | } | |
133 | } | |
134 | }) | |
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 | ||
147 | after(async function () { | |
148 | await cleanupTests([ server ]) | |
149 | }) | |
150 | }) |