Skip to content

Commit

Permalink
fix: fix backend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Jul 5, 2022
1 parent 9de95d3 commit 807b8dd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/backend/package.json
Expand Up @@ -18,7 +18,7 @@
"@graphql-codegen/typescript": "1.22.2",
"@graphql-codegen/typescript-resolvers": "1.19.3",
"@types/ioredis": "^4.22.3",
"@types/jest": "^26.0.22",
"@types/jest": "^28.1.4",
"@types/koa": "^2.13.4",
"@types/koa-bodyparser": "^4.3.0",
"@types/koa__cors": "^3.0.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/open_payments/account/service.test.ts
Expand Up @@ -114,8 +114,9 @@ describe('Open Payments Account Service', (): void => {
let delayProcessAt: Date | null = null

beforeEach((): void => {
jest.useFakeTimers('modern')
jest.setSystemTime(new Date())
jest.useFakeTimers({
now: new Date()
})
if (withdrawalThrottleDelay !== undefined) {
delayProcessAt = new Date(Date.now() + withdrawalThrottleDelay)
}
Expand Down
Expand Up @@ -284,8 +284,9 @@ describe('Incoming Payment Service', (): void => {

test('Sets state of fully paid incoming payment to "completed"', async (): Promise<void> => {
const now = new Date()
jest.useFakeTimers('modern')
jest.setSystemTime(now)
jest.useFakeTimers({
now
})
await expect(
incomingPayment.onCredit({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -352,8 +353,7 @@ describe('Incoming Payment Service', (): void => {
).resolves.toBeUndefined()

const now = incomingPayment.expiresAt
jest.useFakeTimers('modern')
jest.setSystemTime(now)
jest.useFakeTimers({ now })
await expect(incomingPaymentService.processNext()).resolves.toBe(
incomingPayment.id
)
Expand All @@ -377,8 +377,7 @@ describe('Incoming Payment Service', (): void => {
expiresAt: new Date(Date.now() + 30_000),
externalRef: '#123'
})
jest.useFakeTimers('modern')
jest.setSystemTime(incomingPayment.expiresAt)
jest.useFakeTimers({ now: incomingPayment.expiresAt })
await expect(incomingPaymentService.processNext()).resolves.toBe(
incomingPayment.id
)
Expand Down Expand Up @@ -418,8 +417,7 @@ describe('Incoming Payment Service', (): void => {
})
).resolves.toBeUndefined()
if (eventType === IncomingPaymentEventType.IncomingPaymentExpired) {
jest.useFakeTimers('modern')
jest.setSystemTime(incomingPayment.expiresAt)
jest.useFakeTimers({ now: incomingPayment.expiresAt })
await expect(incomingPaymentService.processNext()).resolves.toBe(
incomingPayment.id
)
Expand Down Expand Up @@ -454,8 +452,7 @@ describe('Incoming Payment Service', (): void => {
})
).resolves.toHaveLength(0)
assert.ok(incomingPayment.processAt)
jest.useFakeTimers('modern')
jest.setSystemTime(incomingPayment.processAt)
jest.useFakeTimers({ now: incomingPayment.processAt })
await expect(incomingPaymentService.processNext()).resolves.toBe(
incomingPayment.id
)
Expand Down Expand Up @@ -595,8 +592,7 @@ describe('Incoming Payment Service', (): void => {
})
).resolves.toBeUndefined()
const future = new Date(Date.now() + 40_000)
jest.useFakeTimers('modern')
jest.setSystemTime(future)
jest.useFakeTimers({ now: future })
await expect(incomingPaymentService.processNext()).resolves.toBe(
incomingPayment.id
)
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/rates/service.test.ts
Expand Up @@ -37,8 +37,7 @@ describe('Rates service', function () {
deps = await initIocContainer(config)
deps.bind('messageProducer', async () => mockMessageProducer)
appContainer = await createTestApp(deps)
jest.useFakeTimers('modern')
jest.setSystemTime(1600000000000)
jest.useFakeTimers({ now: 1600000000000 })
}
)

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/session/service.test.ts
Expand Up @@ -23,7 +23,7 @@ describe('Session Key Service', (): void => {

beforeEach(
async (): Promise<void> => {
jest.useFakeTimers('modern')
jest.useFakeTimers()
}
)

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -4999,7 +4999,7 @@ __metadata:
"@koa/router": ^10.0.0
"@types/bcrypt": ^5.0.0
"@types/ioredis": ^4.22.3
"@types/jest": ^26.0.22
"@types/jest": ^28.1.4
"@types/koa": ^2.13.4
"@types/koa-bodyparser": ^4.3.0
"@types/koa__cors": ^3.0.2
Expand Down

0 comments on commit 807b8dd

Please sign in to comment.