Skip to content

Commit ea4d23c

Browse files
committed
chore: param obj instead of scalars
1 parent 90772a5 commit ea4d23c

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

packages/nhsNotifyLambda/src/utils/notify.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import {loadSecrets, NotifySecrets} from "./secrets"
1414
import {tokenExchange} from "./auth"
1515
import {NOTIFY_REQUEST_MAX_BYTES, NOTIFY_REQUEST_MAX_ITEMS, DUMMY_NOTIFY_DELAY_MS} from "./constants"
1616

17+
export interface NotifyConfig {
18+
routingPlanId: string
19+
notifyApiBaseUrl: string
20+
notifySecrets: NotifySecrets
21+
}
22+
1723
/**
1824
* Returns the original array, chunked in batches of up to <size>
1925
*
@@ -75,7 +81,12 @@ export async function handleNotifyRequests(
7581
throw new Error("NOTIFY_API_BASE_URL is not defined in the environment variables!")
7682
} else {
7783
const notifySecrets = await loadSecrets()
78-
return await makeRealNotifyRequest(logger, routingPlanId, notifyApiBaseUrl, notifySecrets, data, messages)
84+
const config: NotifyConfig = {
85+
routingPlanId,
86+
notifyApiBaseUrl,
87+
notifySecrets
88+
}
89+
return await makeRealNotifyRequest(logger, config, data, messages)
7990
}
8091
}
8192

@@ -120,18 +131,15 @@ async function makeFakeNotifyRequest(
120131
* Handles splitting large batches into smaller ones as needed.
121132
*
122133
* @param logger - AWS logging object
123-
* @param routingPlanId - The Notify routing plan ID with which to process the data
124-
* @param notifyBaseUrl - The base URL for the Notify endpoint to use
134+
* @param config - configuration for talking to NHS Notify
125135
* @param data - PSU SQS messages to process
126136
* @param messages - The data being sent to NHS Notify
127137
* @param bearerToken - lazy initialised Bearer token to communicate with Notify
128138
* @param axiosInstance - lazy initialised HTTP client
129139
*/
130140
export async function makeRealNotifyRequest(
131141
logger: Logger,
132-
routingPlanId: string,
133-
notifyBaseUrl: string,
134-
notifySecrets: NotifySecrets,
142+
config: NotifyConfig,
135143
data: Array<NotifyDataItemMessage>,
136144
messages: Array<MessageBatchItem>,
137145
bearerToken?: string,
@@ -145,16 +153,16 @@ export async function makeRealNotifyRequest(
145153
data: {
146154
type: "MessageBatch" as const,
147155
attributes: {
148-
routingPlanId,
156+
routingPlanId: config.routingPlanId,
149157
messageBatchReference,
150158
messages
151159
}
152160
}
153161
}
154162

155163
// Lazily get the bearer token and axios instance, so we only do it once even if we recurse
156-
axiosInstance ??= setupAxios(logger, notifyBaseUrl)
157-
bearerToken ??= await tokenExchange(logger, axiosInstance, notifyBaseUrl, notifySecrets)
164+
axiosInstance ??= setupAxios(logger, config.notifyApiBaseUrl)
165+
bearerToken ??= await tokenExchange(logger, axiosInstance, config.notifyApiBaseUrl, config.notifySecrets)
158166

159167
// Recursive split if too large
160168
if (messages.length >= NOTIFY_REQUEST_MAX_ITEMS || estimateSize(body) > NOTIFY_REQUEST_MAX_BYTES) {
@@ -168,16 +176,16 @@ export async function makeRealNotifyRequest(
168176
// send both halves in parallel
169177
const [res1, res2] = await Promise.all([
170178
makeRealNotifyRequest(
171-
logger, routingPlanId, notifyBaseUrl, notifySecrets, data, firstHalf, bearerToken, axiosInstance
179+
logger, config, data, firstHalf, bearerToken, axiosInstance
172180
),
173181
makeRealNotifyRequest(
174-
logger, routingPlanId, notifyBaseUrl, notifySecrets, data, secondHalf, bearerToken, axiosInstance
182+
logger, config, data, secondHalf, bearerToken, axiosInstance
175183
)
176184
])
177185
return [...res1, ...res2]
178186
}
179187

180-
logger.info("Making a request for notifications to NHS notify", {count: messages.length, routingPlanId})
188+
logger.info("Request notifications of NHS notify", {count: messages.length, routingPlanId: config.routingPlanId})
181189

182190
try {
183191
const headers = {

packages/nhsNotifyLambda/tests/testUtils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,11 +795,11 @@ describe("NHS notify lambda helper functions", () => {
795795

796796
// Two calls
797797
expect(infoSpy).toHaveBeenCalledWith(
798-
"Making a request for notifications to NHS notify",
798+
expect.anything(), // not a reporting msg
799799
{count: 3, routingPlanId: "plan-large"}
800800
)
801801
expect(infoSpy).toHaveBeenCalledWith(
802-
"Making a request for notifications to NHS notify",
802+
expect.anything(), // not a reporting msg
803803
{count: 4, routingPlanId: "plan-large"}
804804
)
805805
})

0 commit comments

Comments
 (0)