Skip to content

Commit

Permalink
Rppl 1448 Create unit tests for Ripple Contracts with ExtnPayloadProv…
Browse files Browse the repository at this point in the history
…iders in Ripple SDK (#404)

* RPPL-1448: Add unit tests for Ripple Contracts with ExtnPayloadProviders
  • Loading branch information
sakshihcst authored Feb 6, 2024
1 parent 3409eb6 commit c3e23fd
Show file tree
Hide file tree
Showing 55 changed files with 1,837 additions and 276 deletions.
14 changes: 13 additions & 1 deletion core/sdk/src/api/accessory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{

use super::device::device_accessory::{AccessoryDeviceListResponse, AccessoryDeviceResponse};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum RemoteAccessoryResponse {
None(()),
Expand Down Expand Up @@ -58,3 +58,15 @@ impl ExtnPayloadProvider for RemoteAccessoryResponse {
RippleContract::RemoteAccessory
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::utils::test_utils::test_extn_payload_provider;
#[test]
fn test_extn_payload_provider_for_remote_accessory_response() {
let remote_accessory_response = RemoteAccessoryResponse::Boolean(true);
let contract_type = RippleContract::RemoteAccessory;
test_extn_payload_provider(remote_accessory_response, contract_type);
}
}
31 changes: 29 additions & 2 deletions core/sdk/src/api/account_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use super::{
gateway::rpc_gateway_api::CallContext,
};

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum AccountLinkRequest {
SignIn(CallContext),
Expand All @@ -36,7 +36,7 @@ pub enum AccountLinkRequest {
Watched(WatchedRequest),
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WatchedRequest {
pub context: CallContext,
Expand All @@ -61,3 +61,30 @@ impl ExtnPayloadProvider for AccountLinkRequest {
RippleContract::AccountLink
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::api::account_link::AccountLinkRequest;
use crate::api::gateway::rpc_gateway_api::{ApiProtocol, CallContext};
use crate::utils::test_utils::test_extn_payload_provider;

#[test]
fn test_extn_request_account_link() {
let call_context = CallContext {
session_id: "test_session_id".to_string(),
request_id: "test_request_id".to_string(),
app_id: "test_app_id".to_string(),
call_id: 123,
protocol: ApiProtocol::Bridge,
method: "some_method".to_string(),
cid: Some("test_cid".to_string()),
gateway_secure: true,
};

let account_link_request = AccountLinkRequest::SignIn(call_context);
let contract_type: RippleContract = RippleContract::AccountLink;

test_extn_payload_provider(account_link_request, contract_type);
}
}
34 changes: 31 additions & 3 deletions core/sdk/src/api/app_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
framework::ripple_contract::RippleContract,
};

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub enum AppCatalogRequest {
CheckForUpdates,
}
Expand All @@ -27,7 +27,7 @@ impl ExtnPayloadProvider for AppCatalogRequest {
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct AppMetadata {
pub id: String,
pub title: String,
Expand All @@ -54,7 +54,7 @@ impl AppMetadata {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct AppsUpdate {
pub apps: Vec<AppMetadata>,
}
Expand Down Expand Up @@ -82,3 +82,31 @@ impl ExtnPayloadProvider for AppsUpdate {
RippleContract::AppCatalog
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::utils::test_utils::test_extn_payload_provider;

#[test]
fn test_extn_request_app_catalog() {
let check_for_updates_request = AppCatalogRequest::CheckForUpdates;
let contract_type: RippleContract = RippleContract::AppCatalog;
test_extn_payload_provider(check_for_updates_request, contract_type);
}

#[test]
fn test_extn_payload_provider_for_apps_update() {
let apps_update = AppsUpdate {
apps: vec![AppMetadata {
id: String::from("app1"),
title: String::from("App 1"),
version: String::from("1.0"),
uri: String::from("https://example.com/app1"),
data: Some(String::from("app1_data")),
}],
};
let contract_type: RippleContract = RippleContract::AppCatalog;
test_extn_payload_provider(apps_update, contract_type);
}
}
42 changes: 34 additions & 8 deletions core/sdk/src/api/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use super::{
gateway::rpc_gateway_api::CallContext,
};

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct AppSession {
pub app: AppBasicInfo,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -68,15 +68,15 @@ impl AppSession {
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct AppBasicInfo {
pub id: String,
pub catalog: Option<String>,
pub url: Option<String>,
pub title: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum AppRuntimeTransport {
Bridge,
Expand All @@ -87,14 +87,14 @@ fn runtime_transport_default() -> AppRuntimeTransport {
AppRuntimeTransport::Websocket
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct AppRuntime {
pub id: Option<String>,
#[serde(default = "runtime_transport_default")]
pub transport: AppRuntimeTransport,
}

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
pub struct AppLaunchInfo {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub intent: Option<NavigationIntent>,
Expand Down Expand Up @@ -177,7 +177,7 @@ impl AppRequest {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum AppManagerResponse {
None,
State(LifecycleState),
Expand Down Expand Up @@ -227,7 +227,7 @@ pub enum AppMethod {
NewLoadedSession(AppSession),
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum CloseReason {
RemoteButton,
Expand Down Expand Up @@ -274,7 +274,7 @@ pub struct AppEvent {
pub app_id: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub enum AppEventRequest {
Emit(AppEvent),
Register(CallContext, String, ListenRequest),
Expand All @@ -301,3 +301,29 @@ impl ExtnPayloadProvider for AppEventRequest {
RippleContract::AppEvents
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::utils::test_utils::test_extn_payload_provider;

#[test]
fn test_extn_payload_provider_for_app_response() {
let app_response: AppResponse = Ok(AppManagerResponse::State(LifecycleState::Initializing));
let contract_type: RippleContract = RippleContract::LifecycleManagement;
test_extn_payload_provider(app_response, contract_type);
}

#[test]
fn test_extn_payload_provider_for_app_event_request() {
let app_event_request = AppEventRequest::Emit(AppEvent {
event_name: String::from("your_event_name"),
result: serde_json::to_value("your_event_result").unwrap(),
context: Some(serde_json::to_value("your_event_context").unwrap()),
app_id: Some(String::from("your_app_id")),
});

let contract_type: RippleContract = RippleContract::AppEvents;
test_extn_payload_provider(app_event_request, contract_type);
}
}
29 changes: 28 additions & 1 deletion core/sdk/src/api/caps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{

use super::firebolt::fb_capabilities::RoleInfo;

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum CapsRequest {
Permitted(String, Vec<RoleInfo>),
Expand All @@ -47,3 +47,30 @@ impl ExtnPayloadProvider for CapsRequest {
RippleContract::Caps
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::api::firebolt::fb_capabilities::{CapabilityRole, FireboltCap};
use crate::utils::test_utils::test_extn_payload_provider;

#[test]
fn test_extn_request_caps() {
let app_id = "test_app_id".to_string();
let role_infos = vec![
RoleInfo {
role: Some(CapabilityRole::Use),
capability: FireboltCap::Short("test_short_cap".to_string()),
},
RoleInfo {
role: Some(CapabilityRole::Manage),
capability: FireboltCap::Full("test_full_cap".to_string()),
},
];

let caps_request = CapsRequest::Permitted(app_id, role_infos);

let contract_type: RippleContract = RippleContract::Caps;
test_extn_payload_provider(caps_request, contract_type);
}
}
56 changes: 53 additions & 3 deletions core/sdk/src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use super::manifest::{

use super::manifest::device_manifest::AppLibraryEntry;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum Config {
AllDefaultApps,
DefaultApp,
Expand Down Expand Up @@ -87,7 +87,7 @@ impl ExtnPayloadProvider for Config {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct RfcRequest {
pub flag: String,
}
Expand Down Expand Up @@ -122,7 +122,7 @@ pub enum ConfigResponse {
IdSalt(IdSalt),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct LauncherConfig {
pub retention_policy: RetentionPolicy,
pub lifecycle_policy: LifecyclePolicy,
Expand Down Expand Up @@ -150,3 +150,53 @@ impl ExtnPayloadProvider for LauncherConfig {
RippleContract::Config
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::api::manifest::device_manifest::{AppManifestLoad, BootState};
use crate::utils::test_utils::test_extn_payload_provider;
use std::collections::HashMap;

#[test]
fn test_extn_request_config() {
let contract_type: RippleContract = RippleContract::Config;
test_extn_payload_provider(Config::DefaultValues, contract_type);
}

#[test]
fn test_extn_payload_provider_for_rfc_request() {
let rfc_request = RfcRequest {
flag: String::from("test_flag"),
};
let contract_type: RippleContract = RippleContract::RemoteFeatureControl;
test_extn_payload_provider(rfc_request, contract_type);
}

#[test]
fn test_extn_payload_provider_for_launcher_config() {
let launcher_config = LauncherConfig {
retention_policy: RetentionPolicy {
max_retained: 10,
min_available_mem_kb: 1024,
always_retained: vec!["app1".to_string(), "app2".to_string()],
},
lifecycle_policy: LifecyclePolicy {
app_ready_timeout_ms: 5000,
app_finished_timeout_ms: 10000,
},
app_library_state: AppLibraryState {
default_apps: vec![AppLibraryEntry {
app_id: "app1".to_string(),
manifest: AppManifestLoad::Remote(
"https://example.com/app1/manifest".to_string(),
),
boot_state: BootState::Inactive,
}],
providers: HashMap::new(),
},
};
let contract_type: RippleContract = RippleContract::Config;
test_extn_payload_provider(launcher_config, contract_type);
}
}
Loading

0 comments on commit c3e23fd

Please sign in to comment.