]>
Commit | Line | Data |
---|---|---|
97b65ce5 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
302eba0d C |
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' | |
6c5065a0 | 8 | import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' |
97b65ce5 C |
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 | ||
89d241a7 | 19 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) |
97b65ce5 C |
20 | }) |
21 | ||
302eba0d C |
22 | describe('DB storage', function () { |
23 | ||
24 | it('Should correctly store a subkey', async function () { | |
89d241a7 | 25 | await server.servers.waitUntilLog('superkey stored value is toto') |
302eba0d C |
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 () { | |
89d241a7 | 41 | dataPath = server.servers.buildDirectory('plugins/data') |
302eba0d C |
42 | pluginDataPath = join(dataPath, 'peertube-plugin-test-six') |
43 | }) | |
44 | ||
45 | it('Should have created the directory on install', async function () { | |
89d241a7 | 46 | const dataPath = server.servers.buildDirectory('plugins/data') |
302eba0d C |
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 () { | |
89d241a7 | 67 | await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' }) |
302eba0d C |
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 () { | |
89d241a7 | 74 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) |
302eba0d C |
75 | |
76 | const content = await getFileContent() | |
77 | expect(content).to.equal('Prince Ali') | |
78 | }) | |
97b65ce5 C |
79 | }) |
80 | ||
81 | after(async function () { | |
82 | await cleanupTests([ server ]) | |
83 | }) | |
84 | }) |