]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/plugin-storage.ts
Merge branch 'release/4.3.0' into develop
[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 { expect } from 'chai'
4 import { pathExists, readdir, readFile } from 'fs-extra'
5 import { join } from 'path'
6 import {
7 cleanupTests,
8 createSingleServer,
9 makeGetRequest,
10 PeerTubeServer,
11 PluginsCommand,
12 setAccessTokensToServers
13 } from '@shared/server-commands'
14 import { HttpStatusCode } from '@shared/models'
15
16 describe('Test plugin storage', function () {
17 let server: PeerTubeServer
18
19 before(async function () {
20 this.timeout(30000)
21
22 server = await createSingleServer(1)
23 await setAccessTokensToServers([ server ])
24
25 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
26 })
27
28 describe('DB storage', function () {
29 it('Should correctly store a subkey', async function () {
30 await server.servers.waitUntilLog('superkey stored value is toto')
31 })
32
33 it('Should correctly retrieve an array as array from the storage.', async function () {
34 await server.servers.waitUntilLog('storedArrayKey isArray is true')
35 await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2')
36 })
37 })
38
39 describe('Disk storage', function () {
40 let dataPath: string
41 let pluginDataPath: string
42
43 async function getFileContent () {
44 const files = await readdir(pluginDataPath)
45 expect(files).to.have.lengthOf(1)
46
47 return readFile(join(pluginDataPath, files[0]), 'utf8')
48 }
49
50 before(function () {
51 dataPath = server.servers.buildDirectory('plugins/data')
52 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
53 })
54
55 it('Should have created the directory on install', async function () {
56 const dataPath = server.servers.buildDirectory('plugins/data')
57 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
58
59 expect(await pathExists(dataPath)).to.be.true
60 expect(await pathExists(pluginDataPath)).to.be.true
61 expect(await readdir(pluginDataPath)).to.have.lengthOf(0)
62 })
63
64 it('Should have created a file', async function () {
65 await makeGetRequest({
66 url: server.url,
67 token: server.accessToken,
68 path: '/plugins/test-six/router/create-file',
69 expectedStatus: HttpStatusCode.OK_200
70 })
71
72 const content = await getFileContent()
73 expect(content).to.equal('Prince Ali')
74 })
75
76 it('Should still have the file after an uninstallation', async function () {
77 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
78
79 const content = await getFileContent()
80 expect(content).to.equal('Prince Ali')
81 })
82
83 it('Should still have the file after the reinstallation', async function () {
84 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
85
86 const content = await getFileContent()
87 expect(content).to.equal('Prince Ali')
88 })
89 })
90
91 after(async function () {
92 await cleanupTests([ server ])
93 })
94 })