1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { pathExists, readdir, readFile } from 'fs-extra'
6 import { join } from 'path'
7 import { HttpStatusCode } from '@shared/core-utils'
15 setAccessTokensToServers,
17 } from '@shared/extra-utils'
19 describe('Test plugin storage', function () {
20 let server: ServerInfo
22 before(async function () {
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
28 await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') })
31 describe('DB storage', function () {
33 it('Should correctly store a subkey', async function () {
34 await waitUntilLog(server, 'superkey stored value is toto')
38 describe('Disk storage', function () {
40 let pluginDataPath: string
42 async function getFileContent () {
43 const files = await readdir(pluginDataPath)
44 expect(files).to.have.lengthOf(1)
46 return readFile(join(pluginDataPath, files[0]), 'utf8')
50 dataPath = buildServerDirectory(server, 'plugins/data')
51 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
54 it('Should have created the directory on install', async function () {
55 const dataPath = buildServerDirectory(server, 'plugins/data')
56 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
58 expect(await pathExists(dataPath)).to.be.true
59 expect(await pathExists(pluginDataPath)).to.be.true
60 expect(await readdir(pluginDataPath)).to.have.lengthOf(0)
63 it('Should have created a file', async function () {
64 await makeGetRequest({
66 token: server.accessToken,
67 path: '/plugins/test-six/router/create-file',
68 statusCodeExpected: HttpStatusCode.OK_200
71 const content = await getFileContent()
72 expect(content).to.equal('Prince Ali')
75 it('Should still have the file after an uninstallation', async function () {
76 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-six' })
78 const content = await getFileContent()
79 expect(content).to.equal('Prince Ali')
82 it('Should still have the file after the reinstallation', async function () {
83 await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') })
85 const content = await getFileContent()
86 expect(content).to.equal('Prince Ali')
90 after(async function () {
91 await cleanupTests([ server ])