mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
104f84f252
As discussed with the product team we want to enforce kebab-case file names for all files, with the exception of files which export a single class, in which case they should be PascalCase and reflect the class which they export. This will help find classes faster, and should push better naming for them too. Some files and packages have been excluded from this linting, specifically when a library or framework depends on the naming of a file for the functionality e.g. Ember, knex-migrator, adapter-manager
94 lines
2.8 KiB
JavaScript
94 lines
2.8 KiB
JavaScript
const sinon = require('sinon');
|
|
const RouterController = require('../../../../lib/controllers/RouterController');
|
|
|
|
describe('RouterController', function () {
|
|
describe('createCheckoutSession', function (){
|
|
let offersAPI;
|
|
let paymentsService;
|
|
let tiersService;
|
|
let stripeAPIService;
|
|
let labsService;
|
|
let getPaymentLinkSpy;
|
|
|
|
beforeEach(async function () {
|
|
getPaymentLinkSpy = sinon.spy();
|
|
|
|
tiersService = {
|
|
api: {
|
|
read: sinon.stub().resolves({
|
|
id: 'tier_123'
|
|
})
|
|
}
|
|
};
|
|
|
|
paymentsService = {
|
|
getPaymentLink: getPaymentLinkSpy
|
|
};
|
|
|
|
offersAPI = {
|
|
getOffer: sinon.stub().resolves({
|
|
id: 'offer_123',
|
|
tier: {
|
|
id: 'tier_123'
|
|
}
|
|
}),
|
|
findOne: sinon.stub().resolves({
|
|
related: () => {
|
|
return {
|
|
query: sinon.stub().returns({
|
|
fetchOne: sinon.stub().resolves({})
|
|
}),
|
|
toJSON: sinon.stub().returns([]),
|
|
fetch: sinon.stub().resolves({
|
|
toJSON: sinon.stub().returns({})
|
|
})
|
|
};
|
|
},
|
|
toJSON: sinon.stub().returns({})
|
|
}),
|
|
edit: sinon.stub().resolves({
|
|
attributes: {},
|
|
_previousAttributes: {}
|
|
})
|
|
};
|
|
|
|
stripeAPIService = {
|
|
configured: true
|
|
};
|
|
labsService = {
|
|
isSet: sinon.stub().returns(true)
|
|
};
|
|
});
|
|
|
|
it('passes offer metadata to payment link method', async function (){
|
|
const routerController = new RouterController({
|
|
tiersService,
|
|
paymentsService,
|
|
offersAPI,
|
|
stripeAPIService,
|
|
labsService
|
|
});
|
|
|
|
await routerController.createCheckoutSession({
|
|
body: {
|
|
offerId: 'offer_123'
|
|
}
|
|
}, {
|
|
writeHead: () => {},
|
|
end: () => {}
|
|
});
|
|
|
|
getPaymentLinkSpy.calledOnce.should.be.true();
|
|
|
|
// Payment link is called with the offer id in metadata
|
|
getPaymentLinkSpy.calledWith(sinon.match({
|
|
metadata: {offer: 'offer_123'}
|
|
})).should.be.true();
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
});
|
|
});
|