Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/merino/src/worldcup/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct WorldCupQueryParams {
pub limit: Option<u32>,
pub teams: Option<String>,
pub accept_language: Option<String>,
pub date: Option<String>,
}

pub trait HttpClientTrait {
Expand All @@ -27,7 +28,7 @@ impl HttpClientTrait for HttpClient {
}

pub fn build_url(endpoint_url: Url, params: &WorldCupQueryParams) -> Url {
if params.limit.is_none() && params.teams.is_none() {
if params.limit.is_none() && params.teams.is_none() && params.date.is_none() {
return endpoint_url;
}
let mut url = endpoint_url;
Expand All @@ -39,6 +40,9 @@ pub fn build_url(endpoint_url: Url, params: &WorldCupQueryParams) -> Url {
if let Some(v) = &params.teams {
pairs.append_pair("teams", v);
}
if let Some(v) = &params.date {
pairs.append_pair("date", v);
}
}
url
}
Expand Down Expand Up @@ -112,6 +116,7 @@ mod tests {
limit: Some(5),
teams: Some("FRA,ENG".to_string()),
accept_language: Some("en-GB".to_string()),
date: None,
};
let url = build_url(base_url(), &options);
assert!(has_param(&url, "limit", "5"));
Expand All @@ -131,6 +136,7 @@ mod tests {
limit: Some(3),
teams: Some("FRA".to_string()),
accept_language: Some("en-US".to_string()),
date: None,
};
let url = build_url(base_url(), &options);
assert_eq!(
Expand Down
1 change: 1 addition & 0 deletions components/merino/src/worldcup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl<T: http::HttpClientTrait> WorldCupClientInner<T> {
limit: options.limit,
teams,
accept_language: options.accept_language,
date: options.date,
}
}

Expand Down
2 changes: 2 additions & 0 deletions components/merino/src/worldcup/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ pub struct WorldCupOptions {
pub teams: Option<Vec<String>>,
/// Language for results (e.g. `"en-US"`). (Not supported yet)
pub accept_language: Option<String>,
/// ISO 8601 date string to filter matches by date (e.g. `"2026-06-14"`).
pub date: Option<String>,
}
25 changes: 25 additions & 0 deletions components/merino/src/worldcup/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn default_options() -> WorldCupOptions {
limit: None,
teams: None,
accept_language: None,
date: None,
}
}

Expand Down Expand Up @@ -162,6 +163,7 @@ fn test_accept_language_is_passed_as_header() {
limit: None,
teams: None,
accept_language: Some("en-US".to_string()),
date: None,
},
);
let response = result.unwrap().unwrap();
Expand Down Expand Up @@ -212,6 +214,7 @@ fn test_matches_endpoint_url_with_limit() {
limit: Some(2),
teams: None,
accept_language: None,
date: None,
},
);
let captured = captured_url.lock().unwrap();
Expand Down Expand Up @@ -246,3 +249,25 @@ fn test_builder_fails_with_invalid_base_host() {
Ok(_) => panic!("Expected error for invalid base_host"),
}
}

#[test]
fn test_matches_endpoint_url_with_date() {
let captured_url = std::sync::Arc::new(std::sync::Mutex::new(None::<Url>));
let client_inner = WorldCupClientInner::new_with_client(FakeCapturingClient {
captured_url: captured_url.clone(),
});
let _ = client_inner.make_request(
base_url().join("matches").unwrap(),
WorldCupOptions {
limit: None,
teams: None,
accept_language: None,
date: Some("2026-06-14".to_string()),
},
);
let captured = captured_url.lock().unwrap();
assert_eq!(
captured.as_ref().unwrap().as_str(),
"https://merino.services.mozilla.com/api/v1/wcs/matches?date=2026-06-14"
);
}
5 changes: 5 additions & 0 deletions examples/merino-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ enum Commands {
/// Language for results (e.g. "en-US")
#[arg(long)]
accept_language: Option<String>,
/// Date to filter matches by, in `YYYY-MM-DD` format (e.g. "2026-06-14")
#[arg(long)]
date: Option<String>,

#[command(subcommand)]
endpoint: WorldCupEndpoint,
Expand Down Expand Up @@ -182,6 +185,7 @@ fn main() -> Result<()> {
limit,
teams,
accept_language,
date,
endpoint,
} => {
let client = WorldCupClient::new(WorldCupConfig {
Expand All @@ -191,6 +195,7 @@ fn main() -> Result<()> {
limit,
teams,
accept_language,
date,
};
let result = match endpoint {
WorldCupEndpoint::Teams => client.get_teams(options),
Expand Down