Skip to content

Commit

Permalink
Resolving issue with deleting reactions from issues. (#555)
Browse files Browse the repository at this point in the history
* Resolving issue with deleting reactions from issues.
Issue: manchicken#182

* Reverting changes to CHANGELOG.md since that's automated.
  • Loading branch information
manchicken committed Jan 24, 2024
1 parent 07e09ed commit c4c3a21
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/api/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,9 @@ impl<'octo> IssueHandler<'octo> {
reaction_id = reaction_id.into(),
);

self.crab.delete(route, None::<&()>).await
self.crab._delete(route, None::<&()>).await?;

Ok(())
}

/// Deletes a reaction for an issue comment.
Expand Down
60 changes: 60 additions & 0 deletions tests/issues_reactions_delete_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
mod mock_error;

use mock_error::setup_error_handler;
use octocrab::Octocrab;
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
};

async fn setup_remove_reaction_api(template: ResponseTemplate) -> MockServer {
let owner: &str = "org";
let repo: &str = "some-repo";
let issue_number: u64 = 123;
let reaction_id: u64 = 456;

let mock_server = MockServer::start().await;

Mock::given(method("DELETE"))
.and(path(format!(
"/repos/{owner}/{repo}/issues/{issue_number}/reactions/{reaction_id}"
)))
.respond_with(template.clone())
.mount(&mock_server)
.await;

setup_error_handler(
&mock_server,
&format!("DELETE on /repos/{owner}/{repo}/issues/{issue_number}/reactions/{reaction_id} was not received"),
)
.await;
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

const OWNER: &str = "org";
const REPO: &str = "some-repo";
const ISSUE_NUMBER: u64 = 123;
const REACTION_ID: u64 = 456;

#[tokio::test]
async fn should_delete_reaction() {
let template = ResponseTemplate::new(204);
let mock_server = setup_remove_reaction_api(template).await;
let client = setup_octocrab(&mock_server.uri());

let issues = client.issues(OWNER.to_owned(), REPO.to_owned());

let result = issues
.delete_reaction(ISSUE_NUMBER.to_owned(), REACTION_ID.to_owned())
.await;

assert!(
result.is_ok(),
"expected successful result, got error: {:#?}",
result
);
}

0 comments on commit c4c3a21

Please sign in to comment.