Skip to content

Commit 87fd5fb

Browse files
fix dates
1 parent c9c59eb commit 87fd5fb

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ describe("supplier-config service", () => {
122122
);
123123
expect(deps.logger.error).toHaveBeenCalled();
124124
});
125+
it("returns group details when start date and end date are both today", async () => {
126+
const today = new Date().toISOString();
127+
const group = {
128+
id: "g4",
129+
status: "PROD",
130+
startDate: today,
131+
endDate: today,
132+
} as any;
133+
const deps = makeDeps();
134+
deps.supplierConfigRepo.getVolumeGroup = jest
135+
.fn()
136+
.mockResolvedValue(group);
137+
138+
const result = await getVolumeGroupDetails("g4", deps);
139+
140+
expect(result).toBe(group);
141+
});
125142
});
126143

127144
describe("getSupplierAllocationsForVolumeGroup", () => {

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,24 @@ export async function getVolumeGroupDetails(
2222
const groupDetails: VolumeGroup =
2323
await deps.supplierConfigRepo.getVolumeGroup(groupId);
2424

25+
const startOfDay = new Date();
26+
startOfDay.setHours(0, 0, 0, 0);
27+
const endOfDay = new Date();
28+
endOfDay.setHours(23, 59, 59, 999);
2529
deps.logger.info({
26-
description: "Comparing dates for volume group",
27-
startdate: new Date(groupDetails.startDate),
28-
endDate: groupDetails.endDate ? new Date(groupDetails.endDate) : null,
29-
currentDate: new Date(),
30+
description: "Checking if volume group is active based on status and dates",
31+
groupId,
32+
status: groupDetails.status,
33+
startDate: groupDetails.startDate,
34+
endDate: groupDetails.endDate,
35+
startOfDay: startOfDay.toISOString(),
36+
endOfDay: endOfDay.toISOString(),
3037
});
38+
3139
if (
3240
groupDetails.status === "PROD" &&
33-
new Date(groupDetails.startDate) <= new Date() &&
34-
(!groupDetails.endDate || new Date(groupDetails.endDate) >= new Date())
41+
new Date(groupDetails.startDate) < endOfDay &&
42+
(!groupDetails.endDate || new Date(groupDetails.endDate) >= startOfDay)
3543
) {
3644
return groupDetails;
3745
}

0 commit comments

Comments
 (0)