tests for new post notifications and dashboard stats
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user