Skip to content

Commit 557a4e8

Browse files
fix dates
1 parent c9c59eb commit 557a4e8

2 files changed

Lines changed: 24 additions & 8 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: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ export async function getVolumeGroupDetails(
2222
const groupDetails: VolumeGroup =
2323
await deps.supplierConfigRepo.getVolumeGroup(groupId);
2424

25-
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-
});
25+
const startOfDay = new Date();
26+
startOfDay.setHours(0, 0, 0, 0);
27+
const endOfDay = new Date();
28+
endOfDay.setHours(23, 59, 59, 999);
29+
3130
if (
3231
groupDetails.status === "PROD" &&
33-
new Date(groupDetails.startDate) <= new Date() &&
34-
(!groupDetails.endDate || new Date(groupDetails.endDate) >= new Date())
32+
new Date(groupDetails.startDate) < endOfDay &&
33+
(!groupDetails.endDate || new Date(groupDetails.endDate) > startOfDay)
3534
) {
3635
return groupDetails;
3736
}

0 commit comments

Comments
 (0)