diff options
Diffstat (limited to 'server/tests/plugins')
-rw-r--r-- | server/tests/plugins/plugin-helpers.ts | 40 | ||||
-rw-r--r-- | server/tests/plugins/plugin-storage.ts | 80 |
2 files changed, 117 insertions, 3 deletions
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 325d20e84..2ac070b41 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts | |||
@@ -100,6 +100,46 @@ describe('Test plugin helpers', function () { | |||
100 | 100 | ||
101 | expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/') | 101 | expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/') |
102 | }) | 102 | }) |
103 | |||
104 | it('Should get the base static route', async function () { | ||
105 | const baseRouter = '/plugins/test-four/0.0.1/router/' | ||
106 | |||
107 | const res = await makeGetRequest({ | ||
108 | url: servers[0].url, | ||
109 | path: baseRouter + 'router-route', | ||
110 | statusCodeExpected: HttpStatusCode.OK_200 | ||
111 | }) | ||
112 | |||
113 | expect(res.body.routerRoute).to.equal(baseRouter) | ||
114 | }) | ||
115 | }) | ||
116 | |||
117 | describe('User', function () { | ||
118 | |||
119 | it('Should not get a user if not authenticated', async function () { | ||
120 | const res = await makeGetRequest({ | ||
121 | url: servers[0].url, | ||
122 | path: '/plugins/test-four/router/user', | ||
123 | statusCodeExpected: HttpStatusCode.OK_200 | ||
124 | }) | ||
125 | |||
126 | expect(res.body.user).to.be.undefined | ||
127 | }) | ||
128 | |||
129 | it('Should get a user if authenticated', async function () { | ||
130 | const res = await makeGetRequest({ | ||
131 | url: servers[0].url, | ||
132 | token: servers[0].accessToken, | ||
133 | path: '/plugins/test-four/router/user', | ||
134 | statusCodeExpected: HttpStatusCode.OK_200 | ||
135 | }) | ||
136 | |||
137 | expect(res.body.user).to.exist | ||
138 | expect(res.body.username).to.equal('root') | ||
139 | expect(res.body.isAdmin).to.be.true | ||
140 | expect(res.body.isModerator).to.be.false | ||
141 | expect(res.body.isUser).to.be.false | ||
142 | }) | ||
103 | }) | 143 | }) |
104 | 144 | ||
105 | describe('Moderation', function () { | 145 | describe('Moderation', function () { |
diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 356692eb9..3c46b2585 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts | |||
@@ -1,7 +1,18 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils' | 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' | ||
8 | import { | ||
9 | buildServerDirectory, | ||
10 | getPluginTestPath, | ||
11 | installPlugin, | ||
12 | makeGetRequest, | ||
13 | setAccessTokensToServers, | ||
14 | uninstallPlugin | ||
15 | } from '../../../shared/extra-utils' | ||
5 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' | 16 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' |
6 | 17 | ||
7 | describe('Test plugin storage', function () { | 18 | describe('Test plugin storage', function () { |
@@ -20,8 +31,71 @@ describe('Test plugin storage', function () { | |||
20 | }) | 31 | }) |
21 | }) | 32 | }) |
22 | 33 | ||
23 | it('Should correctly store a subkey', async function () { | 34 | describe('DB storage', function () { |
24 | await waitUntilLog(server, 'superkey stored value is toto') | 35 | |
36 | it('Should correctly store a subkey', async function () { | ||
37 | await waitUntilLog(server, 'superkey stored value is toto') | ||
38 | }) | ||
39 | }) | ||
40 | |||
41 | describe('Disk storage', function () { | ||
42 | let dataPath: string | ||
43 | let pluginDataPath: string | ||
44 | |||
45 | async function getFileContent () { | ||
46 | const files = await readdir(pluginDataPath) | ||
47 | expect(files).to.have.lengthOf(1) | ||
48 | |||
49 | return readFile(join(pluginDataPath, files[0]), 'utf8') | ||
50 | } | ||
51 | |||
52 | before(function () { | ||
53 | dataPath = buildServerDirectory(server, 'plugins/data') | ||
54 | pluginDataPath = join(dataPath, 'peertube-plugin-test-six') | ||
55 | }) | ||
56 | |||
57 | it('Should have created the directory on install', async function () { | ||
58 | const dataPath = buildServerDirectory(server, 'plugins/data') | ||
59 | const pluginDataPath = join(dataPath, 'peertube-plugin-test-six') | ||
60 | |||
61 | expect(await pathExists(dataPath)).to.be.true | ||
62 | expect(await pathExists(pluginDataPath)).to.be.true | ||
63 | expect(await readdir(pluginDataPath)).to.have.lengthOf(0) | ||
64 | }) | ||
65 | |||
66 | it('Should have created a file', async function () { | ||
67 | await makeGetRequest({ | ||
68 | url: server.url, | ||
69 | token: server.accessToken, | ||
70 | path: '/plugins/test-six/router/create-file', | ||
71 | statusCodeExpected: HttpStatusCode.OK_200 | ||
72 | }) | ||
73 | |||
74 | const content = await getFileContent() | ||
75 | expect(content).to.equal('Prince Ali') | ||
76 | }) | ||
77 | |||
78 | it('Should still have the file after an uninstallation', async function () { | ||
79 | await uninstallPlugin({ | ||
80 | url: server.url, | ||
81 | accessToken: server.accessToken, | ||
82 | npmName: 'peertube-plugin-test-six' | ||
83 | }) | ||
84 | |||
85 | const content = await getFileContent() | ||
86 | expect(content).to.equal('Prince Ali') | ||
87 | }) | ||
88 | |||
89 | it('Should still have the file after the reinstallation', async function () { | ||
90 | await installPlugin({ | ||
91 | url: server.url, | ||
92 | accessToken: server.accessToken, | ||
93 | path: getPluginTestPath('-six') | ||
94 | }) | ||
95 | |||
96 | const content = await getFileContent() | ||
97 | expect(content).to.equal('Prince Ali') | ||
98 | }) | ||
25 | }) | 99 | }) |
26 | 100 | ||
27 | after(async function () { | 101 | after(async function () { |