Skip to content

Commit fc5582e

Browse files
committed
tests/util: Add MockTokenUser::for_token() fn
This makes it possible to construct `MockTokenUser` instances from an existing plaintext token.
1 parent 203808c commit fc5582e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/tests/util.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use http::header;
3939
use secrecy::ExposeSecret;
4040
use serde_json::json;
4141
use std::collections::HashMap;
42+
use std::fmt::Display;
4243
use std::net::SocketAddr;
4344
use tower::ServiceExt;
4445

@@ -370,6 +371,14 @@ impl RequestHelper for MockTokenUser {
370371
}
371372

372373
impl MockTokenUser {
374+
pub fn for_token(token: impl Display, app: TestApp) -> Self {
375+
Self {
376+
app,
377+
token: None,
378+
plaintext: format!("Bearer {token}"),
379+
}
380+
}
381+
373382
/// Returns a reference to the database `ApiToken` model
374383
pub fn as_model(&self) -> &ApiToken {
375384
const ERROR: &str = "Original `ApiToken` was not set on this `MockTokenUser` instance";

0 commit comments

Comments
 (0)