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