Skip to content

Commit

Permalink
Fixed the `projects().delete_project().send() function (XAMPPRocky#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
manchicken authored and dmgorsky committed Mar 6, 2024
1 parent 8b7df0b commit 32b4374
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/api/projects/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ impl<'octo, 'r> DeleteProjectBuilder<'octo, 'r> {
}
}

pub async fn send(self) -> crate::Result<crate::models::Project> {
pub async fn send(self) -> crate::Result<()> {
let route = format!("/projects/{project_id}", project_id = self.project_id);

self.handler.crab.delete(route, None::<&()>).await
crate::map_github_error(self.handler.crab._delete(route, None::<&()>).await?)
.await
.map(drop)
}
}

Expand Down
50 changes: 37 additions & 13 deletions tests/projects_project_delete_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,46 @@ fn setup_octocrab(uri: &str) -> Octocrab {
}

#[tokio::test]
async fn should_delete_project() {
let org_project: Project =
serde_json::from_str(include_str!("resources/project.json")).unwrap();
async fn should_delete_project_204() {
let template = ResponseTemplate::new(204);
let mock_server = setup_api(template).await;

let client = setup_octocrab(&mock_server.uri());
let result = client.projects().delete_project(PROJECT_ID).send().await;

let page_response = FakeProject(org_project);
assert!(
result.is_ok(),
"expected successful result, got error: {:#?}",
result
);
}

let template = ResponseTemplate::new(200).set_body_json(&page_response);
#[tokio::test]
async fn should_delete_project_410() {
let template = ResponseTemplate::new(410);
let mock_server = setup_api(template).await;

let client = setup_octocrab(&mock_server.uri());
let project = client
.projects()
.delete_project(PROJECT_ID)
.send()
.await
.unwrap();

assert_eq!(project.creator.login, "octocat");
let result = client.projects().delete_project(PROJECT_ID).send().await;

assert!(
result.is_err(),
"expected error result, got success somehow: {:#?}",
result
);
}

#[tokio::test]
async fn should_delete_project_500() {
let template = ResponseTemplate::new(500);
let mock_server = setup_api(template).await;

let client = setup_octocrab(&mock_server.uri());
let result = client.projects().delete_project(PROJECT_ID).send().await;

assert!(
result.is_err(),
"expected error result, got success somehow: {:#?}",
result
);
}

0 comments on commit 32b4374

Please sign in to comment.