Skip to content

Commit 365558e

Browse files
added more validity checks
1 parent 0a26a23 commit 365558e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

internal/datastore/src/supplier-config-repository.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,18 @@ export class SupplierConfigRepository {
110110
TableName: this.config.supplierConfigTableName,
111111
IndexName: "packSpecificationId-index",
112112
KeyConditionExpression: "#pk = :pk AND #packSpecId = :packSpecId",
113+
FilterExpression: "#status = :status AND #approval = :approval",
113114
ExpressionAttributeNames: {
114115
"#pk": "PK",
115116
"#packSpecId": "packSpecificationId",
117+
"#status": "status",
118+
"#approval": "approval",
116119
},
117120
ExpressionAttributeValues: {
118121
":pk": "SUPPLIER_PACK",
119122
":packSpecId": packSpecId,
123+
":status": "PROD",
124+
":approval": "APPROVED",
120125
},
121126
}),
122127
);

lambdas/supplier-allocator/src/services/__tests__/supplier-config.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,11 @@ describe("supplier-config service", () => {
419419

420420
describe("getPackSpecification", () => {
421421
it("returns pack specification when found", async () => {
422-
const packSpec = { id: "spec1", name: "Pack Spec 1" } as any;
422+
const packSpec = {
423+
id: "spec1",
424+
name: "Pack Spec 1",
425+
status: "PROD",
426+
} as any;
423427
const deps = makeDeps();
424428
deps.supplierConfigRepo.getPackSpecification = jest
425429
.fn()
@@ -429,6 +433,29 @@ describe("supplier-config service", () => {
429433

430434
expect(result).toBe(packSpec);
431435
});
436+
437+
it("throws when pack specification is not active based on status", async () => {
438+
const packSpec = {
439+
id: "spec2",
440+
name: "Pack Spec 2",
441+
status: "DRAFT",
442+
} as any;
443+
const deps = makeDeps();
444+
deps.supplierConfigRepo.getPackSpecification = jest
445+
.fn()
446+
.mockResolvedValue(packSpec);
447+
448+
await expect(getPackSpecification("spec2", deps)).rejects.toThrow(
449+
/not active/,
450+
);
451+
expect(deps.logger.error).toHaveBeenCalledWith(
452+
expect.objectContaining({
453+
description: "Pack specification is not active based on status",
454+
packSpecId: "spec2",
455+
status: "DRAFT",
456+
}),
457+
);
458+
});
432459
});
433460

434461
describe("getSuppliersWithValidPack", () => {

lambdas/supplier-allocator/src/services/supplier-config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ export async function getPackSpecification(
154154
): Promise<PackSpecification> {
155155
const packSpec =
156156
await deps.supplierConfigRepo.getPackSpecification(packSpecId);
157+
if (packSpec.status !== "PROD") {
158+
deps.logger.error({
159+
description: "Pack specification is not active based on status",
160+
packSpecId,
161+
status: packSpec.status,
162+
});
163+
throw new Error(`Pack specification with id ${packSpecId} is not active`);
164+
}
157165
return packSpec;
158166
}
159167

0 commit comments

Comments
 (0)