Skip to content
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
22 changes: 2 additions & 20 deletions src/cmd/issue/attachment/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,9 @@ pub fn delete_with(args: &IssueAttachmentDeleteArgs, api: &dyn BacklogApi) -> Re
#[cfg(test)]
mod tests {
use super::*;
use crate::api::issue::{IssueAttachment, IssueUser};
use crate::api::issue::IssueAttachment;
use crate::cmd::issue::attachment::sample_attachment;
use anyhow::anyhow;
use std::collections::BTreeMap;

fn sample_attachment() -> IssueAttachment {
IssueAttachment {
id: 1,
name: "file.txt".to_string(),
size: 1024,
created_user: IssueUser {
id: 1,
user_id: Some("john".to_string()),
name: "John Doe".to_string(),
role_type: 1,
lang: None,
mail_address: None,
extra: BTreeMap::new(),
},
created: "2024-01-01T00:00:00Z".to_string(),
}
}

struct MockApi {
attachment: Option<IssueAttachment>,
Expand Down
26 changes: 2 additions & 24 deletions src/cmd/issue/attachment/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,9 @@ pub fn list_with(args: &IssueAttachmentListArgs, api: &dyn BacklogApi) -> Result
#[cfg(test)]
mod tests {
use super::*;
use crate::api::issue::{IssueAttachment, IssueUser};
use crate::api::issue::IssueAttachment;
use crate::cmd::issue::attachment::sample_attachment;
use anyhow::anyhow;
use std::collections::BTreeMap;

fn sample_user() -> IssueUser {
IssueUser {
id: 1,
user_id: Some("john".to_string()),
name: "John Doe".to_string(),
role_type: 1,
lang: None,
mail_address: None,
extra: BTreeMap::new(),
}
}

fn sample_attachment() -> IssueAttachment {
IssueAttachment {
id: 1,
name: "file.txt".to_string(),
size: 1024,
created_user: sample_user(),
created: "2024-01-01T00:00:00Z".to_string(),
}
}

struct MockApi {
attachments: Option<Vec<IssueAttachment>>,
Expand Down
21 changes: 21 additions & 0 deletions src/cmd/issue/attachment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,24 @@ mod list;
pub use delete::{IssueAttachmentDeleteArgs, delete};
pub use get::{IssueAttachmentGetArgs, get};
pub use list::{IssueAttachmentListArgs, list};

#[cfg(test)]
pub(crate) fn sample_attachment() -> crate::api::issue::IssueAttachment {
use std::collections::BTreeMap;
let user = crate::api::issue::IssueUser {
id: 1,
user_id: Some("john".to_string()),
name: "John Doe".to_string(),
role_type: 1,
lang: None,
mail_address: None,
extra: BTreeMap::new(),
};
crate::api::issue::IssueAttachment {
id: 1,
name: "file.txt".to_string(),
size: 1024,
created_user: user,
created: "2024-01-01T00:00:00Z".to_string(),
}
}
27 changes: 7 additions & 20 deletions src/cmd/project/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ pub fn delete_with(args: &ProjectAdminDeleteArgs, api: &dyn BacklogApi) -> Resul
mod tests {
use super::*;
use crate::api::project::ProjectUser;
use crate::cmd::project::sample_project_user;
use anyhow::anyhow;
use std::collections::BTreeMap;

struct MockApi {
users: Option<Vec<ProjectUser>>,
Expand Down Expand Up @@ -129,23 +129,10 @@ mod tests {
}
}

fn sample_user() -> ProjectUser {
ProjectUser {
id: 1,
user_id: Some("john".to_string()),
name: "John Doe".to_string(),
role_type: 1,
lang: Some("ja".to_string()),
mail_address: Some("john@example.com".to_string()),
last_login_time: None,
extra: BTreeMap::new(),
}
}

#[test]
fn list_with_text_output_succeeds() {
let api = MockApi {
users: Some(vec![sample_user()]),
users: Some(vec![sample_project_user()]),
user: None,
};
assert!(list_with(&ProjectAdminListArgs::new("TEST".to_string(), false), &api).is_ok());
Expand All @@ -154,7 +141,7 @@ mod tests {
#[test]
fn list_with_json_output_succeeds() {
let api = MockApi {
users: Some(vec![sample_user()]),
users: Some(vec![sample_project_user()]),
user: None,
};
assert!(list_with(&ProjectAdminListArgs::new("TEST".to_string(), true), &api).is_ok());
Expand All @@ -175,7 +162,7 @@ mod tests {
fn add_with_text_output_succeeds() {
let api = MockApi {
users: None,
user: Some(sample_user()),
user: Some(sample_project_user()),
};
assert!(
add_with(
Expand All @@ -190,7 +177,7 @@ mod tests {
fn add_with_json_output_succeeds() {
let api = MockApi {
users: None,
user: Some(sample_user()),
user: Some(sample_project_user()),
};
assert!(add_with(&ProjectAdminAddArgs::new("TEST".to_string(), 1, true), &api).is_ok());
}
Expand All @@ -213,7 +200,7 @@ mod tests {
fn delete_with_text_output_succeeds() {
let api = MockApi {
users: None,
user: Some(sample_user()),
user: Some(sample_project_user()),
};
assert!(
delete_with(
Expand All @@ -228,7 +215,7 @@ mod tests {
fn delete_with_json_output_succeeds() {
let api = MockApi {
users: None,
user: Some(sample_user()),
user: Some(sample_project_user()),
};
assert!(
delete_with(
Expand Down
16 changes: 1 addition & 15 deletions src/cmd/project/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ fn format_project(p: &Project) -> String {
#[cfg(test)]
mod tests {
use super::*;
use crate::cmd::project::sample_project;
use anyhow::anyhow;
use std::collections::BTreeMap;

struct MockApi {
project: Option<Project>,
Expand All @@ -87,20 +87,6 @@ mod tests {
}
}

fn sample_project() -> Project {
Project {
id: 1,
project_key: "TEST".to_string(),
name: "Test Project".to_string(),
chart_enabled: false,
subtasking_enabled: false,
project_leader_can_edit_project_leader: false,
text_formatting_rule: "markdown".to_string(),
archived: false,
extra: BTreeMap::new(),
}
}

fn args(json: bool) -> ProjectCreateArgs {
ProjectCreateArgs::new(
"Test Project".to_string(),
Expand Down
16 changes: 1 addition & 15 deletions src/cmd/project/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub fn delete_with(args: &ProjectDeleteArgs, api: &dyn BacklogApi) -> Result<()>
mod tests {
use super::*;
use crate::api::project::Project;
use crate::cmd::project::sample_project;
use anyhow::anyhow;
use std::collections::BTreeMap;

struct MockApi {
project: Option<Project>,
Expand All @@ -49,20 +49,6 @@ mod tests {
}
}

fn sample_project() -> Project {
Project {
id: 1,
project_key: "TEST".to_string(),
name: "Test Project".to_string(),
chart_enabled: false,
subtasking_enabled: false,
project_leader_can_edit_project_leader: false,
text_formatting_rule: "markdown".to_string(),
archived: false,
extra: BTreeMap::new(),
}
}

fn args(json: bool) -> ProjectDeleteArgs {
ProjectDeleteArgs::new("TEST".to_string(), json)
}
Expand Down
16 changes: 1 addition & 15 deletions src/cmd/project/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub fn list_with(args: &ProjectListArgs, api: &dyn BacklogApi) -> Result<()> {
mod tests {
use super::*;
use crate::api::project::Project;
use crate::cmd::project::sample_project;
use anyhow::anyhow;
use std::collections::BTreeMap;

fn format_project_row(p: &Project) -> String {
let archived = if p.archived { " [archived]" } else { "" };
Expand All @@ -61,20 +61,6 @@ mod tests {
}
}

fn sample_project() -> Project {
Project {
id: 1,
project_key: "TEST".to_string(),
name: "Test Project".to_string(),
chart_enabled: false,
subtasking_enabled: false,
project_leader_can_edit_project_leader: false,
text_formatting_rule: "markdown".to_string(),
archived: false,
extra: BTreeMap::new(),
}
}

fn sample_archived_project() -> Project {
Project {
archived: true,
Expand Down
31 changes: 31 additions & 0 deletions src/cmd/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,34 @@ pub(crate) fn format_project_user_row(u: &crate::api::project::ProjectUser) -> S
_ => format!("[{}] {}", u.id, u.name),
}
}

#[cfg(test)]
pub(crate) fn sample_project() -> crate::api::project::Project {
use std::collections::BTreeMap;
crate::api::project::Project {
id: 1,
project_key: "TEST".to_string(),
name: "Test Project".to_string(),
chart_enabled: false,
subtasking_enabled: false,
project_leader_can_edit_project_leader: false,
text_formatting_rule: "markdown".to_string(),
archived: false,
extra: BTreeMap::new(),
}
}

#[cfg(test)]
pub(crate) fn sample_project_user() -> crate::api::project::ProjectUser {
use std::collections::BTreeMap;
crate::api::project::ProjectUser {
id: 1,
user_id: Some("john".to_string()),
name: "John Doe".to_string(),
role_type: 1,
lang: Some("ja".to_string()),
mail_address: Some("john@example.com".to_string()),
last_login_time: None,
extra: BTreeMap::new(),
}
}
16 changes: 1 addition & 15 deletions src/cmd/project/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fn format_project_detail(p: &Project) -> String {
#[cfg(test)]
mod tests {
use super::*;
use crate::cmd::project::sample_project;
use anyhow::anyhow;
use std::collections::BTreeMap;

struct MockApi {
project: Option<Project>,
Expand All @@ -55,20 +55,6 @@ mod tests {
}
}

fn sample_project() -> Project {
Project {
id: 1,
project_key: "TEST".to_string(),
name: "Test Project".to_string(),
chart_enabled: false,
subtasking_enabled: false,
project_leader_can_edit_project_leader: false,
text_formatting_rule: "markdown".to_string(),
archived: false,
extra: BTreeMap::new(),
}
}

#[test]
fn show_with_text_output_succeeds() {
let api = MockApi {
Expand Down
16 changes: 1 addition & 15 deletions src/cmd/project/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub fn update_with(args: &ProjectUpdateArgs, api: &dyn BacklogApi) -> Result<()>
mod tests {
use super::*;
use crate::api::project::Project;
use crate::cmd::project::sample_project;
use anyhow::anyhow;
use std::collections::BTreeMap;

struct MockApi {
project: Option<Project>,
Expand All @@ -117,20 +117,6 @@ mod tests {
}
}

fn sample_project() -> Project {
Project {
id: 1,
project_key: "TEST".to_string(),
name: "Test Project".to_string(),
chart_enabled: false,
subtasking_enabled: false,
project_leader_can_edit_project_leader: false,
text_formatting_rule: "markdown".to_string(),
archived: false,
extra: BTreeMap::new(),
}
}

fn args(json: bool) -> ProjectUpdateArgs {
ProjectUpdateArgs::try_new(
"TEST".to_string(),
Expand Down
Loading