tests for new post notifications and dashboard stats
All checks were successful
Rust / Test (push) Successful in 3m47s
Rust / Rustfmt (push) Successful in 21s
Rust / Clippy (push) Successful in 1m14s
Rust / Code coverage (push) Successful in 3m49s

This commit is contained in:
Alphonse Paix
2025-09-29 18:22:15 +02:00
parent de44564ba0
commit 22c462fba3
8 changed files with 494 additions and 23 deletions

View File

@@ -2,7 +2,13 @@ use argon2::{
Algorithm, Argon2, Params, PasswordHasher, Version,
password_hash::{SaltString, rand_core::OsRng},
};
use fake::{Fake, faker::internet::en::SafeEmail};
use fake::{
Fake,
faker::{
internet::en::SafeEmail,
lorem::en::{Paragraph, Sentence},
},
};
use linkify::{Link, LinkFinder};
use once_cell::sync::Lazy;
use sqlx::PgPool;
@@ -183,6 +189,22 @@ impl TestApp {
}
}
pub fn get_post_urls(&self, request: &wiremock::Request) -> ConfirmationLinks {
let body: serde_json::Value = serde_json::from_slice(&request.body).unwrap();
let get_link = |s: &str| {
let links = get_links(s);
assert!(!links.is_empty());
let mut confirmation_link = reqwest::Url::parse(links[0].as_str()).unwrap();
assert_eq!(confirmation_link.host_str().unwrap(), "127.0.0.1");
confirmation_link.set_port(Some(self.port)).unwrap();
confirmation_link
};
let html = get_link(body["html"].as_str().unwrap());
let text = get_link(body["text"].as_str().unwrap());
ConfirmationLinks { html, text }
}
pub fn get_unsubscribe_links(&self, request: &wiremock::Request) -> ConfirmationLinks {
let body: serde_json::Value = serde_json::from_slice(&request.body).unwrap();
let get_link = |s: &str| {
@@ -395,3 +417,11 @@ pub fn get_links(s: &'_ str) -> Vec<Link<'_>> {
.filter(|l| *l.kind() == linkify::LinkKind::Url)
.collect()
}
pub fn subject() -> String {
Sentence(1..2).fake()
}
pub fn content() -> String {
Paragraph(1..10).fake()
}