0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/test/unit/web/parent/vhost-utils.test.js
Hannah Wolfe f08a55c21f
Renamed tests to .test.js & updated commands
refs: https://github.com/TryGhost/Team/issues/856
refs: https://github.com/TryGhost/Team/issues/756

- The .test.js extension is better than _spec.js as it's more obvious that it's an extension
- It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test`
- It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856)
- Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
2021-07-06 20:45:01 +01:00

61 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(/.*/);
});
});
});