summaryrefslogtreecommitdiff
path: root/src/test/fixtures/channel.rs
blob: a1dda61b4b2ee859fbdd5891551a82c6e60d201a (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
use std::future;

use faker_rand::{
    en_us::{addresses::CityName, names::FullName},
    faker_impl_from_templates,
};
use rand;

use crate::{
    app::App,
    channel::{self, Channel},
    clock::RequestedAt,
    event::Event,
};

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

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

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

pub fn events(event: Event) -> future::Ready<Option<channel::Event>> {
    future::ready(match event {
        Event::Channel(channel) => Some(channel),
        _ => None,
    })
}

pub fn created(event: channel::Event) -> future::Ready<Option<channel::event::Created>> {
    future::ready(match event {
        channel::Event::Created(event) => Some(event),
        channel::Event::Deleted(_) => None,
    })
}