Extract login() from test function

This commit is contained in:
Kitaiti Makoto 2021-01-24 21:38:51 +09:00
parent 7f54f418a8
commit 4ef6561cc6

View File

@ -389,7 +389,7 @@ mod tests {
};
use rocket::{
http::{Cookie, Cookies, SameSite},
local::Client,
local::{Client, LocalRequest},
};
#[test]
@ -409,11 +409,7 @@ mod tests {
assert!(!body.contains(&edit_link));
let request = client.get(&blog_path);
request.inner().guard::<Cookies>().unwrap().add_private(
Cookie::build(AUTH_COOKIE, user.id.to_string())
.same_site(SameSite::Lax)
.finish(),
);
login(&request, &user);
let mut response = request.dispatch();
let body = response.body_string().unwrap();
assert!(body.contains(&edit_link));
@ -499,4 +495,12 @@ mod tests {
})
.unwrap()
}
fn login(request: &LocalRequest, user: &User) {
request.inner().guard::<Cookies>().unwrap().add_private(
Cookie::build(AUTH_COOKIE, user.id.to_string())
.same_site(SameSite::Lax)
.finish(),
);
}
}