services.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import {
  4. cleanupTests,
  5. flushAndRunServer,
  6. makeGetRequest,
  7. ServerInfo,
  8. setAccessTokensToServers,
  9. uploadVideo
  10. } from '../../../../shared/extra-utils'
  11. describe('Test services API validators', function () {
  12. let server: ServerInfo
  13. // ---------------------------------------------------------------
  14. before(async function () {
  15. this.timeout(60000)
  16. server = await flushAndRunServer(1)
  17. await setAccessTokensToServers([ server ])
  18. const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
  19. server.video = res.body.video
  20. })
  21. describe('Test oEmbed API validators', function () {
  22. it('Should fail with an invalid url', async function () {
  23. const embedUrl = 'hello.com'
  24. await checkParamEmbed(server, embedUrl)
  25. })
  26. it('Should fail with an invalid host', async function () {
  27. const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
  28. await checkParamEmbed(server, embedUrl)
  29. })
  30. it('Should fail with an invalid video id', async function () {
  31. const embedUrl = `http://localhost:${server.port}/videos/watch/blabla`
  32. await checkParamEmbed(server, embedUrl)
  33. })
  34. it('Should fail with an unknown video', async function () {
  35. const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
  36. await checkParamEmbed(server, embedUrl, 404)
  37. })
  38. it('Should fail with an invalid path', async function () {
  39. const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}`
  40. await checkParamEmbed(server, embedUrl)
  41. })
  42. it('Should fail with an invalid max height', async function () {
  43. const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
  44. await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' })
  45. })
  46. it('Should fail with an invalid max width', async function () {
  47. const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
  48. await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' })
  49. })
  50. it('Should fail with an invalid format', async function () {
  51. const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
  52. await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' })
  53. })
  54. it('Should fail with a non supported format', async function () {
  55. const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
  56. await checkParamEmbed(server, embedUrl, 501, { format: 'xml' })
  57. })
  58. it('Should succeed with the correct params', async function () {
  59. const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
  60. const query = {
  61. format: 'json',
  62. maxheight: 400,
  63. maxwidth: 400
  64. }
  65. await checkParamEmbed(server, embedUrl, 200, query)
  66. })
  67. })
  68. after(async function () {
  69. await cleanupTests([ server ])
  70. })
  71. })
  72. function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) {
  73. const path = '/services/oembed'
  74. return makeGetRequest({
  75. url: server.url,
  76. path,
  77. query: Object.assign(query, { url: embedUrl }),
  78. statusCodeExpected
  79. })
  80. }