diff --git a/crates/robonode-client/src/authenticate.rs b/crates/robonode-client/src/authenticate.rs index 5948529a6..adc90804c 100644 --- a/crates/robonode-client/src/authenticate.rs +++ b/crates/robonode-client/src/authenticate.rs @@ -185,6 +185,7 @@ mod tests { AuthenticateResponse { auth_ticket: vec![1, 2, 3].into(), auth_ticket_signature: vec![4, 5, 6].into(), + scan_result_blob: Some("blob".to_owned()), } ) } @@ -322,7 +323,7 @@ mod tests { | AuthenticateError::FaceScanRejected(_) | AuthenticateError::SignatureInvalid(_) | AuthenticateError::LogicInternal(_) => ResponseTemplate::new(case.0) - .set_body_json(mkerr_returning_blob(case.1, "scan result blob")), + .set_body_json(mkerr_containing_blob(case.1, "scan result blob")), _ => ResponseTemplate::new(case.0).set_body_json(mkerr(case.1)), }; @@ -343,69 +344,6 @@ mod tests { } } - #[tokio::test] - async fn mock_error_response_containing_blob() { - let cases = [ - ( - StatusCode::BAD_REQUEST, - "AUTHENTICATE_INVALID_LIVENESS_DATA", - AuthenticateError::InvalidLivenessData, - ), - ( - StatusCode::NOT_FOUND, - "AUTHENTICATE_PERSON_NOT_FOUND", - AuthenticateError::PersonNotFound, - ), - ( - StatusCode::FORBIDDEN, - "AUTHENTICATE_FACE_SCAN_REJECTED", - AuthenticateError::FaceScanRejected, - ), - ( - StatusCode::FORBIDDEN, - "AUTHENTICATE_SIGNATURE_INVALID", - AuthenticateError::SignatureInvalid, - ), - ( - StatusCode::INTERNAL_SERVER_ERROR, - "LOGIC_INTERNAL_ERROR", - AuthenticateError::LogicInternal, - ), - ( - StatusCode::BAD_REQUEST, - "MY_ERR_CODE", - AuthenticateError::UnknownCode("MY_ERR_CODE".to_owned()), - ), - ]; - - for case in cases { - let mock_server = MockServer::start().await; - - let sample_request = AuthenticateRequest { - liveness_data: b"dummy liveness data", - liveness_data_signature: 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("/authenticate")) - .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.authenticate(sample_request).await.unwrap_err(); - assert_matches!(actual_error, Error::Call(err) if err == case.2); - } - } - #[tokio::test] async fn mock_error_unknown() { let mock_server = MockServer::start().await; diff --git a/crates/robonode-client/src/enroll.rs b/crates/robonode-client/src/enroll.rs index c7b5ca3dd..04e8b4f57 100644 --- a/crates/robonode-client/src/enroll.rs +++ b/crates/robonode-client/src/enroll.rs @@ -276,7 +276,7 @@ mod tests { EnrollError::FaceScanRejected(_) | EnrollError::PersonAlreadyEnrolled(_) | EnrollError::LogicInternal(_) => ResponseTemplate::new(case.0) - .set_body_json(mkerr_returning_blob(case.1, "scan result blob")), + .set_body_json(mkerr_containing_blob(case.1, "scan result blob")), _ => ResponseTemplate::new(case.0).set_body_json(mkerr(case.1)), }; @@ -297,75 +297,6 @@ mod tests { } } - #[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::FaceScanRejected, - ), - ( - StatusCode::CONFLICT, - "ENROLL_PUBLIC_KEY_ALREADY_USED", - EnrollError::PublicKeyAlreadyUsed, - ), - ( - StatusCode::CONFLICT, - "ENROLL_PERSON_ALREADY_ENROLLED", - EnrollError::PersonAlreadyEnrolled, - ), - ( - StatusCode::INTERNAL_SERVER_ERROR, - "LOGIC_INTERNAL_ERROR", - EnrollError::LogicInternal, - ), - ( - 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)) - .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_unknown() { let mock_server = MockServer::start().await; diff --git a/crates/robonode-client/src/error_response.rs b/crates/robonode-client/src/error_response.rs index 1ee827cef..7e59a5783 100644 --- a/crates/robonode-client/src/error_response.rs +++ b/crates/robonode-client/src/error_response.rs @@ -39,8 +39,8 @@ pub mod tests { } #[test] - fn decodes_returning_blob() { - let err = mkerr_returning_blob("MY_ERR_CODE", "scan result blob").to_string(); + fn decodes_containing_blob() { + let err = mkerr_containing_blob("MY_ERR_CODE", "scan result blob").to_string(); let ErrorResponse { error_code, scan_result_blob, @@ -48,11 +48,4 @@ pub mod tests { assert_eq!(error_code, "MY_ERR_CODE"); assert_eq!(scan_result_blob, Some("scan result blob".to_owned())); } - - #[test] - fn decodes_containing_blob() { - let err = mkerr_containing_blob("MY_ERR_CODE", "scan result blob").to_string(); - let ErrorResponse { error_code } = err.try_into().unwrap(); - assert_eq!(error_code, "MY_ERR_CODE"); - } } diff --git a/crates/robonode-client/src/test_utils.rs b/crates/robonode-client/src/test_utils.rs index 0bfdfd329..624e34460 100644 --- a/crates/robonode-client/src/test_utils.rs +++ b/crates/robonode-client/src/test_utils.rs @@ -2,10 +2,6 @@ pub fn mkerr(error_code: &str) -> serde_json::Value { serde_json::json!({ "errorCode": error_code }) } -pub fn mkerr_returning_blob(error_code: &str, scan_result_blob: &str) -> serde_json::Value { - serde_json::json!({ "errorCode": error_code, "scanResultBlob": scan_result_blob }) -} - pub fn mkerr_containing_blob(error_code: &str, scan_result_blob: &str) -> serde_json::Value { serde_json::json!({ "errorCode": error_code, "scanResultBlob": scan_result_blob }) } @@ -21,12 +17,6 @@ mod tests { serde_json::json!({ "errorCode": "MY_ERR_CODE" }).to_string() ); - assert_eq!( - mkerr_returning_blob("MY_ERR_CODE", "scan result blob").to_string(), - serde_json::json!({ "errorCode": "MY_ERR_CODE", "scanResultBlob": "scan result blob" }) - .to_string() - ); - assert_eq!( mkerr_containing_blob("MY_ERR_CODE", "scan result blob").to_string(), serde_json::json!({ "errorCode": "MY_ERR_CODE", "scanResultBlob": "scan result blob" })