Skip to content

Commit

Permalink
Return mock_error_response_containing_blob to explicitly check test
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Sep 16, 2024
1 parent 77f2c10 commit 0f7eb7a
Showing 1 changed file with 84 additions and 6 deletions.
90 changes: 84 additions & 6 deletions crates/robonode-client/src/enroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,92 @@ mod tests {
public_key: b"123",
};

let response = match case.2 {
EnrollError::FaceScanRejected(_)
| EnrollError::PersonAlreadyEnrolled(_)
| EnrollError::LogicInternal(_) => ResponseTemplate::new(case.0)
.set_body_json(mkerr_containing_blob(case.1, "scan result blob")),
_ => ResponseTemplate::new(case.0).set_body_json(mkerr(case.1)),
let response = ResponseTemplate::new(case.0).set_body_json(mkerr(case.1));

Mock::given(matchers::method("POST"))
.and(matchers::path("/enroll"))
.and(matchers::body_json(&sample_request))
.respond_with(response)
.mount(&mock_server)
.await;

let client = Client {
base_url: mock_server.uri(),
reqwest: reqwest::Client::new(),
};

let actual_error = client.enroll(sample_request).await.unwrap_err();
assert_matches!(actual_error, Error::Call(err) if err == case.2);
}
}

#[tokio::test]
async fn mock_error_response_containing_blob() {
let cases = [
(
StatusCode::BAD_REQUEST,
"ENROLL_INVALID_PUBLIC_KEY",
EnrollError::InvalidPublicKey,
),
(
StatusCode::BAD_REQUEST,
"ENROLL_INVALID_LIVENESS_DATA",
EnrollError::InvalidLivenessData,
),
(
StatusCode::FORBIDDEN,
"ENROLL_FACE_SCAN_REJECTED",
EnrollError::FaceScanRejectedNoBlob,
),
(
StatusCode::FORBIDDEN,
"ENROLL_FACE_SCAN_REJECTED",
EnrollError::FaceScanRejected("scan result blob".to_owned()),
),
(
StatusCode::CONFLICT,
"ENROLL_PUBLIC_KEY_ALREADY_USED",
EnrollError::PublicKeyAlreadyUsed,
),
(
StatusCode::CONFLICT,
"ENROLL_PERSON_ALREADY_ENROLLED",
EnrollError::PersonAlreadyEnrolledNoBlob,
),
(
StatusCode::CONFLICT,
"ENROLL_PERSON_ALREADY_ENROLLED",
EnrollError::PersonAlreadyEnrolled("scan result blob".to_owned()),
),
(
StatusCode::INTERNAL_SERVER_ERROR,
"LOGIC_INTERNAL_ERROR",
EnrollError::LogicInternalNoBlob,
),
(
StatusCode::INTERNAL_SERVER_ERROR,
"LOGIC_INTERNAL_ERROR",
EnrollError::LogicInternal("scan result blob".to_owned()),
),
(
StatusCode::BAD_REQUEST,
"MY_ERR_CODE",
EnrollError::UnknownCode("MY_ERR_CODE".to_owned()),
),
];

for case in cases {
let mock_server = MockServer::start().await;

let sample_request = EnrollRequest {
liveness_data: b"dummy liveness data",
liveness_data_signature: b"signature",
public_key: b"123",
};

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

Mock::given(matchers::method("POST"))
.and(matchers::path("/enroll"))
.and(matchers::body_json(&sample_request))
Expand Down

0 comments on commit 0f7eb7a

Please sign in to comment.