add functionality to normalize the spots available if over capacity

This commit is contained in:
2025-04-16 17:18:48 -07:00
parent 658222b91a
commit 02e440773a
2 changed files with 18 additions and 4 deletions

View File

@@ -48,7 +48,7 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository
} }
} }
private constructIParkingStructureFromJson(jsonStructure: any) { public constructIParkingStructureFromJson(jsonStructure: any) {
const structureToReturn: IParkingStructure = { const structureToReturn: IParkingStructure = {
capacity: jsonStructure.Capacity, capacity: jsonStructure.Capacity,
coordinates: { coordinates: {
@@ -57,7 +57,7 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository
}, },
id: ChapmanApiBasedParkingRepositoryLoader.generateId(jsonStructure.Address), id: ChapmanApiBasedParkingRepositoryLoader.generateId(jsonStructure.Address),
name: jsonStructure.Name, name: jsonStructure.Name,
spotsAvailable: jsonStructure.CurrentCount, spotsAvailable: jsonStructure.CurrentCount > jsonStructure.Capacity ? jsonStructure.Capacity : jsonStructure.CurrentCount,
address: jsonStructure.Address address: jsonStructure.Address
} }

View File

@@ -42,8 +42,6 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => {
}); });
}); });
describe("fetchAndUpdateParkingStructures", () => { describe("fetchAndUpdateParkingStructures", () => {
it("fetches and update parking structures with unique IDs", async () => { it("fetches and update parking structures with unique IDs", async () => {
updateGlobalFetchMockJson(chapmanParkingStructureData); updateGlobalFetchMockJson(chapmanParkingStructureData);
@@ -89,4 +87,20 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => {
}); });
}) })
}); });
describe("constructIParkingStructureFromJson", () => {
it("normalizes the spots available if it's over the capacity", async () => {
const sampleJsonStructure: any = {
Capacity: 10,
Latitude: 1,
Longitude: 1,
Address: "300 E Walnut, Orange, CA 92867",
Name: "Anderson Structure",
CurrentCount: 11,
};
const returnedStructure = loader.constructIParkingStructureFromJson(sampleJsonStructure);
expect(returnedStructure.spotsAvailable).toEqual(returnedStructure.capacity);
});
});
}); });