Skip to content

Commit 253192c

Browse files
committed
Change times route-matching to be case-insensitive
While this applied with BLUE already it’s now a lot more widespread.
1 parent dd6bc39 commit 253192c

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/commands/times.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ pub async fn handle_times_request(
6363
_ => panic!("Unexpected type parsing route number"),
6464
};
6565

66-
if !command.routes.is_empty() && !command.routes.contains(route_number) {
66+
if !command.routes.is_empty()
67+
&& !command
68+
.routes
69+
.iter()
70+
.any(|r| r.eq_ignore_ascii_case(route_number))
71+
{
6772
continue;
6873
}
6974

tests/times.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,49 @@ async fn stop_number_returns_single_route_stop_schedule_to_approved_number(db: P
198198
);
199199
}
200200

201+
#[sqlx::test(fixtures("numbers-approved"))]
202+
async fn stop_number_returns_single_route_ignoring_case(db: PgPool) {
203+
let mock_winnipeg_transit_api = MockServer::start().await;
204+
let mock_stop_schedule_response = fs::read_to_string("tests/fixtures/times/stop_schedule.json")
205+
.expect("Failed to read stop schedule fixture");
206+
207+
Mock::given(method("GET"))
208+
.and(path_regex(r"^/v4/stops/.*/schedule.json$"))
209+
.respond_with(
210+
ResponseTemplate::new(200).set_body_string(mock_stop_schedule_response.clone()),
211+
)
212+
.expect(1)
213+
.mount(&mock_winnipeg_transit_api)
214+
.await;
215+
216+
let response = get(
217+
"/twilio?Body=10619 blue&From=approved&To=textabus&MessageSid=SM1849",
218+
InjectableServices {
219+
db: db.clone(),
220+
twilio_address: None,
221+
winnipeg_transit_api_address: Some(mock_winnipeg_transit_api.uri()),
222+
},
223+
)
224+
.await
225+
.expect("Failed to execute request");
226+
227+
assert!(response.status().is_success());
228+
assert_eq!(response.headers()["content-type"], "text/xml");
229+
230+
let document = Document::from(response.text().await.unwrap().as_str());
231+
let body = &document.find(Name("body")).next().unwrap().text();
232+
233+
let expected_body = indoc! {"
234+
10619 WB Graham@Vaughan (The Bay)
235+
12:19p BLUE Downtown (8min late)
236+
12:22p BLUE Downtown
237+
12:33p BLUE Downtown
238+
12:45p BLUE Downtown
239+
"};
240+
241+
assert_that(body).contains(expected_body);
242+
}
243+
201244
#[sqlx::test(fixtures("numbers-approved"))]
202245
async fn incorrect_stop_number_returns_error(db: PgPool) {
203246
let mock_winnipeg_transit_api = MockServer::start().await;

0 commit comments

Comments
 (0)