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/server-commands'
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 () {
30 it('Should correctly store a subkey', async function () {
31 await server.servers.waitUntilLog('superkey stored value is toto')
34 it('Should correctly retrieve an array as array from the storage.', async function () {
35 await server.servers.waitUntilLog('storedArrayKey isArray is true')
36 await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2')
40 describe('Disk storage', function () {
42 let pluginDataPath: string
44 async function getFileContent () {
45 const files = await readdir(pluginDataPath)
46 expect(files).to.have.lengthOf(1)
48 return readFile(join(pluginDataPath, files[0]), 'utf8')
52 dataPath = server.servers.buildDirectory('plugins/data')
53 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
56 it('Should have created the directory on install', async function () {
57 const dataPath = server.servers.buildDirectory('plugins/data')
58 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
60 expect(await pathExists(dataPath)).to.be.true
61 expect(await pathExists(pluginDataPath)).to.be.true
62 expect(await readdir(pluginDataPath)).to.have.lengthOf(0)
65 it('Should have created a file', async function () {
66 await makeGetRequest({
68 token: server.accessToken,
69 path: '/plugins/test-six/router/create-file',
70 expectedStatus: HttpStatusCode.OK_200
73 const content = await getFileContent()
74 expect(content).to.equal('Prince Ali')
77 it('Should still have the file after an uninstallation', async function () {
78 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
80 const content = await getFileContent()
81 expect(content).to.equal('Prince Ali')
84 it('Should still have the file after the reinstallation', async function () {
85 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
87 const content = await getFileContent()
88 expect(content).to.equal('Prince Ali')
92 after(async function () {
93 await cleanupTests([ server ])