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