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