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