From d066667abd3ba2cbfcbfdfec665ce565e31da342 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 00:34:36 +0000 Subject: [PATCH 1/4] chore(deps): update dependency sinon to v19 --- package-lock.json | 91 +++++++++++++++++++++++++---------------------- package.json | 2 +- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index f235a4cee8d..2c60fac242f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -165,7 +165,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", @@ -10895,39 +10895,43 @@ } }, "node_modules/@sinonjs/fake-timers": { - "version": "11.2.2", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz", - "integrity": "sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw==", + "version": "13.0.5", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz", + "integrity": "sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { - "@sinonjs/commons": "^3.0.0" + "@sinonjs/commons": "^3.0.1" } }, "node_modules/@sinonjs/samsam": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.0.tgz", - "integrity": "sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.2.tgz", + "integrity": "sha512-v46t/fwnhejRSFTGqbpn9u+LQ9xJDse10gNnPgAcxgdoCDMXj/G2asWAC/8Qs+BAZDicX+MNZouXT1A7c83kVw==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { - "@sinonjs/commons": "^2.0.0", + "@sinonjs/commons": "^3.0.1", "lodash.get": "^4.4.2", - "type-detect": "^4.0.8" + "type-detect": "^4.1.0" } }, - "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", - "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "node_modules/@sinonjs/samsam/node_modules/type-detect": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", + "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", "dev": true, - "dependencies": { - "type-detect": "4.0.8" + "license": "MIT", + "engines": { + "node": ">=4" } }, "node_modules/@sinonjs/text-encoding": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", - "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", - "dev": true + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.3.tgz", + "integrity": "sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==", + "dev": true, + "license": "(Unlicense OR Apache-2.0)" }, "node_modules/@smithy/abort-controller": { "version": "3.1.6", @@ -21404,25 +21408,28 @@ "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" }, "node_modules/nise": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/nise/-/nise-6.0.0.tgz", - "integrity": "sha512-K8ePqo9BFvN31HXwEtTNGzgrPpmvgciDsFz8aztFjt4LqKO/JeFD8tBOeuDiCMXrIl/m1YvfH8auSpxfaD09wg==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/nise/-/nise-6.1.1.tgz", + "integrity": "sha512-aMSAzLVY7LyeM60gvBS423nBmIPP+Wy7St7hsb+8/fc1HmeoHJfLO8CKse4u3BtOZvQLJghYPI2i/1WZrEj5/g==", "dev": true, "license": "BSD-3-Clause", "dependencies": { - "@sinonjs/commons": "^3.0.0", - "@sinonjs/fake-timers": "^11.2.2", - "@sinonjs/text-encoding": "^0.7.2", + "@sinonjs/commons": "^3.0.1", + "@sinonjs/fake-timers": "^13.0.1", + "@sinonjs/text-encoding": "^0.7.3", "just-extend": "^6.2.0", - "path-to-regexp": "^6.2.1" + "path-to-regexp": "^8.1.0" } }, "node_modules/nise/node_modules/path-to-regexp": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.2.tgz", - "integrity": "sha512-GQX3SSMokngb36+whdpRXE+3f9V8UzyAorlYvOGx87ufGHehNTn5lCxrKtLyZ4Yl/wEKnNnr98ZzOwwDZV5ogw==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", + "integrity": "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==", "dev": true, - "license": "MIT" + "license": "MIT", + "engines": { + "node": ">=16" + } }, "node_modules/nock": { "version": "13.5.0", @@ -24832,18 +24839,18 @@ } }, "node_modules/sinon": { - "version": "18.0.0", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-18.0.0.tgz", - "integrity": "sha512-+dXDXzD1sBO6HlmZDd7mXZCR/y5ECiEiGCBSGuFD/kZ0bDTofPYc6JaeGmPSF+1j1MejGUWkORbYOLDyvqCWpA==", + "version": "19.0.2", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-19.0.2.tgz", + "integrity": "sha512-euuToqM+PjO4UgXeLETsfQiuoyPXlqFezr6YZDFwHR3t4qaX0fZUe1MfPMznTL5f8BWrVS89KduLdMUsxFCO6g==", "dev": true, "license": "BSD-3-Clause", "dependencies": { "@sinonjs/commons": "^3.0.1", - "@sinonjs/fake-timers": "^11.2.2", - "@sinonjs/samsam": "^8.0.0", - "diff": "^5.2.0", - "nise": "^6.0.0", - "supports-color": "^7" + "@sinonjs/fake-timers": "^13.0.2", + "@sinonjs/samsam": "^8.0.1", + "diff": "^7.0.0", + "nise": "^6.1.1", + "supports-color": "^7.2.0" }, "funding": { "type": "opencollective", @@ -24861,9 +24868,9 @@ } }, "node_modules/sinon/node_modules/diff": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", - "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz", + "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==", "dev": true, "license": "BSD-3-Clause", "engines": { diff --git a/package.json b/package.json index b1e34366079..b2340746806 100644 --- a/package.json +++ b/package.json @@ -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", From 1e49881f7dcaa261930e82316e7f317f989c87fd Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 11 Dec 2024 22:00:19 -0300 Subject: [PATCH 2/4] Fix breaking change in sinon fake timers --- test/cron/monthly/host-settlement.test.js | 4 ++-- test/server/graphql/common/transactions.test.js | 2 +- test/server/graphql/v1/invoices.test.js | 2 +- .../graphql/v2/mutation/OrderMutations.test.ts | 14 +++++++------- .../v2/mutation/UploadedFileMutations.test.ts | 2 +- .../graphql/v2/query/HostMetricsQuery.test.js | 4 ++-- test/server/lib/auth.test.js | 5 ++++- test/server/lib/recurring-contributions.test.js | 2 +- test/server/lib/spam.test.js | 2 +- test/server/lib/subscriptions.test.ts | 6 +++--- test/server/models/PaymentMethod.test.js | 2 +- test/server/routes/oauth.test.ts | 2 +- test/stores/index.js | 2 +- test/stories/platform-migration.test.ts | 6 +++--- 14 files changed, 29 insertions(+), 26 deletions(-) diff --git a/test/cron/monthly/host-settlement.test.js b/test/cron/monthly/host-settlement.test.js index faa651d9425..25b25164980 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(moment(lastMonth).add(1, 'day').toDate()); + let clock = sinon.useFakeTimers({ shouldAdvanceTime: true, 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(lastMonth.toDate()); // Manually setting today's date + clock = useFakeTimers({ now: lastMonth.toDate(), shouldAdvanceTime: true }); // 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 c491cc705b4..90fcf3f69f6 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(new Date('2020-07-23 0:0').getTime()); + timer = useFakeTimers({ now: new Date('2020-07-23 0:0').getTime(), shouldAdvanceTime: true }); 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 2994f0ce7df..0b82ee4f41f 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(new Date(createdAt).getTime()); + const timer = useFakeTimers({ shouldAdvanceTime: true, 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 e234c1ce6a5..4b067551040 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(today.toDate()); // Manually setting today's date + clock = useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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(today.toDate()); // Manually setting today's date + clock = useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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(today.toDate()); // Manually setting today's date + clock = useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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(today.toDate()); // Manually setting today's date + clock = useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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(today.toDate()); // Manually setting today's date + clock = useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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(today.toDate()); // Manually setting today's date + clock = useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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(today.toDate()); // Manually setting today's date + clock = useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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 f4004786c12..00ff1673534 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(moment().subtract(20, 'hours').toDate()); + clock = sinon.useFakeTimers({ now: moment().subtract(20, 'hours').toDate(), shouldAdvanceTime: true }); 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 784866d4373..4baacdb2de0 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(new Date('2021-02-01 0:0').getTime()); + let clock = useFakeTimers({ now: new Date('2021-02-01 0:0').getTime(), shouldAdvanceTime: true }); try { const order1 = await fakeOrder({ CollectiveId: collective1.id, @@ -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(), shouldAdvanceTime: true }); 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 bb3e88859b6..7deb968271b 100644 --- a/test/server/lib/auth.test.js +++ b/test/server/lib/auth.test.js @@ -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, + shouldAdvanceTime: true, + }); // When the token is generated const token = auth.createJwt('subject', { foo: 'bar' }, 5); diff --git a/test/server/lib/recurring-contributions.test.js b/test/server/lib/recurring-contributions.test.js index b0b49130098..11b66b7d078 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(new Date('2018-01-28 0:0').getTime()); + const clock = useFakeTimers({ now: new Date('2018-01-28 0:0').getTime(), shouldAdvanceTime: true }); // When dates are updated with failure const updatedDates = getNextChargeAndPeriodStartDates('failure', order); diff --git a/test/server/lib/spam.test.js b/test/server/lib/spam.test.js index d2ed3e1f3d4..e55df6afa46 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(new Date('2020-01-01T00:00:00.000Z')); + clock = useFakeTimers({ now: new Date('2020-01-01T00:00:00.000Z'), shouldAdvanceTime: true }); }); after(() => { diff --git a/test/server/lib/subscriptions.test.ts b/test/server/lib/subscriptions.test.ts index fcf211613c9..32187333b87 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(today.toDate()); // Manually setting today's date + clock = sinon.useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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(today.toDate()); // Manually setting today's date + clock = sinon.useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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(today.toDate()); // Manually setting today's date + clock = sinon.useFakeTimers({ now: today.toDate(), shouldAdvanceTime: true }); // 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 7003d59a6ae..8b22ee61ec1 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(new Date('2017-09-01 00:00:00').getTime()); + timer = useFakeTimers({ now: new Date('2017-09-01 00:00:00').getTime(), shouldAdvanceTime: true }); }); after(() => { timer.restore(); diff --git a/test/server/routes/oauth.test.ts b/test/server/routes/oauth.test.ts index 3a585cda1bc..dd905c92300 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(fakeNow); + clock = useFakeTimers({ now: fakeNow, shouldAdvanceTime: true }); const application = await fakeApplication(); // Get authorization code diff --git a/test/stores/index.js b/test/stores/index.js index 1f7749da85d..73aebd9b3fd 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(new Date(createdAt).getTime()); + sandbox.useFakeTimers({ now: new Date(createdAt).getTime(), shouldAdvanceTime: true }); } // 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 c03344d56ce..83bd605abc7 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(moment('2024-10-01T00:00:00Z').toDate()); + sandbox.useFakeTimers({ now: moment('2024-10-01T00:00:00Z').toDate(), shouldAdvanceTime: true }); expect(PlatformConstants.PlatformCollectiveId).to.equal(8686); }); it('platform collective id is migrated after migration cutoff', () => { - sandbox.useFakeTimers(moment('2024-10-01T00:00:01Z').toDate()); + sandbox.useFakeTimers({ now: moment('2024-10-01T00:00:01Z').toDate(), shouldAdvanceTime: true }); 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(tc.when); + sandbox.useFakeTimers({ now: tc.when, shouldAdvanceTime: true }); const result = await makeContribution( { From 50183ad25b81c374b7602cdc8af848d320ec633e Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 11 Dec 2024 22:36:06 -0300 Subject: [PATCH 3/4] Add missing method calls --- test/server/lib/recurring-contributions.test.js | 2 +- test/server/models/User.test.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/server/lib/recurring-contributions.test.js b/test/server/lib/recurring-contributions.test.js index 11b66b7d078..8f1d6c8a29c 100644 --- a/test/server/lib/recurring-contributions.test.js +++ b/test/server/lib/recurring-contributions.test.js @@ -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(), shouldAdvanceTime: true }); // when dates are updated with 'updated' status const updatedDates = getNextChargeAndPeriodStartDates('updated', order); diff --git a/test/server/models/User.test.js b/test/server/models/User.test.js index b1f8a39d8e7..1d6983b16a3 100644 --- a/test/server/models/User.test.js +++ b/test/server/models/User.test.js @@ -84,7 +84,13 @@ describe('server/models/User', () => { // Ensure the date will start at 0 instead of starting at epoch so // date related things can be tested let clock; - beforeEach(() => (clock = useFakeTimers())); + beforeEach( + () => + (clock = useFakeTimers({ + now: 0, + shouldAdvanceTime: true, + })), + ); afterEach(() => clock.restore()); it('should generate valid JWTokens with user data', async () => { From c1af332683f54cff7406d0dc716d3a222a45d5f1 Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 11 Dec 2024 23:02:52 -0300 Subject: [PATCH 4/4] stub only Date.now --- .../71-send-resume-subscription-emails.test.ts | 8 ++++---- test/cron/monthly/host-settlement.test.js | 4 ++-- test/server/graphql/common/transactions.test.js | 2 +- test/server/graphql/v1/invoices.test.js | 2 +- .../graphql/v2/mutation/OrderMutations.test.ts | 14 +++++++------- .../v2/mutation/UploadedFileMutations.test.ts | 2 +- .../graphql/v2/query/HostMetricsQuery.test.js | 4 ++-- test/server/lib/auth.test.js | 2 +- test/server/lib/recurring-contributions.test.js | 4 ++-- test/server/lib/spam.test.js | 2 +- test/server/lib/subscriptions.test.ts | 6 +++--- test/server/models/PaymentMethod.test.js | 2 +- test/server/models/User.test.js | 2 +- test/server/routes/oauth.test.ts | 2 +- test/stores/index.js | 2 +- test/stories/platform-migration.test.ts | 6 +++--- 16 files changed, 32 insertions(+), 32 deletions(-) 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( {