diff options
Diffstat (limited to 'server/tests/client.ts')
-rw-r--r-- | server/tests/client.ts | 196 |
1 files changed, 110 insertions, 86 deletions
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 | ||