Skip to content

Commit

Permalink
Improve naming in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Sep 16, 2024
1 parent d33fdec commit dee48ba
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
19 changes: 10 additions & 9 deletions crates/robonode-client/src/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod tests {
use wiremock::{matchers, Mock, MockServer, ResponseTemplate};

use super::*;
use crate::test_utils::{mkerr, mkerr_containing_blob};
use crate::test_utils::{mkerr, mkerr_before_2023_05};

#[test]
fn request_serialization() {
Expand All @@ -115,7 +115,7 @@ mod tests {
}

#[test]
fn response_deserialization() {
fn response_deserialization_before_2023_05() {
let sample_response = serde_json::json!({
"authTicket": [1, 2, 3],
"authTicketSignature": [4, 5, 6],
Expand All @@ -132,7 +132,7 @@ mod tests {
}

#[test]
fn response_deserialization_containing_blob() {
fn response_deserialization() {
let sample_response = serde_json::json!({
"authTicket": [1, 2, 3],
"authTicketSignature": [4, 5, 6],
Expand All @@ -150,7 +150,7 @@ mod tests {
}

#[tokio::test]
async fn mock_success() {
async fn mock_success_before_2023_05() {
let mock_server = MockServer::start().await;

let sample_request = AuthenticateRequest {
Expand Down Expand Up @@ -182,7 +182,7 @@ mod tests {
}

#[tokio::test]
async fn mock_success_containing_blob() {
async fn mock_success() {
let mock_server = MockServer::start().await;

let sample_request = AuthenticateRequest {
Expand Down Expand Up @@ -215,7 +215,7 @@ mod tests {
}

#[tokio::test]
async fn mock_error_response() {
async fn mock_error_response_before_2023_05() {
let cases = [
(
StatusCode::BAD_REQUEST,
Expand Down Expand Up @@ -257,7 +257,8 @@ mod tests {
liveness_data_signature: b"123",
};

let response = ResponseTemplate::new(case.0).set_body_json(mkerr(case.1));
let response =
ResponseTemplate::new(case.0).set_body_json(mkerr_before_2023_05(case.1));

Mock::given(matchers::method("POST"))
.and(matchers::path("/authenticate"))
Expand All @@ -277,7 +278,7 @@ mod tests {
}

#[tokio::test]
async fn mock_error_response_containing_blob() {
async fn mock_error_response() {
let cases = [
(
StatusCode::BAD_REQUEST,
Expand Down Expand Up @@ -320,7 +321,7 @@ mod tests {
};

let response =
ResponseTemplate::new(case.0).set_body_json(mkerr_containing_blob(case.1, "blob"));
ResponseTemplate::new(case.0).set_body_json(mkerr(case.1, "scan result blob"));

Mock::given(matchers::method("POST"))
.and(matchers::path("/authenticate"))
Expand Down
15 changes: 8 additions & 7 deletions crates/robonode-client/src/enroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod tests {
use wiremock::{matchers, Mock, MockServer, ResponseTemplate};

use super::*;
use crate::test_utils::{mkerr, mkerr_containing_blob};
use crate::test_utils::{mkerr, mkerr_before_2023_05};

#[test]
fn request_serialization() {
Expand All @@ -110,7 +110,7 @@ mod tests {
}

#[tokio::test]
async fn mock_success() {
async fn mock_success_before_2023_05() {
let mock_server = MockServer::start().await;

let sample_request = EnrollRequest {
Expand All @@ -135,7 +135,7 @@ mod tests {
}

#[tokio::test]
async fn mock_success_containing_blob() {
async fn mock_success() {
let mock_server = MockServer::start().await;

let sample_request = EnrollRequest {
Expand Down Expand Up @@ -163,7 +163,7 @@ mod tests {
}

#[tokio::test]
async fn mock_error_response() {
async fn mock_error_response_before_2023_05() {
let cases = [
(
StatusCode::BAD_REQUEST,
Expand Down Expand Up @@ -211,7 +211,8 @@ mod tests {
public_key: b"123",
};

let response = ResponseTemplate::new(case.0).set_body_json(mkerr(case.1));
let response =
ResponseTemplate::new(case.0).set_body_json(mkerr_before_2023_05(case.1));

Mock::given(matchers::method("POST"))
.and(matchers::path("/enroll"))
Expand All @@ -231,7 +232,7 @@ mod tests {
}

#[tokio::test]
async fn mock_error_response_containing_blob() {
async fn mock_error_response() {
let cases = [
(
StatusCode::BAD_REQUEST,
Expand Down Expand Up @@ -280,7 +281,7 @@ mod tests {
};

let response =
ResponseTemplate::new(case.0).set_body_json(mkerr_containing_blob(case.1, "blob"));
ResponseTemplate::new(case.0).set_body_json(mkerr(case.1, "scan result blob"));

Mock::given(matchers::method("POST"))
.and(matchers::path("/enroll"))
Expand Down
10 changes: 5 additions & 5 deletions crates/robonode-client/src/error_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ impl TryFrom<String> for ErrorResponse {
#[cfg(test)]
pub mod tests {
use super::*;
use crate::test_utils::{mkerr, mkerr_containing_blob};
use crate::test_utils::{mkerr, mkerr_before_2023_05};

#[test]
fn decodes() {
let err = mkerr("MY_ERR_CODE").to_string();
fn decodes_before_2023_05() {
let err = mkerr_before_2023_05("MY_ERR_CODE").to_string();
let ErrorResponse { error_code } = err.try_into().unwrap();
assert_eq!(error_code, "MY_ERR_CODE");
}

#[test]
fn decodes_containing_blob() {
let err = mkerr_containing_blob("MY_ERR_CODE", "scan result blob").to_string();
fn decodes() {
let err = mkerr("MY_ERR_CODE", "scan result blob").to_string();
let ErrorResponse { error_code } = err.try_into().unwrap();
assert_eq!(error_code, "MY_ERR_CODE");
}
Expand Down
8 changes: 4 additions & 4 deletions crates/robonode-client/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub fn mkerr(error_code: &str) -> serde_json::Value {
pub fn mkerr_before_2023_05(error_code: &str) -> serde_json::Value {
serde_json::json!({ "errorCode": error_code })
}

pub fn mkerr_containing_blob(error_code: &str, scan_result_blob: &str) -> serde_json::Value {
pub fn mkerr(error_code: &str, scan_result_blob: &str) -> serde_json::Value {
serde_json::json!({ "errorCode": error_code, "scanResultBlob": scan_result_blob })
}

Expand All @@ -13,12 +13,12 @@ mod tests {
#[test]
fn evals_properly() {
assert_eq!(
mkerr("MY_ERR_CODE").to_string(),
mkerr_before_2023_05("MY_ERR_CODE").to_string(),
serde_json::json!({ "errorCode": "MY_ERR_CODE" }).to_string()
);

assert_eq!(
mkerr_containing_blob("MY_ERR_CODE", "scan result blob").to_string(),
mkerr("MY_ERR_CODE", "scan result blob").to_string(),
serde_json::json!({ "errorCode": "MY_ERR_CODE", "scanResultBlob": "scan result blob" })
.to_string()
);
Expand Down

0 comments on commit dee48ba

Please sign in to comment.