Source code

Revision control

Copy as Markdown

Other Tools

/* 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 std::collections::HashMap;
use url::Url;
use crate::mars::{
ad_request::{AdContentCategory, AdPlacementRequest, IABContentTaxonomy},
ad_response::{
AdCallbacks, AdImage, AdResponse, AdSpoc, AdTile, SpocFrequencyCaps, SpocRanking,
},
};
pub const TEST_CONTEXT_ID: &str = "00000000-0000-4000-8000-000000000001";
pub fn make_happy_placement_requests() -> Vec<AdPlacementRequest> {
vec![
AdPlacementRequest {
content: Some(AdContentCategory {
categories: vec!["entertainment".to_string()],
taxonomy: IABContentTaxonomy::IAB2_1,
}),
count: 1,
placement: "example_placement_1".to_string(),
},
AdPlacementRequest {
content: Some(AdContentCategory {
categories: vec!["entertainment".to_string()],
taxonomy: IABContentTaxonomy::IAB2_1,
}),
count: 1,
placement: "example_placement_2".to_string(),
},
]
}
pub fn get_example_happy_image_response() -> AdResponse<AdImage> {
let base_url = mockito::server_url();
AdResponse {
data: HashMap::from([
(
"example_placement_1".to_string(),
vec![AdImage {
format: "billboard".to_string(),
block_key: "abc123".into(),
alt_text: Some("An ad for a puppy".to_string()),
callbacks: AdCallbacks {
click: Url::parse(&format!("{}/click/example_ad_1", base_url)).unwrap(),
impression: Url::parse(&format!("{}/impression/example_ad_1", base_url))
.unwrap(),
report: Some(
Url::parse(&format!("{}/report/example_ad_1", base_url)).unwrap(),
),
},
}],
),
(
"example_placement_2".to_string(),
vec![AdImage {
format: "skyscraper".to_string(),
block_key: "abc123".into(),
alt_text: Some("An ad for a pet duck".to_string()),
callbacks: AdCallbacks {
click: Url::parse(&format!("{}/click/example_ad_2", base_url)).unwrap(),
impression: Url::parse(&format!("{}/impression/example_ad_2", base_url))
.unwrap(),
report: Some(
Url::parse(&format!("{}/report/example_ad_2", base_url)).unwrap(),
),
},
}],
),
]),
}
}
pub fn get_example_happy_spoc_response() -> AdResponse<AdSpoc> {
AdResponse {
data: HashMap::from([
(
"example_placement_1".to_string(),
vec![AdSpoc {
format: "spoc".to_string(),
block_key: "spoc123".into(),
title: "Example Spoc Title".to_string(),
excerpt: "This is an example spoc excerpt".to_string(),
domain: "example.com".to_string(),
sponsor: "Example Sponsor".to_string(),
sponsored_by_override: None,
caps: SpocFrequencyCaps {
cap_key: "spoc_cap_1".to_string(),
day: 7,
},
ranking: SpocRanking {
priority: 1,
personalization_models: Some(HashMap::from([("model1".to_string(), 10)])),
item_score: 0.85,
},
callbacks: AdCallbacks {
.unwrap(),
impression: Url::parse(
)
.unwrap(),
report: Some(
.unwrap(),
),
},
}],
),
(
"example_placement_2".to_string(),
vec![AdSpoc {
format: "spoc".to_string(),
block_key: "spoc456".into(),
title: "Another Spoc Title".to_string(),
excerpt: "This is another example spoc excerpt".to_string(),
domain: "another-example.com".to_string(),
sponsor: "Another Sponsor".to_string(),
sponsored_by_override: Some("Override Sponsor".to_string()),
caps: SpocFrequencyCaps {
cap_key: "spoc_cap_2".to_string(),
day: 14,
},
ranking: SpocRanking {
priority: 2,
personalization_models: None,
item_score: 0.75,
},
callbacks: AdCallbacks {
.unwrap(),
impression: Url::parse(
)
.unwrap(),
report: Some(
.unwrap(),
),
},
}],
),
]),
}
}
pub fn get_example_happy_uatile_response() -> AdResponse<AdTile> {
AdResponse {
data: HashMap::from([
(
"example_placement_1".to_string(),
vec![AdTile {
format: "uatile".to_string(),
block_key: "uatile123".into(),
name: "Example UA Tile".to_string(),
callbacks: AdCallbacks {
.unwrap(),
impression: Url::parse(
)
.unwrap(),
report: Some(
.unwrap(),
),
},
}],
),
(
"example_placement_2".to_string(),
vec![AdTile {
format: "uatile".to_string(),
block_key: "uatile456".into(),
name: "Another UA Tile".to_string(),
callbacks: AdCallbacks {
.unwrap(),
impression: Url::parse(
)
.unwrap(),
report: Some(
.unwrap(),
),
},
}],
),
]),
}
}