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