use super::*;
#[test]
fn ok() {
let store = gen_bag();
let url = Url::parse("http://localhost/").unwrap();
let opt = url::Url::options().base_url(Some(&url));
const URL: &str = "/comments";
const INTENTION: CibouletteIntention = CibouletteIntention::Read;
const BODY: Option<&str> = Some(
r#"
{
"data":
{
"id": "6720877a-e27e-4e9e-9ac0-3fff4deb55f2",
"type": "comments",
"attributes":
{
"body": "world"
}
}
}
"#,
);
let parsed_url = opt.parse(URL).unwrap();
let builder = CibouletteRequestBuilder::new(INTENTION, &parsed_url, &BODY);
let request = builder.build(&store).unwrap();
let res = CibouletteReadRequest::try_from(request);
assert_eq!(res.is_ok(), true);
}
#[test]
fn wrong_intention() {
let store = gen_bag();
let url = Url::parse("http://localhost/").unwrap();
let opt = url::Url::options().base_url(Some(&url));
const URL: &str = "/comments";
const INTENTION: CibouletteIntention = CibouletteIntention::Delete;
const BODY: Option<&str> = Some(
r#"
{
"data":
{
"id": "6720877a-e27e-4e9e-9ac0-3fff4deb55f2",
"type": "comments",
"attributes":
{
"body": "world"
}
}
}
"#,
);
let parsed_url = opt.parse(URL).unwrap();
let builder = CibouletteRequestBuilder::new(INTENTION, &parsed_url, &BODY);
let request = builder.build(&store).unwrap();
let res = CibouletteReadRequest::try_from(request);
assert_eq!(
matches!(
res,
Err(CibouletteError::WrongIntention(x, y))
if x == CibouletteIntention::Delete && y == CibouletteIntention::Read
),
true
);
}