]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/client.ts
Translated using Weblate (Malayalam)
[github/Chocobozzz/PeerTube.git] / server / tests / client.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
0e1dc3e7
C
2
3import 'mocha'
4import * as chai from 'chai'
012580d9 5import { omit } from 'lodash'
012580d9 6import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
d4a8e7a6 7import { Account, CustomConfig, HTMLServerConfig, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy } from '@shared/models'
0e1dc3e7 8import {
39433fa5 9 addVideoInPlaylist,
7c3b7976 10 cleanupTests,
39433fa5 11 createVideoPlaylist,
a59f210f
C
12 doubleFollow,
13 flushAndRunMultipleServers,
39433fa5 14 getAccount,
aea0b0e7 15 getConfig,
590fb506
C
16 getCustomConfig,
17 getVideosList,
012580d9 18 makeGetRequest,
590fb506 19 makeHTMLRequest,
590fb506 20 ServerInfo,
a59f210f 21 setAccessTokensToServers,
39433fa5 22 setDefaultVideoChannel,
590fb506
C
23 updateCustomConfig,
24 updateCustomSubConfig,
39433fa5 25 updateMyUser,
e5024f51 26 updateVideoChannel,
a59f210f
C
27 uploadVideo,
28 waitJobs
94565d52 29} from '../../shared/extra-utils'
590fb506
C
30
31const expect = chai.expect
5bcfd029 32
aea0b0e7 33function checkIndexTags (html: string, title: string, description: string, css: string, config: ServerConfig) {
5bcfd029
C
34 expect(html).to.contain('<title>' + title + '</title>')
35 expect(html).to.contain('<meta name="description" content="' + description + '" />')
36 expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
aea0b0e7
C
37
38 const htmlConfig: HTMLServerConfig = omit(config, 'signup')
39 expect(html).to.contain(`<script type="application/javascript">window.PeerTubeServerConfig = '${JSON.stringify(htmlConfig)}'</script>`)
5bcfd029 40}
0e1dc3e7
C
41
42describe('Test a client controllers', function () {
e5024f51 43 let servers: ServerInfo[] = []
39433fa5
C
44 let account: Account
45
46 const videoName = 'my super name for server 1'
a073c912
RK
47 const videoDescription = 'my<br> super __description__ for *server* 1<p></p>'
48 const videoDescriptionPlainText = 'my super description for server 1'
39433fa5
C
49
50 const playlistName = 'super playlist name'
51 const playlistDescription = 'super playlist description'
d4a8e7a6 52 let playlist: VideoPlaylistCreateResult
39433fa5
C
53
54 const channelDescription = 'my super channel description'
0e1dc3e7 55
a1eda903
C
56 const watchVideoBasePaths = [ '/videos/watch/', '/w/' ]
57 const watchPlaylistBasePaths = [ '/videos/watch/playlist/', '/w/p/' ]
58
d4a8e7a6
C
59 let videoIds: (string | number)[] = []
60 let playlistIds: (string | number)[] = []
61
0e1dc3e7
C
62 before(async function () {
63 this.timeout(120000)
64
e5024f51 65 servers = await flushAndRunMultipleServers(2)
e5024f51
TC
66
67 await setAccessTokensToServers(servers)
68
e5024f51
TC
69 await doubleFollow(servers[0], servers[1])
70
a59f210f 71 await setDefaultVideoChannel(servers)
0e1dc3e7 72
a59f210f 73 await updateVideoChannel(servers[0].url, servers[0].accessToken, servers[0].videoChannel.name, { description: channelDescription })
8d987ec6 74
39433fa5 75 // Video
8d987ec6 76
39433fa5 77 const videoAttributes = { name: videoName, description: videoDescription }
a59f210f 78 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
0e1dc3e7 79
a59f210f 80 const resVideosRequest = await getVideosList(servers[0].url)
8d987ec6 81 const videos = resVideosRequest.body.data
0e1dc3e7
C
82 expect(videos.length).to.equal(1)
83
d4a8e7a6
C
84 const video = videos[0]
85 servers[0].video = video
86 videoIds = [ video.id, video.uuid, video.shortUUID ]
8d987ec6
K
87
88 // Playlist
89
90 const playlistAttrs = {
39433fa5
C
91 displayName: playlistName,
92 description: playlistDescription,
93 privacy: VideoPlaylistPrivacy.PUBLIC,
a59f210f 94 videoChannelId: servers[0].videoChannel.id
8d987ec6
K
95 }
96
a59f210f 97 const resVideoPlaylistRequest = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs })
d4a8e7a6
C
98 playlist = resVideoPlaylistRequest.body.videoPlaylist
99 playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ]
8d987ec6
K
100
101 await addVideoInPlaylist({
a59f210f
C
102 url: servers[0].url,
103 token: servers[0].accessToken,
d4a8e7a6
C
104 playlistId: playlist.shortUUID,
105 elementAttrs: { videoId: video.id }
8d987ec6
K
106 })
107
108 // Account
109
a59f210f 110 await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' })
8d987ec6 111
a59f210f 112 const resAccountRequest = await getAccount(servers[0].url, `${servers[0].user.username}@${servers[0].host}`)
39433fa5 113 account = resAccountRequest.body
a59f210f
C
114
115 await waitJobs(servers)
0e1dc3e7
C
116 })
117
6fad8e51 118 describe('oEmbed', function () {
a1eda903 119
6fad8e51 120 it('Should have valid oEmbed discovery tags for videos', async function () {
a1eda903 121 for (const basePath of watchVideoBasePaths) {
d4a8e7a6
C
122 for (const id of videoIds) {
123 const res = await makeGetRequest({
124 url: servers[0].url,
125 path: basePath + id,
126 accept: 'text/html',
127 statusCodeExpected: HttpStatusCode.OK_200
128 })
0e1dc3e7 129
d4a8e7a6 130 const port = servers[0].port
0e1dc3e7 131
d4a8e7a6
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}%2Fw%2F${servers[0].video.uuid}" ` +
134 `title="${servers[0].video.name}" />`
8d987ec6 135
d4a8e7a6
C
136 expect(res.text).to.contain(expectedLink)
137 }
a1eda903 138 }
6fad8e51 139 })
8d987ec6 140
6fad8e51 141 it('Should have valid oEmbed discovery tags for a playlist', async function () {
a1eda903 142 for (const basePath of watchPlaylistBasePaths) {
d4a8e7a6
C
143 for (const id of playlistIds) {
144 const res = await makeGetRequest({
145 url: servers[0].url,
146 path: basePath + id,
147 accept: 'text/html',
148 statusCodeExpected: HttpStatusCode.OK_200
149 })
6fad8e51 150
d4a8e7a6 151 const port = servers[0].port
8d987ec6 152
d4a8e7a6
C
153 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
154 `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2Fp%2F${playlist.uuid}" ` +
155 `title="${playlistName}" />`
8d987ec6 156
d4a8e7a6
C
157 expect(res.text).to.contain(expectedLink)
158 }
a1eda903 159 }
6fad8e51 160 })
8d987ec6
K
161 })
162
6fad8e51 163 describe('Open Graph', function () {
8d987ec6 164
012580d9
C
165 async function accountPageTest (path: string) {
166 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
167 const text = res.text
9a911038 168
012580d9
C
169 expect(text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
170 expect(text).to.contain(`<meta property="og:description" content="${account.description}" />`)
171 expect(text).to.contain('<meta property="og:type" content="website" />')
172 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`)
173 }
9a911038 174
012580d9
C
175 async function channelPageTest (path: string) {
176 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
177 const text = res.text
0e1dc3e7 178
012580d9
C
179 expect(text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`)
180 expect(text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
181 expect(text).to.contain('<meta property="og:type" content="website" />')
182 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`)
183 }
184
a1eda903
C
185 async function watchVideoPageTest (path: string) {
186 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
187 const text = res.text
188
189 expect(text).to.contain(`<meta property="og:title" content="${videoName}" />`)
190 expect(text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`)
191 expect(text).to.contain('<meta property="og:type" content="video" />')
192 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/${servers[0].video.uuid}" />`)
193 }
194
195 async function watchPlaylistPageTest (path: string) {
196 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
197 const text = res.text
198
199 expect(text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
200 expect(text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
201 expect(text).to.contain('<meta property="og:type" content="video" />')
d4a8e7a6 202 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/p/${playlist.uuid}" />`)
a1eda903
C
203 }
204
012580d9
C
205 it('Should have valid Open Graph tags on the account page', async function () {
206 await accountPageTest('/accounts/' + servers[0].user.username)
207 await accountPageTest('/a/' + servers[0].user.username)
208 await accountPageTest('/@' + servers[0].user.username)
6fad8e51 209 })
d8755eed 210
6fad8e51 211 it('Should have valid Open Graph tags on the channel page', async function () {
012580d9
C
212 await channelPageTest('/video-channels/' + servers[0].videoChannel.name)
213 await channelPageTest('/c/' + servers[0].videoChannel.name)
214 await channelPageTest('/@' + servers[0].videoChannel.name)
6fad8e51 215 })
d8755eed 216
a1eda903 217 it('Should have valid Open Graph tags on the watch page', async function () {
d4a8e7a6
C
218 for (const path of watchVideoBasePaths) {
219 for (const id of videoIds) {
220 await watchVideoPageTest(path + id)
221 }
222 }
6fad8e51 223 })
8d987ec6 224
6fad8e51 225 it('Should have valid Open Graph tags on the watch playlist page', async function () {
d4a8e7a6
C
226 for (const path of watchPlaylistBasePaths) {
227 for (const id of playlistIds) {
228 await watchPlaylistPageTest(path + id)
229 }
230 }
6fad8e51 231 })
8d987ec6
K
232 })
233
6fad8e51 234 describe('Twitter card', async function () {
8d987ec6 235
012580d9 236 describe('Not whitelisted', function () {
8d987ec6 237
012580d9
C
238 async function accountPageTest (path: string) {
239 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
240 const text = res.text
8d987ec6 241
012580d9
C
242 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
243 expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
244 expect(text).to.contain(`<meta property="twitter:title" content="${account.name}" />`)
245 expect(text).to.contain(`<meta property="twitter:description" content="${account.description}" />`)
246 }
8be1afa1 247
012580d9
C
248 async function channelPageTest (path: string) {
249 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
250 const text = res.text
8be1afa1 251
012580d9
C
252 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
253 expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
254 expect(text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`)
255 expect(text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`)
9a911038
K
256 }
257
a1eda903
C
258 async function watchVideoPageTest (path: string) {
259 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
260 const text = res.text
8be1afa1 261
a1eda903
C
262 expect(text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
263 expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
264 expect(text).to.contain(`<meta property="twitter:title" content="${videoName}" />`)
265 expect(text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`)
266 }
267
268 async function watchPlaylistPageTest (path: string) {
269 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
270 const text = res.text
271
272 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
273 expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
274 expect(text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`)
275 expect(text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`)
276 }
277
278 it('Should have valid twitter card on the watch video page', async function () {
d4a8e7a6
C
279 for (const path of watchVideoBasePaths) {
280 for (const id of videoIds) {
281 await watchVideoPageTest(path + id)
282 }
283 }
012580d9 284 })
9a911038 285
012580d9 286 it('Should have valid twitter card on the watch playlist page', async function () {
d4a8e7a6
C
287 for (const path of watchPlaylistBasePaths) {
288 for (const id of playlistIds) {
289 await watchPlaylistPageTest(path + id)
290 }
291 }
012580d9
C
292 })
293
294 it('Should have valid twitter card on the account page', async function () {
295 await accountPageTest('/accounts/' + account.name)
296 await accountPageTest('/a/' + account.name)
297 await accountPageTest('/@' + account.name)
298 })
299
300 it('Should have valid twitter card on the channel page', async function () {
301 await channelPageTest('/video-channels/' + servers[0].videoChannel.name)
302 await channelPageTest('/c/' + servers[0].videoChannel.name)
303 await channelPageTest('/@' + servers[0].videoChannel.name)
304 })
6fad8e51 305 })
8d987ec6 306
012580d9 307 describe('Whitelisted', function () {
8d987ec6 308
012580d9
C
309 before(async function () {
310 const res = await getCustomConfig(servers[0].url, servers[0].accessToken)
311 const config = res.body as CustomConfig
312 config.services.twitter = {
313 username: '@Kuja',
314 whitelisted: true
315 }
8d987ec6 316
012580d9
C
317 await updateCustomConfig(servers[0].url, servers[0].accessToken, config)
318 })
8d987ec6 319
012580d9
C
320 async function accountPageTest (path: string) {
321 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
322 const text = res.text
8be1afa1 323
012580d9
C
324 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
325 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
9a911038
K
326 }
327
012580d9
C
328 async function channelPageTest (path: string) {
329 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
330 const text = res.text
9a911038 331
012580d9
C
332 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
333 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
334 }
9a911038 335
a1eda903
C
336 async function watchVideoPageTest (path: string) {
337 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
338 const text = res.text
6fad8e51 339
a1eda903
C
340 expect(text).to.contain('<meta property="twitter:card" content="player" />')
341 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
342 }
343
344 async function watchPlaylistPageTest (path: string) {
345 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
346 const text = res.text
347
348 expect(text).to.contain('<meta property="twitter:card" content="player" />')
349 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
350 }
351
352 it('Should have valid twitter card on the watch video page', async function () {
d4a8e7a6
C
353 for (const path of watchVideoBasePaths) {
354 for (const id of videoIds) {
355 await watchVideoPageTest(path + id)
356 }
357 }
012580d9 358 })
9a911038 359
012580d9 360 it('Should have valid twitter card on the watch playlist page', async function () {
d4a8e7a6
C
361 for (const path of watchPlaylistBasePaths) {
362 for (const id of playlistIds) {
363 await watchPlaylistPageTest(path + id)
364 }
365 }
012580d9
C
366 })
367
368 it('Should have valid twitter card on the account page', async function () {
369 await accountPageTest('/accounts/' + account.name)
370 await accountPageTest('/a/' + account.name)
371 await accountPageTest('/@' + account.name)
372 })
373
374 it('Should have valid twitter card on the channel page', async function () {
375 await channelPageTest('/video-channels/' + servers[0].videoChannel.name)
376 await channelPageTest('/c/' + servers[0].videoChannel.name)
377 await channelPageTest('/@' + servers[0].videoChannel.name)
378 })
6fad8e51 379 })
5bcfd029
C
380 })
381
6fad8e51
C
382 describe('Index HTML', function () {
383
384 it('Should have valid index html tags (title, description...)', async function () {
aea0b0e7 385 const resConfig = await getConfig(servers[0].url)
a59f210f 386 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
6fad8e51
C
387
388 const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
aea0b0e7 389 checkIndexTags(res.text, 'PeerTube', description, '', resConfig.body)
590fb506 390 })
5bcfd029 391
6fad8e51 392 it('Should update the customized configuration and have the correct index html tags', async function () {
a59f210f 393 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
6fad8e51
C
394 instance: {
395 name: 'PeerTube updated',
396 shortDescription: 'my short description',
397 description: 'my super description',
398 terms: 'my super terms',
6fad8e51 399 defaultNSFWPolicy: 'blur',
3da68f0a 400 defaultClientRoute: '/videos/recently-added',
6fad8e51
C
401 customizations: {
402 javascript: 'alert("coucou")',
403 css: 'body { background-color: red; }'
404 }
405 }
406 })
5bcfd029 407
aea0b0e7 408 const resConfig = await getConfig(servers[0].url)
a59f210f 409 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
6fad8e51 410
aea0b0e7 411 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body)
6fad8e51 412 })
5bcfd029 413
6fad8e51 414 it('Should have valid index html updated tags (title, description...)', async function () {
aea0b0e7 415 const resConfig = await getConfig(servers[0].url)
a59f210f 416 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
5bcfd029 417
aea0b0e7 418 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body)
6fad8e51 419 })
e5024f51
TC
420
421 it('Should use the original video URL for the canonical tag', async function () {
a1eda903 422 for (const basePath of watchVideoBasePaths) {
d4a8e7a6
C
423 for (const id of videoIds) {
424 const res = await makeHTMLRequest(servers[1].url, basePath + id)
425 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
426 }
a1eda903 427 }
a59f210f
C
428 })
429
430 it('Should use the original account URL for the canonical tag', async function () {
9a911038
K
431 const accountURLtest = (res) => {
432 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`)
433 }
434
435 accountURLtest(await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host))
436 accountURLtest(await makeHTMLRequest(servers[1].url, '/a/root@' + servers[0].host))
437 accountURLtest(await makeHTMLRequest(servers[1].url, '/@root@' + servers[0].host))
a59f210f
C
438 })
439
440 it('Should use the original channel URL for the canonical tag', async function () {
9a911038
K
441 const channelURLtests = (res) => {
442 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`)
443 }
444
445 channelURLtests(await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host))
446 channelURLtests(await makeHTMLRequest(servers[1].url, '/c/root_channel@' + servers[0].host))
447 channelURLtests(await makeHTMLRequest(servers[1].url, '/@root_channel@' + servers[0].host))
a59f210f
C
448 })
449
450 it('Should use the original playlist URL for the canonical tag', async function () {
a1eda903 451 for (const basePath of watchPlaylistBasePaths) {
d4a8e7a6
C
452 for (const id of playlistIds) {
453 const res = await makeHTMLRequest(servers[1].url, basePath + id)
454 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlist.uuid}" />`)
455 }
a1eda903 456 }
e5024f51 457 })
5bcfd029
C
458 })
459
aea0b0e7
C
460 describe('Embed HTML', function () {
461
462 it('Should have the correct embed html tags', async function () {
463 const resConfig = await getConfig(servers[0].url)
464 const res = await makeHTMLRequest(servers[0].url, servers[0].video.embedPath)
465
466 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body)
467 })
468 })
469
7c3b7976 470 after(async function () {
a59f210f 471 await cleanupTests(servers)
0e1dc3e7
C
472 })
473})