summaryrefslogtreecommitdiff
path: root/src/test/fixtures/user.rs
blob: 086f8667bbcf7952c4b181941f52450a726670af (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
42
43
44
45
46
47
48
49
50
51
52
use faker_rand::{en_us::internet, lorem::Paragraphs};
use uuid::Uuid;

use crate::{
    app::App,
    clock::RequestedAt,
    name::Name,
    password::Password,
    user::{self, User},
};

pub async fn create_with_password(app: &App, created_at: &RequestedAt) -> (Name, Password) {
    let (name, password) = propose();
    let user = app
        .users()
        .create(&name, &password, created_at)
        .await
        .expect("should always succeed if the login is actually new");

    (user.name, password)
}

pub async fn create(app: &App, created_at: &RequestedAt) -> User {
    let (name, password) = propose();
    app.users()
        .create(&name, &password, created_at)
        .await
        .expect("should always succeed if the login is actually new")
}

pub fn fictitious() -> User {
    User {
        id: user::Id::generate(),
        name: propose_name(),
    }
}

pub fn propose() -> (Name, Password) {
    (propose_name(), propose_password())
}

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

fn propose_name() -> Name {
    rand::random::<internet::Username>().to_string().into()
}

pub fn propose_password() -> Password {
    Uuid::new_v4().to_string().into()
}