Extract login() from test function
This commit is contained in:
parent
7f54f418a8
commit
4ef6561cc6
@ -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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user