Removed some hidden v2 and v3 tests

refs: https://github.com/TryGhost/Toolbox/issues/168

- These are all test files I missed in ffcd3fbe313b4a413833da9a7473376cb21246fd

We're going to be dropping the idea of having multiple versions of the API in each Ghost version.
Because this has not achieved the goal of making it easier to make breaking changes, but it has
created an ordinate amount of technical debt and maintenance overhead.

As we know this is going away in the next major, there is no benefit to us constantly running tests
that check if those versions still work, especially given how long they take.

Instead we're starting work to ensure that all of our test work on canary, and that canary has
excellent test coverage so that we can be sure that our one API version works really well and that
any changes, no matter how subtle are deliberate, tracked and understood.
This commit is contained in:
Hannah Wolfe 2022-01-21 14:20:52 +00:00
parent b6c0f8bddd
commit e47b55b466
No known key found for this signature in database
GPG Key ID: AB586C3B5AE5C037
6 changed files with 796 additions and 2770 deletions

View File

@ -3,9 +3,8 @@ const sinon = require('sinon');
const settingsCache = require('../../../../../core/shared/settings-cache'); const settingsCache = require('../../../../../core/shared/settings-cache');
const controllers = require('../../../../../core/frontend/services/routing/controllers'); const controllers = require('../../../../../core/frontend/services/routing/controllers');
const TaxonomyRouter = require('../../../../../core/frontend/services/routing/TaxonomyRouter'); const TaxonomyRouter = require('../../../../../core/frontend/services/routing/TaxonomyRouter');
const RESOURCE_CONFIG_V2 = require('../../../../../core/frontend/services/routing/config/v2');
const RESOURCE_CONFIG_CANARY = require('../../../../../core/frontend/services/routing/config/canary'); const RESOURCE_CONFIG = require('../../../../../core/frontend/services/routing/config/canary');
const RESOURCE_CONFIG_V3 = require('../../../../../core/frontend/services/routing/config/v3');
describe('UNIT - services/routing/TaxonomyRouter', function () { describe('UNIT - services/routing/TaxonomyRouter', function () {
let req; let req;
@ -63,8 +62,8 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
taxonomyRouter.mountRoute.args[2][1].should.eql(taxonomyRouter._redirectEditOption.bind(taxonomyRouter)); taxonomyRouter.mountRoute.args[2][1].should.eql(taxonomyRouter._redirectEditOption.bind(taxonomyRouter));
}); });
it('v2:fn: _prepareContext', function () { it('_prepareContext behaves as expected', function () {
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_V2, routerCreatedSpy); const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG, routerCreatedSpy);
taxonomyRouter._prepareContext(req, res, next); taxonomyRouter._prepareContext(req, res, next);
next.calledOnce.should.eql(true); next.calledOnce.should.eql(true);
@ -72,45 +71,9 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
type: 'channel', type: 'channel',
name: 'tag', name: 'tag',
permalinks: '/tag/:slug/', permalinks: '/tag/:slug/',
resourceType: RESOURCE_CONFIG_V2.QUERY.tag.resource, resourceType: RESOURCE_CONFIG.QUERY.tag.resource,
data: {tag: RESOURCE_CONFIG_V2.QUERY.tag}, data: {tag: RESOURCE_CONFIG.QUERY.tag},
filter: RESOURCE_CONFIG_V2.TAXONOMIES.tag.filter, filter: RESOURCE_CONFIG.TAXONOMIES.tag.filter,
context: ['tag'],
slugTemplate: true,
identifier: taxonomyRouter.identifier
});
});
it('canary:fn: _prepareContext', function () {
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_CANARY, routerCreatedSpy);
taxonomyRouter._prepareContext(req, res, next);
next.calledOnce.should.eql(true);
res.routerOptions.should.eql({
type: 'channel',
name: 'tag',
permalinks: '/tag/:slug/',
resourceType: RESOURCE_CONFIG_V2.QUERY.tag.resource,
data: {tag: RESOURCE_CONFIG_V2.QUERY.tag},
filter: RESOURCE_CONFIG_V2.TAXONOMIES.tag.filter,
context: ['tag'],
slugTemplate: true,
identifier: taxonomyRouter.identifier
});
});
it('v3:fn: _prepareContext', function () {
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_V3, routerCreatedSpy);
taxonomyRouter._prepareContext(req, res, next);
next.calledOnce.should.eql(true);
res.routerOptions.should.eql({
type: 'channel',
name: 'tag',
permalinks: '/tag/:slug/',
resourceType: RESOURCE_CONFIG_V2.QUERY.tag.resource,
data: {tag: RESOURCE_CONFIG_V2.QUERY.tag},
filter: RESOURCE_CONFIG_V2.TAXONOMIES.tag.filter,
context: ['tag'], context: ['tag'],
slugTemplate: true, slugTemplate: true,
identifier: taxonomyRouter.identifier identifier: taxonomyRouter.identifier

View File

@ -3,12 +3,11 @@ const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const testUtils = require('../../../../../utils'); const testUtils = require('../../../../../utils');
const configUtils = require('../../../../../utils/configUtils'); const configUtils = require('../../../../../utils/configUtils');
const api = require('../../../../../../core/server/api'); const api = require('../../../../../../core/server/api').canary;
const controllers = require('../../../../../../core/frontend/services/routing/controllers'); const controllers = require('../../../../../../core/frontend/services/routing/controllers');
const helpers = require('../../../../../../core/frontend/services/routing/helpers'); const helpers = require('../../../../../../core/frontend/services/routing/helpers');
const urlService = require('../../../../../../core/server/services/url'); const urlService = require('../../../../../../core/server/services/url');
const urlUtils = require('../../../../../../core/shared/url-utils'); const urlUtils = require('../../../../../../core/shared/url-utils');
const EDITOR_URL = '/#/editor/post/';
describe('Unit - services/routing/controllers/preview', function () { describe('Unit - services/routing/controllers/preview', function () {
let secureStub; let secureStub;
@ -30,77 +29,6 @@ describe('Unit - services/routing/controllers/preview', function () {
configUtils.restore(); configUtils.restore();
}); });
describe('v2', function () {
let previewStub;
beforeEach(function () {
post = testUtils.DataGenerator.forKnex.createPost({status: 'draft'});
apiResponse = {
preview: [post]
};
req = {
path: '/',
params: {
uuid: 'something'
},
route: {}
};
res = {
routerOptions: {
query: {controller: 'preview', resource: 'preview'}
},
locals: {
apiVersion: 'v2'
},
render: sinon.spy(),
redirect: sinon.spy(),
set: sinon.spy()
};
secureStub = sinon.stub();
sinon.stub(urlUtils, 'redirectToAdmin');
sinon.stub(urlUtils, 'redirect301');
sinon.stub(urlService, 'getUrlByResourceId');
sinon.stub(helpers, 'secure').get(function () {
return secureStub;
});
renderStub = sinon.stub();
sinon.stub(helpers, 'renderEntry').get(function () {
return function () {
return renderStub;
};
});
previewStub = sinon.stub();
previewStub.withArgs({
uuid: req.params.uuid,
status: 'all',
include: 'authors,tags'
}).resolves(apiResponse);
sinon.stub(api.v2, 'preview').get(() => {
return {
read: previewStub
};
});
});
it('should render post', function (done) {
controllers.preview(req, res, failTest(done)).then(function () {
renderStub.called.should.be.true();
secureStub.called.should.be.true();
done();
}).catch(done);
});
});
describe('canary', function () {
let previewStub; let previewStub;
beforeEach(function () { beforeEach(function () {
@ -154,7 +82,7 @@ describe('Unit - services/routing/controllers/preview', function () {
include: 'authors,tags' include: 'authors,tags'
}).resolves(apiResponse); }).resolves(apiResponse);
sinon.stub(api.canary, 'preview').get(() => { sinon.stub(api, 'preview').get(() => {
return { return {
read: previewStub read: previewStub
}; };
@ -168,75 +96,4 @@ describe('Unit - services/routing/controllers/preview', function () {
done(); done();
}).catch(done); }).catch(done);
}); });
});
describe('v3', function () {
let previewStub;
beforeEach(function () {
post = testUtils.DataGenerator.forKnex.createPost({status: 'draft'});
apiResponse = {
preview: [post]
};
req = {
path: '/',
params: {
uuid: 'something'
},
route: {}
};
res = {
routerOptions: {
query: {controller: 'preview', resource: 'preview'}
},
locals: {
apiVersion: 'v3'
},
render: sinon.spy(),
redirect: sinon.spy(),
set: sinon.spy()
};
secureStub = sinon.stub();
sinon.stub(urlUtils, 'redirectToAdmin');
sinon.stub(urlUtils, 'redirect301');
sinon.stub(urlService, 'getUrlByResourceId');
sinon.stub(helpers, 'secure').get(function () {
return secureStub;
});
renderStub = sinon.stub();
sinon.stub(helpers, 'renderEntry').get(function () {
return function () {
return renderStub;
};
});
previewStub = sinon.stub();
previewStub.withArgs({
uuid: req.params.uuid,
status: 'all',
include: 'authors,tags'
}).resolves(apiResponse);
sinon.stub(api.v3, 'preview').get(() => {
return {
read: previewStub
};
});
});
it('should render post', function (done) {
controllers.preview(req, res, failTest(done)).then(function () {
renderStub.called.should.be.true();
secureStub.called.should.be.true();
done();
}).catch(done);
});
});
}); });

View File

@ -12,111 +12,6 @@ describe('Unit - services/routing/helpers/entry-lookup', function () {
sinon.restore(); sinon.restore();
}); });
describe('v2', function () {
describe('static pages', function () {
const routerOptions = {
permalinks: '/:slug/',
query: {controller: 'pagesPublic', resource: 'pages'}
};
let pages;
let postsReadStub;
let pagesReadStub;
beforeEach(function () {
pages = [
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test', page: true})
];
postsReadStub = sinon.stub();
pagesReadStub = sinon.stub();
pagesReadStub//.withArgs({slug: pages[0].slug, include: 'author,authors,tags'})
.resolves({
pages: pages
});
sinon.stub(api.v2, 'posts').get(() => {
return {
read: postsReadStub
};
});
sinon.stub(api.v2, 'pagesPublic').get(() => {
return {
read: pagesReadStub
};
});
locals = {apiVersion: 'v2'};
});
it('ensure pages controller is triggered', function () {
const testUrl = 'http://127.0.0.1:2369' + pages[0].url;
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
postsReadStub.called.should.be.false();
pagesReadStub.calledOnce.should.be.true();
should.exist(lookup.entry);
lookup.entry.should.have.property('url', pages[0].url);
lookup.isEditURL.should.be.false();
});
});
});
describe('posts', function () {
const routerOptions = {
permalinks: '/:slug/',
query: {controller: 'posts', resource: 'posts'}
};
let posts;
let postsReadStub;
let pagesReadStub;
beforeEach(function () {
posts = [
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test'})
];
postsReadStub = sinon.stub();
pagesReadStub = sinon.stub();
postsReadStub//.withArgs({slug: posts[0].slug, include: 'author,authors,tags'})
.resolves({
posts: posts
});
sinon.stub(api.v2, 'posts').get(() => {
return {
read: postsReadStub
};
});
sinon.stub(api.v2, 'pagesPublic').get(() => {
return {
read: pagesReadStub
};
});
locals = {apiVersion: 'v2'};
});
it('ensure posts controller is triggered', function () {
const testUrl = 'http://127.0.0.1:2369' + posts[0].url;
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
postsReadStub.calledOnce.should.be.true();
pagesReadStub.called.should.be.false();
should.exist(lookup.entry);
lookup.entry.should.have.property('url', posts[0].url);
lookup.isEditURL.should.be.false();
});
});
});
});
describe('canary', function () {
describe('static pages', function () { describe('static pages', function () {
const routerOptions = { const routerOptions = {
permalinks: '/:slug/', permalinks: '/:slug/',
@ -218,109 +113,4 @@ describe('Unit - services/routing/helpers/entry-lookup', function () {
}); });
}); });
}); });
});
describe('v3', function () {
describe('static pages', function () {
const routerOptions = {
permalinks: '/:slug/',
query: {controller: 'pagesPublic', resource: 'pages'}
};
let pages;
let postsReadStub;
let pagesReadStub;
beforeEach(function () {
pages = [
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test', page: true})
];
postsReadStub = sinon.stub();
pagesReadStub = sinon.stub();
pagesReadStub//.withArgs({slug: pages[0].slug, include: 'author,authors,tags'})
.resolves({
pages: pages
});
sinon.stub(api.v3, 'posts').get(() => {
return {
read: postsReadStub
};
});
sinon.stub(api.v3, 'pagesPublic').get(() => {
return {
read: pagesReadStub
};
});
locals = {apiVersion: 'v3'};
});
it('ensure pages controller is triggered', function () {
const testUrl = 'http://127.0.0.1:2369' + pages[0].url;
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
postsReadStub.called.should.be.false();
pagesReadStub.calledOnce.should.be.true();
should.exist(lookup.entry);
lookup.entry.should.have.property('url', pages[0].url);
lookup.isEditURL.should.be.false();
});
});
});
describe('posts', function () {
const routerOptions = {
permalinks: '/:slug/',
query: {controller: 'posts', resource: 'posts'}
};
let posts;
let postsReadStub;
let pagesReadStub;
beforeEach(function () {
posts = [
testUtils.DataGenerator.forKnex.createPost({url: '/test/', slug: 'test'})
];
postsReadStub = sinon.stub();
pagesReadStub = sinon.stub();
postsReadStub//.withArgs({slug: posts[0].slug, include: 'author,authors,tags'})
.resolves({
posts: posts
});
sinon.stub(api.v3, 'posts').get(() => {
return {
read: postsReadStub
};
});
sinon.stub(api.v3, 'pagesPublic').get(() => {
return {
read: pagesReadStub
};
});
locals = {apiVersion: 'v3'};
});
it('ensure posts controller is triggered', function () {
const testUrl = 'http://127.0.0.1:2369' + posts[0].url;
return helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) {
postsReadStub.calledOnce.should.be.true();
pagesReadStub.called.should.be.false();
should.exist(lookup.entry);
lookup.entry.should.have.property('url', posts[0].url);
lookup.isEditURL.should.be.false();
});
});
});
});
}); });

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +0,0 @@
const should = require('should');
const middleware = require('../../../../../../../core/server/web/api/v2/content/middleware');
describe('Content Api v2 middleware', function () {
it('exports an authenticatePublic middleware', function () {
should.exist(middleware.authenticatePublic);
});
describe('authenticatePublic', function () {
it('uses brute content api middleware as the first middleware in the chain', function () {
const firstMiddleware = middleware.authenticatePublic[0];
const brute = require('../../../../../../../core/server/web/shared/middleware/brute');
should.equal(firstMiddleware, brute.contentApiKey);
});
});
});

View File

@ -1,17 +0,0 @@
const should = require('should');
const middleware = require('../../../../../../../core/server/web/api/v3/content/middleware');
describe('Content Api v3 middleware', function () {
it('exports an authenticatePublic middleware', function () {
should.exist(middleware.authenticatePublic);
});
describe('authenticatePublic', function () {
it('uses brute content api middleware as the first middleware in the chain', function () {
const firstMiddleware = middleware.authenticatePublic[0];
const brute = require('../../../../../../../core/server/web/shared/middleware/brute');
should.equal(firstMiddleware, brute.contentApiKey);
});
});
});