Ghost/core/test/unit/web/parent-app_spec.js
Nazar Gargol 57271127f4 Added v2 api endpoints (#9874)
refs #9866

- Registered Content API under /ghost/api/v2/content/
- Registered Admin API under /ghost/api/v2/admin/
- Moved API v0.1 implementation to web/api/v0.1
- Created web/api/v2 for the new api endpoints
- Started with reducing the implementation for the new Content API (the Content api does not serve admin api endpoints, that's why it was reducible)
- Covered parent-app module with basic test checking correct applications/routes are being mounted
- Added a readme file, which contains a warning using v2, because it's under active development!
- This PR does only make the new endpoints available, we have not:
  - optimised the web folder (e.g. res.isAdmin)
  - started with different API controllers
  - reason: we want to do more preparation tasks before we copy the api controllers
2018-09-18 15:59:06 +02:00

58 lines
1.6 KiB
JavaScript

var should = require('should'),
sinon = require('sinon'),
proxyquire = require('proxyquire'),
sandbox = sinon.sandbox.create();
describe('parent app', function () {
let expressStub;
let use;
let apiV01Spy;
let apiContentV2Spy;
let apiAdminV2Spy;
let parentApp;
let adminSpy;
let siteSpy;
beforeEach(function () {
use = sandbox.spy();
expressStub = () => ({
use,
enable: () => {}
});
apiV01Spy = sinon.spy();
apiContentV2Spy = sinon.spy();
apiAdminV2Spy = sinon.spy();
adminSpy = sinon.spy();
siteSpy = sinon.spy();
parentApp = proxyquire('../../../server/web/parent-app', {
express: expressStub,
'./api/v0.1/app': apiV01Spy,
'./api/v2/content/app': apiContentV2Spy,
'./api/v2/admin/app': apiAdminV2Spy,
'./admin': adminSpy,
'./site': siteSpy
});
});
afterEach(function () {
sandbox.restore();
});
it('should mount 5 apps and assign correct routes to them', function () {
parentApp();
use.calledWith('/ghost/api/v0.1/').should.be.true();
use.calledWith('/ghost/api/v2/content/').should.be.true();
use.calledWith('/ghost/api/v2/admin/').should.be.true();
use.calledWith('/ghost').should.be.true();
apiV01Spy.called.should.be.true();
apiContentV2Spy.called.should.be.true();
apiAdminV2Spy.called.should.be.true();
adminSpy.called.should.be.true();
siteSpy.called.should.be.true();
});
});