Skip to content

Commit e65f17b

Browse files
committed
console.log the metric to be picked up
1 parent b47ebbd commit e65f17b

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

lambdas/authorizer/src/__tests__/index.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ describe("Authorizer Lambda Function", () => {
5656
});
5757

5858
describe("Certificate expiry check", () => {
59+
let consoleLogSpy: jest.SpyInstance;
60+
5961
beforeEach(() => {
6062
jest
6163
.useFakeTimers({ doNotFake: ["nextTick"] })
6264
.setSystemTime(new Date("2025-11-03T14:19:00Z"));
65+
consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
6366
});
6467

6568
afterEach(() => {
6669
jest.useRealTimers();
70+
consoleLogSpy.mockRestore();
6771
});
6872

6973
it("Should not log CloudWatch metric when certificate is null", async () => {
@@ -73,10 +77,7 @@ describe("Authorizer Lambda Function", () => {
7377
handler(mockEvent, mockContext, mockCallback);
7478
await new Promise(process.nextTick);
7579

76-
const mockedInfo = mockedDeps.logger.info as jest.Mock;
77-
expect(mockedInfo.mock.calls).not.toContainEqual(
78-
expect.stringContaining("CloudWatchMetrics"),
79-
);
80+
expect(consoleLogSpy).not.toHaveBeenCalled();
8081
});
8182

8283
it("Should log CloudWatch metric when the certificate expiry threshold is reached", async () => {
@@ -88,8 +89,7 @@ describe("Authorizer Lambda Function", () => {
8889
handler(mockEvent, mockContext, mockCallback);
8990
await new Promise(process.nextTick);
9091

91-
const mockedInfo = mockedDeps.logger.info as jest.Mock;
92-
expect(mockedInfo.mock.calls.map((call) => call[0])).toContain(
92+
expect(consoleLogSpy).toHaveBeenCalledWith(
9393
JSON.stringify({
9494
_aws: {
9595
Timestamp: 1_762_179_540_000,
@@ -123,10 +123,7 @@ describe("Authorizer Lambda Function", () => {
123123
handler(mockEvent, mockContext, mockCallback);
124124
await new Promise(process.nextTick);
125125

126-
const mockedInfo = mockedDeps.logger.info as jest.Mock;
127-
expect(mockedInfo.mock.calls).not.toContainEqual(
128-
expect.stringContaining("CloudWatchMetrics"),
129-
);
126+
expect(consoleLogSpy).not.toHaveBeenCalled();
130127
});
131128
});
132129

lambdas/authorizer/src/authorizer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,8 @@ async function checkCertificateExpiry(
146146
const expiry = getCertificateExpiryInDays(certificate);
147147

148148
if (expiry <= deps.env.CLIENT_CERTIFICATE_EXPIRATION_ALERT_DAYS) {
149-
deps.logger.info(
150-
JSON.stringify(
151-
buildCloudWatchMetric(deps.env.CLOUDWATCH_NAMESPACE, certificate),
152-
),
153-
);
149+
let metric = buildCloudWatchMetric(deps.env.CLOUDWATCH_NAMESPACE, certificate);
150+
deps.logger.warn(metric, `APIM Certificated expiry in ${expiry} days`);
151+
console.log(JSON.stringify(metric));
154152
}
155153
}

0 commit comments

Comments
 (0)