aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/client.ts')
-rw-r--r--server/tests/client.ts129
1 files changed, 77 insertions, 52 deletions
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 253a95624..7c4fb4e46 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -3,9 +3,8 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import * as request from 'supertest'
7import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 6import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
8import { Account, CustomConfig, HTMLServerConfig, ServerConfig, VideoPlaylistPrivacy } from '@shared/models' 7import { Account, CustomConfig, HTMLServerConfig, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy } from '@shared/models'
9import { 8import {
10 addVideoInPlaylist, 9 addVideoInPlaylist,
11 cleanupTests, 10 cleanupTests,
@@ -50,13 +49,16 @@ describe('Test a client controllers', function () {
50 49
51 const playlistName = 'super playlist name' 50 const playlistName = 'super playlist name'
52 const playlistDescription = 'super playlist description' 51 const playlistDescription = 'super playlist description'
53 let playlistUUID: string 52 let playlist: VideoPlaylistCreateResult
54 53
55 const channelDescription = 'my super channel description' 54 const channelDescription = 'my super channel description'
56 55
57 const watchVideoBasePaths = [ '/videos/watch/', '/w/' ] 56 const watchVideoBasePaths = [ '/videos/watch/', '/w/' ]
58 const watchPlaylistBasePaths = [ '/videos/watch/playlist/', '/w/p/' ] 57 const watchPlaylistBasePaths = [ '/videos/watch/playlist/', '/w/p/' ]
59 58
59 let videoIds: (string | number)[] = []
60 let playlistIds: (string | number)[] = []
61
60 before(async function () { 62 before(async function () {
61 this.timeout(120000) 63 this.timeout(120000)
62 64
@@ -79,7 +81,9 @@ describe('Test a client controllers', function () {
79 const videos = resVideosRequest.body.data 81 const videos = resVideosRequest.body.data
80 expect(videos.length).to.equal(1) 82 expect(videos.length).to.equal(1)
81 83
82 servers[0].video = videos[0] 84 const video = videos[0]
85 servers[0].video = video
86 videoIds = [ video.id, video.uuid, video.shortUUID ]
83 87
84 // Playlist 88 // Playlist
85 89
@@ -91,16 +95,14 @@ describe('Test a client controllers', function () {
91 } 95 }
92 96
93 const resVideoPlaylistRequest = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) 97 const resVideoPlaylistRequest = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs })
94 98 playlist = resVideoPlaylistRequest.body.videoPlaylist
95 const playlist = resVideoPlaylistRequest.body.videoPlaylist 99 playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ]
96 const playlistId = playlist.id
97 playlistUUID = playlist.uuid
98 100
99 await addVideoInPlaylist({ 101 await addVideoInPlaylist({
100 url: servers[0].url, 102 url: servers[0].url,
101 token: servers[0].accessToken, 103 token: servers[0].accessToken,
102 playlistId, 104 playlistId: playlist.shortUUID,
103 elementAttrs: { videoId: servers[0].video.id } 105 elementAttrs: { videoId: video.id }
104 }) 106 })
105 107
106 // Account 108 // Account
@@ -117,36 +119,43 @@ describe('Test a client controllers', function () {
117 119
118 it('Should have valid oEmbed discovery tags for videos', async function () { 120 it('Should have valid oEmbed discovery tags for videos', async function () {
119 for (const basePath of watchVideoBasePaths) { 121 for (const basePath of watchVideoBasePaths) {
120 const path = basePath + servers[0].video.uuid 122 for (const id of videoIds) {
121 const res = await request(servers[0].url) 123 const res = await makeGetRequest({
122 .get(path) 124 url: servers[0].url,
123 .set('Accept', 'text/html') 125 path: basePath + id,
124 .expect(HttpStatusCode.OK_200) 126 accept: 'text/html',
127 statusCodeExpected: HttpStatusCode.OK_200
128 })
125 129
126 const port = servers[0].port 130 const port = servers[0].port
127 131
128 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + 132 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
129 `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2F${servers[0].video.uuid}" ` + 133 `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2F${servers[0].video.uuid}" ` +
130 `title="${servers[0].video.name}" />` 134 `title="${servers[0].video.name}" />`
131 135
132 expect(res.text).to.contain(expectedLink) 136 expect(res.text).to.contain(expectedLink)
137 }
133 } 138 }
134 }) 139 })
135 140
136 it('Should have valid oEmbed discovery tags for a playlist', async function () { 141 it('Should have valid oEmbed discovery tags for a playlist', async function () {
137 for (const basePath of watchPlaylistBasePaths) { 142 for (const basePath of watchPlaylistBasePaths) {
138 const res = await request(servers[0].url) 143 for (const id of playlistIds) {
139 .get(basePath + playlistUUID) 144 const res = await makeGetRequest({
140 .set('Accept', 'text/html') 145 url: servers[0].url,
141 .expect(HttpStatusCode.OK_200) 146 path: basePath + id,
147 accept: 'text/html',
148 statusCodeExpected: HttpStatusCode.OK_200
149 })
142 150
143 const port = servers[0].port 151 const port = servers[0].port
144 152
145 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + 153 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
146 `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2Fp%2F${playlistUUID}" ` + 154 `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2Fp%2F${playlist.uuid}" ` +
147 `title="${playlistName}" />` 155 `title="${playlistName}" />`
148 156
149 expect(res.text).to.contain(expectedLink) 157 expect(res.text).to.contain(expectedLink)
158 }
150 } 159 }
151 }) 160 })
152 }) 161 })
@@ -190,7 +199,7 @@ describe('Test a client controllers', function () {
190 expect(text).to.contain(`<meta property="og:title" content="${playlistName}" />`) 199 expect(text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
191 expect(text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`) 200 expect(text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
192 expect(text).to.contain('<meta property="og:type" content="video" />') 201 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}" />`) 202 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/p/${playlist.uuid}" />`)
194 } 203 }
195 204
196 it('Should have valid Open Graph tags on the account page', async function () { 205 it('Should have valid Open Graph tags on the account page', async function () {
@@ -206,15 +215,19 @@ describe('Test a client controllers', function () {
206 }) 215 })
207 216
208 it('Should have valid Open Graph tags on the watch page', async function () { 217 it('Should have valid Open Graph tags on the watch page', async function () {
209 await watchVideoPageTest('/videos/watch/' + servers[0].video.id) 218 for (const path of watchVideoBasePaths) {
210 await watchVideoPageTest('/videos/watch/' + servers[0].video.uuid) 219 for (const id of videoIds) {
211 await watchVideoPageTest('/w/' + servers[0].video.uuid) 220 await watchVideoPageTest(path + id)
212 await watchVideoPageTest('/w/' + servers[0].video.id) 221 }
222 }
213 }) 223 })
214 224
215 it('Should have valid Open Graph tags on the watch playlist page', async function () { 225 it('Should have valid Open Graph tags on the watch playlist page', async function () {
216 await watchPlaylistPageTest('/videos/watch/playlist/' + playlistUUID) 226 for (const path of watchPlaylistBasePaths) {
217 await watchPlaylistPageTest('/w/p/' + playlistUUID) 227 for (const id of playlistIds) {
228 await watchPlaylistPageTest(path + id)
229 }
230 }
218 }) 231 })
219 }) 232 })
220 233
@@ -263,15 +276,19 @@ describe('Test a client controllers', function () {
263 } 276 }
264 277
265 it('Should have valid twitter card on the watch video page', async function () { 278 it('Should have valid twitter card on the watch video page', async function () {
266 await watchVideoPageTest('/videos/watch/' + servers[0].video.id) 279 for (const path of watchVideoBasePaths) {
267 await watchVideoPageTest('/videos/watch/' + servers[0].video.uuid) 280 for (const id of videoIds) {
268 await watchVideoPageTest('/w/' + servers[0].video.uuid) 281 await watchVideoPageTest(path + id)
269 await watchVideoPageTest('/w/' + servers[0].video.id) 282 }
283 }
270 }) 284 })
271 285
272 it('Should have valid twitter card on the watch playlist page', async function () { 286 it('Should have valid twitter card on the watch playlist page', async function () {
273 await watchPlaylistPageTest('/videos/watch/playlist/' + playlistUUID) 287 for (const path of watchPlaylistBasePaths) {
274 await watchPlaylistPageTest('/w/p/' + playlistUUID) 288 for (const id of playlistIds) {
289 await watchPlaylistPageTest(path + id)
290 }
291 }
275 }) 292 })
276 293
277 it('Should have valid twitter card on the account page', async function () { 294 it('Should have valid twitter card on the account page', async function () {
@@ -333,15 +350,19 @@ describe('Test a client controllers', function () {
333 } 350 }
334 351
335 it('Should have valid twitter card on the watch video page', async function () { 352 it('Should have valid twitter card on the watch video page', async function () {
336 await watchVideoPageTest('/videos/watch/' + servers[0].video.id) 353 for (const path of watchVideoBasePaths) {
337 await watchVideoPageTest('/videos/watch/' + servers[0].video.uuid) 354 for (const id of videoIds) {
338 await watchVideoPageTest('/w/' + servers[0].video.uuid) 355 await watchVideoPageTest(path + id)
339 await watchVideoPageTest('/w/' + servers[0].video.id) 356 }
357 }
340 }) 358 })
341 359
342 it('Should have valid twitter card on the watch playlist page', async function () { 360 it('Should have valid twitter card on the watch playlist page', async function () {
343 await watchPlaylistPageTest('/videos/watch/playlist/' + playlistUUID) 361 for (const path of watchPlaylistBasePaths) {
344 await watchPlaylistPageTest('/w/p/' + playlistUUID) 362 for (const id of playlistIds) {
363 await watchPlaylistPageTest(path + id)
364 }
365 }
345 }) 366 })
346 367
347 it('Should have valid twitter card on the account page', async function () { 368 it('Should have valid twitter card on the account page', async function () {
@@ -399,8 +420,10 @@ describe('Test a client controllers', function () {
399 420
400 it('Should use the original video URL for the canonical tag', async function () { 421 it('Should use the original video URL for the canonical tag', async function () {
401 for (const basePath of watchVideoBasePaths) { 422 for (const basePath of watchVideoBasePaths) {
402 const res = await makeHTMLRequest(servers[1].url, basePath + servers[0].video.uuid) 423 for (const id of videoIds) {
403 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`) 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 }
404 } 427 }
405 }) 428 })
406 429
@@ -426,8 +449,10 @@ describe('Test a client controllers', function () {
426 449
427 it('Should use the original playlist URL for the canonical tag', async function () { 450 it('Should use the original playlist URL for the canonical tag', async function () {
428 for (const basePath of watchPlaylistBasePaths) { 451 for (const basePath of watchPlaylistBasePaths) {
429 const res = await makeHTMLRequest(servers[1].url, basePath + playlistUUID) 452 for (const id of playlistIds) {
430 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlistUUID}" />`) 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 }
431 } 456 }
432 }) 457 })
433 }) 458 })