summaryrefslogtreecommitdiff
path: root/src/test/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/fixtures')
-rw-r--r--src/test/fixtures/boot.rs11
-rw-r--r--src/test/fixtures/conversation.rs11
-rw-r--r--src/test/fixtures/cookie.rs14
-rw-r--r--src/test/fixtures/identity.rs21
-rw-r--r--src/test/fixtures/invite.rs12
-rw-r--r--src/test/fixtures/message.rs13
6 files changed, 56 insertions, 26 deletions
diff --git a/src/test/fixtures/boot.rs b/src/test/fixtures/boot.rs
index 120726f..7421512 100644
--- a/src/test/fixtures/boot.rs
+++ b/src/test/fixtures/boot.rs
@@ -1,7 +1,12 @@
-use crate::{app::App, event::Sequence};
+use axum::extract::FromRef;
-pub async fn resume_point(app: &App) -> Sequence {
- app.boot()
+use crate::{boot::app::Boot, event::Sequence};
+
+pub async fn resume_point<App>(app: &App) -> Sequence
+where
+ Boot: FromRef<App>,
+{
+ Boot::from_ref(app)
.snapshot()
.await
.expect("boot always succeeds")
diff --git a/src/test/fixtures/conversation.rs b/src/test/fixtures/conversation.rs
index fb2f58d..f0d8c8c 100644
--- a/src/test/fixtures/conversation.rs
+++ b/src/test/fixtures/conversation.rs
@@ -1,3 +1,4 @@
+use axum::extract::FromRef;
use faker_rand::{
en_us::{addresses::CityName, names::FullName},
faker_impl_from_templates,
@@ -6,15 +7,17 @@ use faker_rand::{
use rand;
use crate::{
- app::App,
clock::RequestedAt,
- conversation::{self, Conversation},
+ conversation::{self, Conversation, app::Conversations},
name::Name,
};
-pub async fn create(app: &App, created_at: &RequestedAt) -> Conversation {
+pub async fn create<App>(app: &App, created_at: &RequestedAt) -> Conversation
+where
+ Conversations: FromRef<App>,
+{
let name = propose();
- app.conversations()
+ Conversations::from_ref(app)
.create(&name, created_at)
.await
.expect("should always succeed if the conversation is actually new")
diff --git a/src/test/fixtures/cookie.rs b/src/test/fixtures/cookie.rs
index 7dc5083..0b5ec9b 100644
--- a/src/test/fixtures/cookie.rs
+++ b/src/test/fixtures/cookie.rs
@@ -1,21 +1,25 @@
+use axum::extract::FromRef;
use uuid::Uuid;
use crate::{
- app::App, clock::RequestedAt, name::Name, password::Password, token::extract::IdentityCookie,
+ clock::RequestedAt, login::app::Logins, name::Name, password::Password,
+ token::extract::IdentityCookie,
};
pub fn not_logged_in() -> IdentityCookie {
IdentityCookie::new()
}
-pub async fn logged_in(
+pub async fn logged_in<App>(
app: &App,
credentials: &(Name, Password),
now: &RequestedAt,
-) -> IdentityCookie {
+) -> IdentityCookie
+where
+ Logins: FromRef<App>,
+{
let (name, password) = credentials;
- let secret = app
- .logins()
+ let secret = Logins::from_ref(app)
.with_password(name, password, now)
.await
.expect("should succeed given known-valid credentials");
diff --git a/src/test/fixtures/identity.rs b/src/test/fixtures/identity.rs
index 93e4a38..20929f9 100644
--- a/src/test/fixtures/identity.rs
+++ b/src/test/fixtures/identity.rs
@@ -1,11 +1,15 @@
+use axum::extract::FromRef;
+
use crate::{
app::App,
clock::RequestedAt,
+ login::app::Logins,
name::Name,
password::Password,
test::fixtures,
token::{
Token,
+ app::Tokens,
extract::{Identity, IdentityCookie},
},
};
@@ -15,23 +19,30 @@ pub async fn create(app: &App, created_at: &RequestedAt) -> Identity {
logged_in(app, &credentials, created_at).await
}
-pub async fn from_cookie(
+pub async fn from_cookie<App>(
app: &App,
cookie: &IdentityCookie,
validated_at: &RequestedAt,
-) -> Identity {
+) -> Identity
+where
+ Tokens: FromRef<App>,
+{
let secret = cookie.secret().expect("identity token has a secret");
- app.tokens()
+ Tokens::from_ref(app)
.validate(&secret, validated_at)
.await
.expect("always validates newly-issued secret")
}
-pub async fn logged_in(
+pub async fn logged_in<App>(
app: &App,
credentials: &(Name, Password),
issued_at: &RequestedAt,
-) -> Identity {
+) -> Identity
+where
+ Tokens: FromRef<App>,
+ Logins: FromRef<App>,
+{
let secret = fixtures::cookie::logged_in(app, credentials, issued_at).await;
from_cookie(app, &secret, issued_at).await
}
diff --git a/src/test/fixtures/invite.rs b/src/test/fixtures/invite.rs
index 654d1b4..5a5d4d0 100644
--- a/src/test/fixtures/invite.rs
+++ b/src/test/fixtures/invite.rs
@@ -1,12 +1,16 @@
+use axum::extract::FromRef;
+
use crate::{
- app::App,
clock::DateTime,
- invite::{self, Invite},
+ invite::{self, Invite, app::Invites},
login::Login,
};
-pub async fn issue(app: &App, issuer: &Login, issued_at: &DateTime) -> Invite {
- app.invites()
+pub async fn issue<App>(app: &App, issuer: &Login, issued_at: &DateTime) -> Invite
+where
+ Invites: FromRef<App>,
+{
+ Invites::from_ref(app)
.issue(issuer, issued_at)
.await
.expect("issuing invites never fails")
diff --git a/src/test/fixtures/message.rs b/src/test/fixtures/message.rs
index 92ac1f5..0bd0b7a 100644
--- a/src/test/fixtures/message.rs
+++ b/src/test/fixtures/message.rs
@@ -1,22 +1,25 @@
+use axum::extract::FromRef;
use faker_rand::lorem::Paragraphs;
use crate::{
- app::App,
clock::RequestedAt,
conversation::Conversation,
login::Login,
- message::{self, Body, Message},
+ message::{self, Body, Message, app::Messages},
};
-pub async fn send(
+pub async fn send<App>(
app: &App,
conversation: &Conversation,
sender: &Login,
sent_at: &RequestedAt,
-) -> Message {
+) -> Message
+where
+ Messages: FromRef<App>,
+{
let body = propose();
- app.messages()
+ Messages::from_ref(app)
.send(&conversation.id, sender, sent_at, &body)
.await
.expect("should succeed if the conversation exists")