Skip to content

Commit

Permalink
Increased unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tluijken committed Dec 21, 2023
1 parent 292bd4c commit a8c4fc1
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/accounts/accounts_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,56 @@ mod tests {

assert!(request.is_err());
}

#[test]
fn test_accounts_set_sponsor_valid() {
let request = AccountsRequest::new()
.set_sponsor_filter(
"GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string(),
)
.unwrap();
assert_eq!(
request.sponsor.0,
"GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7"
);
}

#[test]
fn test_set_cursor_valid() {
let request = AccountsRequest::new().set_cursor(12345).unwrap();
assert_eq!(request.cursor.unwrap(), 12345);
}

#[test]
fn test_set_cursor_invalid() {
let request = AccountsRequest::new().set_cursor(0);
assert_eq!(
request.err().unwrap(),
"cursor must be greater than or equal to 1".to_string()
);
}

#[test]
fn test_set_limit_valid() {
let request = AccountsRequest::new().set_limit(20).unwrap();
assert_eq!(request.limit.unwrap(), 20);
}

#[test]
fn test_set_limit_invalid_low() {
let request = AccountsRequest::new().set_limit(0);
assert_eq!(
request.err().unwrap(),
"limit must be between 1 and 200".to_string()
);
}

#[test]
fn test_set_limit_invalid_high() {
let request = AccountsRequest::new().set_limit(201);
assert_eq!(
request.err().unwrap(),
"limit must be between 1 and 200".to_string()
);
}
}
80 changes: 80 additions & 0 deletions src/assets/all_assets_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,83 @@ impl AllAssetsRequest {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_set_asset_code_valid() {
let request = AllAssetsRequest::new().set_asset_code("XLM").unwrap();
assert_eq!(request.asset_code.unwrap(), "XLM");
}

#[test]
fn test_set_asset_code_invalid() {
let request = AllAssetsRequest::new().set_asset_code("XLM123456789012");
assert_eq!(
request.err().unwrap(),
"asset_code must be 12 characters or less"
);
}

#[test]
fn test_set_asset_issuer_valid() {
let request = AllAssetsRequest::new()
.set_asset_issuer("Baseflow_TechnologyInnovationAndSoftwareDevelopment_2023")
.unwrap();
assert_eq!(
request.asset_issuer.unwrap(),
"Baseflow_TechnologyInnovationAndSoftwareDevelopment_2023"
);
}

#[test]
fn test_set_asset_issuer_invalid() {
let request = AllAssetsRequest::new()
.set_asset_issuer("BaseflowSoftwareDevelopmentPowerhouse_InnovativeSolutions2023");
assert_eq!(
request.err().unwrap(),
"asset_issuer must be 56 characters".to_string()
);
}

#[test]
fn test_set_cursor_valid() {
let request = AllAssetsRequest::new().set_cursor(12345).unwrap();
assert_eq!(request.cursor.unwrap(), 12345);
}

#[test]
fn test_set_cursor_invalid() {
let request = AllAssetsRequest::new().set_cursor(0);
assert_eq!(
request.err().unwrap(),
"cursor must be greater than or equal to 1".to_string()
);
}

#[test]
fn test_set_limit_valid() {
let request = AllAssetsRequest::new().set_limit(20).unwrap();
assert_eq!(request.limit.unwrap(), 20);
}

#[test]
fn test_set_limit_invalid_low() {
let request = AllAssetsRequest::new().set_limit(0);
assert_eq!(
request.err().unwrap(),
"limit must be between 1 and 200".to_string()
);
}

#[test]
fn test_set_limit_invalid_high() {
let request = AllAssetsRequest::new().set_limit(201);
assert_eq!(
request.err().unwrap(),
"limit must be between 1 and 200".to_string()
);
}
}
46 changes: 46 additions & 0 deletions src/claimable_balances/all_claimable_balances_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,49 @@ impl AllClaimableBalancesRequest {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_set_cursor_valid() {
let request = AllClaimableBalancesRequest::new()
.set_cursor(12345)
.unwrap();
assert_eq!(request.cursor.unwrap(), 12345);
}

#[test]
fn test_set_cursor_invalid() {
let request = AllClaimableBalancesRequest::new().set_cursor(0);
assert_eq!(
request.err().unwrap(),
"cursor must be greater than or equal to 1".to_string()
);
}

#[test]
fn test_set_limit_valid() {
let request = AllClaimableBalancesRequest::new().set_limit(20).unwrap();
assert_eq!(request.limit.unwrap(), 20);
}

#[test]
fn test_set_limit_invalid_low() {
let request = AllClaimableBalancesRequest::new().set_limit(0);
assert_eq!(
request.err().unwrap(),
"limit must be between 1 and 200".to_string()
);
}

#[test]
fn test_set_limit_invalid_high() {
let request = AllClaimableBalancesRequest::new().set_limit(201);
assert_eq!(
request.err().unwrap(),
"limit must be between 1 and 200".to_string()
);
}
}

0 comments on commit a8c4fc1

Please sign in to comment.