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'
13 setAccessTokensToServers
14 } from '@shared/extra-utils'
15 import { HttpStatusCode } from '@shared/models'
17 describe('Test plugin storage', function () {
18 let server: PeerTubeServer
20 before(async function () {
23 server = await createSingleServer(1)
24 await setAccessTokensToServers([ server ])
26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
29 describe('DB storage', function () {
31 it('Should correctly store a subkey', async function () {
32 await server.servers.waitUntilLog('superkey stored value is toto')
36 describe('Disk storage', function () {
38 let pluginDataPath: string
40 async function getFileContent () {
41 const files = await readdir(pluginDataPath)
42 expect(files).to.have.lengthOf(1)
44 return readFile(join(pluginDataPath, files[0]), 'utf8')
48 dataPath = server.servers.buildDirectory('plugins/data')
49 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
52 it('Should have created the directory on install', async function () {
53 const dataPath = server.servers.buildDirectory('plugins/data')
54 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
56 expect(await pathExists(dataPath)).to.be.true
57 expect(await pathExists(pluginDataPath)).to.be.true
58 expect(await readdir(pluginDataPath)).to.have.lengthOf(0)
61 it('Should have created a file', async function () {
62 await makeGetRequest({
64 token: server.accessToken,
65 path: '/plugins/test-six/router/create-file',
66 expectedStatus: HttpStatusCode.OK_200
69 const content = await getFileContent()
70 expect(content).to.equal('Prince Ali')
73 it('Should still have the file after an uninstallation', async function () {
74 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
76 const content = await getFileContent()
77 expect(content).to.equal('Prince Ali')
80 it('Should still have the file after the reinstallation', async function () {
81 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
83 const content = await getFileContent()
84 expect(content).to.equal('Prince Ali')
88 after(async function () {
89 await cleanupTests([ server ])