Skip to content

Commit

Permalink
Enhance disable feature (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwatson484 authored May 26, 2023
1 parent 1cac593 commit 4486191
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/keep-alive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const keepAlive = () => {
setInterval(() => {}, 60000)
}

module.exports = {
keepAlive
}
2 changes: 2 additions & 0 deletions app/messaging/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { MessageReceiver } = require('ffc-messaging')
const config = require('../config')
const processFileMessage = require('./process-file-message')
const { keepAlive } = require('../keep-alive')
let messageReceiver

const start = async () => {
Expand All @@ -12,6 +13,7 @@ const start = async () => {
console.info('Ready to transfer file')
} else {
console.info('File transfers are disabled in this environment')
keepAlive()
}
}

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-file-receiver",
"version": "1.0.3",
"version": "1.0.4",
"description": "Transfer files from DAX",
"homepage": "https://github.com/DEFRA/ffc-pay-file-receiver",
"main": "app/index.js",
Expand Down
12 changes: 12 additions & 0 deletions test/unit/keep-alive.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.useFakeTimers()

const setIntervalSpy = jest.spyOn(global, 'setInterval')

const { keepAlive } = require('../../app/keep-alive')

describe('keep alive', () => {
test('should call setInterval', () => {
keepAlive()
expect(setIntervalSpy).toHaveBeenCalled()
})
})
9 changes: 9 additions & 0 deletions test/unit/messaging/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jest.mock('ffc-messaging', () => {

jest.mock('../../../app/messaging/process-file-message')

jest.mock('../../../app/keep-alive')
const { keepAlive: mockKeepAlive } = require('../../../app/keep-alive')

const config = require('../../../app/config')

const { start, stop } = require('../../../app/messaging')
Expand Down Expand Up @@ -48,6 +51,12 @@ describe('messaging start', () => {
await start()
expect(mockSubscribe).toHaveBeenCalledTimes(0)
})

test('calls keep alive if service disabled', async () => {
config.enabled = false
await start()
expect(mockKeepAlive).toHaveBeenCalledTimes(1)
})
})

describe('messaging stop', () => {
Expand Down

0 comments on commit 4486191

Please sign in to comment.