test: move logic to helpers
Some checks failed
Rust / Test (push) Has been cancelled
Rust / Rustfmt (push) Has been cancelled
Rust / Clippy (push) Has been cancelled
Rust / Code coverage (push) Has been cancelled

This commit is contained in:
Sandro Eiler 2024-04-18 23:48:34 +02:00
parent efd1137c71
commit 6e07d9c33a
3 changed files with 38 additions and 31 deletions

View file

@ -17,24 +17,10 @@ async fn the_link_returned_by_subscribe_returns_a_200_if_called() {
app.post_subscriptions(body.into()).await;
let email_request = &app.email_server.received_requests().await.unwrap()[0];
let body: serde_json::Value = serde_json::from_slice(&email_request.body).unwrap();
// Extract the link from one of the request fields.
let get_link = |s: &str| {
let links: Vec<_> = linkify::LinkFinder::new()
.links(s)
.filter(|l| *l.kind() == linkify::LinkKind::Url)
.collect();
assert_eq!(links.len(), 1);
links[0].as_str().to_owned()
};
let raw_confirmation_link = &get_link(body["HtmlBody"].as_str().unwrap());
let mut confirmation_link = Url::parse(raw_confirmation_link).unwrap();
assert_eq!(confirmation_link.host_str().unwrap(), "127.0.0.1");
confirmation_link.set_port(Some(app.port)).unwrap();
let confirmation_links = app.get_confirmation_links(email_request);
// Act
let response = reqwest::get(confirmation_link).await.unwrap();
let response = reqwest::get(confirmation_links.html).await.unwrap();
// Assert
assert_eq!(response.status().as_u16(), 200);