Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module "client_transform_filter_lambda" {
log_subscription_role_arn = local.acct.log_subscription_role_arn

lambda_env_vars = {
CLIENT_SUBSCRIPTION_CONFIG_BUCKET = module.client_config_bucket.id
CLIENT_SUBSCRIPTION_CONFIG_PREFIX = "client_subscriptions/"
CLIENT_SUBSCRIPTION_CACHE_TTL_SECONDS = "60"
}
}

Expand Down
7 changes: 5 additions & 2 deletions lambdas/client-transform-filter-lambda/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"dependencies": {
"esbuild": "^0.25.0"
"@aws-sdk/client-s3": "^3.821.0",
"pino": "^9.6.0",
"zod": "^4.1.13"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.2",
"@types/aws-lambda": "^8.10.148",
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.7",
"typescript": "^5.8.2"
"typescript": "^5.8.2",
"esbuild": "^0.25.0"
},
"name": "nhs-notify-client-transform-filter-lambda",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { resolveCacheTtlMs } from "..";

describe("cache ttl configuration", () => {
it("falls back to default TTL when invalid", () => {
const ttlMs = resolveCacheTtlMs({
CLIENT_SUBSCRIPTION_CACHE_TTL_SECONDS: "not-a-number",
} as NodeJS.ProcessEnv);

expect(ttlMs).toBe(60_000);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { resolveCacheTtlMs } from "..";

describe("cache ttl configuration", () => {
it("uses the configured TTL when valid", () => {
const ttlMs = resolveCacheTtlMs({
CLIENT_SUBSCRIPTION_CACHE_TTL_SECONDS: "120",
} as NodeJS.ProcessEnv);

expect(ttlMs).toBe(120_000);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* eslint-disable import-x/first */
// eslint-disable-next-line unicorn/no-useless-undefined
const mockLoadClientConfig = jest.fn().mockResolvedValue(undefined);
const mockConfigLoader = jest.fn().mockImplementation(() => ({
loadClientConfig: mockLoadClientConfig,
}));

jest.mock("services/config-loader", () => ({
ConfigLoader: mockConfigLoader,
}));

import { EventTypes } from "models/status-transition-event";
import { handler } from "..";

describe("config prefix resolution", () => {
beforeEach(() => {
mockLoadClientConfig.mockClear();
mockConfigLoader.mockClear();
});

it("uses the default prefix when env is not set", async () => {
const originalBucket = process.env.CLIENT_SUBSCRIPTION_CONFIG_BUCKET;
const originalPrefix = process.env.CLIENT_SUBSCRIPTION_CONFIG_PREFIX;

process.env.CLIENT_SUBSCRIPTION_CONFIG_BUCKET = "bucket";
delete process.env.CLIENT_SUBSCRIPTION_CONFIG_PREFIX;

const event = {
profileversion: "1.0",
profilepublished: "2025-01-01",
specversion: "1.0",
id: "event-id",
source: "source-a",
subject: "subject",
type: EventTypes.MESSAGE_STATUS_TRANSITIONED,
time: "2025-01-01T10:00:00Z",
recordedtime: "2025-01-01T10:00:00Z",
datacontenttype: "application/json",
dataschema: "schema",
severitynumber: 1,
severitytext: "INFO",
traceparent: "traceparent",
data: {
"notify-payload": {
"notify-data": {
messageId: "msg-123",
messageReference: "ref-123",
messageStatus: "DELIVERED",
channels: [],
timestamp: "2025-01-01T10:00:00Z",
routingPlan: {
id: "plan-id",
name: "plan-name",
version: "1",
createdDate: "2025-01-01T10:00:00Z",
},
clientId: "client-1",
},
"notify-metadata": {
teamResponsible: "Team 1",
notifyDomain: "Delivering",
microservice: "service",
repositoryUrl: "https://example.com/repo",
accountId: "account",
environment: "development",
instance: "instance",
microserviceInstanceId: "instance-id",
microserviceVersion: "1.0",
},
},
},
};

await handler(event);

expect(mockConfigLoader).toHaveBeenCalledWith(
expect.objectContaining({
keyPrefix: "client_subscriptions/",
}),
);

if (originalBucket === undefined) {
delete process.env.CLIENT_SUBSCRIPTION_CONFIG_BUCKET;
} else {
process.env.CLIENT_SUBSCRIPTION_CONFIG_BUCKET = originalBucket;
}

if (originalPrefix === undefined) {
delete process.env.CLIENT_SUBSCRIPTION_CONFIG_PREFIX;
} else {
process.env.CLIENT_SUBSCRIPTION_CONFIG_PREFIX = originalPrefix;
}
});
});
Loading
Loading