Skip to content

Commit

Permalink
Add IssueNotFound error
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed May 6, 2024
1 parent db5077d commit 309ec7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
39 changes: 19 additions & 20 deletions backend/src/bounty/api/claim.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::bounty::api::state::{Contributor, BOUNTY_STATE};
use crate::bounty::api::state::{Contributor, IssueId, PullRequestId, BOUNTY_STATE};
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};

Expand All @@ -9,6 +9,7 @@ use crate::provider::github::client::IGithubClient;

#[derive(Debug, Serialize, Deserialize, CandidType)]
pub enum ClaimError {
IssueNotFound { github_issue_id: i32 },
PRNotAccepted { github_pr_id: i32 },
PRNotMerged { github_pr_id: i32 },
}
Expand Down Expand Up @@ -41,28 +42,29 @@ impl IGithubClient for GithubClientMock {
#[cfg(test)]
pub async fn claim_impl(
github_client: &dyn IGithubClient,
github_issue_id: i32,
github_pr_id: i32,
github_issue_id: IssueId,
github_pr_id: PullRequestId,
) -> Option<ClaimError> {
let contributor_opt: Option<Contributor> = BOUNTY_STATE.with(|state| {
use crate::bounty::api::state::Issue;

let issue_opt: Option<Issue> = BOUNTY_STATE.with(|state| {
match state.borrow().as_ref() {
Some(bounty_state) => {
// Access the interested_contributors HashMap from the BountyState
return bounty_state
.github_issues
.get(&github_pr_id)
.and_then(|issue| issue.bounty.accepted_prs.get(&github_pr_id))
.map(|pr| pr.contributor.clone())
return bounty_state.github_issues.get(&github_issue_id).cloned();
}
None => panic!("Bounty canister state not initialized"),
}
});
match contributor_opt {
None => Some(ClaimError::PRNotAccepted { github_pr_id }),
Some(contributor) => {
let issue = github_client.get_issue(github_issue_id).await;
todo!()
}

match issue_opt {
None => return Some(ClaimError::IssueNotFound { github_issue_id }),
Some(issue) => match issue.bounty.accepted_prs.get(&github_pr_id) {
None => Some(ClaimError::PRNotAccepted { github_pr_id }),
Some(pull_request) => {
todo!()
}
},
}
}

Expand Down Expand Up @@ -117,17 +119,14 @@ mod test_claim {
principal: authority,
};

let result = block_on(claim_impl(
&github_client,
github_issue_id,
2,
));
let result = block_on(claim_impl(&github_client, github_issue_id, 2));

match result {
None => assert!(true),
Some(claim_error) => match claim_error {
ClaimError::PRNotAccepted { github_pr_id: _ } => assert!(false),
ClaimError::PRNotMerged { github_pr_id: _ } => assert!(false),
ClaimError::IssueNotFound { github_issue_id: _ } => assert!(false),
},
}

Expand Down
4 changes: 2 additions & 2 deletions backend/src/bounty/api/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::collections::HashMap;
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};

type IssueId = i32;
type PullRequestId = i32;
pub type IssueId = i32;
pub type PullRequestId = i32;

#[derive(Debug, Serialize, Deserialize, CandidType, Clone, Builder)]
pub struct Contributor {
Expand Down

0 comments on commit 309ec7b

Please sign in to comment.