Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Dec 20, 2023
1 parent 1a7c9a2 commit 33e23c2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
11 changes: 5 additions & 6 deletions profile/src/v100/address/account_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,11 @@ mod tests {
}

#[test]
fn not_equal() {
let b: AccountAddress =
"account_rdx129qdd2yp9vs8jkkn2uwn6sw0ejwmcwr3r4c3usr2hp0nau67m2kzdm"
.try_into()
.unwrap();
assert_ne!(AccountAddress::placeholder(), b)
fn inequality() {
assert_ne!(
AccountAddress::placeholder_alice(),
AccountAddress::placeholder_bob()
)
}

#[test]
Expand Down
11 changes: 11 additions & 0 deletions profile/src/v100/app_preferences/app_preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ impl AppPreferences {
Transaction::placeholder(),
)
}

/// A placeholder used to facilitate unit tests.
pub fn placeholder_other() -> Self {
Self::new(
AppDisplay::placeholder_other(),
Gateways::placeholder_other(),
P2PLinks::placeholder(),
Security::placeholder_other(),
Transaction::placeholder_other(),
)
}
}

#[cfg(test)]
Expand Down
35 changes: 31 additions & 4 deletions profile/src/v100/header/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use iso8601_timestamp::Timestamp;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use wallet_kit_common::utils::factory::{id, now};
use wallet_kit_common::utils::factory::id;

use super::{
content_hint::ContentHint, device_info::DeviceInfo,
Expand Down Expand Up @@ -167,6 +167,23 @@ impl Header {
Header::with_values(
Uuid::from_str("12345678-bbbb-cccc-dddd-abcd12345678").unwrap(),
device,
ContentHint::with_counters(4, 0, 2),
date,
)
}

/// A placeholder used to facilitate unit tests.
pub fn placeholder_other() -> Self {
//let date = NaiveDateTime::parse_from_str("2023-09-11T16:05:56.000Z", "%Y-%m-%dT%H:%M:%S").unwrap();
let date = Timestamp::parse("2023-12-20T16:05:56Z").unwrap();
let device = DeviceInfo::with_values(
Uuid::from_str("aabbccdd-a9d9-49e5-8152-beefbeefbeef").unwrap(),
date.clone(),
"iPhone".to_string(),
);
Header::with_values(
Uuid::from_str("87654321-bbbb-cccc-dddd-87654321dcba").unwrap(),
device,
ContentHint::new(),
date,
)
Expand All @@ -182,13 +199,23 @@ pub mod tests {
content_hint::ContentHint, device_info::DeviceInfo,
profilesnapshot_version::ProfileSnapshotVersion,
};
use chrono::NaiveDateTime;
use iso8601_timestamp::Timestamp;
use uuid::Uuid;
use wallet_kit_common::{json::assert_eq_after_json_roundtrip, utils::factory::id};

use super::Header;

#[test]
fn inequality() {
assert_ne!(Header::placeholder(), Header::placeholder_other());
}

#[test]
fn equality() {
assert_eq!(Header::placeholder(), Header::placeholder());
assert_eq!(Header::placeholder_other(), Header::placeholder_other());
}

#[test]
fn json_roundtrip_placeholder() {
let sut = Header::placeholder();
Expand All @@ -210,9 +237,9 @@ pub mod tests {
},
"lastModified": "2023-09-11T16:05:56.000Z",
"contentHint": {
"numberOfAccountsOnAllNetworksInTotal": 0,
"numberOfAccountsOnAllNetworksInTotal": 4,
"numberOfPersonasOnAllNetworksInTotal": 0,
"numberOfNetworks": 0
"numberOfNetworks": 2
}
}
"#,
Expand Down
35 changes: 35 additions & 0 deletions profile/src/v100/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,41 @@ mod tests {
sut.set_factor_sources(FactorSources::new());
}

#[test]
fn set_header() {
let profile = Profile::placeholder();
assert_eq!(profile.header(), Header::placeholder());
profile.set_header(Header::placeholder_other());
assert_eq!(profile.header(), Header::placeholder_other());
}

#[test]
fn set_factor_sources() {
let profile = Profile::placeholder();
assert_eq!(profile.factor_sources(), FactorSources::placeholder());
profile.set_factor_sources(FactorSources::placeholder_other());
assert_eq!(profile.factor_sources(), FactorSources::placeholder_other());
}

#[test]
fn set_app_preferences() {
let profile = Profile::placeholder();
assert_eq!(profile.app_preferences(), AppPreferences::placeholder());
profile.set_app_preferences(AppPreferences::placeholder_other());
assert_eq!(
profile.app_preferences(),
AppPreferences::placeholder_other()
);
}

#[test]
fn set_networks() {
let profile = Profile::placeholder();
assert_eq!(profile.networks(), Networks::placeholder());
profile.set_networks(Networks::placeholder_other());
assert_eq!(profile.networks(), Networks::placeholder_other());
}

#[test]
fn json_roundtrip() {
let sut = Profile::placeholder();
Expand Down
2 changes: 2 additions & 0 deletions profile/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ fn v100_100() {
profile.header().snapshot_version(),
ProfileSnapshotVersion::V100
);
let serialized = serde_json::to_value(&profile).unwrap();
println!("{}", serialized);
}

0 comments on commit 33e23c2

Please sign in to comment.