services.ts 3.2 KB

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