Skip to content

Commit

Permalink
feat(filter): add filtering bike stations by hasAvailableDocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Alises committed Nov 14, 2020
1 parent 6ee0c84 commit f0ad193
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,5 @@ input OnlyFilterByInputBike {
hasAvailableBikes: Boolean
hasAvailableElectricalBikes: Boolean
isInService: Boolean
hasAvailableDocks: Boolean
}
47 changes: 47 additions & 0 deletions src/datasources/__fixtures__/BikeStationsFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export const mockBikeStationsInfoAPIResponse: any = {
capacity: 21,
nearby_distance: 1000.0,
},
{
station_id: 5,
name: "PG. LLUIS COMPANYS, 11 (ARC TRIOMF)",
physical_configuration: "ELECTRICBIKESTATION",
lat: 41.3911035,
lon: 2.1801763,
altitude: 7.0,
address: "PG. LLUIS COMPANYS, 11 (ARC TRIOMF)",
post_code: "08018",
capacity: 39,
nearby_distance: 1000.0,
},
],
},
};
Expand Down Expand Up @@ -120,6 +132,21 @@ export const mockBikeStationsStatusAPIResponse: any = {
is_renting: 1,
is_returning: 1,
},
{
station_id: 5,
num_bikes_available: 37,
num_bikes_available_types: {
mechanical: 37,
ebike: 0,
},
num_docks_available: 0,
last_reported: 1605388149,
is_charging_station: true,
status: "IN_SERVICE",
is_installed: 1,
is_renting: 1,
is_returning: 1,
},
],
},
};
Expand Down Expand Up @@ -205,4 +232,24 @@ export const mockBikeStationsResponse: any = [
name: "C/ RIBES, 13",
status: "MAINTENANCE",
},
{
available: {
bikes: {
electrical: 0,
mechanical: 37,
total: 37,
},
docks: 0,
},
capacity: 39,
id: "5",
lastUpdated: 1605388149,
location: {
altitude: 7,
latitude: 41.3911035,
longitude: 2.1801763,
},
name: "PG. LLUIS COMPANYS, 11 (ARC TRIOMF)",
status: "IN_SERVICE",
},
];
3 changes: 3 additions & 0 deletions src/inputs/FilterByInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const FilterByInputBike = new GraphQLInputObjectType({
isInService: {
type: GraphQLBoolean,
},
hasAvailableDocks: {
type: GraphQLBoolean,
},
},
}),
},
Expand Down
4 changes: 4 additions & 0 deletions src/queries/BikeStationsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const filterBikeStations = (
return Number(station?.available?.bikes?.electrical ?? null) > 0;
}

if (only?.hasAvailableDocks) {
return Number(station?.available?.docks ?? null) > 0;
}

if (only?.isInService) {
return station?.status === "IN_SERVICE";
}
Expand Down
14 changes: 14 additions & 0 deletions src/queries/__tests__/BikeStationsQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ describe("bikeStations Query", () => {
expect(returnedStationWithNoElectricalBikes).toBeNull();
});

it("Fetches list of bike stations with available docks", async () => {
const res = await query({
query: GET_BIKE_STATIONS,
variables: { filterBy: { only: { hasAvailableDocks: true } } },
});

//There is no station returned that has no docks
const returnedStationWithNoDocks =
res?.data?.bikeStations.stations.edges.find(
({ node }) => node.available.docs === 0
) ?? null;

expect(returnedStationWithNoDocks).toBeNull();
});
it("Fetches list of bike stations that are in service ", async () => {
const res = await query({
query: GET_BIKE_STATIONS,
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,5 @@ export type OnlyFilterByInputBike = {
hasAvailableBikes?: Maybe<Scalars['Boolean']>;
hasAvailableElectricalBikes?: Maybe<Scalars['Boolean']>;
isInService?: Maybe<Scalars['Boolean']>;
hasAvailableDocks?: Maybe<Scalars['Boolean']>;
};

0 comments on commit f0ad193

Please sign in to comment.