diff --git a/crates/robonode-client/src/enroll.rs b/crates/robonode-client/src/enroll.rs index 4257bc022..3a2d8b959 100644 --- a/crates/robonode-client/src/enroll.rs +++ b/crates/robonode-client/src/enroll.rs @@ -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))