Ghost/test/unit/server/web/parent/vhost-utils.test.js
Hannah Wolfe 9e96b04542
Moved server unit tests into the server folder
- this is a small part of a bit of cleanup of our test files
- the goal is to make the existing tests clearer with a view to making it easier to write more tests
- this makes the test structure follow the codebase structure more closely
- eventually we will colocate the tests as we break the codebase down further
2021-10-06 12:01:09 +01:00

62 lines
2.2 KiB
JavaScript

const should = require('should');
const configUtils = require('../../../../utils/configUtils');
const vhostUtils = require('../../../../../core/server/web/parent/vhost-utils');
describe('vhost utils', function () {
beforeEach(function () {
configUtils.set('url', 'http://ghost.blog');
});
afterEach(function () {
configUtils.restore();
});
it('exposes two methods', function () {
Object.keys(vhostUtils).should.be.an.Array().with.lengthOf(2);
vhostUtils.should.have.properties('getBackendHostArg', 'getFrontendHostArg');
});
// url = 'https://ghost.blog'
describe('without separate admin url', function () {
it('uses the default arg for both backend and frontend', function () {
vhostUtils.getBackendHostArg().should.eql(/.*/);
vhostUtils.getFrontendHostArg().should.eql(/.*/);
});
});
// url = 'https://ghost.blog'
// admin.url = 'https://admin.ghost.blog'
describe('with separate admin url', function () {
beforeEach(function () {
configUtils.set('admin:url', 'https://admin.ghost.blog');
});
it('should use admin url and inverse as args', function () {
vhostUtils.getBackendHostArg().should.eql('admin.ghost.blog');
vhostUtils.getFrontendHostArg().should.eql(/^(?!admin\.ghost\.blog).*/);
});
it('should have regex that excludes admin traffic on front-end', function () {
const frontendRegex = vhostUtils.getFrontendHostArg();
frontendRegex.test('localhost').should.be.true();
frontendRegex.test('ghost.blog').should.be.true();
frontendRegex.test('admin.ghost.blog').should.be.false();
});
});
// url = 'http://ghost.blog'
// admin.url = 'https://ghost.blog'
describe('with separate admin protocol', function () {
beforeEach(function () {
configUtils.set('admin:url', 'https://ghost.blog');
});
it('should mount and assign correct routes', function () {
vhostUtils.getBackendHostArg().should.eql(/.*/);
vhostUtils.getFrontendHostArg().should.eql(/.*/);
});
});
});