Skip to content

Commit

Permalink
Added backlog() basic method
Browse files Browse the repository at this point in the history
  • Loading branch information
expobrain committed Dec 8, 2018
1 parent 1d72ffe commit e7cb85d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/backlog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Interfaces for accessing and managing the backlog

use crate::{EmptyResponse, Jira, Result};

#[derive(Debug, Serialize)]
struct BacklogIssues {
issues: Vec<String>,
}

#[derive(Debug)]
pub struct Backlog {
jira: Jira,
}

impl Backlog {
pub fn new(jira: &Jira) -> Self {
Backlog { jira: jira.clone() }
}

// See https://docs.atlassian.com/jira-software/REST/7.0.4/#agile/1.0/backlog
pub fn put(&self, issues: Vec<String>) -> Result<EmptyResponse> {
let data = BacklogIssues { issues };

self.jira.post("agile", "/backlog/issue", data)
}
}

#[cfg(test)]
mod test {
extern crate serde_json;

use super::*;

#[test]
fn serialise_backlog_issue() {
let backlog = BacklogIssues {
issues: vec!["PR-1".to_owned(), "10001".to_owned(), "PR-3".to_owned()],
};

let result: String = serde_json::to_string(&backlog).unwrap();
let expected = r#"{"issues":["PR-1","10001","PR-3"]}"#;

assert_eq!(result, expected);
}

}
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub mod resolution;
pub use crate::boards::*;
pub mod sprints;
pub use crate::sprints::*;
pub mod backlog;
pub use crate::backlog::*;

#[derive(Deserialize, Debug)]
pub struct EmptyResponse;
Expand Down Expand Up @@ -109,6 +111,11 @@ impl Jira {
Sprints::new(self)
}

// return backlog interface
pub fn backlog(&self) -> Backlog {
Backlog::new(self)
}

fn post<D, S>(&self, api_name: &str, endpoint: &str, body: S) -> Result<D>
where
D: DeserializeOwned,
Expand Down Expand Up @@ -164,6 +171,7 @@ impl Jira {
}),
_ => {
let data = if body == "" { "null" } else { &body };

Ok(serde_json::from_str::<D>(data)?)
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/jira_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extern crate goji;
extern crate serde_json;

use goji::*;

#[test]
fn deserialise_empty_response() {
let empty_response_str = "null";
let empty_response: EmptyResponse = serde_json::from_str(empty_response_str).unwrap();

assert_eq!(format!("{:#?}", empty_response), "EmptyResponse");
}

0 comments on commit e7cb85d

Please sign in to comment.