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.ts270
1 files changed, 119 insertions, 151 deletions
diff --git a/server/tests/client.ts b/server/tests/client.ts
index d9a472fdd..f33e5c1da 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -2,8 +2,10 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash'
5import * as request from 'supertest' 6import * as request from 'supertest'
6import { Account, HTMLServerConfig, ServerConfig, VideoPlaylistPrivacy } from '@shared/models' 7import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
8import { Account, CustomConfig, HTMLServerConfig, ServerConfig, VideoPlaylistPrivacy } from '@shared/models'
7import { 9import {
8 addVideoInPlaylist, 10 addVideoInPlaylist,
9 cleanupTests, 11 cleanupTests,
@@ -14,6 +16,7 @@ import {
14 getConfig, 16 getConfig,
15 getCustomConfig, 17 getCustomConfig,
16 getVideosList, 18 getVideosList,
19 makeGetRequest,
17 makeHTMLRequest, 20 makeHTMLRequest,
18 ServerInfo, 21 ServerInfo,
19 setAccessTokensToServers, 22 setAccessTokensToServers,
@@ -25,8 +28,6 @@ import {
25 uploadVideo, 28 uploadVideo,
26 waitJobs 29 waitJobs
27} from '../../shared/extra-utils' 30} from '../../shared/extra-utils'
28import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
29import { omit } from 'lodash'
30 31
31const expect = chai.expect 32const expect = chai.expect
32 33
@@ -144,52 +145,36 @@ describe('Test a client controllers', function () {
144 145
145 describe('Open Graph', function () { 146 describe('Open Graph', function () {
146 147
147 it('Should have valid Open Graph tags on the account page', async function () { 148 async function accountPageTest (path: string) {
148 const accountPageTests = (res) => { 149 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
149 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) 150 const text = res.text
150 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
151 expect(res.text).to.contain('<meta property="og:type" content="website" />')
152 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`)
153 }
154 151
155 accountPageTests(await request(servers[0].url) 152 expect(text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
156 .get('/accounts/' + servers[0].user.username) 153 expect(text).to.contain(`<meta property="og:description" content="${account.description}" />`)
157 .set('Accept', 'text/html') 154 expect(text).to.contain('<meta property="og:type" content="website" />')
158 .expect(HttpStatusCode.OK_200)) 155 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`)
156 }
159 157
160 accountPageTests(await request(servers[0].url) 158 async function channelPageTest (path: string) {
161 .get('/a/' + servers[0].user.username) 159 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
162 .set('Accept', 'text/html') 160 const text = res.text
163 .expect(HttpStatusCode.OK_200))
164 161
165 accountPageTests(await request(servers[0].url) 162 expect(text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`)
166 .get('/@' + servers[0].user.username) 163 expect(text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
167 .set('Accept', 'text/html') 164 expect(text).to.contain('<meta property="og:type" content="website" />')
168 .expect(HttpStatusCode.OK_200)) 165 expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`)
166 }
167
168 it('Should have valid Open Graph tags on the account page', async function () {
169 await accountPageTest('/accounts/' + servers[0].user.username)
170 await accountPageTest('/a/' + servers[0].user.username)
171 await accountPageTest('/@' + servers[0].user.username)
169 }) 172 })
170 173
171 it('Should have valid Open Graph tags on the channel page', async function () { 174 it('Should have valid Open Graph tags on the channel page', async function () {
172 const channelPageOGtests = (res) => { 175 await channelPageTest('/video-channels/' + servers[0].videoChannel.name)
173 expect(res.text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`) 176 await channelPageTest('/c/' + servers[0].videoChannel.name)
174 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) 177 await channelPageTest('/@' + servers[0].videoChannel.name)
175 expect(res.text).to.contain('<meta property="og:type" content="website" />')
176 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`)
177 }
178
179 channelPageOGtests(await request(servers[0].url)
180 .get('/video-channels/' + servers[0].videoChannel.name)
181 .set('Accept', 'text/html')
182 .expect(HttpStatusCode.OK_200))
183
184 channelPageOGtests(await request(servers[0].url)
185 .get('/c/' + servers[0].videoChannel.name)
186 .set('Accept', 'text/html')
187 .expect(HttpStatusCode.OK_200))
188
189 channelPageOGtests(await request(servers[0].url)
190 .get('/@' + servers[0].videoChannel.name)
191 .set('Accept', 'text/html')
192 .expect(HttpStatusCode.OK_200))
193 }) 178 })
194 179
195 it('Should have valid Open Graph tags on the watch page with video id', async function () { 180 it('Should have valid Open Graph tags on the watch page with video id', async function () {
@@ -231,142 +216,125 @@ describe('Test a client controllers', function () {
231 216
232 describe('Twitter card', async function () { 217 describe('Twitter card', async function () {
233 218
234 it('Should have valid twitter card on the watch video page', async function () { 219 describe('Not whitelisted', function () {
235 const res = await request(servers[0].url)
236 .get('/videos/watch/' + servers[0].video.uuid)
237 .set('Accept', 'text/html')
238 .expect(HttpStatusCode.OK_200)
239 220
240 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />') 221 async function accountPageTest (path: string) {
241 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 222 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
242 expect(res.text).to.contain(`<meta property="twitter:title" content="${videoName}" />`) 223 const text = res.text
243 expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`)
244 })
245 224
246 it('Should have valid twitter card on the watch playlist page', async function () { 225 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
247 const res = await request(servers[0].url) 226 expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
248 .get('/videos/watch/playlist/' + playlistUUID) 227 expect(text).to.contain(`<meta property="twitter:title" content="${account.name}" />`)
249 .set('Accept', 'text/html') 228 expect(text).to.contain(`<meta property="twitter:description" content="${account.description}" />`)
250 .expect(HttpStatusCode.OK_200) 229 }
251 230
252 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 231 async function channelPageTest (path: string) {
253 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 232 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
254 expect(res.text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`) 233 const text = res.text
255 expect(res.text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`)
256 })
257 234
258 it('Should have valid twitter card on the account page', async function () { 235 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
259 const accountPageTests = (res) => { 236 expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
260 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 237 expect(text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`)
261 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 238 expect(text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`)
262 expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`)
263 expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`)
264 } 239 }
265 240
266 accountPageTests(await request(servers[0].url) 241 it('Should have valid twitter card on the watch video page', async function () {
267 .get('/accounts/' + account.name) 242 const res = await request(servers[0].url)
268 .set('Accept', 'text/html') 243 .get('/videos/watch/' + servers[0].video.uuid)
269 .expect(HttpStatusCode.OK_200)) 244 .set('Accept', 'text/html')
245 .expect(HttpStatusCode.OK_200)
270 246
271 accountPageTests(await request(servers[0].url) 247 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
272 .get('/a/' + account.name) 248 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
273 .set('Accept', 'text/html') 249 expect(res.text).to.contain(`<meta property="twitter:title" content="${videoName}" />`)
274 .expect(HttpStatusCode.OK_200)) 250 expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`)
251 })
275 252
276 accountPageTests(await request(servers[0].url) 253 it('Should have valid twitter card on the watch playlist page', async function () {
277 .get('/@' + account.name) 254 const res = await request(servers[0].url)
278 .set('Accept', 'text/html') 255 .get('/videos/watch/playlist/' + playlistUUID)
279 .expect(HttpStatusCode.OK_200)) 256 .set('Accept', 'text/html')
280 }) 257 .expect(HttpStatusCode.OK_200)
281 258
282 it('Should have valid twitter card on the channel page', async function () {
283 const channelPageTests = (res) => {
284 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 259 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
285 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 260 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
286 expect(res.text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`) 261 expect(res.text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`)
287 expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) 262 expect(res.text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`)
288 } 263 })
289
290 channelPageTests(await request(servers[0].url)
291 .get('/video-channels/' + servers[0].videoChannel.name)
292 .set('Accept', 'text/html')
293 .expect(HttpStatusCode.OK_200))
294 264
295 channelPageTests(await request(servers[0].url) 265 it('Should have valid twitter card on the account page', async function () {
296 .get('/c/' + servers[0].videoChannel.name) 266 await accountPageTest('/accounts/' + account.name)
297 .set('Accept', 'text/html') 267 await accountPageTest('/a/' + account.name)
298 .expect(HttpStatusCode.OK_200)) 268 await accountPageTest('/@' + account.name)
269 })
299 270
300 channelPageTests(await request(servers[0].url) 271 it('Should have valid twitter card on the channel page', async function () {
301 .get('/@' + servers[0].videoChannel.name) 272 await channelPageTest('/video-channels/' + servers[0].videoChannel.name)
302 .set('Accept', 'text/html') 273 await channelPageTest('/c/' + servers[0].videoChannel.name)
303 .expect(HttpStatusCode.OK_200)) 274 await channelPageTest('/@' + servers[0].videoChannel.name)
275 })
304 }) 276 })
305 277
306 it('Should have valid twitter card if Twitter is whitelisted', async function () { 278 describe('Whitelisted', function () {
307 const res1 = await getCustomConfig(servers[0].url, servers[0].accessToken)
308 const config = res1.body
309 config.services.twitter = {
310 username: '@Kuja',
311 whitelisted: true
312 }
313 await updateCustomConfig(servers[0].url, servers[0].accessToken, config)
314
315 const resVideoRequest = await request(servers[0].url)
316 .get('/videos/watch/' + servers[0].video.uuid)
317 .set('Accept', 'text/html')
318 .expect(HttpStatusCode.OK_200)
319 279
320 expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />') 280 before(async function () {
321 expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 281 const res = await getCustomConfig(servers[0].url, servers[0].accessToken)
282 const config = res.body as CustomConfig
283 config.services.twitter = {
284 username: '@Kuja',
285 whitelisted: true
286 }
322 287
323 const resVideoPlaylistRequest = await request(servers[0].url) 288 await updateCustomConfig(servers[0].url, servers[0].accessToken, config)
324 .get('/videos/watch/playlist/' + playlistUUID) 289 })
325 .set('Accept', 'text/html')
326 .expect(HttpStatusCode.OK_200)
327 290
328 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />') 291 async function accountPageTest (path: string) {
329 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 292 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
293 const text = res.text
330 294
331 const accountTests = (res) => { 295 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
332 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 296 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
333 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
334 } 297 }
335 298
336 accountTests(await request(servers[0].url) 299 async function channelPageTest (path: string) {
337 .get('/accounts/' + account.name) 300 const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
338 .set('Accept', 'text/html') 301 const text = res.text
339 .expect(HttpStatusCode.OK_200))
340 302
341 accountTests(await request(servers[0].url) 303 expect(text).to.contain('<meta property="twitter:card" content="summary" />')
342 .get('/a/' + account.name) 304 expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />')
343 .set('Accept', 'text/html') 305 }
344 .expect(HttpStatusCode.OK_200))
345 306
346 accountTests(await request(servers[0].url) 307 it('Should have valid twitter card on the watch video page', async function () {
347 .get('/@' + account.name) 308 const res = await request(servers[0].url)
348 .set('Accept', 'text/html') 309 .get('/videos/watch/' + servers[0].video.uuid)
349 .expect(HttpStatusCode.OK_200)) 310 .set('Accept', 'text/html')
311 .expect(HttpStatusCode.OK_200)
350 312
351 const channelTests = (res) => { 313 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
352 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
353 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 314 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
354 } 315 })
355 316
356 channelTests(await request(servers[0].url) 317 it('Should have valid twitter card on the watch playlist page', async function () {
357 .get('/video-channels/' + servers[0].videoChannel.name) 318 const res = await request(servers[0].url)
358 .set('Accept', 'text/html') 319 .get('/videos/watch/playlist/' + playlistUUID)
359 .expect(HttpStatusCode.OK_200)) 320 .set('Accept', 'text/html')
321 .expect(HttpStatusCode.OK_200)
360 322
361 channelTests(await request(servers[0].url) 323 expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
362 .get('/c/' + servers[0].videoChannel.name) 324 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
363 .set('Accept', 'text/html') 325 })
364 .expect(HttpStatusCode.OK_200))
365 326
366 channelTests(await request(servers[0].url) 327 it('Should have valid twitter card on the account page', async function () {
367 .get('/@' + servers[0].videoChannel.name) 328 await accountPageTest('/accounts/' + account.name)
368 .set('Accept', 'text/html') 329 await accountPageTest('/a/' + account.name)
369 .expect(HttpStatusCode.OK_200)) 330 await accountPageTest('/@' + account.name)
331 })
332
333 it('Should have valid twitter card on the channel page', async function () {
334 await channelPageTest('/video-channels/' + servers[0].videoChannel.name)
335 await channelPageTest('/c/' + servers[0].videoChannel.name)
336 await channelPageTest('/@' + servers[0].videoChannel.name)
337 })
370 }) 338 })
371 }) 339 })
372 340