Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some additional logging for service bus messages #198

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/plugins/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export default {
'/public/fonts/bold-b542beb274-v2.woff2'
]
}
}
}
3 changes: 3 additions & 0 deletions server/routes/__tests__/feedback.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ describe(url, () => {
const response = await submitPostRequest(options, 302, session)
expect(sendMessage).toHaveBeenCalledTimes(1)
expect(sendMessage).toHaveBeenCalledWith(expect.objectContaining({
info: expect.any(Function)
}),
expect.objectContaining({
givingFeedbackToAEnvironmentalProblemReport: expect.objectContaining({
feedbackRating: 'vsatisfied',
feedbackText: 'This is test feedback',
Expand Down
3 changes: 3 additions & 0 deletions server/routes/__tests__/smell/other-information.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ describe(url, () => {
const response = await submitPostRequest(options, 302, session)
expect(sendMessage).toHaveBeenCalledTimes(1)
expect(sendMessage).toHaveBeenCalledWith(expect.objectContaining({
info: expect.any(Function)
}),
expect.objectContaining({
reportingAnEnvironmentalProblem: expect.objectContaining({
reportType: 200,
reporterName: 'John Smith',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ describe(url, () => {
const response = await submitPostRequest(options, 302, session)
expect(sendMessage).toHaveBeenCalledTimes(1)
expect(sendMessage).toHaveBeenCalledWith(expect.objectContaining({
info: expect.any(Function)
}),
expect.objectContaining({
reportingAnEnvironmentalProblem: expect.objectContaining({
reportType: 100,
reporterName: 'John Smith',
Expand Down
2 changes: 1 addition & 1 deletion server/routes/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const handlers = {
throw new Error('Invalid payload')
}

await sendMessage(payload, '-feedback')
await sendMessage(request.logger, payload, '-feedback')

return h.redirect(constants.routes.FEEDBACK_SUCCESS)
}
Expand Down
2 changes: 1 addition & 1 deletion server/routes/smell/other-information.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const handlers = {
throw new Error('Invalid payload')
}

await sendMessage(payload)
await sendMessage(request.logger, payload)

return h.redirect(constants.routes.REPORT_SENT)
}
Expand Down
2 changes: 1 addition & 1 deletion server/routes/water-pollution/other-information.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const handlers = {
throw new Error('Invalid payload')
}

await sendMessage(payload)
await sendMessage(request.logger, payload)

return h.redirect(constants.routes.REPORT_SENT)
}
Expand Down
6 changes: 5 additions & 1 deletion server/services/__tests__/service-bus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ const senderMock = {
sendMessages: mockSendMessages,
close: mockClose
}
const loggerMock = {
info: jest.fn()
}

describe('service-bus', () => {
it('Send a message to the service bus', async () => {
jest.spyOn(ServiceBusClient.prototype, 'createSender').mockImplementation(() => {
return senderMock
})
await sendMessage(payload)
await sendMessage(loggerMock, payload)
expect(mockSendMessages).toHaveBeenCalledTimes(1)
expect(mockClose).toHaveBeenCalledTimes(1)
expect(mockTryAddMessage).toHaveBeenCalledTimes(1)
expect(mockTryAddMessage).toHaveBeenCalledWith({ body: payload })
expect(loggerMock.info).toHaveBeenCalledTimes(1)
})
})
3 changes: 2 additions & 1 deletion server/services/service-bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import config from '../utils/config.js'
const connectionString = config.serviceBusConnectionString
const queueName = config.serviceBusQueueName

const sendMessage = async (message, queueSuffix = '') => {
const sendMessage = async (logger, message, queueSuffix = '') => {
logger.info(`service-bus.js:sendMessage ${JSON.stringify(message)} to service bus ${queueName}${queueSuffix}`)
const sbClient = new ServiceBusClient(connectionString)
const sender = sbClient.createSender(`${queueName}${queueSuffix}`)
const batch = await sender.createMessageBatch()
Expand Down
Loading