mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-08 20:22:53 +03:00
22e13acd65
- All var declarations are now const or let as per ES6 - All comma-separated lists / chained declarations are now one declaration per line - This is for clarity/readability but also made running the var-to-const/let switch smoother - ESLint rules updated to match How this was done: - npm install -g jscodeshift - git clone https://github.com/cpojer/js-codemod.git - git clone git@github.com:TryGhost/Ghost.git shallow-ghost - cd shallow-ghost - jscodeshift -t ../js-codemod/transforms/unchain-variables.js . -v=2 - jscodeshift -t ../js-codemod/transforms/no-vars.js . -v=2 - yarn - yarn test - yarn lint / fix various lint errors (almost all indent) by opening files and saving in vscode - grunt test-regression - sorted!
81 lines
2.4 KiB
JavaScript
81 lines
2.4 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const rewire = require('rewire');
|
|
const urlUtils = require('../../../../core/server/lib/url-utils');
|
|
const testUtils = require('../../../utils');
|
|
|
|
let getAmpUrl = rewire('../../../../core/frontend/meta/amp_url');
|
|
|
|
describe('getAmpUrl', function () {
|
|
let getUrlStub;
|
|
|
|
beforeEach(function () {
|
|
getUrlStub = sinon.stub();
|
|
|
|
getAmpUrl = rewire('../../../../core/frontend/meta/amp_url');
|
|
getAmpUrl.__set__('getUrl', getUrlStub);
|
|
|
|
sinon.stub(urlUtils, 'urlJoin');
|
|
sinon.stub(urlUtils, 'urlFor').withArgs('home', true).returns('http://localhost:9999');
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
it('should return amp url for post', function () {
|
|
const post = testUtils.DataGenerator.forKnex.createPost();
|
|
|
|
// @TODO: WTF?
|
|
post.context = ['post'];
|
|
|
|
getUrlStub.withArgs(post, false).returns('url');
|
|
urlUtils.urlJoin.withArgs('http://localhost:9999', 'url', 'amp/').returns('url');
|
|
|
|
should.exist(getAmpUrl(post));
|
|
|
|
urlUtils.urlJoin.calledOnce.should.be.true();
|
|
urlUtils.urlFor.calledOnce.should.be.true();
|
|
getUrlStub.calledOnce.should.be.true();
|
|
});
|
|
|
|
it('should not return amp url for tag', function () {
|
|
const tag = testUtils.DataGenerator.forKnex.createTag();
|
|
|
|
// @TODO: WTF?
|
|
tag.context = ['tag'];
|
|
|
|
should.not.exist(getAmpUrl(tag));
|
|
|
|
urlUtils.urlJoin.called.should.be.false();
|
|
urlUtils.urlFor.called.should.be.false();
|
|
getUrlStub.called.should.be.false();
|
|
});
|
|
|
|
it('should not return amp url for author', function () {
|
|
const author = testUtils.DataGenerator.forKnex.createUser();
|
|
|
|
// @TODO: WTF?
|
|
author.context = ['author'];
|
|
|
|
should.not.exist(getAmpUrl(author));
|
|
|
|
urlUtils.urlJoin.called.should.be.false();
|
|
urlUtils.urlFor.called.should.be.false();
|
|
getUrlStub.called.should.be.false();
|
|
});
|
|
|
|
it('should not return amp url for amp post', function () {
|
|
const post = testUtils.DataGenerator.forKnex.createPost();
|
|
|
|
// @TODO: WTF?
|
|
post.context = ['amp', 'post'];
|
|
|
|
should.not.exist(getAmpUrl(post));
|
|
|
|
urlUtils.urlJoin.called.should.be.false();
|
|
urlUtils.urlFor.called.should.be.false();
|
|
getUrlStub.called.should.be.false();
|
|
});
|
|
});
|