From e032aec9b92be25a996923361f83a96a89505254 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Jul 2018 09:52:46 +0200 Subject: Render CSS/title/description tags on server side --- server/tests/api/server/config.ts | 26 +++++++++++++++++++++++++- server/tests/real-world/populate-database.ts | 11 ++++++----- server/tests/utils/requests/requests.ts | 8 ++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 79b5aaf2d..7d21b6ce9 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { About } from '../../../../shared/models/server/about.model' import { CustomConfig } from '../../../../shared/models/server/custom-config.model' -import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils' +import { deleteCustomConfig, getAbout, killallServers, makeHTMLRequest, reRunServer } from '../../utils' const expect = chai.expect import { @@ -69,6 +69,12 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.transcoding.resolutions['1080p']).to.be.false } +function checkIndexTags (html: string, title: string, description: string, css: string) { + expect(html).to.contain('' + title + '') + expect(html).to.contain('') + expect(html).to.contain('') +} + describe('Test config', function () { let server = null @@ -109,6 +115,14 @@ describe('Test config', function () { checkInitialConfig(data) }) + it('Should have valid index html tags (title, description...)', async function () { + const res = await makeHTMLRequest(server.url, '/videos/trending') + + const description = 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' + + 'with WebTorrent and Angular.' + checkIndexTags(res.text, 'PeerTube', description, '') + }) + it('Should update the customized configuration', async function () { const newCustomConfig: CustomConfig = { instance: { @@ -167,6 +181,12 @@ describe('Test config', function () { checkUpdatedConfig(data) }) + it('Should have valid index html updated tags (title, description...)', async function () { + const res = await makeHTMLRequest(server.url, '/videos/trending') + + checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') + }) + it('Should have the configuration updated after a restart', async function () { this.timeout(10000) @@ -178,6 +198,10 @@ describe('Test config', function () { const data = res.body checkUpdatedConfig(data) + + // Check HTML too + const resHtml = await makeHTMLRequest(server.url, '/videos/trending') + checkIndexTags(resHtml.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') }) it('Should fetch the about information', async function () { diff --git a/server/tests/real-world/populate-database.ts b/server/tests/real-world/populate-database.ts index 5f93d09db..f0f82f7f8 100644 --- a/server/tests/real-world/populate-database.ts +++ b/server/tests/real-world/populate-database.ts @@ -19,6 +19,12 @@ start() // ---------------------------------------------------------------------------- async function start () { + await flushTests() + + console.log('Flushed tests.') + + const server = await runServer(6) + process.on('exit', async () => { killallServers([ server ]) return @@ -26,11 +32,6 @@ async function start () { process.on('SIGINT', goodbye) process.on('SIGTERM', goodbye) - await flushTests() - - console.log('Flushed tests.') - - const server = await runServer(6) await setAccessTokensToServers([ server ]) console.log('Servers ran.') diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index ebde692cd..b88b3ce5b 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts @@ -123,6 +123,13 @@ function makePutBodyRequest (options: { .expect(options.statusCodeExpected) } +function makeHTMLRequest (url: string, path: string) { + return request(url) + .get(path) + .set('Accept', 'text/html') + .expect(200) +} + function updateAvatarRequest (options: { url: string, path: string, @@ -149,6 +156,7 @@ function updateAvatarRequest (options: { // --------------------------------------------------------------------------- export { + makeHTMLRequest, makeGetRequest, makeUploadRequest, makePostBodyRequest, -- cgit v1.2.3