Skip to content

Commit

Permalink
test: Test paginated action requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tlater-famedly committed Jan 16, 2025
1 parent 6680e7c commit 835a51c
Showing 1 changed file with 108 additions and 16 deletions.
124 changes: 108 additions & 16 deletions tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ async fn tear_down(zitadel: &Zitadel) {
let id = user.user_id().expect("Couldn't get user id during tear down.");
zitadel.delete_user(id).await.expect("Error deleting user");
}

let mut stream = zitadel
.search_actions(ListActionsRequest::new(vec![V1ActionQuery::new()]))
.expect("Error getting the list of actions to tear down");

while let Some(action) = stream.next().await {
let id = action.id().expect("Couldn't get action id during tear down.");
zitadel.delete_action(id.clone()).await.expect("Error deleting action");
}
}

#[tokio::test]
Expand Down Expand Up @@ -109,16 +118,55 @@ async fn test_e2e_create_application() -> Result<()> {

let project_id = project.id().expect("Must have created a project with a valid ID");

let res = zitadel
zitadel
.create_application(
project_id.to_owned(),
ManagementServiceAddApiAppBody::new("TestApp".to_owned()),
)
.await;
.await?;

// TODO: Once we have a list application method, we should check
// that the org was actually created
assert!(res.is_ok());
let stream = zitadel.list_applications(
project_id.to_owned(),
ListApplicationsRequest::new(vec![V1AppQuery::new()
.with_name_query(V1AppNameQuery::new().with_name("TestApp".to_owned()))]),
)?;

let apps: Vec<String> =
stream.map(|app| app.name().expect("App name must be set").clone()).collect().await;
assert_eq!(apps, ["TestApp"]);

tear_down(&zitadel).await;

Ok(())
}

#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_list_applications() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf()).await?;

let project =
zitadel.create_project(V1AddProjectRequest::new("TestProject".to_owned())).await?;

let project_id = project.id().expect("Must have created a project with a valid ID");

let mut application_names = Vec::new();

for i in 0..10 {
let name = format!("TestApp{i}");
let application = ManagementServiceAddApiAppBody::new(name.to_owned());
application_names.push(name);
assert!(zitadel.create_application(project_id.to_owned(), application).await.is_ok());
}

let stream =
zitadel.list_applications(project_id.to_owned(), ListApplicationsRequest::new(vec![]))?;

let found_application_names: Vec<String> =
stream.map(|app| app.name().expect("No name found for action").clone()).collect().await;
assert_eq!(found_application_names, application_names);

tear_down(&zitadel).await;

Expand All @@ -139,10 +187,49 @@ async fn test_e2e_create_action() -> Result<()> {
))
.await;

// TODO: Once we have a list action method, we should check that
// the action was actually created
assert!(res.is_ok());

let stream = zitadel.search_actions(ListActionsRequest::new(vec![V1ActionQuery::new()
.with_action_name_query(V1ActionNameQuery::new().with_name("test-action".to_owned()))]))?;

let actions: Vec<String> = stream
.map(|action| action.name().expect("No name found for action").clone())
.collect()
.await;
assert_eq!(actions, vec!["test-action"]);

tear_down(&zitadel).await;

Ok(())
}

#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_list_actions() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf()).await?;

let mut action_names = Vec::new();

for i in 0..10 {
let name = format!("test-action-{i}");

let action =
V1CreateActionRequest::new(name.clone(), "console.log('test-action')".to_owned());

action_names.push(name);
assert!(zitadel.create_action(action).await.is_ok());
}

let stream = zitadel.search_actions(ListActionsRequest::new(vec![]))?;

let found_action_names: Vec<String> = stream
.map(|action| action.name().expect("No name found for action").clone())
.collect()
.await;
assert_eq!(found_action_names, action_names);

tear_down(&zitadel).await;

Ok(())
Expand All @@ -164,19 +251,23 @@ async fn test_e2e_update_action() -> Result<()> {

let action_id = res.id().expect("Must have created an action with a valid ID");

let res = zitadel
zitadel
.update_action(
action_id.to_owned(),
ManagementServiceUpdateActionBody::new(
"test-action".to_owned(),
"console.log('test-action-update')".to_owned(),
),
)
.await;
.await?;

// TODO: Once we have a list action method, we should check that
// the action was actually updated
assert!(res.is_ok());
let mut stream = zitadel.search_actions(ListActionsRequest::new(vec![V1ActionQuery::new()
.with_action_name_query(V1ActionNameQuery::new().with_name("test-action".to_owned()))]))?;

let action = stream.next().await.expect("Action must exist");

assert_eq!(action.name(), Some(&"test-action".to_owned()));
assert_eq!(action.script(), Some(&"console.log('test-action-update')".to_owned()));

tear_down(&zitadel).await;

Expand All @@ -199,11 +290,12 @@ async fn test_e2e_delete_action() -> Result<()> {

let action_id = res.id().expect("Must have created an action with a valid ID");

let res = zitadel.delete_action(action_id.to_owned()).await;
zitadel.delete_action(action_id.to_owned()).await?;

// TODO: Once we have a list action method, we should check that
// the action was actually deleted
assert!(res.is_ok());
let stream = zitadel.search_actions(ListActionsRequest::new(vec![V1ActionQuery::new()
.with_action_name_query(V1ActionNameQuery::new().with_name("test-action".to_owned()))]))?;

assert_eq!(stream.count().await, 0);

tear_down(&zitadel).await;

Expand Down

0 comments on commit 835a51c

Please sign in to comment.