Skip to content

Commit

Permalink
chore(deps): update dependency sinon to v19 (#10342)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency sinon to v19

* Fix breaking change in sinon fake timers

* Add missing method calls

* stub only Date.now

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Henrique <[email protected]>
  • Loading branch information
renovate[bot] and hdiniz authored Dec 12, 2024
1 parent e7fc5fe commit a478ff9
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 75 deletions.
91 changes: 49 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"nyc": "^17.0.0",
"opentelemetry-instrumentation-sequelize": "^0.41.0",
"prettier": "3.4.2",
"sinon": "^18.0.0",
"sinon": "^19.0.0",
"sinon-chai": "^3.7.0",
"supertest": "^7.0.0",
"ts-unused-exports": "^10.1.0",
Expand Down
8 changes: 4 additions & 4 deletions test/cron/hourly/71-send-resume-subscription-emails.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('cron/hourly/71-send-resume-subscription-emails', () => {
);

// 1st reminder
clock = sandbox.useFakeTimers({ now: moment(nextReminderDate).add(1, 'day').toDate(), shouldAdvanceTime: true });
clock = sandbox.useFakeTimers({ now: moment(nextReminderDate).add(1, 'day').toDate(), toFake: ['Date'] });
updatedOrders = await runCronJob();
expect(updatedOrders).to.have.length(1);
expect(updatedOrders[0].status).to.equal(OrderStatuses.PAUSED);
Expand All @@ -125,7 +125,7 @@ describe('cron/hourly/71-send-resume-subscription-emails', () => {

// 2nd reminder
clock.restore();
clock = sandbox.useFakeTimers({ now: moment(nextReminderDate).add(1, 'day').toDate(), shouldAdvanceTime: true });
clock = sandbox.useFakeTimers({ now: moment(nextReminderDate).add(1, 'day').toDate(), toFake: ['Date'] });
updatedOrders = await runCronJob();
expect(updatedOrders).to.have.length(1);
expect(updatedOrders[0].status).to.equal(OrderStatuses.PAUSED);
Expand All @@ -148,7 +148,7 @@ describe('cron/hourly/71-send-resume-subscription-emails', () => {

// 3rd and final reminder
clock.restore();
clock = sandbox.useFakeTimers({ now: moment(nextReminderDate).add(1, 'day').toDate(), shouldAdvanceTime: true });
clock = sandbox.useFakeTimers({ now: moment(nextReminderDate).add(1, 'day').toDate(), toFake: ['Date'] });
updatedOrders = await runCronJob();
expect(updatedOrders).to.have.length(1);
expect(updatedOrders[0].data.resumeContribution.reminder).to.equal(4);
Expand All @@ -165,7 +165,7 @@ describe('cron/hourly/71-send-resume-subscription-emails', () => {

// No more reminders
clock.restore();
clock = sandbox.useFakeTimers({ now: moment(nextReminderDate).add(60, 'day').toDate(), shouldAdvanceTime: true });
clock = sandbox.useFakeTimers({ now: moment(nextReminderDate).add(60, 'day').toDate(), toFake: ['Date'] });
updatedOrders = await runCronJob();
expect(updatedOrders).to.have.length(0);
});
Expand Down
4 changes: 2 additions & 2 deletions test/cron/monthly/host-settlement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('cron/monthly/host-settlement', () => {
);

// Refund contributions that must be
let clock = sinon.useFakeTimers(moment(lastMonth).add(1, 'day').toDate());
let clock = sinon.useFakeTimers({ toFake: ['Date'], now: moment(lastMonth).add(1, 'day').toDate() });
await createRefundTransaction(unsettledRefundedContribution, 0, null, user, fakeUUID('00000008'));
await createRefundTransaction(settledRefundedContribution, 0, null, user, fakeUUID('00000009'));
clock.restore();
Expand All @@ -225,7 +225,7 @@ describe('cron/monthly/host-settlement', () => {
});

// Create Contributions
clock = useFakeTimers(lastMonth.toDate()); // Manually setting today's date
clock = useFakeTimers({ now: lastMonth.toDate(), toFake: ['Date'] }); // Manually setting today's date
const order = await fakeOrder({
description: 'EUR Contribution with tip + host fee',
CollectiveId: eurCollective.id,
Expand Down
2 changes: 1 addition & 1 deletion test/server/graphql/common/transactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('server/graphql/common/transactions', () => {
kind: TransactionKind.CONTRIBUTION,
OrderId: order.id,
});
timer = useFakeTimers(new Date('2020-07-23 0:0').getTime());
timer = useFakeTimers({ now: new Date('2020-07-23 0:0').getTime(), toFake: ['Date'] });
oldTransaction = await fakeTransaction({
CollectiveId: collective.id,
FromCollectiveId: contributor.CollectiveId,
Expand Down
2 changes: 1 addition & 1 deletion test/server/graphql/v1/invoices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as utils from '../../../utils';
* The payment method is always stripe for now.
*/
async function donate(user, currency, amount, createdAt, collective) {
const timer = useFakeTimers(new Date(createdAt).getTime());
const timer = useFakeTimers({ toFake: ['Date'], now: new Date(createdAt).getTime() });
try {
await store.stripeConnectedAccount(collective.HostCollectiveId);
await store.stripeOneTimeDonation({
Expand Down
14 changes: 7 additions & 7 deletions test/server/graphql/v2/mutation/OrderMutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2840,7 +2840,7 @@ describe('server/graphql/v2/mutation/OrderMutations', () => {
describe('when charge is due today', () => {
it('from monthly to yearly', async () => {
const today = moment(new Date(2022, 0, 1)); // 1st of January 2022
clock = useFakeTimers(today.toDate()); // Manually setting today's date
clock = useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date
const { result, order } = await updateFakeOrder(today, 'month', 'year');
expect(result.errors).to.not.exist;
expect(result.data.updateOrder.tier.name).to.eq(fixedYearlyTier.name);
Expand All @@ -2852,7 +2852,7 @@ describe('server/graphql/v2/mutation/OrderMutations', () => {

it('from yearly to monthly', async () => {
const today = moment(new Date(2022, 0, 1)); // 1st of January 2022
clock = useFakeTimers(today.toDate()); // Manually setting today's date
clock = useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date
const { result, order } = await updateFakeOrder(today, 'year', 'month');
expect(result.errors).to.not.exist;
expect(result.data.updateOrder.tier.name).to.eq(fixedMonthlyTier.name);
Expand All @@ -2866,7 +2866,7 @@ describe('server/graphql/v2/mutation/OrderMutations', () => {
describe('with a recent past charge (keep the existing date)', () => {
it('from monthly to yearly', async () => {
const today = moment(new Date(2022, 0, 12)); // 12th of January 2022
clock = useFakeTimers(today.toDate()); // Manually setting today's date
clock = useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date
const firstOfJanuary = moment(new Date(2022, 0, 1)); // 1st of January 2022
const { result, order } = await updateFakeOrder(firstOfJanuary, 'month', 'year');
expect(result.errors).to.not.exist;
Expand All @@ -2879,7 +2879,7 @@ describe('server/graphql/v2/mutation/OrderMutations', () => {

it('from yearly to monthly', async () => {
const today = moment(new Date(2022, 0, 12)); // 12th of January 2022
clock = useFakeTimers(today.toDate()); // Manually setting today's date
clock = useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date
const firstOfJanuary = moment(new Date(2022, 0, 1)); // 1st of January 2022
const { result, order } = await updateFakeOrder(firstOfJanuary, 'year', 'month');
expect(result.errors).to.not.exist;
Expand All @@ -2894,7 +2894,7 @@ describe('server/graphql/v2/mutation/OrderMutations', () => {
describe('with an old dur charge', () => {
it('from monthly to yearly', async () => {
const today = moment(new Date(2022, 6, 1)); // 1st of July 2022
clock = useFakeTimers(today.toDate()); // Manually setting today's date
clock = useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date
const firstOfJanuary = moment(new Date(2022, 0, 1)); // 1st of January 2022
const { result, order } = await updateFakeOrder(firstOfJanuary, 'month', 'year');
expect(result.errors).to.not.exist;
Expand All @@ -2907,7 +2907,7 @@ describe('server/graphql/v2/mutation/OrderMutations', () => {

it('from yearly to monthly', async () => {
const today = moment(new Date(2022, 6, 12)); // 12th of July 2022
clock = useFakeTimers(today.toDate()); // Manually setting today's date
clock = useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date
const firstOfJanuary = moment(new Date(2022, 0, 1)); // 1st of January 2022
const { result, order } = await updateFakeOrder(firstOfJanuary, 'year', 'month');
expect(result.errors).to.not.exist;
Expand All @@ -2920,7 +2920,7 @@ describe('server/graphql/v2/mutation/OrderMutations', () => {

it('from yearly to monthly (on the 1st of the month)', async () => {
const today = moment(new Date(2022, 6, 1)); // 1st of July 2022
clock = useFakeTimers(today.toDate()); // Manually setting today's date
clock = useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date
const firstOfJanuary = moment(new Date(2022, 0, 1)); // 1st of January 2022
const { result, order } = await updateFakeOrder(firstOfJanuary, 'year', 'month');
expect(result.errors).to.not.exist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('server/graphql/v2/mutation/UploadedFileMutations', () => {
const hourlyLimit = config.limits.klippa.perUser.hour;

// Mock the clock to make sure we don't trigger the hourly limit
clock = sinon.useFakeTimers(moment().subtract(20, 'hours').toDate());
clock = sinon.useFakeTimers({ now: moment().subtract(20, 'hours').toDate(), toFake: ['Date'] });
const validRequests = [];
for (let i = 0; i < dailyLimit; i++) {
const result = await graphqlQueryV2(uploadFileMutation, args, user);
Expand Down
4 changes: 2 additions & 2 deletions test/server/graphql/v2/query/HostMetricsQuery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('server/graphql/v2/query/HostMetricsQuery', () => {
collective1 = await fakeCollective({ admin: collectiveAdminUser, HostCollectiveId: host.id, hostFeePercent: 30 });
collective2 = await fakeCollective({ admin: collectiveAdminUser, HostCollectiveId: host.id, hostFeePercent: 30 });

let clock = useFakeTimers(new Date('2021-02-01 0:0').getTime());
let clock = useFakeTimers({ now: new Date('2021-02-01 0:0').getTime(), toFake: ['Date'] });
try {
const order1 = await fakeOrder({
CollectiveId: collective1.id,
Expand All @@ -72,7 +72,7 @@ describe('server/graphql/v2/query/HostMetricsQuery', () => {
clock.restore();
}

clock = useFakeTimers(new Date('2021-06-01 0:0').getTime());
clock = useFakeTimers({ now: new Date('2021-06-01 0:0').getTime(), toFake: ['Date'] });
try {
const order2 = await fakeOrder({
CollectiveId: collective2.id,
Expand Down
5 changes: 4 additions & 1 deletion test/server/lib/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import * as auth from '../../../server/lib/auth';
describe('server/lib/auth', () => {
it('should generate valid tokens', () => {
// Given that time `Date.now` returns zero (0)
const clock = useFakeTimers();
const clock = useFakeTimers({
now: 0,
toFake: ['Date'],
});

// When the token is generated
const token = auth.createJwt('subject', { foo: 'bar' }, 5);
Expand Down
4 changes: 2 additions & 2 deletions test/server/lib/recurring-contributions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('server/lib/recurring-contributions', () => {
};

// And given that we freeze time
const clock = useFakeTimers(new Date('2018-01-28 0:0').getTime());
const clock = useFakeTimers({ now: new Date('2018-01-28 0:0').getTime(), toFake: ['Date'] });

// When dates are updated with failure
const updatedDates = getNextChargeAndPeriodStartDates('failure', order);
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('server/lib/recurring-contributions', () => {
};

// And given that we freeze time
const clock = useFakeTimers(new Date('2018-01-28 0:0').getTime());
const clock = useFakeTimers({ now: new Date('2018-01-28 0:0').getTime(), toFake: ['Date'] });

// when dates are updated with 'updated' status
const updatedDates = getNextChargeAndPeriodStartDates('updated', order);
Expand Down
2 changes: 1 addition & 1 deletion test/server/lib/spam.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('server/lib/spam', () => {
let clock;

before(() => {
clock = useFakeTimers(new Date('2020-01-01T00:00:00.000Z'));
clock = useFakeTimers({ now: new Date('2020-01-01T00:00:00.000Z'), toFake: ['Date'] });
});

after(() => {
Expand Down
Loading

0 comments on commit a478ff9

Please sign in to comment.