]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { expect } from 'chai' | |
5 | import { | |
6 | cleanupTests, | |
7 | createSingleServer, | |
8 | makeGetRequest, | |
9 | makePostBodyRequest, | |
10 | PeerTubeServer, | |
11 | PluginsCommand, | |
12 | setAccessTokensToServers | |
13 | } from '@shared/extra-utils' | |
14 | import { HttpStatusCode } from '@shared/models' | |
15 | ||
16 | describe('Test plugin helpers', function () { | |
17 | let server: PeerTubeServer | |
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 createSingleServer(1) | |
27 | await setAccessTokensToServers([ server ]) | |
28 | ||
29 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') }) | |
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', | |
37 | expectedStatus: HttpStatusCode.OK_200 | |
38 | }) | |
39 | ||
40 | expect(res.body.message).to.equal('pong') | |
41 | } | |
42 | }) | |
43 | ||
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 | expectedStatus: 200 | |
51 | }) | |
52 | ||
53 | expect(res.body.isAuthenticated).to.equal(true) | |
54 | ||
55 | const secRes = await makeGetRequest({ | |
56 | url: server.url, | |
57 | path: path + 'is-authenticated', | |
58 | expectedStatus: 200 | |
59 | }) | |
60 | ||
61 | expect(secRes.body.isAuthenticated).to.equal(false) | |
62 | } | |
63 | }) | |
64 | ||
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, | |
77 | expectedStatus: HttpStatusCode.OK_200 | |
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 () { | |
85 | await server.plugins.uninstall({ npmName: 'peertube-plugin-test-five' }) | |
86 | ||
87 | for (const path of basePaths) { | |
88 | await makeGetRequest({ | |
89 | url: server.url, | |
90 | path: path + 'ping', | |
91 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
92 | }) | |
93 | ||
94 | await makePostBodyRequest({ | |
95 | url: server.url, | |
96 | path: path + 'ping', | |
97 | fields: {}, | |
98 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
99 | }) | |
100 | } | |
101 | }) | |
102 | ||
103 | after(async function () { | |
104 | await cleanupTests([ server ]) | |
105 | }) | |
106 | }) |