aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-28 11:36:33 +0200
committerChocobozzz <me@florianbigard.com>2021-05-28 11:38:08 +0200
commita1eda903a497857017495f37a1fd3593ba7ab23c (patch)
treea109f34af8b18c087caf6d5a7264267550f0416d /server/tests
parent012580d98f489e599d44a9a2a0bdc892b9455a90 (diff)
downloadPeerTube-a1eda903a497857017495f37a1fd3593ba7ab23c.tar.gz
PeerTube-a1eda903a497857017495f37a1fd3593ba7ab23c.tar.zst
PeerTube-a1eda903a497857017495f37a1fd3593ba7ab23c.zip
Support '/w/' and '/w/p/' for watch page
And use them as default in client
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/server/services.ts104
-rw-r--r--server/tests/client.ts196
2 files changed, 165 insertions, 135 deletions
diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts
index f0fa91674..ea64e4040 100644
--- a/server/tests/api/server/services.ts
+++ b/server/tests/api/server/services.ts
@@ -67,61 +67,67 @@ describe('Test services', function () {
67 }) 67 })
68 68
69 it('Should have a valid oEmbed video response', async function () { 69 it('Should have a valid oEmbed video response', async function () {
70 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid 70 for (const basePath of [ '/videos/watch/', '/w/' ]) {
71 71 const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid
72 const res = await getOEmbed(server.url, oembedUrl) 72
73 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' + 73 const res = await getOEmbed(server.url, oembedUrl)
74 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` + 74 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
75 'frameborder="0" allowfullscreen></iframe>' 75 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
76 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath 76 'frameborder="0" allowfullscreen></iframe>'
77 77 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath
78 expect(res.body.html).to.equal(expectedHtml) 78
79 expect(res.body.title).to.equal(video.name) 79 expect(res.body.html).to.equal(expectedHtml)
80 expect(res.body.author_name).to.equal(server.videoChannel.displayName) 80 expect(res.body.title).to.equal(video.name)
81 expect(res.body.width).to.equal(560) 81 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
82 expect(res.body.height).to.equal(315) 82 expect(res.body.width).to.equal(560)
83 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) 83 expect(res.body.height).to.equal(315)
84 expect(res.body.thumbnail_width).to.equal(850) 84 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
85 expect(res.body.thumbnail_height).to.equal(480) 85 expect(res.body.thumbnail_width).to.equal(850)
86 expect(res.body.thumbnail_height).to.equal(480)
87 }
86 }) 88 })
87 89
88 it('Should have a valid playlist oEmbed response', async function () { 90 it('Should have a valid playlist oEmbed response', async function () {
89 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/playlist/' + playlistUUID 91 for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) {
90 92 const oembedUrl = 'http://localhost:' + server.port + basePath + playlistUUID
91 const res = await getOEmbed(server.url, oembedUrl) 93
92 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' + 94 const res = await getOEmbed(server.url, oembedUrl)
93 `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` + 95 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
94 'frameborder="0" allowfullscreen></iframe>' 96 `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
95 97 'frameborder="0" allowfullscreen></iframe>'
96 expect(res.body.html).to.equal(expectedHtml) 98
97 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck') 99 expect(res.body.html).to.equal(expectedHtml)
98 expect(res.body.author_name).to.equal(server.videoChannel.displayName) 100 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
99 expect(res.body.width).to.equal(560) 101 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
100 expect(res.body.height).to.equal(315) 102 expect(res.body.width).to.equal(560)
101 expect(res.body.thumbnail_url).exist 103 expect(res.body.height).to.equal(315)
102 expect(res.body.thumbnail_width).to.equal(280) 104 expect(res.body.thumbnail_url).exist
103 expect(res.body.thumbnail_height).to.equal(157) 105 expect(res.body.thumbnail_width).to.equal(280)
106 expect(res.body.thumbnail_height).to.equal(157)
107 }
104 }) 108 })
105 109
106 it('Should have a valid oEmbed response with small max height query', async function () { 110 it('Should have a valid oEmbed response with small max height query', async function () {
107 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid 111 for (const basePath of [ '/videos/watch/', '/w/' ]) {
108 const format = 'json' 112 const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid
109 const maxHeight = 50 113 const format = 'json'
110 const maxWidth = 50 114 const maxHeight = 50
111 115 const maxWidth = 50
112 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth) 116
113 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' + 117 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
114 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` + 118 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
115 'frameborder="0" allowfullscreen></iframe>' 119 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
116 120 'frameborder="0" allowfullscreen></iframe>'
117 expect(res.body.html).to.equal(expectedHtml) 121
118 expect(res.body.title).to.equal(video.name) 122 expect(res.body.html).to.equal(expectedHtml)
119 expect(res.body.author_name).to.equal(server.videoChannel.displayName) 123 expect(res.body.title).to.equal(video.name)
120 expect(res.body.height).to.equal(50) 124 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
121 expect(res.body.width).to.equal(50) 125 expect(res.body.height).to.equal(50)
122 expect(res.body).to.not.have.property('thumbnail_url') 126 expect(res.body.width).to.equal(50)
123 expect(res.body).to.not.have.property('thumbnail_width') 127 expect(res.body).to.not.have.property('thumbnail_url')
124 expect(res.body).to.not.have.property('thumbnail_height') 128 expect(res.body).to.not.have.property('thumbnail_width')
129 expect(res.body).to.not.have.property('thumbnail_height')
130 }
125 }) 131 })
126 132
127 after(async function () { 133 after(async function () {
diff --git a/server/tests/client.ts b/server/tests/client.ts
index f33e5c1da..253a95624 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -54,6 +54,9 @@ describe('Test a client controllers', function () {
54 54
55 const channelDescription = 'my super channel description' 55 const channelDescription = 'my super channel description'
56 56
57 const watchVideoBasePaths = [ '/videos/watch/', '/w/' ]
58 const watchPlaylistBasePaths = [ '/videos/watch/playlist/', '/w/p/' ]
59
57 before(async function () { 60 before(async function () {
58 this.timeout(120000) 61 this.timeout(120000)
59 62
@@ -111,35 +114,40 @@ describe('Test a client controllers', function () {
111 }) 114 })
112 115
113 describe('oEmbed', function () { 116 describe('oEmbed', function () {
117
114 it('Should have valid oEmbed discovery tags for videos', async function () { 118 it('Should have valid oEmbed discovery tags for videos', async function () {
115 const path = '/videos/watch/' + servers[0].video.uuid 119 for (const basePath of watchVideoBasePaths) {
116 const res = await request(servers[0].url) 120 const path = basePath + servers[0].video.uuid
117 .get(path) 121 const res = await request(servers[0].url)
118 .set('Accept', 'text/html') 122 .get(path)
119 .expect(HttpStatusCode.OK_200) 123 .set('Accept', 'text/html')
124 .expect(HttpStatusCode.OK_200)
120 125
121 const port = servers[0].port 126 const port = servers[0].port
122 127
123 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + 128 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%2F${servers[0].video.uuid}" ` + 129 `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2F${servers[0].video.uuid}" ` +
125 `title="${servers[0].video.name}" />` 130 `title="${servers[0].video.name}" />`
126 131
127 expect(res.text).to.contain(expectedLink) 132 expect(res.text).to.contain(expectedLink)
133 }
128 }) 134 })
129 135
130 it('Should have valid oEmbed discovery tags for a playlist', async function () { 136 it('Should have valid oEmbed discovery tags for a playlist', async function () {
131 const res = await request(servers[0].url) 137 for (const basePath of watchPlaylistBasePaths) {
132 .get('/videos/watch/playlist/' + playlistUUID) 138 const res = await request(servers[0].url)
133 .set('Accept', 'text/html') 139 .get(basePath + playlistUUID)
134 .expect(HttpStatusCode.OK_200) 140 .set('Accept', 'text/html')
141 .expect(HttpStatusCode.OK_200)
135 142
136 const port = servers[0].port 143 const port = servers[0].port
137 144
138 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + 145 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
139 `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2Fplaylist%2F${playlistUUID}" ` + 146 `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2Fp%2F${playlistUUID}" ` +
140 `title="${playlistName}" />` 147 `title="${playlistName}" />`
141 148
142 expect(res.text).to.contain(expectedLink) 149 expect(res.text).to.contain(expectedLink)
150 }
143 }) 151 })
144 }) 152 })
145 153
@@ -165,6 +173,26 @@ describe('Test a client controllers', function () {
165 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`) 173 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`)
166 } 174 }
167 175
176 async function watchVideoPageTest (path: string) {
177 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
178 const text = res.text
179
180 expect(text).to.contain(`<meta property="og:title" content="${videoName}" />`)
181 expect(text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`)
182 expect(text).to.contain('<meta property="og:type" content="video" />')
183 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/${servers[0].video.uuid}" />`)
184 }
185
186 async function watchPlaylistPageTest (path: string) {
187 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
188 const text = res.text
189
190 expect(text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
191 expect(text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
192 expect(text).to.contain('<meta property="og:type" content="video" />')
193 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/p/${playlistUUID}" />`)
194 }
195
168 it('Should have valid Open Graph tags on the account page', async function () { 196 it('Should have valid Open Graph tags on the account page', async function () {
169 await accountPageTest('/accounts/' + servers[0].user.username) 197 await accountPageTest('/accounts/' + servers[0].user.username)
170 await accountPageTest('/a/' + servers[0].user.username) 198 await accountPageTest('/a/' + servers[0].user.username)
@@ -177,40 +205,16 @@ describe('Test a client controllers', function () {
177 await channelPageTest('/@' + servers[0].videoChannel.name) 205 await channelPageTest('/@' + servers[0].videoChannel.name)
178 }) 206 })
179 207
180 it('Should have valid Open Graph tags on the watch page with video id', async function () { 208 it('Should have valid Open Graph tags on the watch page', async function () {
181 const res = await request(servers[0].url) 209 await watchVideoPageTest('/videos/watch/' + servers[0].video.id)
182 .get('/videos/watch/' + servers[0].video.id) 210 await watchVideoPageTest('/videos/watch/' + servers[0].video.uuid)
183 .set('Accept', 'text/html') 211 await watchVideoPageTest('/w/' + servers[0].video.uuid)
184 .expect(HttpStatusCode.OK_200) 212 await watchVideoPageTest('/w/' + servers[0].video.id)
185
186 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
187 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`)
188 expect(res.text).to.contain('<meta property="og:type" content="video" />')
189 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
190 })
191
192 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
193 const res = await request(servers[0].url)
194 .get('/videos/watch/' + servers[0].video.uuid)
195 .set('Accept', 'text/html')
196 .expect(HttpStatusCode.OK_200)
197
198 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
199 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`)
200 expect(res.text).to.contain('<meta property="og:type" content="video" />')
201 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
202 }) 213 })
203 214
204 it('Should have valid Open Graph tags on the watch playlist page', async function () { 215 it('Should have valid Open Graph tags on the watch playlist page', async function () {
205 const res = await request(servers[0].url) 216 await watchPlaylistPageTest('/videos/watch/playlist/' + playlistUUID)
206 .get('/videos/watch/playlist/' + playlistUUID) 217 await watchPlaylistPageTest('/w/p/' + playlistUUID)
207 .set('Accept', 'text/html')
208 .expect(HttpStatusCode.OK_200)
209
210 expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
211 expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
212 expect(res.text).to.contain('<meta property="og:type" content="video" />')
213 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/playlist/${playlistUUID}" />`)
214 }) 218 })
215 }) 219 })
216 220
@@ -238,28 +242,36 @@ describe('Test a client controllers', function () {
238 expect(text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) 242 expect(text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`)
239 } 243 }
240 244
241 it('Should have valid twitter card on the watch video page', async function () { 245 async function watchVideoPageTest (path: string) {
242 const res = await request(servers[0].url) 246 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
243 .get('/videos/watch/' + servers[0].video.uuid) 247 const text = res.text
244 .set('Accept', 'text/html')
245 .expect(HttpStatusCode.OK_200)
246 248
247 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />') 249 expect(text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
248 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 250 expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
249 expect(res.text).to.contain(`<meta property="twitter:title" content="${videoName}" />`) 251 expect(text).to.contain(`<meta property="twitter:title" content="${videoName}" />`)
250 expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`) 252 expect(text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`)
253 }
254
255 async function watchPlaylistPageTest (path: string) {
256 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
257 const text = res.text
258
259 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
260 expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
261 expect(text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`)
262 expect(text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`)
263 }
264
265 it('Should have valid twitter card on the watch video page', async function () {
266 await watchVideoPageTest('/videos/watch/' + servers[0].video.id)
267 await watchVideoPageTest('/videos/watch/' + servers[0].video.uuid)
268 await watchVideoPageTest('/w/' + servers[0].video.uuid)
269 await watchVideoPageTest('/w/' + servers[0].video.id)
251 }) 270 })
252 271
253 it('Should have valid twitter card on the watch playlist page', async function () { 272 it('Should have valid twitter card on the watch playlist page', async function () {
254 const res = await request(servers[0].url) 273 await watchPlaylistPageTest('/videos/watch/playlist/' + playlistUUID)
255 .get('/videos/watch/playlist/' + playlistUUID) 274 await watchPlaylistPageTest('/w/p/' + playlistUUID)
256 .set('Accept', 'text/html')
257 .expect(HttpStatusCode.OK_200)
258
259 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
260 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
261 expect(res.text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`)
262 expect(res.text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`)
263 }) 275 })
264 276
265 it('Should have valid twitter card on the account page', async function () { 277 it('Should have valid twitter card on the account page', async function () {
@@ -304,24 +316,32 @@ describe('Test a client controllers', function () {
304 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') 316 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
305 } 317 }
306 318
307 it('Should have valid twitter card on the watch video page', async function () { 319 async function watchVideoPageTest (path: string) {
308 const res = await request(servers[0].url) 320 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
309 .get('/videos/watch/' + servers[0].video.uuid) 321 const text = res.text
310 .set('Accept', 'text/html')
311 .expect(HttpStatusCode.OK_200)
312 322
313 expect(res.text).to.contain('<meta property="twitter:card" content="player" />') 323 expect(text).to.contain('<meta property="twitter:card" content="player" />')
314 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 324 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
325 }
326
327 async function watchPlaylistPageTest (path: string) {
328 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
329 const text = res.text
330
331 expect(text).to.contain('<meta property="twitter:card" content="player" />')
332 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
333 }
334
335 it('Should have valid twitter card on the watch video page', async function () {
336 await watchVideoPageTest('/videos/watch/' + servers[0].video.id)
337 await watchVideoPageTest('/videos/watch/' + servers[0].video.uuid)
338 await watchVideoPageTest('/w/' + servers[0].video.uuid)
339 await watchVideoPageTest('/w/' + servers[0].video.id)
315 }) 340 })
316 341
317 it('Should have valid twitter card on the watch playlist page', async function () { 342 it('Should have valid twitter card on the watch playlist page', async function () {
318 const res = await request(servers[0].url) 343 await watchPlaylistPageTest('/videos/watch/playlist/' + playlistUUID)
319 .get('/videos/watch/playlist/' + playlistUUID) 344 await watchPlaylistPageTest('/w/p/' + playlistUUID)
320 .set('Accept', 'text/html')
321 .expect(HttpStatusCode.OK_200)
322
323 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
324 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
325 }) 345 })
326 346
327 it('Should have valid twitter card on the account page', async function () { 347 it('Should have valid twitter card on the account page', async function () {
@@ -378,8 +398,10 @@ describe('Test a client controllers', function () {
378 }) 398 })
379 399
380 it('Should use the original video URL for the canonical tag', async function () { 400 it('Should use the original video URL for the canonical tag', async function () {
381 const res = await makeHTMLRequest(servers[1].url, '/videos/watch/' + servers[0].video.uuid) 401 for (const basePath of watchVideoBasePaths) {
382 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`) 402 const res = await makeHTMLRequest(servers[1].url, basePath + servers[0].video.uuid)
403 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
404 }
383 }) 405 })
384 406
385 it('Should use the original account URL for the canonical tag', async function () { 407 it('Should use the original account URL for the canonical tag', async function () {
@@ -403,8 +425,10 @@ describe('Test a client controllers', function () {
403 }) 425 })
404 426
405 it('Should use the original playlist URL for the canonical tag', async function () { 427 it('Should use the original playlist URL for the canonical tag', async function () {
406 const res = await makeHTMLRequest(servers[1].url, '/videos/watch/playlist/' + playlistUUID) 428 for (const basePath of watchPlaylistBasePaths) {
407 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlistUUID}" />`) 429 const res = await makeHTMLRequest(servers[1].url, basePath + playlistUUID)
430 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlistUUID}" />`)
431 }
408 }) 432 })
409 }) 433 })
410 434