Upgrade sinonjs (and related libs) (#9914)

* update sinon

* remove errors

* fix unit tests
This commit is contained in:
Matteo Pagliazzi
2018-01-31 10:56:32 +01:00
committed by GitHub
parent 47dbe4561f
commit a85282763f
12 changed files with 129 additions and 19 deletions

View File

@@ -417,6 +417,7 @@ describe('payments/index', () => {
it('awards mystery items when within the timeframe for a mystery item', async () => {
let mayMysteryItemTimeframe = 1464725113000; // May 31st 2016
let fakeClock = sinon.useFakeTimers(mayMysteryItemTimeframe);
data = { paymentMethod: 'PaymentMethod', user, sub: { key: 'basic_3mo' } };
await api.createSubscription(data);

View File

@@ -47,7 +47,7 @@ describe('#upgradeGroupPlan', () => {
});
afterEach(function () {
sinon.restore(amzLib.authorizeOnBillingAgreement);
amzLib.authorizeOnBillingAgreement.restore();
uuid.v4.restore();
});

View File

@@ -58,7 +58,7 @@ describe('subscribe', () => {
cc.validate.restore();
});
it('subscribes with amazon with a coupon', async () => {
it('subscribes with paypal with a coupon', async () => {
sub.discount = 40;
sub.key = 'google_6mo';
coupon = 'example-coupon';

View File

@@ -73,7 +73,7 @@ describe('checkout with subscription', () => {
});
afterEach(function () {
sinon.restore(stripe.subscriptions.update);
stripe.subscriptions.update.restore();
stripe.customers.create.restore();
payments.createSubscription.restore();
});
@@ -144,7 +144,7 @@ describe('checkout with subscription', () => {
cc.validate.restore();
});
it('subscribes with amazon with a coupon', async () => {
it('subscribes with stripe with a coupon', async () => {
sub.discount = 40;
sub.key = 'google_6mo';
coupon = 'example-coupon';

View File

@@ -35,7 +35,10 @@ describe('Stripe - Webhooks', () => {
const error = new Error(`Missing handler for Stripe webhook ${eventType}`);
await stripePayments.handleWebhooks({requestBody: event}, stripe);
expect(logger.error).to.have.been.called.once;
expect(logger.error).to.have.been.calledWith(error, {event: eventRetrieved});
const calledWith = logger.error.getCall(0).args;
expect(calledWith[0].message).to.equal(error.message);
expect(calledWith[1].event).to.equal(eventRetrieved);
});
it('retrieves and validates the event from Stripe', async () => {

View File

@@ -45,7 +45,7 @@ describe('Stripe - Upgrade Group Plan', () => {
});
afterEach(function () {
sinon.restore(stripe.subscriptions.update);
stripe.subscriptions.update.restore();
});
it('updates a group plan quantity', async () => {

View File

@@ -8,7 +8,10 @@ describe('preenHistory', () => {
beforeEach(() => {
// Replace system clocks so we can get predictable results
clock = sinon.useFakeTimers(Number(moment('2013-10-20').zone(0).startOf('day').toDate()), 'Date');
clock = sinon.useFakeTimers({
now: Number(moment('2013-10-20').zone(0).startOf('day').toDate()),
toFake: ['Date'],
});
});
afterEach(() => {
return clock.restore();

View File

@@ -22,7 +22,7 @@ describe('pushNotifications', () => {
sandbox.stub(nconf, 'get').returns('true-key');
sandbox.stub(gcmLib.Sender.prototype, 'send', fcmSendSpy);
sandbox.stub(gcmLib.Sender.prototype, 'send').callsFake(fcmSendSpy);
sandbox.stub(pushNotify, 'apn').returns({
on: () => null,

View File

@@ -24,7 +24,9 @@ describe('ensure access middlewares', () => {
ensureAdmin(req, res, next);
expect(next).to.be.calledWith(new NotAuthorized(i18n.t('noAdminAccess')));
const calledWith = next.getCall(0).args;
expect(calledWith[0].message).to.equal(i18n.t('noAdminAccess'));
expect(calledWith[0] instanceof NotAuthorized).to.equal(true);
});
it('passes when user is an admin', () => {
@@ -43,7 +45,9 @@ describe('ensure access middlewares', () => {
ensureSudo(req, res, next);
expect(next).to.be.calledWith(new NotAuthorized(apiMessages('noSudoAccess')));
const calledWith = next.getCall(0).args;
expect(calledWith[0].message).to.equal(apiMessages('noSudoAccess'));
expect(calledWith[0] instanceof NotAuthorized).to.equal(true);
});
it('passes when user is a sudo user', () => {

View File

@@ -22,7 +22,8 @@ describe('developmentMode middleware', () => {
ensureDevelpmentMode(req, res, next);
expect(next).to.be.calledWith(new NotFound());
const calledWith = next.getCall(0).args;
expect(calledWith[0] instanceof NotFound).to.equal(true);
});
it('passes when not in production', () => {