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'
8 import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
10 describe('Test plugin storage', function () {
11 let server: ServerInfo
13 before(async function () {
16 server = await flushAndRunServer(1)
17 await setAccessTokensToServers([ server ])
19 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
22 describe('DB storage', function () {
24 it('Should correctly store a subkey', async function () {
25 await server.servers.waitUntilLog('superkey stored value is toto')
29 describe('Disk storage', function () {
31 let pluginDataPath: string
33 async function getFileContent () {
34 const files = await readdir(pluginDataPath)
35 expect(files).to.have.lengthOf(1)
37 return readFile(join(pluginDataPath, files[0]), 'utf8')
41 dataPath = server.servers.buildDirectory('plugins/data')
42 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
45 it('Should have created the directory on install', async function () {
46 const dataPath = server.servers.buildDirectory('plugins/data')
47 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
49 expect(await pathExists(dataPath)).to.be.true
50 expect(await pathExists(pluginDataPath)).to.be.true
51 expect(await readdir(pluginDataPath)).to.have.lengthOf(0)
54 it('Should have created a file', async function () {
55 await makeGetRequest({
57 token: server.accessToken,
58 path: '/plugins/test-six/router/create-file',
59 statusCodeExpected: HttpStatusCode.OK_200
62 const content = await getFileContent()
63 expect(content).to.equal('Prince Ali')
66 it('Should still have the file after an uninstallation', async function () {
67 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
69 const content = await getFileContent()
70 expect(content).to.equal('Prince Ali')
73 it('Should still have the file after the reinstallation', async function () {
74 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
76 const content = await getFileContent()
77 expect(content).to.equal('Prince Ali')
81 after(async function () {
82 await cleanupTests([ server ])