Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the `projects().delete_project().send() function #587

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);
}
Loading