1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { pathExists, readdir, readFile } from 'fs-extra'
5 import { join } from 'path'
12 setAccessTokensToServers
13 } from '@shared/server-commands'
14 import { HttpStatusCode } from '@shared/models'
16 describe('Test plugin storage', function () {
17 let server: PeerTubeServer
19 before(async function () {
22 server = await createSingleServer(1)
23 await setAccessTokensToServers([ server ])
25 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
28 describe('DB storage', function () {
29 it('Should correctly store a subkey', async function () {
30 await server.servers.waitUntilLog('superkey stored value is toto')
33 it('Should correctly retrieve an array as array from the storage.', async function () {
34 await server.servers.waitUntilLog('storedArrayKey isArray is true')
35 await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2')
39 describe('Disk storage', function () {
41 let pluginDataPath: string
43 async function getFileContent () {
44 const files = await readdir(pluginDataPath)
45 expect(files).to.have.lengthOf(1)
47 return readFile(join(pluginDataPath, files[0]), 'utf8')
51 dataPath = server.servers.buildDirectory('plugins/data')
52 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
55 it('Should have created the directory on install', async function () {
56 const dataPath = server.servers.buildDirectory('plugins/data')
57 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
59 expect(await pathExists(dataPath)).to.be.true
60 expect(await pathExists(pluginDataPath)).to.be.true
61 expect(await readdir(pluginDataPath)).to.have.lengthOf(0)
64 it('Should have created a file', async function () {
65 await makeGetRequest({
67 token: server.accessToken,
68 path: '/plugins/test-six/router/create-file',
69 expectedStatus: HttpStatusCode.OK_200
72 const content = await getFileContent()
73 expect(content).to.equal('Prince Ali')
76 it('Should still have the file after an uninstallation', async function () {
77 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
79 const content = await getFileContent()
80 expect(content).to.equal('Prince Ali')
83 it('Should still have the file after the reinstallation', async function () {
84 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
86 const content = await getFileContent()
87 expect(content).to.equal('Prince Ali')
91 after(async function () {
92 await cleanupTests([ server ])