diff options
author | Chocobozzz <chocobozzz@cpy.re> | 2021-05-27 15:59:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-27 15:59:55 +0200 |
commit | 2539932e16129992a2c0889b4ff527c265a8e2c7 (patch) | |
tree | fb5048e63e02a2485eb96d27455f43e4b22e8ae0 /server/tests | |
parent | eb34ec30e0b57286fc6f85160490d2e973a3b0b1 (diff) | |
download | PeerTube-2539932e16129992a2c0889b4ff527c265a8e2c7.tar.gz PeerTube-2539932e16129992a2c0889b4ff527c265a8e2c7.tar.zst PeerTube-2539932e16129992a2c0889b4ff527c265a8e2c7.zip |
Instance homepage support (#4007)
* Prepare homepage parsers
* Add ability to update instance hompage
* Add ability to set homepage as landing page
* Add homepage preview in admin
* Dynamically update left menu for homepage
* Inject home content in homepage
* Add videos list and channel miniature custom markup
* Remove unused elements in markup service
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/custom-pages.ts | 81 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/server/homepage.ts | 85 | ||||
-rw-r--r-- | server/tests/api/server/index.ts | 1 |
4 files changed, 168 insertions, 0 deletions
diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts new file mode 100644 index 000000000..74ca3384c --- /dev/null +++ b/server/tests/api/check-params/custom-pages.ts | |||
@@ -0,0 +1,81 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createUser, | ||
8 | flushAndRunServer, | ||
9 | ServerInfo, | ||
10 | setAccessTokensToServers, | ||
11 | userLogin | ||
12 | } from '../../../../shared/extra-utils' | ||
13 | import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests' | ||
14 | |||
15 | describe('Test custom pages validators', function () { | ||
16 | const path = '/api/v1/custom-pages/homepage/instance' | ||
17 | |||
18 | let server: ServerInfo | ||
19 | let userAccessToken: string | ||
20 | |||
21 | // --------------------------------------------------------------- | ||
22 | |||
23 | before(async function () { | ||
24 | this.timeout(120000) | ||
25 | |||
26 | server = await flushAndRunServer(1) | ||
27 | await setAccessTokensToServers([ server ]) | ||
28 | |||
29 | const user = { username: 'user1', password: 'password' } | ||
30 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | ||
31 | |||
32 | userAccessToken = await userLogin(server, user) | ||
33 | }) | ||
34 | |||
35 | describe('When updating instance homepage', function () { | ||
36 | |||
37 | it('Should fail with an unauthenticated user', async function () { | ||
38 | await makePutBodyRequest({ | ||
39 | url: server.url, | ||
40 | path, | ||
41 | fields: { content: 'super content' }, | ||
42 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | ||
43 | }) | ||
44 | }) | ||
45 | |||
46 | it('Should fail with a non admin user', async function () { | ||
47 | await makePutBodyRequest({ | ||
48 | url: server.url, | ||
49 | path, | ||
50 | token: userAccessToken, | ||
51 | fields: { content: 'super content' }, | ||
52 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | ||
53 | }) | ||
54 | }) | ||
55 | |||
56 | it('Should succeed with the correct params', async function () { | ||
57 | await makePutBodyRequest({ | ||
58 | url: server.url, | ||
59 | path, | ||
60 | token: server.accessToken, | ||
61 | fields: { content: 'super content' }, | ||
62 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
63 | }) | ||
64 | }) | ||
65 | }) | ||
66 | |||
67 | describe('When getting instance homapage', function () { | ||
68 | |||
69 | it('Should succeed with the correct params', async function () { | ||
70 | await makeGetRequest({ | ||
71 | url: server.url, | ||
72 | path, | ||
73 | statusCodeExpected: HttpStatusCode.OK_200 | ||
74 | }) | ||
75 | }) | ||
76 | }) | ||
77 | |||
78 | after(async function () { | ||
79 | await cleanupTests([ server ]) | ||
80 | }) | ||
81 | }) | ||
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 143515838..ce2335e42 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -3,6 +3,7 @@ import './accounts' | |||
3 | import './blocklist' | 3 | import './blocklist' |
4 | import './bulk' | 4 | import './bulk' |
5 | import './config' | 5 | import './config' |
6 | import './custom-pages' | ||
6 | import './contact-form' | 7 | import './contact-form' |
7 | import './debug' | 8 | import './debug' |
8 | import './follows' | 9 | import './follows' |
diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts new file mode 100644 index 000000000..e8ba89ca6 --- /dev/null +++ b/server/tests/api/server/homepage.ts | |||
@@ -0,0 +1,85 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { HttpStatusCode } from '@shared/core-utils' | ||
6 | import { CustomPage, ServerConfig } from '@shared/models' | ||
7 | import { | ||
8 | cleanupTests, | ||
9 | flushAndRunServer, | ||
10 | getConfig, | ||
11 | getInstanceHomepage, | ||
12 | killallServers, | ||
13 | reRunServer, | ||
14 | ServerInfo, | ||
15 | setAccessTokensToServers, | ||
16 | updateInstanceHomepage | ||
17 | } from '../../../../shared/extra-utils/index' | ||
18 | |||
19 | const expect = chai.expect | ||
20 | |||
21 | async function getHomepageState (server: ServerInfo) { | ||
22 | const res = await getConfig(server.url) | ||
23 | |||
24 | const config = res.body as ServerConfig | ||
25 | return config.homepage.enabled | ||
26 | } | ||
27 | |||
28 | describe('Test instance homepage actions', function () { | ||
29 | let server: ServerInfo | ||
30 | |||
31 | before(async function () { | ||
32 | this.timeout(30000) | ||
33 | |||
34 | server = await flushAndRunServer(1) | ||
35 | await setAccessTokensToServers([ server ]) | ||
36 | }) | ||
37 | |||
38 | it('Should not have a homepage', async function () { | ||
39 | const state = await getHomepageState(server) | ||
40 | expect(state).to.be.false | ||
41 | |||
42 | await getInstanceHomepage(server.url, HttpStatusCode.NOT_FOUND_404) | ||
43 | }) | ||
44 | |||
45 | it('Should set a homepage', async function () { | ||
46 | await updateInstanceHomepage(server.url, server.accessToken, '<picsou-magazine></picsou-magazine>') | ||
47 | |||
48 | const res = await getInstanceHomepage(server.url) | ||
49 | const page: CustomPage = res.body | ||
50 | expect(page.content).to.equal('<picsou-magazine></picsou-magazine>') | ||
51 | |||
52 | const state = await getHomepageState(server) | ||
53 | expect(state).to.be.true | ||
54 | }) | ||
55 | |||
56 | it('Should have the same homepage after a restart', async function () { | ||
57 | this.timeout(30000) | ||
58 | |||
59 | killallServers([ server ]) | ||
60 | |||
61 | await reRunServer(server) | ||
62 | |||
63 | const res = await getInstanceHomepage(server.url) | ||
64 | const page: CustomPage = res.body | ||
65 | expect(page.content).to.equal('<picsou-magazine></picsou-magazine>') | ||
66 | |||
67 | const state = await getHomepageState(server) | ||
68 | expect(state).to.be.true | ||
69 | }) | ||
70 | |||
71 | it('Should empty the homepage', async function () { | ||
72 | await updateInstanceHomepage(server.url, server.accessToken, '') | ||
73 | |||
74 | const res = await getInstanceHomepage(server.url) | ||
75 | const page: CustomPage = res.body | ||
76 | expect(page.content).to.be.empty | ||
77 | |||
78 | const state = await getHomepageState(server) | ||
79 | expect(state).to.be.false | ||
80 | }) | ||
81 | |||
82 | after(async function () { | ||
83 | await cleanupTests([ server ]) | ||
84 | }) | ||
85 | }) | ||
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index be743973a..56e6eb5da 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts | |||
@@ -5,6 +5,7 @@ import './email' | |||
5 | import './follow-constraints' | 5 | import './follow-constraints' |
6 | import './follows' | 6 | import './follows' |
7 | import './follows-moderation' | 7 | import './follows-moderation' |
8 | import './homepage' | ||
8 | import './handle-down' | 9 | import './handle-down' |
9 | import './jobs' | 10 | import './jobs' |
10 | import './logs' | 11 | import './logs' |