feat: add command 'nextcloud stack get'
This commit is contained in:
parent
aac5ff3f5f
commit
cef45362de
7 changed files with 50 additions and 116 deletions
|
@ -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] trello attachment save - saves to disk
|
||||||
- [x] nextcloud deck get - includes list of boards
|
- [x] nextcloud deck get - includes list of boards
|
||||||
- [x] nextcloud board get - includes list of stacks
|
- [x] nextcloud board get - includes list of stacks
|
||||||
- [ ] nextcloud stack get (was card list)
|
- [x] nextcloud stack get - includes list of cards
|
||||||
- [x] nextcloud card create
|
- [ ] nextcloud card create
|
||||||
- [x] nextcloud card add-label
|
- [ ] nextcloud card add-label
|
||||||
- [ ] nextcloud card add-attachment
|
- [ ] nextcloud card add-attachment
|
|
@ -6,33 +6,37 @@ use crate::{p, FullCtx};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub enum NextcloudStackCommand {
|
pub enum NextcloudStackCommand {
|
||||||
List {
|
Get {
|
||||||
#[clap(long, action = clap::ArgAction::SetTrue)]
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
||||||
dump: bool,
|
dump: bool,
|
||||||
|
board_id: i64,
|
||||||
|
stack_id: i64,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Execute for NextcloudStackCommand {
|
impl Execute for NextcloudStackCommand {
|
||||||
async fn execute(&self, ctx: &FullCtx) -> color_eyre::Result<()> {
|
async fn execute(&self, ctx: &FullCtx) -> color_eyre::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::List { dump } => list(ctx, *dump).await,
|
Self::Get {
|
||||||
}
|
dump,
|
||||||
}
|
board_id,
|
||||||
}
|
stack_id,
|
||||||
|
} => {
|
||||||
pub(crate) async fn list(ctx: &FullCtx, dump: bool) -> color_eyre::Result<()> {
|
|
||||||
let api_result = ctx
|
let api_result = ctx
|
||||||
.deck_client()
|
.deck_client()
|
||||||
.get_stacks(ctx.cfg.nextcloud.board_id)
|
.get_stack((*board_id).into(), (*stack_id).into())
|
||||||
.await;
|
.await;
|
||||||
if dump {
|
if *dump {
|
||||||
p!(ctx.prt, "{}", api_result.text);
|
p!(ctx.prt, "{}", api_result.text);
|
||||||
} else {
|
} else {
|
||||||
let mut stacks = api_result.result?;
|
let mut cards = api_result.result?.cards;
|
||||||
stacks.sort_by_key(|stack| stack.order);
|
cards.sort_by_key(|stack| stack.order);
|
||||||
stacks
|
cards
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|stack| p!(ctx.prt, "{}:{}", stack.id, stack.title));
|
.for_each(|card| p!(ctx.prt, "{}:{}", card.id, card.title));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"));
|
|
||||||
}
|
|
|
@ -4,4 +4,3 @@ use super::*;
|
||||||
mod add_label;
|
mod add_label;
|
||||||
mod create;
|
mod create;
|
||||||
mod get;
|
mod get;
|
||||||
mod list;
|
|
||||||
|
|
|
@ -6,23 +6,29 @@ use crate::Command;
|
||||||
//
|
//
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[rstest::fixture]
|
||||||
|
fn stack_id() -> i64 {
|
||||||
|
318
|
||||||
|
}
|
||||||
|
|
||||||
#[rstest::fixture]
|
#[rstest::fixture]
|
||||||
fn ctx() -> FullCtx {
|
fn ctx() -> FullCtx {
|
||||||
let fs = given::a_filesystem();
|
let fs = given::a_filesystem();
|
||||||
|
|
||||||
let nextcloud_config = given::a_nextcloud_config();
|
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();
|
let mock_net = given::a_network();
|
||||||
mock_net
|
mock_net
|
||||||
.on()
|
.on()
|
||||||
.get(crate::f!(
|
.get(crate::f!(
|
||||||
"https://{}/index.php/apps/deck/api/v1.0/boards/{}/stacks",
|
"https://{hostname}/index.php/apps/deck/api/v1.0/boards/{board_id}/stacks/{stack_id}",
|
||||||
nextcloud_config.hostname,
|
|
||||||
nextcloud_config.board_id
|
|
||||||
))
|
))
|
||||||
.respond(StatusCode::OK)
|
.respond(StatusCode::OK)
|
||||||
.body(include_str!(
|
.body(include_str!(
|
||||||
"../../../tests/responses/nextcloud-stack-list.json"
|
"../../../tests/responses/nextcloud-stack-get.json"
|
||||||
))
|
))
|
||||||
.expect("mock request");
|
.expect("mock request");
|
||||||
|
|
||||||
|
@ -37,7 +43,12 @@ async fn dump(ctx: FullCtx) {
|
||||||
let prt = prt.as_test().unwrap();
|
let prt = prt.as_test().unwrap();
|
||||||
|
|
||||||
//when
|
//when
|
||||||
crate::nextcloud::stack::list(&ctx, true)
|
Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::Get {
|
||||||
|
dump: true,
|
||||||
|
board_id: ctx.cfg.nextcloud.board_id.into(),
|
||||||
|
stack_id: stack_id(),
|
||||||
|
}))
|
||||||
|
.execute(&ctx)
|
||||||
.await
|
.await
|
||||||
.expect("execute");
|
.expect("execute");
|
||||||
|
|
||||||
|
@ -45,7 +56,7 @@ async fn dump(ctx: FullCtx) {
|
||||||
let output = prt.output();
|
let output = prt.output();
|
||||||
assert_peq!(
|
assert_peq!(
|
||||||
output.trim(),
|
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();
|
let prt = prt.as_test().unwrap();
|
||||||
|
|
||||||
//when
|
//when
|
||||||
Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::List {
|
Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::Get {
|
||||||
dump: false,
|
dump: false,
|
||||||
|
board_id: ctx.cfg.nextcloud.board_id.into(),
|
||||||
|
stack_id: stack_id(),
|
||||||
}))
|
}))
|
||||||
.execute(&ctx)
|
.execute(&ctx)
|
||||||
.await
|
.await
|
||||||
|
@ -66,5 +79,5 @@ async fn no_dump(ctx: FullCtx) {
|
||||||
|
|
||||||
//then
|
//then
|
||||||
let output = prt.output();
|
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"));
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
//
|
//
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
mod list;
|
mod get;
|
||||||
|
|
Loading…
Reference in a new issue