client.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import * as chai from 'chai'
  4. import * as request from 'supertest'
  5. import {
  6. cleanupTests,
  7. flushAndRunServer,
  8. getCustomConfig,
  9. getVideosList,
  10. makeHTMLRequest,
  11. ServerInfo,
  12. serverLogin,
  13. updateCustomConfig,
  14. updateCustomSubConfig,
  15. uploadVideo
  16. } from '../../shared/extra-utils'
  17. const expect = chai.expect
  18. function checkIndexTags (html: string, title: string, description: string, css: string) {
  19. expect(html).to.contain('<title>' + title + '</title>')
  20. expect(html).to.contain('<meta name="description" content="' + description + '" />')
  21. expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
  22. }
  23. describe('Test a client controllers', function () {
  24. let server: ServerInfo
  25. before(async function () {
  26. this.timeout(120000)
  27. server = await flushAndRunServer(1)
  28. server.accessToken = await serverLogin(server)
  29. const videoAttributes = {
  30. name: 'my super name for server 1',
  31. description: 'my super description for server 1'
  32. }
  33. await uploadVideo(server.url, server.accessToken, videoAttributes)
  34. const res = await getVideosList(server.url)
  35. const videos = res.body.data
  36. expect(videos.length).to.equal(1)
  37. server.video = videos[0]
  38. })
  39. it('Should have valid Open Graph tags on the watch page with video id', async function () {
  40. const res = await request(server.url)
  41. .get('/videos/watch/' + server.video.id)
  42. .set('Accept', 'text/html')
  43. .expect(200)
  44. expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
  45. expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
  46. })
  47. it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
  48. const res = await request(server.url)
  49. .get('/videos/watch/' + server.video.uuid)
  50. .set('Accept', 'text/html')
  51. .expect(200)
  52. expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
  53. expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
  54. })
  55. it('Should have valid oEmbed discovery tags', async function () {
  56. const path = '/videos/watch/' + server.video.uuid
  57. const res = await request(server.url)
  58. .get(path)
  59. .set('Accept', 'text/html')
  60. .expect(200)
  61. const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:9001/services/oembed?' +
  62. `url=http%3A%2F%2Flocalhost%3A9001%2Fvideos%2Fwatch%2F${server.video.uuid}" ` +
  63. `title="${server.video.name}" />`
  64. expect(res.text).to.contain(expectedLink)
  65. })
  66. it('Should have valid twitter card', async function () {
  67. const res = await request(server.url)
  68. .get('/videos/watch/' + server.video.uuid)
  69. .set('Accept', 'text/html')
  70. .expect(200)
  71. expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
  72. expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
  73. })
  74. it('Should have valid twitter card if Twitter is whitelisted', async function () {
  75. const res1 = await getCustomConfig(server.url, server.accessToken)
  76. const config = res1.body
  77. config.services.twitter = {
  78. username: '@Kuja',
  79. whitelisted: true
  80. }
  81. await updateCustomConfig(server.url, server.accessToken, config)
  82. const res = await request(server.url)
  83. .get('/videos/watch/' + server.video.uuid)
  84. .set('Accept', 'text/html')
  85. .expect(200)
  86. expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
  87. expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
  88. })
  89. it('Should have valid index html tags (title, description...)', async function () {
  90. const res = await makeHTMLRequest(server.url, '/videos/trending')
  91. const description = 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
  92. 'with WebTorrent and Angular.'
  93. checkIndexTags(res.text, 'PeerTube', description, '')
  94. })
  95. it('Should update the customized configuration and have the correct index html tags', async function () {
  96. await updateCustomSubConfig(server.url, server.accessToken, {
  97. instance: {
  98. name: 'PeerTube updated',
  99. shortDescription: 'my short description',
  100. description: 'my super description',
  101. terms: 'my super terms',
  102. defaultClientRoute: '/videos/recently-added',
  103. defaultNSFWPolicy: 'blur',
  104. customizations: {
  105. javascript: 'alert("coucou")',
  106. css: 'body { background-color: red; }'
  107. }
  108. }
  109. })
  110. const res = await makeHTMLRequest(server.url, '/videos/trending')
  111. checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
  112. })
  113. it('Should have valid index html updated tags (title, description...)', async function () {
  114. const res = await makeHTMLRequest(server.url, '/videos/trending')
  115. checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
  116. })
  117. after(async function () {
  118. await cleanupTests([ server ])
  119. })
  120. })