Skip to content

Commit 4c872e6

Browse files
Make the bin/validate script generic
Ensure it works for the current server, whatever that might be, and also add support for the arrivals-and-departures-for-stop endpoint
1 parent 1411ab1 commit 4c872e6

File tree

1 file changed

+58
-23
lines changed

1 file changed

+58
-23
lines changed

bin/validate.sh

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,82 @@ else
99
exit 1
1010
fi
1111

12-
output=$(curl -s "http://localhost:8080/api/where/agencies-with-coverage.json?key=test" | jq '.data.list[0].agencyId')
12+
# Get the first agency from agencies-with-coverage
13+
agency_response=$(curl -s "http://localhost:8080/api/where/agencies-with-coverage.json?key=test")
14+
agency_count=$(echo "$agency_response" | jq '.data.list | length')
1315

14-
if [[ ! -z "$output" && "$output" == "\"unitrans\"" ]]; then
15-
echo "agencies-with-coverage.json endpoint works."
16+
if [[ "$agency_count" -gt 0 ]]; then
17+
echo "agencies-with-coverage.json endpoint works (found $agency_count agencies)."
18+
AGENCY_ID=$(echo "$agency_response" | jq -r '.data.list[0].agencyId')
19+
echo "Using agency: $AGENCY_ID"
1620
else
17-
echo "Error: agencies-with-coverage.json endpoint is not working: $output"
21+
echo "Error: agencies-with-coverage.json endpoint is not working or no agencies found: $agency_count"
1822
exit 1
1923
fi
2024

21-
output=$(curl -s "http://localhost:8080/api/where/routes-for-agency/unitrans.json?key=test" | jq '.data.list | length')
22-
if [[ $output -gt 10 ]]; then
23-
echo "routes-for-agency/unitrans.json endpoint works."
25+
# Get routes for the agency
26+
routes_response=$(curl -s "http://localhost:8080/api/where/routes-for-agency/${AGENCY_ID}.json?key=test")
27+
route_count=$(echo "$routes_response" | jq '.data.list | length')
28+
if [[ "$route_count" -gt 0 ]]; then
29+
echo "routes-for-agency/${AGENCY_ID}.json endpoint works (found $route_count routes)."
30+
ROUTE_ID=$(echo "$routes_response" | jq -r '.data.list[0].id')
31+
echo "Using route: $ROUTE_ID"
2432
else
25-
echo "Error: routes-for-agency/unitrans.json is not working: $output"
33+
echo "Error: routes-for-agency/${AGENCY_ID}.json is not working or no routes found: $route_count"
2634
exit 1
2735
fi
2836

29-
output=$(curl -s "http://localhost:8080/api/where/stops-for-route/unitrans_C.json?key=test" | jq '.data.entry.routeId')
30-
if [[ ! -z "$output" && "$output" == "\"unitrans_C\"" ]]; then
31-
echo "stops-for-route/unitrans_C.json endpoint works."
37+
# Get stops for the route
38+
stops_response=$(curl -s "http://localhost:8080/api/where/stops-for-route/${ROUTE_ID}.json?key=test")
39+
route_id_check=$(echo "$stops_response" | jq -r '.data.entry.routeId')
40+
if [[ ! -z "$route_id_check" && "$route_id_check" == "$ROUTE_ID" ]]; then
41+
echo "stops-for-route/${ROUTE_ID}.json endpoint works."
42+
STOP_ID=$(echo "$stops_response" | jq -r '.data.entry.stopIds[0]')
43+
echo "Using stop: $STOP_ID"
3244
else
33-
echo "Error: stops-for-route/unitrans_C.json endpoint is not working: $output"
45+
echo "Error: stops-for-route/${ROUTE_ID}.json endpoint is not working: $route_id_check"
3446
exit 1
3547
fi
3648

37-
output=$(curl -s "http://localhost:8080/api/where/stop/unitrans_22182.json?key=test" | jq '.data.entry.code')
38-
if [[ ! -z "$output" && "$output" == "\"22182\"" ]]; then
39-
echo "stop/unitrans_22182.json endpoint works."
49+
# Get stop details
50+
stop_response=$(curl -s "http://localhost:8080/api/where/stop/${STOP_ID}.json?key=test")
51+
stop_id_check=$(echo "$stop_response" | jq -r '.data.entry.id')
52+
if [[ ! -z "$stop_id_check" && "$stop_id_check" == "$STOP_ID" ]]; then
53+
echo "stop/${STOP_ID}.json endpoint works."
54+
# Extract coordinates for stops-for-location test
55+
STOP_LAT=$(echo "$stop_response" | jq -r '.data.entry.lat')
56+
STOP_LON=$(echo "$stop_response" | jq -r '.data.entry.lon')
57+
echo "Using coordinates: $STOP_LAT, $STOP_LON"
4058
else
41-
echo "Error: stop/unitrans_22182.json endpoint is not working: $output"
59+
echo "Error: stop/${STOP_ID}.json endpoint is not working: $stop_id_check"
4260
exit 1
4361
fi
4462

45-
output=$(curl -s "http://localhost:8080/api/where/stops-for-location.json?lat=38.555308&lon=-121.735991&key=test" | jq '.data.outOfRange')
46-
if [[ ! -z "$output" && "$output" == "false" ]]; then
47-
echo "stops-for-location/unitrans_false.json endpoint works."
63+
# Test stops-for-location using coordinates from the stop
64+
LOCATION_URL="http://localhost:8080/api/where/stops-for-location.json?lat=${STOP_LAT}&lon=${STOP_LON}&key=test"
65+
location_response=$(curl -s "$LOCATION_URL")
66+
out_of_range=$(echo "$location_response" | jq '.data.outOfRange')
67+
stops_found=$(echo "$location_response" | jq '.data.list | length')
68+
if [[ ! -z "$out_of_range" && "$out_of_range" == "false" && "$stops_found" -gt 0 ]]; then
69+
echo "stops-for-location.json endpoint works (found $stops_found stops)."
4870
else
49-
echo "Error: stops-for-location/unitrans_false.json endpoint is not working: $output"
71+
echo "Error: stops-for-location.json endpoint is not working: outOfRange=$out_of_range, stops=$stops_found"
72+
echo "URL: $LOCATION_URL"
73+
echo "Response: $location_response"
5074
exit 1
5175
fi
5276

53-
# todo: add support for arrivals-and-departures-for-stop endpoint.
54-
# however, it doesn't seem that the unitrans_22182 stop has arrivals and departures on the weekend, so we'll need
55-
# something else to test with. However, for now, this is still a great step forward.
77+
# Test arrivals-and-departures-for-stop endpoint
78+
arrivals_response=$(curl -s "http://localhost:8080/api/where/arrivals-and-departures-for-stop/${STOP_ID}.json?key=test")
79+
arrivals_stop_id=$(echo "$arrivals_response" | jq -r '.data.entry.stopId')
80+
arrivals_count=$(echo "$arrivals_response" | jq '.data.entry.arrivalsAndDepartures | length // 0')
81+
82+
if [[ "$arrivals_stop_id" == "$STOP_ID" ]]; then
83+
if [[ "$arrivals_count" -gt 0 ]]; then
84+
echo "arrivals-and-departures-for-stop/${STOP_ID}.json endpoint works (found $arrivals_count arrivals/departures)."
85+
else
86+
echo "arrivals-and-departures-for-stop/${STOP_ID}.json endpoint works but no arrivals/departures at this time."
87+
fi
88+
else
89+
echo "Warning: arrivals-and-departures-for-stop/${STOP_ID}.json endpoint may not be working correctly."
90+
fi

0 commit comments

Comments
 (0)