|
| 1 | +use chirp_workflow::prelude::*; |
| 2 | +use proto::backend::{pkg::*}; |
| 3 | +use rivet_operation::prelude::proto; |
| 4 | +use rand::Rng; |
| 5 | + |
| 6 | +#[workflow_test] |
| 7 | +async fn empty(ctx: TestCtx) { |
| 8 | + let res = ctx.op(::user::ops::get::Input { |
| 9 | + user_ids: Vec::new(), |
| 10 | + }) |
| 11 | + .await |
| 12 | + .unwrap(); |
| 13 | + assert!(res.users.is_empty()); |
| 14 | +} |
| 15 | + |
| 16 | +#[workflow_test] |
| 17 | +async fn fetch(ctx: TestCtx) { |
| 18 | + struct TestUser { |
| 19 | + user_id: Option<Uuid>, |
| 20 | + display_name: String, |
| 21 | + account_number: i64, |
| 22 | + bio: String, |
| 23 | + } |
| 24 | + |
| 25 | + // Generate test users |
| 26 | + let mut users = std::iter::repeat_with(|| TestUser { |
| 27 | + user_id: None, |
| 28 | + display_name: util::faker::display_name(), |
| 29 | + account_number: rand::thread_rng().gen_range(1..10000), |
| 30 | + bio: util::faker::ident(), |
| 31 | + }) |
| 32 | + .take(8) |
| 33 | + .collect::<Vec<_>>(); |
| 34 | + |
| 35 | + // Insert test users |
| 36 | + for user in &mut users { |
| 37 | + let user_res = op!([ctx] faker_user { }).await.unwrap(); |
| 38 | + let user_id = user_res.user_id.unwrap().as_uuid(); |
| 39 | + |
| 40 | + msg!([ctx] user::msg::profile_set(user_id) -> user::msg::update { |
| 41 | + user_id: Some(user_id.into()), |
| 42 | + display_name: Some(user.display_name.clone()), |
| 43 | + account_number: Some(user.account_number as u32), |
| 44 | + bio: Some(user.bio.clone()), |
| 45 | + }) |
| 46 | + .await |
| 47 | + .unwrap(); |
| 48 | + |
| 49 | + user.user_id = Some(user_id); |
| 50 | + } |
| 51 | + |
| 52 | + // Fetch the users |
| 53 | + let res = ctx.op(::user::ops::get::Input { |
| 54 | + user_ids: users.iter().map(|u| u.user_id.unwrap()).collect(), |
| 55 | + }) |
| 56 | + .await |
| 57 | + .unwrap(); |
| 58 | + |
| 59 | + // Validate the users |
| 60 | + assert_eq!(users.len(), res.users.len()); |
| 61 | + for user in &users { |
| 62 | + let user_res = res |
| 63 | + .users |
| 64 | + .iter() |
| 65 | + .find(|u| u.user_id.unwrap().as_uuid() == user.user_id.unwrap()) |
| 66 | + .expect("user not returned"); |
| 67 | + |
| 68 | + assert_eq!(user.display_name, user_res.display_name); |
| 69 | + assert_eq!(user.account_number, user_res.account_number as i64); |
| 70 | + assert_eq!(user.bio, user_res.bio); |
| 71 | + } |
| 72 | +} |
0 commit comments