Skip to content

Commit

Permalink
Introduce ResponseIncludesBlob logic in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Sep 16, 2024
1 parent dee48ba commit ac66104
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
21 changes: 19 additions & 2 deletions crates/robonode-client/src/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,47 @@ mod tests {

#[tokio::test]
async fn mock_error_response() {
enum ResponseIncludesBlob {
Yes,
No,
}

let cases = [
(
StatusCode::BAD_REQUEST,
"AUTHENTICATE_INVALID_LIVENESS_DATA",
AuthenticateError::InvalidLivenessData,
ResponseIncludesBlob::No,
),
(
StatusCode::NOT_FOUND,
"AUTHENTICATE_PERSON_NOT_FOUND",
AuthenticateError::PersonNotFound,
ResponseIncludesBlob::Yes,
),
(
StatusCode::FORBIDDEN,
"AUTHENTICATE_FACE_SCAN_REJECTED",
AuthenticateError::FaceScanRejected,
ResponseIncludesBlob::Yes,
),
(
StatusCode::FORBIDDEN,
"AUTHENTICATE_SIGNATURE_INVALID",
AuthenticateError::SignatureInvalid,
ResponseIncludesBlob::Yes,
),
(
StatusCode::INTERNAL_SERVER_ERROR,
"LOGIC_INTERNAL_ERROR",
AuthenticateError::LogicInternal,
ResponseIncludesBlob::Yes,
),
(
StatusCode::BAD_REQUEST,
"MY_ERR_CODE",
AuthenticateError::UnknownCode("MY_ERR_CODE".to_owned()),
ResponseIncludesBlob::No,
),
];

Expand All @@ -320,8 +331,14 @@ mod tests {
liveness_data_signature: b"123",
};

let response =
ResponseTemplate::new(case.0).set_body_json(mkerr(case.1, "scan result blob"));
let response = match case.3 {
ResponseIncludesBlob::Yes => {
ResponseTemplate::new(case.0).set_body_json(mkerr(case.1, "scan result blob"))
}
ResponseIncludesBlob::No => {
ResponseTemplate::new(case.0).set_body_json(mkerr_before_2023_05(case.1))
}
};

Mock::given(matchers::method("POST"))
.and(matchers::path("/authenticate"))
Expand Down
22 changes: 20 additions & 2 deletions crates/robonode-client/src/enroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,41 +233,53 @@ mod tests {

#[tokio::test]
async fn mock_error_response() {
enum ResponseIncludesBlob {
Yes,
No,
}

let cases = [
(
StatusCode::BAD_REQUEST,
"ENROLL_INVALID_PUBLIC_KEY",
EnrollError::InvalidPublicKey,
ResponseIncludesBlob::No,
),
(
StatusCode::BAD_REQUEST,
"ENROLL_INVALID_LIVENESS_DATA",
EnrollError::InvalidLivenessData,
ResponseIncludesBlob::No,
),
(
StatusCode::FORBIDDEN,
"ENROLL_FACE_SCAN_REJECTED",
EnrollError::FaceScanRejected,
ResponseIncludesBlob::Yes,
),
(
StatusCode::CONFLICT,
"ENROLL_PUBLIC_KEY_ALREADY_USED",
EnrollError::PublicKeyAlreadyUsed,
ResponseIncludesBlob::No,
),
(
StatusCode::CONFLICT,
"ENROLL_PERSON_ALREADY_ENROLLED",
EnrollError::PersonAlreadyEnrolled,
ResponseIncludesBlob::Yes,
),
(
StatusCode::INTERNAL_SERVER_ERROR,
"LOGIC_INTERNAL_ERROR",
EnrollError::LogicInternal,
ResponseIncludesBlob::Yes,
),
(
StatusCode::BAD_REQUEST,
"MY_ERR_CODE",
EnrollError::UnknownCode("MY_ERR_CODE".to_owned()),
ResponseIncludesBlob::No,
),
];

Expand All @@ -280,8 +292,14 @@ mod tests {
public_key: b"123",
};

let response =
ResponseTemplate::new(case.0).set_body_json(mkerr(case.1, "scan result blob"));
let response = match case.3 {
ResponseIncludesBlob::Yes => {
ResponseTemplate::new(case.0).set_body_json(mkerr(case.1, "scan result blob"))
}
ResponseIncludesBlob::No => {
ResponseTemplate::new(case.0).set_body_json(mkerr_before_2023_05(case.1))
}
};

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

0 comments on commit ac66104

Please sign in to comment.