feat: add command 'nextcloud stack get'
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 1m44s
Test / build (map[name:stable]) (push) Successful in 2m3s
Release Please / Release-plz (push) Failing after 18s

This commit is contained in:
Paul Campbell 2024-12-16 22:38:04 +00:00
parent aac5ff3f5f
commit cef45362de
7 changed files with 50 additions and 116 deletions

View file

@ -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

View file

@ -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(())
}

View file

@ -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"));
}

View file

@ -4,4 +4,3 @@ use super::*;
mod add_label;
mod create;
mod get;
mod list;

View file

@ -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"));
}

View file

@ -1,4 +1,4 @@
//
use super::*;
mod list;
mod get;