summaryrefslogtreecommitdiff
path: root/src/test/fixtures/conversation.rs
blob: f0d8c8cf103c17ec1a7e67d3c9b3bbd9ae19affe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use axum::extract::FromRef;
use faker_rand::{
    en_us::{addresses::CityName, names::FullName},
    faker_impl_from_templates,
    lorem::Paragraphs,
};
use rand;

use crate::{
    clock::RequestedAt,
    conversation::{self, Conversation, app::Conversations},
    name::Name,
};

pub async fn create<App>(app: &App, created_at: &RequestedAt) -> Conversation
where
    Conversations: FromRef<App>,
{
    let name = propose();
    Conversations::from_ref(app)
        .create(&name, created_at)
        .await
        .expect("should always succeed if the conversation is actually new")
}

pub fn propose() -> Name {
    rand::random::<NameTemplate>().to_string().into()
}

pub fn propose_invalid_name() -> Name {
    rand::random::<Paragraphs>().to_string().into()
}

struct NameTemplate(String);
faker_impl_from_templates! {
    NameTemplate; "{} {}", CityName, FullName;
}

pub fn fictitious() -> conversation::Id {
    conversation::Id::generate()
}