plugin-storage.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import 'mocha'
  3. import { expect } from 'chai'
  4. import { pathExists, readdir, readFile } from 'fs-extra'
  5. import { join } from 'path'
  6. import {
  7. cleanupTests,
  8. createSingleServer,
  9. makeGetRequest,
  10. PeerTubeServer,
  11. PluginsCommand,
  12. setAccessTokensToServers
  13. } from '@shared/server-commands'
  14. import { HttpStatusCode } from '@shared/models'
  15. describe('Test plugin storage', function () {
  16. let server: PeerTubeServer
  17. before(async function () {
  18. this.timeout(30000)
  19. server = await createSingleServer(1)
  20. await setAccessTokensToServers([ server ])
  21. await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
  22. })
  23. describe('DB storage', function () {
  24. it('Should correctly store a subkey', async function () {
  25. await server.servers.waitUntilLog('superkey stored value is toto')
  26. })
  27. it('Should correctly retrieve an array as array from the storage.', async function () {
  28. await server.servers.waitUntilLog('storedArrayKey isArray is true')
  29. await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2')
  30. })
  31. })
  32. describe('Disk storage', function () {
  33. let dataPath: string
  34. let pluginDataPath: string
  35. async function getFileContent () {
  36. const files = await readdir(pluginDataPath)
  37. expect(files).to.have.lengthOf(1)
  38. return readFile(join(pluginDataPath, files[0]), 'utf8')
  39. }
  40. before(function () {
  41. dataPath = server.servers.buildDirectory('plugins/data')
  42. pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
  43. })
  44. it('Should have created the directory on install', async function () {
  45. const dataPath = server.servers.buildDirectory('plugins/data')
  46. const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
  47. expect(await pathExists(dataPath)).to.be.true
  48. expect(await pathExists(pluginDataPath)).to.be.true
  49. expect(await readdir(pluginDataPath)).to.have.lengthOf(0)
  50. })
  51. it('Should have created a file', async function () {
  52. await makeGetRequest({
  53. url: server.url,
  54. token: server.accessToken,
  55. path: '/plugins/test-six/router/create-file',
  56. expectedStatus: HttpStatusCode.OK_200
  57. })
  58. const content = await getFileContent()
  59. expect(content).to.equal('Prince Ali')
  60. })
  61. it('Should still have the file after an uninstallation', async function () {
  62. await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
  63. const content = await getFileContent()
  64. expect(content).to.equal('Prince Ali')
  65. })
  66. it('Should still have the file after the reinstallation', async function () {
  67. await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
  68. const content = await getFileContent()
  69. expect(content).to.equal('Prince Ali')
  70. })
  71. })
  72. after(async function () {
  73. await cleanupTests([ server ])
  74. })
  75. })