mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add functionality to normalize the spots available if over capacity
This commit is contained in:
@@ -48,7 +48,7 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository
|
||||
}
|
||||
}
|
||||
|
||||
private constructIParkingStructureFromJson(jsonStructure: any) {
|
||||
public constructIParkingStructureFromJson(jsonStructure: any) {
|
||||
const structureToReturn: IParkingStructure = {
|
||||
capacity: jsonStructure.Capacity,
|
||||
coordinates: {
|
||||
@@ -57,7 +57,7 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository
|
||||
},
|
||||
id: ChapmanApiBasedParkingRepositoryLoader.generateId(jsonStructure.Address),
|
||||
name: jsonStructure.Name,
|
||||
spotsAvailable: jsonStructure.CurrentCount,
|
||||
spotsAvailable: jsonStructure.CurrentCount > jsonStructure.Capacity ? jsonStructure.Capacity : jsonStructure.CurrentCount,
|
||||
address: jsonStructure.Address
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,6 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe("fetchAndUpdateParkingStructures", () => {
|
||||
it("fetches and update parking structures with unique IDs", async () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user