fn try_login(client: &Client) -> Option<Token> {
    let response = &mut client
        .post("/api/v1/users/login")
        .header(ContentType::JSON)
        .body(json_string!({"user": {"email": EMAIL, "password": PASSWORD}}))
        .dispatch();

    if response.status() == Status::UnprocessableEntity {
        return None;
    }

    let value = response_json_value(response);
    let token = value
        .get("user")
        .and_then(|user| user.get("token"))
        .and_then(|token| token.as_str())
        .map(String::from)
        .expect("Cannot extract token");
    Some(token)
}
/// Login as default user returning None if login is not found
Login as default user returning None if login is not found
Login as default user returning None if login is not found
fn try_login(client: &Client) -> Option<Token> {
    let response = &mut client
        .post("/api/v1/users/login")
        .header(ContentType::JSON)
        .body(json_string!({"user": {"email": EMAIL, "password": PASSWORD}}))
        .dispatch();
    if response.status() == Status::UnprocessableEntity {
        return None;
    }
    let value = response_json_value(response);
    let token = value
        .get("user")
        .and_then(|user| user.get("token"))
        .and_then(|token| token.as_str())
        .map(String::from)
        .expect("Cannot extract token");
    Some(token)
}
fn try_login ( client : & Client ) -> Option < Token > { let response = & mut client . post ( " " ) . header ( ContentType :: JSON ) . body ( json_string ! ( { " " { " " EMAIL " " PASSWORD } } ) ) . dispatch ( ) ; if response . status ( ) == Status :: UnprocessableEntity { return None ; } let value = response_json_value ( response ) ; let token = value . get ( " " ) . and_then ( | user | user . get ( " " ) ) . and_then ( | token | token . as_str ( ) ) . map ( String :: from ) . expect ( " " ) ; Some ( token ) }
Login as default user returning None if login is not found
Login as default user returning None if login is not found
client
&Client
client
&Client