-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
452 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use chirp_workflow::prelude::*; | ||
use rivet_operation::prelude::proto::backend; | ||
|
||
const TEST_BODY: &[u8] = b"test file"; | ||
|
||
#[workflow_test] | ||
async fn empty(ctx: TestCtx) { | ||
let user_res = op!([ctx] faker_user {}).await.unwrap(); | ||
let user_id = user_res.user_id.unwrap().as_uuid(); | ||
|
||
// Create the upload | ||
let upload_prepare_res = op!([ctx] upload_prepare { | ||
bucket: "bucket-user-avatar".into(), | ||
files: vec![ | ||
backend::upload::PrepareFile { | ||
path: "image.png".to_owned(), | ||
mime: Some("image/png".into()), | ||
content_length: TEST_BODY.len() as u64, | ||
..Default::default() | ||
}, | ||
], | ||
}) | ||
.await | ||
.unwrap(); | ||
let upload_id = upload_prepare_res.upload_id.unwrap(); | ||
let presigned_request = upload_prepare_res.presigned_requests.first().unwrap(); | ||
|
||
tracing::info!("writing test files"); | ||
let res = reqwest::Client::new() | ||
.put(&presigned_request.url) | ||
.body(TEST_BODY.to_vec()) | ||
.header("content-type", "image/png") | ||
.send() | ||
.await | ||
.expect("failed to upload"); | ||
if res.status().is_success() { | ||
tracing::info!("uploaded successfully"); | ||
} else { | ||
panic!( | ||
"failed to upload ({}): {:?}", | ||
res.status(), | ||
res.text().await | ||
); | ||
} | ||
|
||
ctx.op(::user::ops::avatar_upload_complete::Input { | ||
user_id: user_id, | ||
upload_id: upload_id.as_uuid() | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let uploads_res = op!([ctx] upload_get { | ||
upload_ids: vec![upload_id] | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let upload = uploads_res.uploads.first().unwrap(); | ||
|
||
assert!(upload.complete_ts.is_some(), "Upload did not complete"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use chirp_workflow::prelude::*; | ||
use proto::backend::{pkg::*}; | ||
use rivet_operation::prelude::proto; | ||
use rand::Rng; | ||
|
||
#[workflow_test] | ||
async fn empty(ctx: TestCtx) { | ||
let res = ctx.op(::user::ops::get::Input { | ||
user_ids: Vec::new(), | ||
}) | ||
.await | ||
.unwrap(); | ||
assert!(res.users.is_empty()); | ||
} | ||
|
||
#[workflow_test] | ||
async fn fetch(ctx: TestCtx) { | ||
struct TestUser { | ||
user_id: Option<Uuid>, | ||
display_name: String, | ||
account_number: i64, | ||
bio: String, | ||
} | ||
|
||
// Generate test users | ||
let mut users = std::iter::repeat_with(|| TestUser { | ||
user_id: None, | ||
display_name: util::faker::display_name(), | ||
account_number: rand::thread_rng().gen_range(1..10000), | ||
bio: util::faker::ident(), | ||
}) | ||
.take(8) | ||
.collect::<Vec<_>>(); | ||
|
||
// Insert test users | ||
for user in &mut users { | ||
let user_res = op!([ctx] faker_user { }).await.unwrap(); | ||
let user_id = user_res.user_id.unwrap().as_uuid(); | ||
|
||
msg!([ctx] user::msg::profile_set(user_id) -> user::msg::update { | ||
user_id: Some(user_id.into()), | ||
display_name: Some(user.display_name.clone()), | ||
account_number: Some(user.account_number as u32), | ||
bio: Some(user.bio.clone()), | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
user.user_id = Some(user_id); | ||
} | ||
|
||
// Fetch the users | ||
let res = ctx.op(::user::ops::get::Input { | ||
user_ids: users.iter().map(|u| u.user_id.unwrap()).collect(), | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
// Validate the users | ||
assert_eq!(users.len(), res.users.len()); | ||
for user in &users { | ||
let user_res = res | ||
.users | ||
.iter() | ||
.find(|u| u.user_id.unwrap().as_uuid() == user.user_id.unwrap()) | ||
.expect("user not returned"); | ||
|
||
assert_eq!(user.display_name, user_res.display_name); | ||
assert_eq!(user.account_number, user_res.account_number as i64); | ||
assert_eq!(user.bio, user_res.bio); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use chirp_workflow::prelude::*; | ||
use rivet_operation::prelude::proto::backend; | ||
|
||
#[workflow_test] | ||
async fn email(ctx: TestCtx) { | ||
let user_res = op!([ctx] faker_user { | ||
..Default::default() | ||
}) | ||
.await | ||
.unwrap(); | ||
let user_id = user_res.user_id.unwrap().as_uuid(); | ||
|
||
let email = util::faker::email(); | ||
ctx.op(::user::ops::identity::create::Input { | ||
user_id: user_id, | ||
identity: backend::user_identity::Identity { | ||
kind: Some(backend::user_identity::identity::Kind::Email( | ||
backend::user_identity::identity::Email { | ||
email: email.clone(), | ||
} | ||
)), | ||
}, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let (sql_exists,) = sqlx::query_as::<_, (bool,)>( | ||
"SELECT EXISTS (SELECT 1 FROM db_user_identity.emails WHERE email = $1)", | ||
) | ||
.bind(&email) | ||
.fetch_one(&ctx.crdb().await.unwrap()) | ||
.await | ||
.unwrap(); | ||
assert!(sql_exists, "identity not created"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use chirp_workflow::prelude::*; | ||
use rivet_operation::prelude::proto::backend; | ||
|
||
#[workflow_test] | ||
async fn empty(ctx: TestCtx) { | ||
let user_res = op!([ctx] faker_user { | ||
..Default::default() | ||
}) | ||
.await | ||
.unwrap(); | ||
let user_id = user_res.user_id.unwrap().as_uuid(); | ||
|
||
let email = util::faker::email(); | ||
ctx.op(::user::ops::identity::create::Input { | ||
user_id: user_id, | ||
identity: backend::user_identity::Identity { | ||
kind: Some(backend::user_identity::identity::Kind::Email( | ||
backend::user_identity::identity::Email { | ||
email: email.clone() | ||
} | ||
)), | ||
}, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
ctx.op(::user::ops::identity::delete::Input { | ||
user_ids: vec![user_id], | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let (sql_exists,) = sqlx::query_as::<_, (bool,)>( | ||
"SELECT EXISTS (SELECT 1 FROM db_user_identity.emails WHERE email = $1)", | ||
) | ||
.bind(&email) | ||
.fetch_one(&ctx.crdb().await.unwrap()) | ||
.await | ||
.unwrap(); | ||
assert!(!sql_exists, "identity not deleted"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use chirp_workflow::prelude::*; | ||
use rivet_operation::prelude::proto::backend; | ||
|
||
#[workflow_test] | ||
async fn empty(ctx: TestCtx) { | ||
let user_res = op!([ctx] faker_user { | ||
..Default::default() | ||
}) | ||
.await | ||
.unwrap(); | ||
let user_id = user_res.user_id.unwrap().as_uuid(); | ||
|
||
let email = util::faker::email(); | ||
ctx.op(::user::ops::identity::create::Input { | ||
user_id: user_id, | ||
identity: backend::user_identity::Identity { | ||
kind: Some(backend::user_identity::identity::Kind::Email( | ||
backend::user_identity::identity::Email { | ||
email: email.clone() | ||
} | ||
)), | ||
}, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let res = ctx.op(::user::ops::identity::get::Input { | ||
user_ids: vec![user_id, Uuid::new_v4()], | ||
}) | ||
.await | ||
.unwrap(); | ||
assert_eq!(1, res.users.len()); | ||
assert_eq!( | ||
1, | ||
res.users | ||
.iter() | ||
.find(|u| u.user_id == user_id) | ||
.unwrap() | ||
.identities | ||
.len() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use chirp_workflow::prelude::*; | ||
use rivet_operation::prelude::proto::backend; | ||
|
||
#[workflow_test] | ||
async fn empty(ctx: TestCtx) { | ||
let user_res = op!([ctx] faker_user {}).await.unwrap(); | ||
let user_id = user_res.user_id.as_ref().unwrap().as_uuid(); | ||
|
||
// Register user | ||
let email = util::faker::email(); | ||
let _res = ctx.op(::user::ops::identity::create::Input { | ||
user_id: user_id, | ||
identity: backend::user_identity::Identity { | ||
kind: Some(backend::user_identity::identity::Kind::Email( | ||
backend::user_identity::identity::Email { | ||
email: email.clone() | ||
} | ||
)), | ||
}, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
ctx.op(::user::ops::pending_delete_toggle::Input { | ||
user_id: user_id, | ||
active: true, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let (delete_request_ts,): (Option<i64>,) = sqlx::query_as(indoc!( | ||
" | ||
SELECT delete_request_ts | ||
FROM db_user.users | ||
WHERE | ||
user_id = $1 | ||
", | ||
)) | ||
.bind(user_id) | ||
.fetch_one(&ctx.crdb().await.unwrap()) | ||
.await | ||
.unwrap(); | ||
|
||
assert!(delete_request_ts.is_some()); | ||
|
||
ctx.op(::user::ops::pending_delete_toggle::Input { | ||
user_id: user_id, | ||
active: false, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let (delete_request_ts,): (Option<i64>,) = sqlx::query_as(indoc!( | ||
" | ||
SELECT delete_request_ts | ||
FROM db_user.users | ||
WHERE | ||
user_id = $1 | ||
", | ||
)) | ||
.bind(user_id) | ||
.fetch_one(&ctx.crdb().await.unwrap()) | ||
.await | ||
.unwrap(); | ||
|
||
assert!(delete_request_ts.is_none()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use chirp_workflow::prelude::*; | ||
|
||
#[workflow_test] | ||
async fn empty(ctx: TestCtx) { | ||
let user_res = op!([ctx] faker_user {}).await.unwrap(); | ||
let user_id = user_res.user_id.unwrap().as_uuid(); | ||
|
||
let res = ctx.op(::user::ops::profile_validate::Input { | ||
user_id: user_id, | ||
display_name: Some(" bad display name".to_owned()), | ||
account_number: Some(10000), | ||
bio: Some("bad\n\n\n\n\n\nbio".to_owned()) | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(res.errors.len(), 3, "validation failed"); | ||
} |
Oops, something went wrong.