]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0e1dc3e7 C |
2 | |
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import * as request from 'supertest' | |
39433fa5 | 6 | import { Account, VideoPlaylistPrivacy } from '@shared/models' |
0e1dc3e7 | 7 | import { |
39433fa5 | 8 | addVideoInPlaylist, |
7c3b7976 | 9 | cleanupTests, |
39433fa5 | 10 | createVideoPlaylist, |
7c3b7976 | 11 | flushAndRunServer, |
39433fa5 | 12 | getAccount, |
590fb506 C |
13 | getCustomConfig, |
14 | getVideosList, | |
590fb506 | 15 | makeHTMLRequest, |
590fb506 | 16 | ServerInfo, |
eec63bbc | 17 | serverLogin, |
39433fa5 | 18 | setDefaultVideoChannel, |
590fb506 C |
19 | updateCustomConfig, |
20 | updateCustomSubConfig, | |
8d987ec6 | 21 | uploadVideo, |
39433fa5 C |
22 | updateMyUser, |
23 | updateVideoChannel | |
94565d52 | 24 | } from '../../shared/extra-utils' |
590fb506 C |
25 | |
26 | const expect = chai.expect | |
5bcfd029 C |
27 | |
28 | function checkIndexTags (html: string, title: string, description: string, css: string) { | |
29 | expect(html).to.contain('<title>' + title + '</title>') | |
30 | expect(html).to.contain('<meta name="description" content="' + description + '" />') | |
31 | expect(html).to.contain('<style class="custom-css-style">' + css + '</style>') | |
32 | } | |
0e1dc3e7 C |
33 | |
34 | describe('Test a client controllers', function () { | |
35 | let server: ServerInfo | |
39433fa5 C |
36 | let account: Account |
37 | ||
38 | const videoName = 'my super name for server 1' | |
39 | const videoDescription = 'my super description for server 1' | |
40 | ||
41 | const playlistName = 'super playlist name' | |
42 | const playlistDescription = 'super playlist description' | |
43 | let playlistUUID: string | |
44 | ||
45 | const channelDescription = 'my super channel description' | |
0e1dc3e7 C |
46 | |
47 | before(async function () { | |
48 | this.timeout(120000) | |
49 | ||
210feb6c | 50 | server = await flushAndRunServer(1) |
eec63bbc | 51 | server.accessToken = await serverLogin(server) |
39433fa5 | 52 | await setDefaultVideoChannel([ server ]) |
0e1dc3e7 | 53 | |
39433fa5 | 54 | await updateVideoChannel(server.url, server.accessToken, server.videoChannel.name, { description: channelDescription }) |
8d987ec6 | 55 | |
39433fa5 | 56 | // Video |
8d987ec6 | 57 | |
39433fa5 | 58 | const videoAttributes = { name: videoName, description: videoDescription } |
0e1dc3e7 C |
59 | await uploadVideo(server.url, server.accessToken, videoAttributes) |
60 | ||
8d987ec6 | 61 | const resVideosRequest = await getVideosList(server.url) |
8d987ec6 | 62 | const videos = resVideosRequest.body.data |
0e1dc3e7 C |
63 | expect(videos.length).to.equal(1) |
64 | ||
65 | server.video = videos[0] | |
8d987ec6 K |
66 | |
67 | // Playlist | |
68 | ||
69 | const playlistAttrs = { | |
39433fa5 C |
70 | displayName: playlistName, |
71 | description: playlistDescription, | |
72 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
73 | videoChannelId: server.videoChannel.id | |
8d987ec6 K |
74 | } |
75 | ||
76 | const resVideoPlaylistRequest = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs }) | |
77 | ||
39433fa5 C |
78 | const playlist = resVideoPlaylistRequest.body.videoPlaylist |
79 | const playlistId = playlist.id | |
80 | playlistUUID = playlist.uuid | |
8d987ec6 K |
81 | |
82 | await addVideoInPlaylist({ | |
83 | url: server.url, | |
84 | token: server.accessToken, | |
39433fa5 | 85 | playlistId, |
8d987ec6 K |
86 | elementAttrs: { videoId: server.video.id } |
87 | }) | |
88 | ||
89 | // Account | |
90 | ||
39433fa5 | 91 | await updateMyUser({ url: server.url, accessToken: server.accessToken, description: 'my account description' }) |
8d987ec6 | 92 | |
39433fa5 C |
93 | const resAccountRequest = await getAccount(server.url, `${server.user.username}@${server.host}`) |
94 | account = resAccountRequest.body | |
0e1dc3e7 C |
95 | }) |
96 | ||
6fad8e51 C |
97 | describe('oEmbed', function () { |
98 | it('Should have valid oEmbed discovery tags for videos', async function () { | |
99 | const path = '/videos/watch/' + server.video.uuid | |
100 | const res = await request(server.url) | |
101 | .get(path) | |
102 | .set('Accept', 'text/html') | |
103 | .expect(200) | |
0e1dc3e7 | 104 | |
6fad8e51 | 105 | const port = server.port |
0e1dc3e7 | 106 | |
6fad8e51 C |
107 | const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + |
108 | `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2F${server.video.uuid}" ` + | |
109 | `title="${server.video.name}" />` | |
8d987ec6 | 110 | |
6fad8e51 C |
111 | expect(res.text).to.contain(expectedLink) |
112 | }) | |
8d987ec6 | 113 | |
6fad8e51 C |
114 | it('Should have valid oEmbed discovery tags for a playlist', async function () { |
115 | const res = await request(server.url) | |
116 | .get('/videos/watch/playlist/' + playlistUUID) | |
117 | .set('Accept', 'text/html') | |
118 | .expect(200) | |
119 | ||
120 | const port = server.port | |
8d987ec6 | 121 | |
6fad8e51 C |
122 | const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + |
123 | `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2Fplaylist%2F${playlistUUID}" ` + | |
124 | `title="${playlistName}" />` | |
8d987ec6 | 125 | |
6fad8e51 C |
126 | expect(res.text).to.contain(expectedLink) |
127 | }) | |
8d987ec6 K |
128 | }) |
129 | ||
6fad8e51 | 130 | describe('Open Graph', function () { |
8d987ec6 | 131 | |
6fad8e51 C |
132 | it('Should have valid Open Graph tags on the account page', async function () { |
133 | const res = await request(server.url) | |
134 | .get('/accounts/' + server.user.username) | |
135 | .set('Accept', 'text/html') | |
136 | .expect(200) | |
0e1dc3e7 | 137 | |
6fad8e51 C |
138 | expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) |
139 | expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`) | |
140 | expect(res.text).to.contain('<meta property="og:type" content="website" />') | |
141 | expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/accounts/${server.user.username}" />`) | |
142 | }) | |
d8755eed | 143 | |
6fad8e51 C |
144 | it('Should have valid Open Graph tags on the channel page', async function () { |
145 | const res = await request(server.url) | |
146 | .get('/video-channels/' + server.videoChannel.name) | |
147 | .set('Accept', 'text/html') | |
148 | .expect(200) | |
f4659d73 | 149 | |
6fad8e51 C |
150 | expect(res.text).to.contain(`<meta property="og:title" content="${server.videoChannel.displayName}" />`) |
151 | expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) | |
152 | expect(res.text).to.contain('<meta property="og:type" content="website" />') | |
153 | expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/video-channels/${server.videoChannel.name}" />`) | |
154 | }) | |
d8755eed | 155 | |
6fad8e51 C |
156 | it('Should have valid Open Graph tags on the watch page with video id', async function () { |
157 | const res = await request(server.url) | |
158 | .get('/videos/watch/' + server.video.id) | |
159 | .set('Accept', 'text/html') | |
160 | .expect(200) | |
d8755eed | 161 | |
6fad8e51 C |
162 | expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`) |
163 | expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`) | |
164 | expect(res.text).to.contain('<meta property="og:type" content="video" />') | |
165 | expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/${server.video.uuid}" />`) | |
166 | }) | |
8be1afa1 | 167 | |
6fad8e51 C |
168 | it('Should have valid Open Graph tags on the watch page with video uuid', async function () { |
169 | const res = await request(server.url) | |
170 | .get('/videos/watch/' + server.video.uuid) | |
171 | .set('Accept', 'text/html') | |
172 | .expect(200) | |
8d987ec6 | 173 | |
6fad8e51 C |
174 | expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`) |
175 | expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`) | |
176 | expect(res.text).to.contain('<meta property="og:type" content="video" />') | |
177 | expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/${server.video.uuid}" />`) | |
178 | }) | |
8d987ec6 | 179 | |
6fad8e51 C |
180 | it('Should have valid Open Graph tags on the watch playlist page', async function () { |
181 | const res = await request(server.url) | |
182 | .get('/videos/watch/playlist/' + playlistUUID) | |
183 | .set('Accept', 'text/html') | |
184 | .expect(200) | |
185 | ||
186 | expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`) | |
187 | expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`) | |
188 | expect(res.text).to.contain('<meta property="og:type" content="video" />') | |
189 | expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/playlist/${playlistUUID}" />`) | |
190 | }) | |
8d987ec6 K |
191 | }) |
192 | ||
6fad8e51 | 193 | describe('Twitter card', async function () { |
8d987ec6 | 194 | |
6fad8e51 C |
195 | it('Should have valid twitter card on the watch video page', async function () { |
196 | const res = await request(server.url) | |
197 | .get('/videos/watch/' + server.video.uuid) | |
198 | .set('Accept', 'text/html') | |
199 | .expect(200) | |
8d987ec6 | 200 | |
6fad8e51 C |
201 | expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />') |
202 | expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
203 | expect(res.text).to.contain(`<meta property="twitter:title" content="${videoName}" />`) | |
204 | expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescription}" />`) | |
205 | }) | |
8d987ec6 | 206 | |
6fad8e51 C |
207 | it('Should have valid twitter card on the watch playlist page', async function () { |
208 | const res = await request(server.url) | |
209 | .get('/videos/watch/playlist/' + playlistUUID) | |
210 | .set('Accept', 'text/html') | |
211 | .expect(200) | |
8be1afa1 | 212 | |
6fad8e51 C |
213 | expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') |
214 | expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
215 | expect(res.text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`) | |
216 | expect(res.text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`) | |
217 | }) | |
8be1afa1 | 218 | |
6fad8e51 C |
219 | it('Should have valid twitter card on the account page', async function () { |
220 | const res = await request(server.url) | |
221 | .get('/accounts/' + account.name) | |
222 | .set('Accept', 'text/html') | |
223 | .expect(200) | |
8be1afa1 | 224 | |
6fad8e51 C |
225 | expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') |
226 | expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
227 | expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`) | |
228 | expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`) | |
229 | }) | |
8d987ec6 | 230 | |
6fad8e51 C |
231 | it('Should have valid twitter card on the channel page', async function () { |
232 | const res = await request(server.url) | |
233 | .get('/video-channels/' + server.videoChannel.name) | |
234 | .set('Accept', 'text/html') | |
235 | .expect(200) | |
8d987ec6 | 236 | |
6fad8e51 C |
237 | expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') |
238 | expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
239 | expect(res.text).to.contain(`<meta property="twitter:title" content="${server.videoChannel.displayName}" />`) | |
240 | expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) | |
241 | }) | |
8d987ec6 | 242 | |
6fad8e51 C |
243 | it('Should have valid twitter card if Twitter is whitelisted', async function () { |
244 | const res1 = await getCustomConfig(server.url, server.accessToken) | |
245 | const config = res1.body | |
246 | config.services.twitter = { | |
247 | username: '@Kuja', | |
248 | whitelisted: true | |
249 | } | |
250 | await updateCustomConfig(server.url, server.accessToken, config) | |
8d987ec6 | 251 | |
6fad8e51 C |
252 | const resVideoRequest = await request(server.url) |
253 | .get('/videos/watch/' + server.video.uuid) | |
254 | .set('Accept', 'text/html') | |
255 | .expect(200) | |
8d987ec6 | 256 | |
6fad8e51 C |
257 | expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />') |
258 | expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
8d987ec6 | 259 | |
6fad8e51 C |
260 | const resVideoPlaylistRequest = await request(server.url) |
261 | .get('/videos/watch/playlist/' + playlistUUID) | |
262 | .set('Accept', 'text/html') | |
263 | .expect(200) | |
8be1afa1 | 264 | |
6fad8e51 C |
265 | expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />') |
266 | expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
5bcfd029 | 267 | |
6fad8e51 C |
268 | const resAccountRequest = await request(server.url) |
269 | .get('/accounts/' + account.name) | |
270 | .set('Accept', 'text/html') | |
271 | .expect(200) | |
272 | ||
273 | expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />') | |
274 | expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
275 | ||
276 | const resChannelRequest = await request(server.url) | |
277 | .get('/video-channels/' + server.videoChannel.name) | |
278 | .set('Accept', 'text/html') | |
279 | .expect(200) | |
280 | ||
281 | expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />') | |
282 | expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
283 | }) | |
5bcfd029 C |
284 | }) |
285 | ||
6fad8e51 C |
286 | describe('Index HTML', function () { |
287 | ||
288 | it('Should have valid index html tags (title, description...)', async function () { | |
289 | const res = await makeHTMLRequest(server.url, '/videos/trending') | |
290 | ||
291 | const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' | |
292 | checkIndexTags(res.text, 'PeerTube', description, '') | |
590fb506 | 293 | }) |
5bcfd029 | 294 | |
6fad8e51 C |
295 | it('Should update the customized configuration and have the correct index html tags', async function () { |
296 | await updateCustomSubConfig(server.url, server.accessToken, { | |
297 | instance: { | |
298 | name: 'PeerTube updated', | |
299 | shortDescription: 'my short description', | |
300 | description: 'my super description', | |
301 | terms: 'my super terms', | |
302 | defaultClientRoute: '/videos/recently-added', | |
303 | defaultNSFWPolicy: 'blur', | |
304 | customizations: { | |
305 | javascript: 'alert("coucou")', | |
306 | css: 'body { background-color: red; }' | |
307 | } | |
308 | } | |
309 | }) | |
5bcfd029 | 310 | |
6fad8e51 C |
311 | const res = await makeHTMLRequest(server.url, '/videos/trending') |
312 | ||
313 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') | |
314 | }) | |
5bcfd029 | 315 | |
6fad8e51 C |
316 | it('Should have valid index html updated tags (title, description...)', async function () { |
317 | const res = await makeHTMLRequest(server.url, '/videos/trending') | |
5bcfd029 | 318 | |
6fad8e51 C |
319 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') |
320 | }) | |
5bcfd029 C |
321 | }) |
322 | ||
7c3b7976 C |
323 | after(async function () { |
324 | await cleanupTests([ server ]) | |
0e1dc3e7 C |
325 | }) |
326 | }) |