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