Skip to content

Commit

Permalink
utilise enabled feature flag (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
samplackett authored Sep 17, 2024
1 parent 894d812 commit 74dfaff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
14 changes: 9 additions & 5 deletions app/messaging/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const { MessageReceiver } = require('ffc-messaging')
const { messagingConfig } = require('../config')
const { messagingConfig, processingConfig } = require('../config')
const processDemographicsMessage = require('./process-demographics-message')
let updateReceiver

const start = async () => {
const updateAction = message => processDemographicsMessage(message, updateReceiver)
updateReceiver = new MessageReceiver(messagingConfig.updatesSubscription, updateAction)
await updateReceiver.subscribe()
console.info('Receiver ready to receive demographics updates')
if (processingConfig.enabled) {
const updateAction = message => processDemographicsMessage(message, updateReceiver)
updateReceiver = new MessageReceiver(messagingConfig.updatesSubscription, updateAction)
await updateReceiver.subscribe()
console.info('Receiver ready to receive demographics updates')
} else {
console.info('Demographics updates are not configured in this environment')
}
}

const stop = async () => {
Expand Down
6 changes: 3 additions & 3 deletions app/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const setupBlobServiceClient = () => {
}

const initialiseContainers = async () => {
if (!containersInitialised) {
setupBlobServiceClient()
if (storageConfig.enabled) {
if (storageConfig.enabled) {
if (!containersInitialised) {
setupBlobServiceClient()
if (storageConfig.createContainers) {
console.log('Making sure blob containers exist')
await demographicsContainer.createIfNotExists()
Expand Down
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-demographics",
"version": "1.2.8",
"version": "1.2.9",
"description": "Process customer updates",
"homepage": "https://github.com/DEFRA/ffc-pay-demographics",
"main": "app/index.js",
Expand Down
21 changes: 15 additions & 6 deletions test/unit/messaging/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const mockSubscribe = jest.fn()
const mockCloseConnection = jest.fn()
const mockProcessDemographicsMessage = jest.fn()

const MockMessageReceiver = jest.fn().mockImplementation(() => {
const MockMessageReceiver = jest.fn().mockImplementation((subscription, action) => {
return {
subscribe: mockSubscribe,
closeConnection: mockCloseConnection
Expand All @@ -14,32 +15,40 @@ jest.mock('ffc-messaging', () => {
}
})

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

const config = require('../../../app/config')
jest.mock('../../../app/messaging/process-demographics-message', () => mockProcessDemographicsMessage)

const { messagingConfig, processingConfig } = require('../../../app/config')
const { start, stop } = require('../../../app/messaging')

beforeEach(() => {
jest.clearAllMocks()

config.enabled = true
processingConfig.enabled = true
})

describe('messaging start', () => {
test('creates new message receiver', async () => {
test('creates new message receiver with correct subscription', async () => {
await start()
expect(MockMessageReceiver).toHaveBeenCalledTimes(1)
expect(MockMessageReceiver).toHaveBeenCalledWith(messagingConfig.updatesSubscription, expect.any(Function))
})

test('subscribes to message receiver', async () => {
await start()
expect(mockSubscribe).toHaveBeenCalledTimes(1)
})

test('does not start receiver if processingConfig is disabled', async () => {
processingConfig.enabled = false
await start()
expect(MockMessageReceiver).not.toHaveBeenCalled()
expect(mockSubscribe).not.toHaveBeenCalled()
})
})

describe('messaging stop', () => {
test('closes connection', async () => {
await start()
await stop()
expect(mockCloseConnection).toHaveBeenCalledTimes(1)
})
Expand Down

0 comments on commit 74dfaff

Please sign in to comment.