From cef45362de314eb56c5be65f8d11627192604e14 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 16 Dec 2024 22:38:04 +0000 Subject: [PATCH] feat: add command 'nextcloud stack get' --- README.md | 6 +- src/nextcloud/stack.rs | 42 +++++----- src/nextcloud/tests/card/list.rs | 82 ------------------- src/nextcloud/tests/card/mod.rs | 1 - src/nextcloud/tests/stack/{list.rs => get.rs} | 33 +++++--- src/nextcloud/tests/stack/mod.rs | 2 +- ...ard-list.json => nextcloud-stack-get.json} | 0 7 files changed, 50 insertions(+), 116 deletions(-) delete mode 100644 src/nextcloud/tests/card/list.rs rename src/nextcloud/tests/stack/{list.rs => get.rs} (59%) rename src/tests/responses/{nextcloud-card-list.json => nextcloud-stack-get.json} (100%) diff --git a/README.md b/README.md index a2c6a2f..c6e7aee 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ As part of building the import server, the following commands exercise each oper - [x] trello attachment save - saves to disk - [x] nextcloud deck get - includes list of boards - [x] nextcloud board get - includes list of stacks -- [ ] nextcloud stack get (was card list) -- [x] nextcloud card create -- [x] nextcloud card add-label +- [x] nextcloud stack get - includes list of cards +- [ ] nextcloud card create +- [ ] nextcloud card add-label - [ ] nextcloud card add-attachment \ No newline at end of file diff --git a/src/nextcloud/stack.rs b/src/nextcloud/stack.rs index 1a85f6d..95b8c1f 100644 --- a/src/nextcloud/stack.rs +++ b/src/nextcloud/stack.rs @@ -6,33 +6,37 @@ use crate::{p, FullCtx}; #[derive(Parser, Debug)] pub enum NextcloudStackCommand { - List { + Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, + board_id: i64, + stack_id: i64, }, } impl Execute for NextcloudStackCommand { async fn execute(&self, ctx: &FullCtx) -> color_eyre::Result<()> { match self { - Self::List { dump } => list(ctx, *dump).await, + Self::Get { + dump, + board_id, + stack_id, + } => { + let api_result = ctx + .deck_client() + .get_stack((*board_id).into(), (*stack_id).into()) + .await; + if *dump { + p!(ctx.prt, "{}", api_result.text); + } else { + let mut cards = api_result.result?.cards; + cards.sort_by_key(|stack| stack.order); + cards + .iter() + .for_each(|card| p!(ctx.prt, "{}:{}", card.id, card.title)); + } + Ok(()) + } } } } - -pub(crate) async fn list(ctx: &FullCtx, dump: bool) -> color_eyre::Result<()> { - let api_result = ctx - .deck_client() - .get_stacks(ctx.cfg.nextcloud.board_id) - .await; - if dump { - p!(ctx.prt, "{}", api_result.text); - } else { - let mut stacks = api_result.result?; - stacks.sort_by_key(|stack| stack.order); - stacks - .iter() - .for_each(|stack| p!(ctx.prt, "{}:{}", stack.id, stack.title)); - } - Ok(()) -} diff --git a/src/nextcloud/tests/card/list.rs b/src/nextcloud/tests/card/list.rs deleted file mode 100644 index d841d55..0000000 --- a/src/nextcloud/tests/card/list.rs +++ /dev/null @@ -1,82 +0,0 @@ -// -use super::*; - -#[rstest::fixture] -fn stack_id() -> NextcloudStackId { - NextcloudStackId::new(1) -} - -#[rstest::fixture] -fn ctx() -> FullCtx { - let fs = given::a_filesystem(); - let nextcloud_config = given::a_nextcloud_config(); - - let mock_net = given::a_network(); - mock_net - .on() - .get(crate::f!( - "https://{}/index.php/apps/deck/api/v1.0/boards/{}/stacks/1", - nextcloud_config.hostname, - nextcloud_config.board_id - )) - .respond(StatusCode::OK) - .body(include_str!( - "../../../tests/responses/nextcloud-card-list.json" - )) - .expect("mock request"); - - FullCtx { - fs: fs.as_real(), - net: mock_net.into(), - prt: given::a_printer(), - cfg: AppConfig { - trello: given::a_trello_config(), - nextcloud: nextcloud_config, - }, - } -} - -#[rstest::rstest] -#[test_log::test(tokio::test)] -async fn dump(ctx: FullCtx, stack_id: NextcloudStackId) { - //given - let prt = ctx.prt.clone(); - let prt = prt.as_test().unwrap(); - - //when - Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::List { - dump: true, - stack_id: stack_id.into(), - })) - .execute(&ctx) - .await - .expect("execute"); - - //then - let output = prt.output(); - assert_peq!( - output.trim(), - include_str!("../../../tests/responses/nextcloud-card-list.json").trim() - ); -} - -#[rstest::rstest] -#[test_log::test(tokio::test)] -async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId) { - //given - let prt = ctx.prt.clone(); - let prt = prt.as_test().unwrap(); - - //when - Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::List { - dump: false, - stack_id: stack_id.into(), - })) - .execute(&ctx) - .await - .expect("execute"); - - //then - let output = prt.output(); - assert_peq!(output.trim(), ["322:Lunch: Soup & Toast"].join("\n")); -} diff --git a/src/nextcloud/tests/card/mod.rs b/src/nextcloud/tests/card/mod.rs index 6568867..3a1726d 100644 --- a/src/nextcloud/tests/card/mod.rs +++ b/src/nextcloud/tests/card/mod.rs @@ -4,4 +4,3 @@ use super::*; mod add_label; mod create; mod get; -mod list; diff --git a/src/nextcloud/tests/stack/list.rs b/src/nextcloud/tests/stack/get.rs similarity index 59% rename from src/nextcloud/tests/stack/list.rs rename to src/nextcloud/tests/stack/get.rs index 01b5cb4..b8f55f5 100644 --- a/src/nextcloud/tests/stack/list.rs +++ b/src/nextcloud/tests/stack/get.rs @@ -6,23 +6,29 @@ use crate::Command; // use super::*; +#[rstest::fixture] +fn stack_id() -> i64 { + 318 +} + #[rstest::fixture] fn ctx() -> FullCtx { let fs = given::a_filesystem(); let nextcloud_config = given::a_nextcloud_config(); + let hostname = nextcloud_config.hostname; + let board_id = nextcloud_config.board_id; + let stack_id = stack_id(); let mock_net = given::a_network(); mock_net .on() .get(crate::f!( - "https://{}/index.php/apps/deck/api/v1.0/boards/{}/stacks", - nextcloud_config.hostname, - nextcloud_config.board_id + "https://{hostname}/index.php/apps/deck/api/v1.0/boards/{board_id}/stacks/{stack_id}", )) .respond(StatusCode::OK) .body(include_str!( - "../../../tests/responses/nextcloud-stack-list.json" + "../../../tests/responses/nextcloud-stack-get.json" )) .expect("mock request"); @@ -37,15 +43,20 @@ async fn dump(ctx: FullCtx) { let prt = prt.as_test().unwrap(); //when - crate::nextcloud::stack::list(&ctx, true) - .await - .expect("execute"); + Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::Get { + dump: true, + board_id: ctx.cfg.nextcloud.board_id.into(), + stack_id: stack_id(), + })) + .execute(&ctx) + .await + .expect("execute"); //then let output = prt.output(); assert_peq!( output.trim(), - include_str!("../../../tests/responses/nextcloud-stack-list.json").trim() + include_str!("../../../tests/responses/nextcloud-stack-get.json").trim() ); } @@ -57,8 +68,10 @@ async fn no_dump(ctx: FullCtx) { let prt = prt.as_test().unwrap(); //when - Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::List { + Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::Get { dump: false, + board_id: ctx.cfg.nextcloud.board_id.into(), + stack_id: stack_id(), })) .execute(&ctx) .await @@ -66,5 +79,5 @@ async fn no_dump(ctx: FullCtx) { //then let output = prt.output(); - assert_peq!(output.trim(), ["1:To do", "2:Doing", "3:Done"].join("\n")); + assert_peq!(output.trim(), ["322:Lunch: Soup & Toast"].join("\n")); } diff --git a/src/nextcloud/tests/stack/mod.rs b/src/nextcloud/tests/stack/mod.rs index 9d06791..2563f63 100644 --- a/src/nextcloud/tests/stack/mod.rs +++ b/src/nextcloud/tests/stack/mod.rs @@ -1,4 +1,4 @@ // use super::*; -mod list; +mod get; diff --git a/src/tests/responses/nextcloud-card-list.json b/src/tests/responses/nextcloud-stack-get.json similarity index 100% rename from src/tests/responses/nextcloud-card-list.json rename to src/tests/responses/nextcloud-stack-get.json