]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/plugin-storage.ts
Search channels against handles and not names
[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
14} from '@shared/extra-utils'
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
C
29 describe('DB storage', function () {
30
31 it('Should correctly store a subkey', async function () {
89d241a7 32 await server.servers.waitUntilLog('superkey stored value is toto')
302eba0d
C
33 })
34 })
35
36 describe('Disk storage', function () {
37 let dataPath: string
38 let pluginDataPath: string
39
40 async function getFileContent () {
41 const files = await readdir(pluginDataPath)
42 expect(files).to.have.lengthOf(1)
43
44 return readFile(join(pluginDataPath, files[0]), 'utf8')
45 }
46
47 before(function () {
89d241a7 48 dataPath = server.servers.buildDirectory('plugins/data')
302eba0d
C
49 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
50 })
51
52 it('Should have created the directory on install', async function () {
89d241a7 53 const dataPath = server.servers.buildDirectory('plugins/data')
302eba0d
C
54 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
55
56 expect(await pathExists(dataPath)).to.be.true
57 expect(await pathExists(pluginDataPath)).to.be.true
58 expect(await readdir(pluginDataPath)).to.have.lengthOf(0)
59 })
60
61 it('Should have created a file', async function () {
62 await makeGetRequest({
63 url: server.url,
64 token: server.accessToken,
65 path: '/plugins/test-six/router/create-file',
c0e8b12e 66 expectedStatus: HttpStatusCode.OK_200
302eba0d
C
67 })
68
69 const content = await getFileContent()
70 expect(content).to.equal('Prince Ali')
71 })
72
73 it('Should still have the file after an uninstallation', async function () {
89d241a7 74 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
302eba0d
C
75
76 const content = await getFileContent()
77 expect(content).to.equal('Prince Ali')
78 })
79
80 it('Should still have the file after the reinstallation', async function () {
89d241a7 81 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
302eba0d
C
82
83 const content = await getFileContent()
84 expect(content).to.equal('Prince Ali')
85 })
97b65ce5
C
86 })
87
88 after(async function () {
89 await cleanupTests([ server ])
90 })
91})