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
2 changes: 2 additions & 0 deletions core/main/src/firebolt/handlers/actions_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ mod tests {
context: DiscoveryContext {
source: "voice".to_string(),
age_policy: None,
profile_policy: None,
},
};
let response = ActionsIntentResponse {
Expand All @@ -134,6 +135,7 @@ mod tests {
context: DiscoveryContext {
source: "remote".to_string(),
age_policy: None,
profile_policy: None,
},
};
let original = ActionsIntentResponse {
Expand Down
2 changes: 2 additions & 0 deletions core/sdk/src/api/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ mod tests {
context: DiscoveryContext {
source: "test_source".to_string(),
age_policy: None,
profile_policy: None,
},
};

Expand Down Expand Up @@ -414,6 +415,7 @@ mod tests {
context: DiscoveryContext {
source: "voice".to_string(),
age_policy: None,
profile_policy: None,
},
};
let response = ActionsIntentResponse {
Expand Down
3 changes: 3 additions & 0 deletions core/sdk/src/api/device/entertainment_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ impl Default for HomeIntent {
context: DiscoveryContext {
source: "device".to_string(),
age_policy: None,
profile_policy: None,
},
}
}
Expand Down Expand Up @@ -1044,6 +1045,7 @@ impl Default for ProviderRequestIntent {
context: DiscoveryContext {
source: "device".to_string(),
age_policy: None,
profile_policy: None,
},
}
}
Expand Down Expand Up @@ -1096,6 +1098,7 @@ mod tests {
context: DiscoveryContext {
source: "xrn:firebolt:application:refui".to_owned(),
age_policy: None,
profile_policy: None,
},
});
let value = serde_json::to_string(&intent).unwrap();
Expand Down
39 changes: 39 additions & 0 deletions core/sdk/src/api/firebolt/fb_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ pub struct DiscoveryContext {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "agePolicy")]
pub age_policy: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "profilePolicy")]
pub profile_policy: Option<String>,
}

impl DiscoveryContext {
pub fn new(source: &str, age_policy: Option<String>) -> DiscoveryContext {
DiscoveryContext {
source: source.to_string(),
age_policy,
profile_policy: None,
}
}
}
Expand Down Expand Up @@ -90,6 +94,10 @@ impl AgePolicy {
AgePolicy::Adult => "app:adult",
}
}

pub fn is_child_or_teen(&self) -> bool {
matches!(self, AgePolicy::Child | AgePolicy::Teen)
Comment thread
Vinodsathyaseelan marked this conversation as resolved.
}
}

impl Serialize for AgePolicy {
Expand Down Expand Up @@ -472,6 +480,7 @@ mod tests {
let context = DiscoveryContext::new("test_source", None);
assert_eq!(context.source, "test_source");
assert_eq!(context.age_policy, None);
assert_eq!(context.profile_policy, None);
}

#[test]
Expand All @@ -480,6 +489,7 @@ mod tests {
context: DiscoveryContext {
source: "test_source".to_string(),
age_policy: None,
profile_policy: None,
},
};

Expand All @@ -497,6 +507,7 @@ mod tests {
context: DiscoveryContext {
source: "test_source".to_string(),
age_policy: None,
profile_policy: None,
}
}))
);
Expand Down Expand Up @@ -583,6 +594,13 @@ mod tests {
assert_eq!(watched.age_policy, Some(AgePolicy::Teen));
}

#[test]
fn test_age_policy_is_child_or_teen() {
assert!(AgePolicy::Child.is_child_or_teen());
assert!(AgePolicy::Teen.is_child_or_teen());
assert!(!AgePolicy::Adult.is_child_or_teen());
}

#[test]
fn test_from_entitlements_info_to_content_access_identifiers() {
let entitlements_info = EntitlementsInfo {
Expand Down Expand Up @@ -673,6 +691,7 @@ mod tests {
let context = DiscoveryContext {
source: "app".to_string(),
age_policy: None,
profile_policy: None,
};

let json = serde_json::to_string(&context).unwrap();
Expand All @@ -688,6 +707,7 @@ mod tests {
let context = DiscoveryContext {
source: "".to_string(),
age_policy: None,
profile_policy: None,
};
let json = serde_json::to_string(&context).unwrap();
let deserialized: DiscoveryContext = serde_json::from_str(&json).unwrap();
Expand All @@ -697,12 +717,31 @@ mod tests {
let context = DiscoveryContext {
source: "voice-control/system".to_string(),
age_policy: None,
profile_policy: None,
};
let json = serde_json::to_string(&context).unwrap();
let deserialized: DiscoveryContext = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized.source, "voice-control/system");
}

#[test]
fn test_discovery_context_profile_policy_json() {
// Missing profilePolicy deserializes to None
let context: DiscoveryContext = serde_json::from_str(r#"{"source":"app"}"#).unwrap();
assert_eq!(context.profile_policy, None);

// Provided profilePolicy round-trips
let context = DiscoveryContext {
source: "app".to_string(),
age_policy: None,
profile_policy: Some("teenProfile".to_string()),
};
let json = serde_json::to_string(&context).unwrap();
assert_eq!(json, r#"{"source":"app","profilePolicy":"teenProfile"}"#);
let deserialized: DiscoveryContext = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized, context);
}

#[test]
fn test_discovery_context_json_invalid() {
// Missing required field
Expand Down
1 change: 1 addition & 0 deletions core/sdk/src/api/firebolt/fb_lifecycle_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ mod tests {
context: DiscoveryContext {
source: "test_source".to_string(),
age_policy: None,
profile_policy: None,
},
}),
)),
Expand Down
Loading