diff --git a/test/cron/hourly/71-send-resume-subscription-emails.test.ts b/test/cron/hourly/71-send-resume-subscription-emails.test.ts index a7ccf62b506..03429adf347 100644 --- a/test/cron/hourly/71-send-resume-subscription-emails.test.ts +++ b/test/cron/hourly/71-send-resume-subscription-emails.test.ts @@ -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); @@ -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); @@ -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); @@ -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); }); diff --git a/test/cron/monthly/host-settlement.test.js b/test/cron/monthly/host-settlement.test.js index 25b25164980..641e588077d 100644 --- a/test/cron/monthly/host-settlement.test.js +++ b/test/cron/monthly/host-settlement.test.js @@ -198,7 +198,7 @@ describe('cron/monthly/host-settlement', () => { ); // Refund contributions that must be - let clock = sinon.useFakeTimers({ shouldAdvanceTime: true, now: 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(); @@ -225,7 +225,7 @@ describe('cron/monthly/host-settlement', () => { }); // Create Contributions - clock = useFakeTimers({ now: lastMonth.toDate(), shouldAdvanceTime: true }); // 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, diff --git a/test/server/graphql/common/transactions.test.js b/test/server/graphql/common/transactions.test.js index 90fcf3f69f6..9e9f794cfe8 100644 --- a/test/server/graphql/common/transactions.test.js +++ b/test/server/graphql/common/transactions.test.js @@ -85,7 +85,7 @@ describe('server/graphql/common/transactions', () => { kind: TransactionKind.CONTRIBUTION, OrderId: order.id, }); - timer = useFakeTimers({ now: new Date('2020-07-23 0:0').getTime(), shouldAdvanceTime: true }); + timer = useFakeTimers({ now: new Date('2020-07-23 0:0').getTime(), toFake: ['Date'] }); oldTransaction = await fakeTransaction({ CollectiveId: collective.id, FromCollectiveId: contributor.CollectiveId, diff --git a/test/server/graphql/v1/invoices.test.js b/test/server/graphql/v1/invoices.test.js index 0b82ee4f41f..bad542fc5f2 100644 --- a/test/server/graphql/v1/invoices.test.js +++ b/test/server/graphql/v1/invoices.test.js @@ -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({ shouldAdvanceTime: true, now: new Date(createdAt).getTime() }); + const timer = useFakeTimers({ toFake: ['Date'], now: new Date(createdAt).getTime() }); try { await store.stripeConnectedAccount(collective.HostCollectiveId); await store.stripeOneTimeDonation({ diff --git a/test/server/graphql/v2/mutation/OrderMutations.test.ts b/test/server/graphql/v2/mutation/OrderMutations.test.ts index 4b067551040..ec31155d8e7 100644 --- a/test/server/graphql/v2/mutation/OrderMutations.test.ts +++ b/test/server/graphql/v2/mutation/OrderMutations.test.ts @@ -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({ now: today.toDate(), shouldAdvanceTime: true }); // 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); @@ -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({ now: today.toDate(), shouldAdvanceTime: true }); // 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); @@ -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({ now: today.toDate(), shouldAdvanceTime: true }); // 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; @@ -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({ now: today.toDate(), shouldAdvanceTime: true }); // 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; @@ -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({ now: today.toDate(), shouldAdvanceTime: true }); // 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; @@ -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({ now: today.toDate(), shouldAdvanceTime: true }); // 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; @@ -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({ now: today.toDate(), shouldAdvanceTime: true }); // 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; diff --git a/test/server/graphql/v2/mutation/UploadedFileMutations.test.ts b/test/server/graphql/v2/mutation/UploadedFileMutations.test.ts index 00ff1673534..416dcbbbefb 100644 --- a/test/server/graphql/v2/mutation/UploadedFileMutations.test.ts +++ b/test/server/graphql/v2/mutation/UploadedFileMutations.test.ts @@ -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({ now: moment().subtract(20, 'hours').toDate(), shouldAdvanceTime: true }); + 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); diff --git a/test/server/graphql/v2/query/HostMetricsQuery.test.js b/test/server/graphql/v2/query/HostMetricsQuery.test.js index 4baacdb2de0..66addf9107c 100644 --- a/test/server/graphql/v2/query/HostMetricsQuery.test.js +++ b/test/server/graphql/v2/query/HostMetricsQuery.test.js @@ -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({ now: new Date('2021-02-01 0:0').getTime(), shouldAdvanceTime: true }); + let clock = useFakeTimers({ now: new Date('2021-02-01 0:0').getTime(), toFake: ['Date'] }); try { const order1 = await fakeOrder({ CollectiveId: collective1.id, @@ -72,7 +72,7 @@ describe('server/graphql/v2/query/HostMetricsQuery', () => { clock.restore(); } - clock = useFakeTimers({ now: new Date('2021-06-01 0:0').getTime(), shouldAdvanceTime: true }); + clock = useFakeTimers({ now: new Date('2021-06-01 0:0').getTime(), toFake: ['Date'] }); try { const order2 = await fakeOrder({ CollectiveId: collective2.id, diff --git a/test/server/lib/auth.test.js b/test/server/lib/auth.test.js index 7deb968271b..437ae2b89f2 100644 --- a/test/server/lib/auth.test.js +++ b/test/server/lib/auth.test.js @@ -10,7 +10,7 @@ describe('server/lib/auth', () => { // Given that time `Date.now` returns zero (0) const clock = useFakeTimers({ now: 0, - shouldAdvanceTime: true, + toFake: ['Date'], }); // When the token is generated diff --git a/test/server/lib/recurring-contributions.test.js b/test/server/lib/recurring-contributions.test.js index 8f1d6c8a29c..6bba0e6f254 100644 --- a/test/server/lib/recurring-contributions.test.js +++ b/test/server/lib/recurring-contributions.test.js @@ -121,7 +121,7 @@ describe('server/lib/recurring-contributions', () => { }; // And given that we freeze time - const clock = useFakeTimers({ now: new Date('2018-01-28 0:0').getTime(), shouldAdvanceTime: true }); + 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); @@ -185,7 +185,7 @@ describe('server/lib/recurring-contributions', () => { }; // And given that we freeze time - const clock = useFakeTimers({ now: new Date('2018-01-28 0:0').getTime(), shouldAdvanceTime: true }); + 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); diff --git a/test/server/lib/spam.test.js b/test/server/lib/spam.test.js index e55df6afa46..ed5e4796879 100644 --- a/test/server/lib/spam.test.js +++ b/test/server/lib/spam.test.js @@ -19,7 +19,7 @@ describe('server/lib/spam', () => { let clock; before(() => { - clock = useFakeTimers({ now: new Date('2020-01-01T00:00:00.000Z'), shouldAdvanceTime: true }); + clock = useFakeTimers({ now: new Date('2020-01-01T00:00:00.000Z'), toFake: ['Date'] }); }); after(() => { diff --git a/test/server/lib/subscriptions.test.ts b/test/server/lib/subscriptions.test.ts index 32187333b87..653a8be881e 100644 --- a/test/server/lib/subscriptions.test.ts +++ b/test/server/lib/subscriptions.test.ts @@ -36,7 +36,7 @@ describe('server/lib/subscriptions', () => { describe('with an order that has a pending payment', () => { it('to what it was before, keep the past due date', async () => { const today = moment(new Date(2022, 0, 1)); // 1st of January 2022 - clock = sinon.useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // Manually setting today's date + clock = sinon.useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date const paypalPm = await fakePaymentMethod({ service: PAYMENT_METHOD_SERVICE.PAYPAL, type: PAYMENT_METHOD_TYPE.SUBSCRIPTION, @@ -71,7 +71,7 @@ describe('server/lib/subscriptions', () => { describe('with an order that has a future payment', () => { it('before the 15th of the month => 1st of next month', async () => { const today = moment(new Date(2022, 0, 1)); // 1st of January 2022 - clock = sinon.useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // Manually setting today's date + clock = sinon.useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date const paypalPm = await fakePaymentMethod({ service: PAYMENT_METHOD_SERVICE.PAYPAL, type: PAYMENT_METHOD_TYPE.SUBSCRIPTION, @@ -103,7 +103,7 @@ describe('server/lib/subscriptions', () => { it('after the 15th of the month => skip next month', async () => { const today = moment(new Date(2022, 0, 18)); // 18th of January 2022 - clock = sinon.useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // Manually setting today's date + clock = sinon.useFakeTimers({ now: today.toDate(), toFake: ['Date'] }); // Manually setting today's date const paypalPm = await fakePaymentMethod({ service: PAYMENT_METHOD_SERVICE.PAYPAL, type: PAYMENT_METHOD_TYPE.SUBSCRIPTION, diff --git a/test/server/models/PaymentMethod.test.js b/test/server/models/PaymentMethod.test.js index 8b22ee61ec1..4242b0aa17a 100644 --- a/test/server/models/PaymentMethod.test.js +++ b/test/server/models/PaymentMethod.test.js @@ -16,7 +16,7 @@ describe('server/models/PaymentMethod', () => { .query({ access_key: config.fixer.accessKey, base: 'EUR', symbols: 'USD' }) // eslint-disable-line camelcase .reply(200, { base: 'EUR', date: '2017-09-01', rates: { USD: 1.192 } }); await utils.resetTestDB(); - timer = useFakeTimers({ now: new Date('2017-09-01 00:00:00').getTime(), shouldAdvanceTime: true }); + timer = useFakeTimers({ now: new Date('2017-09-01 00:00:00').getTime(), toFake: ['Date'] }); }); after(() => { timer.restore(); diff --git a/test/server/models/User.test.js b/test/server/models/User.test.js index 1d6983b16a3..4b4c28ab53d 100644 --- a/test/server/models/User.test.js +++ b/test/server/models/User.test.js @@ -88,7 +88,7 @@ describe('server/models/User', () => { () => (clock = useFakeTimers({ now: 0, - shouldAdvanceTime: true, + toFake: ['Date'], })), ); afterEach(() => clock.restore()); diff --git a/test/server/routes/oauth.test.ts b/test/server/routes/oauth.test.ts index dd905c92300..a007d7c8241 100644 --- a/test/server/routes/oauth.test.ts +++ b/test/server/routes/oauth.test.ts @@ -30,7 +30,7 @@ describe('server/routes/oauth', () => { it('goes through the entire OAuth flow', async () => { const fakeNow = new Date(2022, 0, 1); - clock = useFakeTimers({ now: fakeNow, shouldAdvanceTime: true }); + clock = useFakeTimers({ now: fakeNow, toFake: ['Date'] }); const application = await fakeApplication(); // Get authorization code diff --git a/test/stores/index.js b/test/stores/index.js index 73aebd9b3fd..64a9046a52c 100644 --- a/test/stores/index.js +++ b/test/stores/index.js @@ -341,7 +341,7 @@ export async function stripeOneTimeDonation(opt) { // requested creation date. It will be reset right after the // execution of the order. if (createdAt) { - sandbox.useFakeTimers({ now: new Date(createdAt).getTime(), shouldAdvanceTime: true }); + sandbox.useFakeTimers({ now: new Date(createdAt).getTime(), toFake: ['Date'] }); } // Stub the stripe calls before executing the order. diff --git a/test/stories/platform-migration.test.ts b/test/stories/platform-migration.test.ts index 83bd605abc7..733cb46e9c0 100644 --- a/test/stories/platform-migration.test.ts +++ b/test/stories/platform-migration.test.ts @@ -26,12 +26,12 @@ describe('platform constants', () => { }); it('platform collective id is same before migration cutoff', () => { - sandbox.useFakeTimers({ now: moment('2024-10-01T00:00:00Z').toDate(), shouldAdvanceTime: true }); + sandbox.useFakeTimers({ now: moment('2024-10-01T00:00:00Z').toDate(), toFake: ['Date'] }); expect(PlatformConstants.PlatformCollectiveId).to.equal(8686); }); it('platform collective id is migrated after migration cutoff', () => { - sandbox.useFakeTimers({ now: moment('2024-10-01T00:00:01Z').toDate(), shouldAdvanceTime: true }); + sandbox.useFakeTimers({ now: moment('2024-10-01T00:00:01Z').toDate(), toFake: ['Date'] }); expect(PlatformConstants.PlatformCollectiveId).to.equal(845576); }); }); @@ -253,7 +253,7 @@ describe('platform transactions', () => { }, ].map(tc => ('only' in tc && tc.only ? it.only : it)(tc.title, async () => { - sandbox.useFakeTimers({ now: tc.when, shouldAdvanceTime: true }); + sandbox.useFakeTimers({ now: tc.when, toFake: ['Date'] }); const result = await makeContribution( {