plugin-router.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import 'mocha'
  3. import { expect } from 'chai'
  4. import {
  5. cleanupTests,
  6. createSingleServer,
  7. makeGetRequest,
  8. makePostBodyRequest,
  9. PeerTubeServer,
  10. PluginsCommand,
  11. setAccessTokensToServers
  12. } from '@shared/server-commands'
  13. import { HttpStatusCode } from '@shared/models'
  14. describe('Test plugin helpers', function () {
  15. let server: PeerTubeServer
  16. const basePaths = [
  17. '/plugins/test-five/router/',
  18. '/plugins/test-five/0.0.1/router/'
  19. ]
  20. before(async function () {
  21. this.timeout(30000)
  22. server = await createSingleServer(1)
  23. await setAccessTokensToServers([ server ])
  24. await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') })
  25. })
  26. it('Should answer "pong"', async function () {
  27. for (const path of basePaths) {
  28. const res = await makeGetRequest({
  29. url: server.url,
  30. path: path + 'ping',
  31. expectedStatus: HttpStatusCode.OK_200
  32. })
  33. expect(res.body.message).to.equal('pong')
  34. }
  35. })
  36. it('Should check if authenticated', async function () {
  37. for (const path of basePaths) {
  38. const res = await makeGetRequest({
  39. url: server.url,
  40. path: path + 'is-authenticated',
  41. token: server.accessToken,
  42. expectedStatus: 200
  43. })
  44. expect(res.body.isAuthenticated).to.equal(true)
  45. const secRes = await makeGetRequest({
  46. url: server.url,
  47. path: path + 'is-authenticated',
  48. expectedStatus: 200
  49. })
  50. expect(secRes.body.isAuthenticated).to.equal(false)
  51. }
  52. })
  53. it('Should mirror post body', async function () {
  54. const body = {
  55. hello: 'world',
  56. riri: 'fifi',
  57. loulou: 'picsou'
  58. }
  59. for (const path of basePaths) {
  60. const res = await makePostBodyRequest({
  61. url: server.url,
  62. path: path + 'form/post/mirror',
  63. fields: body,
  64. expectedStatus: HttpStatusCode.OK_200
  65. })
  66. expect(res.body).to.deep.equal(body)
  67. }
  68. })
  69. it('Should remove the plugin and remove the routes', async function () {
  70. await server.plugins.uninstall({ npmName: 'peertube-plugin-test-five' })
  71. for (const path of basePaths) {
  72. await makeGetRequest({
  73. url: server.url,
  74. path: path + 'ping',
  75. expectedStatus: HttpStatusCode.NOT_FOUND_404
  76. })
  77. await makePostBodyRequest({
  78. url: server.url,
  79. path: path + 'ping',
  80. fields: {},
  81. expectedStatus: HttpStatusCode.NOT_FOUND_404
  82. })
  83. }
  84. })
  85. after(async function () {
  86. await cleanupTests([ server ])
  87. })
  88. })