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