Skip to content

Commit

Permalink
add try catch to disconnect method (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
samplackett authored Feb 5, 2025
1 parent a3ba331 commit de89c9a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/polling/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ const poll = async () => {
} catch (err) {
console.error(err)
} finally {
await disconnect(transfer.server)
try {
await disconnect(transfer.server)
} catch (disconnectError) {
console.error(`Disconnection from server ${transfer.server} failed: `, disconnectError)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "ffc-pay-gateway",
"version": "1.4.26",
"version": "1.4.27",
"description": "Managed Gateway integration",
"homepage": "https://github.com/DEFRA/ffc-pay-gateway",
"main": "app/index.js",
Expand Down
13 changes: 13 additions & 0 deletions test/unit/polling/poll.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
jest.mock('../../../app/transfer')
jest.mock('../../../app/sftp')
const { getActiveTransfers, transferInboundFiles, transferOutboundFiles } = require('../../../app/transfer')
const { connect, disconnect } = require('../../../app/sftp')

const { INBOUND, OUTBOUND } = require('../../../app/constants/directions')

Expand All @@ -9,6 +11,8 @@ describe('poll', () => {
beforeEach(() => {
jest.clearAllMocks()
getActiveTransfers.mockReturnValue([])
connect.mockResolvedValue()
disconnect.mockResolvedValue()
})

test('should get active transfers', async () => {
Expand Down Expand Up @@ -67,4 +71,13 @@ describe('poll', () => {
await poll()
expect(transferOutboundFiles).toHaveBeenCalledTimes(2)
})

test('should continue to transfer files if disconnect throws error', async () => {
getActiveTransfers.mockReturnValueOnce([{ direction: INBOUND }, { direction: OUTBOUND }])
disconnect.mockImplementationOnce(() => { throw new Error() })
await poll()
expect(transferInboundFiles).toHaveBeenCalledTimes(1)
expect(transferOutboundFiles).toHaveBeenCalledTimes(1)
expect(disconnect).toHaveBeenCalledTimes(2)
})
})

0 comments on commit de89c9a

Please sign in to comment.