]>
Commit | Line | Data |
---|---|---|
5e2b2e27 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
ae2abfd3 | 4 | import { expect } from 'chai' |
5e2b2e27 | 5 | import { |
ae2abfd3 | 6 | cleanupTests, |
254d3579 | 7 | createSingleServer, |
5e2b2e27 C |
8 | makeGetRequest, |
9 | makePostBodyRequest, | |
254d3579 | 10 | PeerTubeServer, |
4c7e60bc | 11 | PluginsCommand, |
ae2abfd3 C |
12 | setAccessTokensToServers |
13 | } from '@shared/extra-utils' | |
4c7e60bc | 14 | import { HttpStatusCode } from '@shared/models' |
5e2b2e27 C |
15 | |
16 | describe('Test plugin helpers', function () { | |
254d3579 | 17 | let server: PeerTubeServer |
5e2b2e27 C |
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 | ||
254d3579 | 26 | server = await createSingleServer(1) |
5e2b2e27 C |
27 | await setAccessTokensToServers([ server ]) |
28 | ||
89d241a7 | 29 | await server.plugins.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', | |
c0e8b12e | 37 | expectedStatus: 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, | |
c0e8b12e | 50 | expectedStatus: 200 |
f17faefb | 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', | |
c0e8b12e | 58 | expectedStatus: 200 |
f17faefb | 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, | |
c0e8b12e | 77 | expectedStatus: 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 () { | |
89d241a7 | 85 | await server.plugins.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', | |
c0e8b12e | 91 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
5e2b2e27 C |
92 | }) |
93 | ||
94 | await makePostBodyRequest({ | |
95 | url: server.url, | |
96 | path: path + 'ping', | |
97 | fields: {}, | |
c0e8b12e | 98 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
5e2b2e27 C |
99 | }) |
100 | } | |
101 | }) | |
102 | ||
103 | after(async function () { | |
104 | await cleanupTests([ server ]) | |
105 | }) | |
106 | }) |