Skip to content

Commit

Permalink
unit tests improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
iganev committed Feb 29, 2024
1 parent 9fa9865 commit 766dcad
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,28 @@ mod tests {
/// Check https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do
const GOOGLE_MOCK_SECRET:&str = "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe";

const UNKNOWN_ERROR:&str = "trololo-detected";

#[tokio::test]
async fn it_works() {

assert!(matches!("missing-input-secret".to_string().try_into(), Ok(RecaptchaError::MissingInputSecret)));
assert!(matches!("invalid-input-secret".to_string().try_into(), Ok(RecaptchaError::InvalidInputSecret)));
assert!(matches!("missing-input-response".to_string().try_into(), Ok(RecaptchaError::MissingInputResponse)));
assert!(matches!("invalid-input-response".to_string().try_into(), Ok(RecaptchaError::InvalidInputResponse)));
assert!(matches!("bad-request".to_string().try_into(), Ok(RecaptchaError::BadRequest)));
assert!(matches!("timeout-or-duplicate".to_string().try_into(), Ok(RecaptchaError::TimeoutOrDuplicate)));

assert!(matches!(UNKNOWN_ERROR.to_string().try_into(), Ok(RecaptchaError::Unknown(Some(s))) if s == UNKNOWN_ERROR ));

//

let res: Result<(), RecaptchaError> = verify("test", "test", None).await;

assert!(matches!(res, Err(RecaptchaError::InvalidInputSecret)));

//

let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let res: Result<(), RecaptchaError> = verify(GOOGLE_MOCK_SECRET, "test", Some(&localhost_v4)).await;

Expand Down

0 comments on commit 766dcad

Please sign in to comment.