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