From 12fa6d3b32ccfb7746a6c777758ac2104ba676e7 Mon Sep 17 00:00:00 2001 From: Mike Stemle Date: Fri, 23 Feb 2024 09:03:53 -0500 Subject: [PATCH] Fixed the `projects().delete_project().send() function - This endpoint, `DELETE /projects/{project_id}` [is documented](https://docs.github.com/en/enterprise-cloud@latest/rest/projects/projects?apiVersion=2022-11-28#delete-a-project) as never returning 200. - The test was incorrectly verifying a 200 case, and the function broke in a 204 - I fixed the function - I fixed the test - I added coverage for 410 and 500 cases, too --- src/api/projects/projects.rs | 6 ++-- tests/projects_project_delete_test.rs | 50 ++++++++++++++++++++------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/api/projects/projects.rs b/src/api/projects/projects.rs index eb89e130..4ef4a278 100644 --- a/src/api/projects/projects.rs +++ b/src/api/projects/projects.rs @@ -93,10 +93,12 @@ impl<'octo, 'r> DeleteProjectBuilder<'octo, 'r> { } } - pub async fn send(self) -> crate::Result { + 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) } } diff --git a/tests/projects_project_delete_test.rs b/tests/projects_project_delete_test.rs index aa3fbf3d..76e5d200 100644 --- a/tests/projects_project_delete_test.rs +++ b/tests/projects_project_delete_test.rs @@ -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 + ); }