]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/plugin-storage.ts
9babfc83e0d1a141329a3c89102a6e84d6a92786
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / plugin-storage.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
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'
9
10 describe('Test plugin storage', function () {
11 let server: ServerInfo
12
13 before(async function () {
14 this.timeout(30000)
15
16 server = await flushAndRunServer(1)
17 await setAccessTokensToServers([ server ])
18
19 await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') })
20 })
21
22 describe('DB storage', function () {
23
24 it('Should correctly store a subkey', async function () {
25 await server.serversCommand.waitUntilLog('superkey stored value is toto')
26 })
27 })
28
29 describe('Disk storage', function () {
30 let dataPath: string
31 let pluginDataPath: string
32
33 async function getFileContent () {
34 const files = await readdir(pluginDataPath)
35 expect(files).to.have.lengthOf(1)
36
37 return readFile(join(pluginDataPath, files[0]), 'utf8')
38 }
39
40 before(function () {
41 dataPath = server.serversCommand.buildDirectory('plugins/data')
42 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
43 })
44
45 it('Should have created the directory on install', async function () {
46 const dataPath = server.serversCommand.buildDirectory('plugins/data')
47 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
48
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)
52 })
53
54 it('Should have created a file', async function () {
55 await makeGetRequest({
56 url: server.url,
57 token: server.accessToken,
58 path: '/plugins/test-six/router/create-file',
59 statusCodeExpected: HttpStatusCode.OK_200
60 })
61
62 const content = await getFileContent()
63 expect(content).to.equal('Prince Ali')
64 })
65
66 it('Should still have the file after an uninstallation', async function () {
67 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-six' })
68
69 const content = await getFileContent()
70 expect(content).to.equal('Prince Ali')
71 })
72
73 it('Should still have the file after the reinstallation', async function () {
74 await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') })
75
76 const content = await getFileContent()
77 expect(content).to.equal('Prince Ali')
78 })
79 })
80
81 after(async function () {
82 await cleanupTests([ server ])
83 })
84 })