]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/plugin-storage.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / plugin-storage.ts
CommitLineData
97b65ce5
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
302eba0d
C
3import { expect } from 'chai'
4import { pathExists, readdir, readFile } from 'fs-extra'
5import { join } from 'path'
254d3579
C
6import {
7 cleanupTests,
8 createSingleServer,
9 makeGetRequest,
10 PeerTubeServer,
11 PluginsCommand,
12 setAccessTokensToServers
bf54587a 13} from '@shared/server-commands'
4c7e60bc 14import { HttpStatusCode } from '@shared/models'
97b65ce5
C
15
16describe('Test plugin storage', function () {
254d3579 17 let server: PeerTubeServer
97b65ce5
C
18
19 before(async function () {
20 this.timeout(30000)
21
254d3579 22 server = await createSingleServer(1)
97b65ce5
C
23 await setAccessTokensToServers([ server ])
24
89d241a7 25 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
97b65ce5
C
26 })
27
302eba0d 28 describe('DB storage', function () {
302eba0d 29 it('Should correctly store a subkey', async function () {
89d241a7 30 await server.servers.waitUntilLog('superkey stored value is toto')
302eba0d 31 })
ced38c0f 32
33 it('Should correctly retrieve an array as array from the storage.', async function () {
51872b82 34 await server.servers.waitUntilLog('storedArrayKey isArray is true')
ced38c0f 35 await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2')
36 })
302eba0d
C
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 () {
89d241a7 51 dataPath = server.servers.buildDirectory('plugins/data')
302eba0d
C
52 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
53 })
54
55 it('Should have created the directory on install', async function () {
89d241a7 56 const dataPath = server.servers.buildDirectory('plugins/data')
302eba0d
C
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',
c0e8b12e 69 expectedStatus: HttpStatusCode.OK_200
302eba0d
C
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 () {
89d241a7 77 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
302eba0d
C
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 () {
89d241a7 84 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
302eba0d
C
85
86 const content = await getFileContent()
87 expect(content).to.equal('Prince Ali')
88 })
97b65ce5
C
89 })
90
91 after(async function () {
92 await cleanupTests([ server ])
93 })
94})