summaryrefslogtreecommitdiff
path: root/src/boot/routes/test.rs
blob: 8808b70da917519a0898d43f3169a4b40d4e6e0d (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use axum::extract::State;

use super::get;
use crate::test::fixtures;

#[tokio::test]
async fn returns_identity() {
    let app = fixtures::scratch_app().await;

    let viewer = fixtures::identity::fictitious();
    let response = get::handler(State(app), viewer.clone())
        .await
        .expect("boot always succeeds");

    assert_eq!(viewer.login, response.login);
}

#[tokio::test]
async fn includes_logins() {
    let app = fixtures::scratch_app().await;
    let spectator = fixtures::login::create(&app, &fixtures::now()).await;

    let viewer = fixtures::identity::fictitious();
    let response = get::handler(State(app), viewer)
        .await
        .expect("boot always succeeds");

    assert!(response.snapshot.logins.contains(&spectator));
}

#[tokio::test]
async fn includes_channels() {
    let app = fixtures::scratch_app().await;
    let channel = fixtures::channel::create(&app, &fixtures::now()).await;

    let viewer = fixtures::identity::fictitious();
    let response = get::handler(State(app), viewer)
        .await
        .expect("boot always succeeds");

    assert!(response.snapshot.channels.contains(&channel));
}

#[tokio::test]
async fn includes_messages() {
    let app = fixtures::scratch_app().await;
    let sender = fixtures::login::create(&app, &fixtures::now()).await;
    let channel = fixtures::channel::create(&app, &fixtures::now()).await;
    let message = fixtures::message::send(&app, &channel, &sender, &fixtures::now()).await;

    let viewer = fixtures::identity::fictitious();
    let response = get::handler(State(app), viewer)
        .await
        .expect("boot always succeeds");

    assert!(response.snapshot.messages.contains(&message));
}

#[tokio::test]
async fn excludes_expired_messages() {
    let app = fixtures::scratch_app().await;
    let sender = fixtures::login::create(&app, &fixtures::ancient()).await;
    let channel = fixtures::channel::create(&app, &fixtures::ancient()).await;
    let expired_message =
        fixtures::message::send(&app, &channel, &sender, &fixtures::ancient()).await;

    app.messages()
        .expire(&fixtures::now())
        .await
        .expect("expiry never fails");

    let viewer = fixtures::identity::fictitious();
    let response = get::handler(State(app), viewer)
        .await
        .expect("boot always succeeds");

    assert!(!response.snapshot.messages.contains(&expired_message));
}

#[tokio::test]
async fn excludes_deleted_messages() {
    let app = fixtures::scratch_app().await;
    let sender = fixtures::login::create(&app, &fixtures::now()).await;
    let channel = fixtures::channel::create(&app, &fixtures::now()).await;
    let deleted_message = fixtures::message::send(&app, &channel, &sender, &fixtures::now()).await;

    app.messages()
        .delete(&deleted_message.id, &fixtures::now())
        .await
        .expect("deleting valid message succeeds");

    let viewer = fixtures::identity::fictitious();
    let response = get::handler(State(app), viewer)
        .await
        .expect("boot always succeeds");

    assert!(!response.snapshot.messages.contains(&deleted_message));
}

#[tokio::test]
async fn excludes_expired_channels() {
    let app = fixtures::scratch_app().await;
    let expired_channel = fixtures::channel::create(&app, &fixtures::ancient()).await;

    app.channels()
        .expire(&fixtures::now())
        .await
        .expect("expiry never fails");

    let viewer = fixtures::identity::fictitious();
    let response = get::handler(State(app), viewer)
        .await
        .expect("boot always succeeds");

    assert!(!response.snapshot.channels.contains(&expired_channel));
}

#[tokio::test]
async fn excludes_deleted_channels() {
    let app = fixtures::scratch_app().await;
    let deleted_channel = fixtures::channel::create(&app, &fixtures::now()).await;

    app.channels()
        .delete(&deleted_channel.id, &fixtures::now())
        .await
        .expect("deleting a valid channel succeeds");

    let viewer = fixtures::identity::fictitious();
    let response = get::handler(State(app), viewer)
        .await
        .expect("boot always succeeds");

    assert!(!response.snapshot.channels.contains(&deleted_channel));
}