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