Skip to content

Commit 883775d

Browse files
committed
feat(users): user wf tests
1 parent c70fe90 commit 883775d

File tree

16 files changed

+116
-36
lines changed

16 files changed

+116
-36
lines changed

packages/services/monolith/standalone/workflow-worker/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ job-run.workspace = true
1717
linode.workspace = true
1818
pegboard.workspace = true
1919
rivet-config.workspace = true
20+
user.workspace = true

packages/services/monolith/standalone/workflow-worker/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ pub async fn run_from_env(
1515
.merge(linode::registry()?)?
1616
.merge(ds::registry()?)?
1717
.merge(job_run::registry()?)?
18-
.merge(pegboard::registry()?)?;
18+
.merge(pegboard::registry()?)?
19+
.merge(user::registry()?)?;
1920

2021
let db = db::DatabaseCrdbNats::from_pools(pools.crdb()?, pools.nats()?);
2122
let worker = Worker::new(reg.handle(), db);

packages/services/user/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
use chirp_workflow::prelude::*;
2+
13
pub mod ops;
24
pub mod types;
35
pub mod workflows;
6+
7+
pub fn registry() -> WorkflowResult<Registry> {
8+
use workflows::*;
9+
10+
let mut registry = Registry::new();
11+
registry.register_workflow::<user::Workflow>()?;
12+
13+
Ok(registry)
14+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// use chirp_workflow::prelude::*;
2+
3+
// #[derive(Debug, Default)]
4+
// pub struct Input {}
5+
6+
// #[derive(Debug)]
7+
// pub struct Output {
8+
// pub user_id: Uuid,
9+
// }
10+
11+
// #[operation]
12+
// async fn user(ctx: &OperationCtx, input: &Input) -> GlobalResult<Output> {
13+
// let user_id = Uuid::new_v4();
14+
15+
// // TODO: Move back to faker op after ops can dispatch workflows
16+
// let mut creation_sub = ctx
17+
// .subscribe::<crate::workflows::user::CreateComplete>(("user_id", user_id))
18+
// .await?;
19+
20+
// ctx.workflow(crate::workflows::user::Input {
21+
// user_id,
22+
// display_name: None,
23+
// })
24+
// .tag("user_id", user_id)
25+
// .dispatch()
26+
// .await?;
27+
28+
// creation_sub.next().await?;
29+
30+
// Ok(Output {
31+
// user_id: user_id,
32+
// })
33+
// }

packages/services/user/src/ops/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub mod resolve_display_name;
66
pub mod resolve_email;
77
pub mod team_list;
88
pub mod token_create;
9-
9+
// pub mod faker;
1010
pub mod identity;

packages/services/user/src/workflows/user/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct Input {
2424
}
2525

2626
#[workflow]
27-
pub async fn user(ctx: &mut WorkflowCtx, input: &Input) -> GlobalResult<()> {
27+
pub async fn user(ctx: &mut WorkflowCtx, input: &Input) -> GlobalResult<()> {
2828
let (display_name, _account_number) = ctx.activity(InsertDbInput {
2929
user_id: input.user_id,
3030
display_name: input.display_name.clone(),
@@ -273,7 +273,7 @@ async fn insert_db(ctx: &ActivityCtx, input: &InsertDbInput) -> GlobalResult<(St
273273
};
274274

275275
let account_number = gen_account_number();
276-
tracing::debug!(%display_name, %account_number, "insert user attempt");
276+
tracing::info!(%display_name, %account_number, "insert user attempt");
277277

278278
sql_execute!(
279279
[ctx]

packages/services/user/tests/avatar_upload_complete.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use chirp_workflow::prelude::*;
22
use rivet_operation::prelude::proto::backend;
33

4+
mod common;
5+
46
const TEST_BODY: &[u8] = b"test file";
57

68
#[workflow_test]
79
async fn empty(ctx: TestCtx) {
8-
let user_res = op!([ctx] faker_user {}).await.unwrap();
9-
let user_id = user_res.user_id.unwrap().as_uuid();
10+
let user_res = common::make_test_user(&ctx).await.unwrap();
11+
let user_id = user_res.user_id;
1012

1113
// Create the upload
1214
let upload_prepare_res = op!([ctx] upload_prepare {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use chirp_workflow::prelude::*;
2+
3+
// TODO: Move back to faker op after ops can dispatch workflows
4+
#[derive(Debug)]
5+
pub struct FakerUserOutput {
6+
pub user_id: Uuid,
7+
}
8+
9+
pub async fn make_test_user(ctx: &TestCtx) -> GlobalResult<FakerUserOutput> {
10+
tracing::info!("attempting to make test user");
11+
let user_id = Uuid::new_v4();
12+
13+
let mut creation_sub = ctx
14+
.subscribe::<user::workflows::user::CreateComplete>(("user_id", user_id))
15+
.await?;
16+
17+
ctx.workflow(user::workflows::user::Input {
18+
user_id,
19+
display_name: None,
20+
})
21+
.tag("user_id", user_id)
22+
.dispatch()
23+
.await?;
24+
25+
creation_sub.next().await?;
26+
27+
tracing::info!("creation sub received");
28+
29+
Ok(FakerUserOutput {
30+
user_id
31+
})
32+
}

packages/services/user/tests/get.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use proto::backend::{pkg::*};
33
use rivet_operation::prelude::proto;
44
use rand::Rng;
55

6+
mod common;
7+
68
#[workflow_test]
79
async fn empty(ctx: TestCtx) {
810
let res = ctx.op(::user::ops::get::Input {

packages/services/user/tests/identity_create.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use chirp_workflow::prelude::*;
22
use rivet_operation::prelude::proto::backend;
33

4+
mod common;
5+
46
#[workflow_test]
57
async fn email(ctx: TestCtx) {
6-
let user_res = op!([ctx] faker_user {
7-
..Default::default()
8-
})
9-
.await
10-
.unwrap();
11-
let user_id = user_res.user_id.unwrap().as_uuid();
8+
let user_res = common::make_test_user(&ctx).await.unwrap();
9+
let user_id = user_res.user_id;
1210

1311
let email = util::faker::email();
1412
ctx.op(::user::ops::identity::create::Input {

0 commit comments

Comments
 (0)