/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use super::*;
use url::Url;
use viaduct::{Headers, Method, Response};
const SAMPLE_RESPONSE: &str = r#"{
"suggestions": [
{
"title": "Wikipedia - Apple Inc.",
"url": "https://en.wikipedia.org/wiki/Apple_Inc.",
"provider": "wikipedia",
"is_sponsored": false,
"score": 0.23,
"icon": "https://merino-images.services.mozilla.com/favicons/4c8bf96d667fa2e9f072bdd8e9f25c8ba6ba2ad55df1af7d9ea0dd575c12abee_1313.png",
"categories": [6],
"full_keyword": "apple",
"advertiser": "dynamic-wikipedia",
"block_id": 0
}
],
"request_id": "938abd549272454c8fc7b8615b57d34a",
"client_variants": [],
"server_variants": []
}"#;
fn make_response(status: u16, body: &str) -> Response {
Response {
request_method: Method::Get,
url: Url::parse("https://merino.services.mozilla.com/api/v1/suggest").unwrap(),
status,
headers: Headers::new(),
body: body.as_bytes().to_vec(),
}
}
fn default_options() -> SuggestOptions {
SuggestOptions {
providers: None,
source: None,
country: None,
region: None,
city: None,
client_variants: None,
request_type: None,
accept_language: None,
}
}
struct FakeHttpClientSuccess;
impl http::HttpClientTrait for FakeHttpClientSuccess {
fn make_suggest_request(
&self,
_query: &str,
_options: http::SuggestQueryParams<'_>,
_endpoint_url: Url,
) -> Result