diff --git a/src/nextcloud/tests.rs b/src/nextcloud/tests.rs index 3b3c428..5061b16 100644 --- a/src/nextcloud/tests.rs +++ b/src/nextcloud/tests.rs @@ -2,13 +2,19 @@ use kxio::net::StatusCode; use crate::{ - nextcloud::model::{ - Board, Card, NextcloudBoardColour, NextcloudBoardId, NextcloudBoardOwner, - NextcloudBoardTitle, NextcloudCardId, NextcloudCardTitle, NextcloudETag, NextcloudHostname, - NextcloudOrder, NextcloudPassword, NextcloudStackId, NextcloudStackTitle, - NextcloudUsername, Stack, + execute::Execute, + nextcloud::{ + board::NextcloudBoardCommand, + model::{ + Card, NextcloudBoardId, NextcloudCardId, NextcloudCardTitle, NextcloudETag, + NextcloudHostname, NextcloudOrder, NextcloudPassword, NextcloudStackId, + NextcloudStackTitle, NextcloudUsername, Stack, + }, + NextcloudCommand, }, s, + tests::given, + Command, }; mod config { @@ -99,7 +105,7 @@ mod commands { use super::*; #[tokio::test] - async fn list() { + async fn list_dump() { //given let mock_net = kxio::net::mock(); @@ -113,30 +119,59 @@ mod commands { // let fs = given::a_filesystem(); let ctx = given::a_full_context(mock_net); + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); //when - let result = ctx - .deck_client() - .get_boards() - .await - .result - .expect("get boards"); + Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::List { + dump: true, + })) + .execute(ctx) + .await + .expect("execute"); + let output = prt.output(); assert_eq!( - result.first(), - Some(&Board { - id: NextcloudBoardId::new(1), - title: NextcloudBoardTitle::new("Personal Board"), - owner: NextcloudBoardOwner { - primary_key: s!("pcampbell"), - uid: s!("pcampbell"), - display_name: s!("Paul Campbell"), - }, - color: NextcloudBoardColour::new("0087C5"), - archived: false, - labels: vec![], - acl: vec![] - }) + output.trim(), + include_str!("../tests/responses/nextcloud-board-list.json").trim() + ); + } + + #[tokio::test] + async fn list_no_dump() { + //given + let mock_net = kxio::net::mock(); + + mock_net + .on() + .get("https://host-name/index.php/apps/deck/api/v1.0/boards") + .basic_auth("username", Some("password")) + .respond(StatusCode::OK) + .body(include_str!("../tests/responses/nextcloud-board-list.json")) + .expect("mock request"); + + // let fs = given::a_filesystem(); + let ctx = given::a_full_context(mock_net); + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::List { + dump: false, + })) + .execute(ctx) + .await + .expect("execute"); + + let output = prt.output(); + assert_eq!( + output.trim(), + [ + "4:4 Published: Cossmass Infinities", + "5:Fulfilment: Cossmass Infinities", + "1:Personal Board" + ] + .join("\n") ); } } @@ -449,7 +484,7 @@ mod commands { json!({ "labelId":400, }) - .to_string(), + .to_string(), ) .respond(StatusCode::OK) .mock() @@ -474,58 +509,3 @@ mod commands { } } } - -mod given { - use kxio::{net::MockNet, print::Printer}; - - use crate::nextcloud::model::{ - NextcloudBoardId, NextcloudHostname, NextcloudPassword, NextcloudUsername, - }; - use crate::nextcloud::NextcloudConfig; - use crate::trello::TrelloConfig; - use crate::{s, AppConfig, FullCtx}; - - pub(crate) fn a_nextcloud_config() -> NextcloudConfig { - let hostname = NextcloudHostname::new("host-name"); - let username = NextcloudUsername::new("username"); - let password = NextcloudPassword::new("password"); - let board_id = NextcloudBoardId::new(2); - NextcloudConfig { - hostname, - username, - password, - board_id, - } - } - - pub(crate) fn a_printer() -> Printer { - kxio::print::test() - } - - // pub(crate) fn a_filesystem() -> TempFileSystem { - // kxio::fs::temp().expect("temp fs") - // } - - pub(crate) fn a_trello_config() -> TrelloConfig { - TrelloConfig { - api_key: s!("trello-api-key").into(), - api_secret: s!("trello-api-secret").into(), - board_name: s!("trello-board-name").into(), - } - } - - pub(crate) fn a_full_context( - mock_net: MockNet, - // fs: TempFileSystem - ) -> FullCtx { - FullCtx { - // fs: fs.as_real(), - net: mock_net.into(), - prt: a_printer(), - cfg: AppConfig { - trello: a_trello_config(), - nextcloud: a_nextcloud_config(), - }, - } - } -} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 89cc2e2..c1c668f 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -115,8 +115,15 @@ mod template { } } -mod given { +pub(crate) mod given { use super::*; + use crate::config::AppConfig; + use crate::nextcloud::model::{ + NextcloudBoardId, NextcloudHostname, NextcloudPassword, NextcloudUsername, + }; + use crate::nextcloud::NextcloudConfig; + use crate::trello::TrelloConfig; + use crate::{s, FullCtx}; use kxio::{ fs::{FileSystem, TempFileSystem}, net::{MockNet, Net}, @@ -126,6 +133,22 @@ mod given { pub(crate) fn a_context(fs: FileSystem, net: Net, prt: Printer) -> Ctx { Ctx { fs, net, prt } } + + pub(crate) fn a_full_context( + mock_net: MockNet, + // fs: TempFileSystem + ) -> FullCtx { + FullCtx { + // fs: fs.as_real(), + net: mock_net.into(), + prt: a_printer(), + cfg: AppConfig { + trello: a_trello_config(), + nextcloud: a_nextcloud_config(), + }, + } + } + pub(crate) fn a_filesystem() -> TempFileSystem { kxio::fs::temp().expect("temp fs") } @@ -137,4 +160,25 @@ mod given { pub(crate) fn a_printer() -> Printer { kxio::print::test() } + + pub(crate) fn a_trello_config() -> TrelloConfig { + TrelloConfig { + api_key: s!("trello-api-key").into(), + api_secret: s!("trello-api-secret").into(), + board_name: s!("trello-board-name").into(), + } + } + + pub(crate) fn a_nextcloud_config() -> NextcloudConfig { + let hostname = NextcloudHostname::new("host-name"); + let username = NextcloudUsername::new("username"); + let password = NextcloudPassword::new("password"); + let board_id = NextcloudBoardId::new(2); + NextcloudConfig { + hostname, + username, + password, + board_id, + } + } }