]>
Commit | Line | Data |
---|---|---|
5e2b2e27 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | |
5 | import { | |
6 | getPluginTestPath, | |
7 | installPlugin, | |
8 | makeGetRequest, | |
9 | makePostBodyRequest, | |
10 | setAccessTokensToServers, uninstallPlugin | |
11 | } from '../../../shared/extra-utils' | |
12 | import { expect } from 'chai' | |
2d53be02 | 13 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
5e2b2e27 C |
14 | |
15 | describe('Test plugin helpers', function () { | |
16 | let server: ServerInfo | |
17 | const basePaths = [ | |
18 | '/plugins/test-five/router/', | |
19 | '/plugins/test-five/0.0.1/router/' | |
20 | ] | |
21 | ||
22 | before(async function () { | |
23 | this.timeout(30000) | |
24 | ||
25 | server = await flushAndRunServer(1) | |
26 | await setAccessTokensToServers([ server ]) | |
27 | ||
28 | await installPlugin({ | |
29 | url: server.url, | |
30 | accessToken: server.accessToken, | |
31 | path: getPluginTestPath('-five') | |
32 | }) | |
33 | }) | |
34 | ||
35 | it('Should answer "pong"', async function () { | |
36 | for (const path of basePaths) { | |
37 | const res = await makeGetRequest({ | |
38 | url: server.url, | |
39 | path: path + 'ping', | |
2d53be02 | 40 | statusCodeExpected: HttpStatusCode.OK_200 |
5e2b2e27 C |
41 | }) |
42 | ||
43 | expect(res.body.message).to.equal('pong') | |
44 | } | |
45 | }) | |
46 | ||
47 | it('Should mirror post body', async function () { | |
48 | const body = { | |
49 | hello: 'world', | |
50 | riri: 'fifi', | |
51 | loulou: 'picsou' | |
52 | } | |
53 | ||
54 | for (const path of basePaths) { | |
55 | const res = await makePostBodyRequest({ | |
56 | url: server.url, | |
57 | path: path + 'form/post/mirror', | |
58 | fields: body, | |
2d53be02 | 59 | statusCodeExpected: HttpStatusCode.OK_200 |
5e2b2e27 C |
60 | }) |
61 | ||
62 | expect(res.body).to.deep.equal(body) | |
63 | } | |
64 | }) | |
65 | ||
66 | it('Should remove the plugin and remove the routes', async function () { | |
67 | await uninstallPlugin({ | |
68 | url: server.url, | |
69 | accessToken: server.accessToken, | |
70 | npmName: 'peertube-plugin-test-five' | |
71 | }) | |
72 | ||
73 | for (const path of basePaths) { | |
74 | await makeGetRequest({ | |
75 | url: server.url, | |
76 | path: path + 'ping', | |
2d53be02 | 77 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
5e2b2e27 C |
78 | }) |
79 | ||
80 | await makePostBodyRequest({ | |
81 | url: server.url, | |
82 | path: path + 'ping', | |
83 | fields: {}, | |
2d53be02 | 84 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
5e2b2e27 C |
85 | }) |
86 | } | |
87 | }) | |
88 | ||
89 | after(async function () { | |
90 | await cleanupTests([ server ]) | |
91 | }) | |
92 | }) |