test: rewrite nextcloud board list tests

This commit is contained in:
Paul Campbell 2024-12-11 22:23:34 +00:00
parent 570fadbfdd
commit 8692bb2be4
2 changed files with 107 additions and 83 deletions

View file

@ -2,13 +2,19 @@
use kxio::net::StatusCode; use kxio::net::StatusCode;
use crate::{ use crate::{
nextcloud::model::{ execute::Execute,
Board, Card, NextcloudBoardColour, NextcloudBoardId, NextcloudBoardOwner, nextcloud::{
NextcloudBoardTitle, NextcloudCardId, NextcloudCardTitle, NextcloudETag, NextcloudHostname, board::NextcloudBoardCommand,
NextcloudOrder, NextcloudPassword, NextcloudStackId, NextcloudStackTitle, model::{
NextcloudUsername, Stack, Card, NextcloudBoardId, NextcloudCardId, NextcloudCardTitle, NextcloudETag,
NextcloudHostname, NextcloudOrder, NextcloudPassword, NextcloudStackId,
NextcloudStackTitle, NextcloudUsername, Stack,
},
NextcloudCommand,
}, },
s, s,
tests::given,
Command,
}; };
mod config { mod config {
@ -107,7 +113,7 @@ mod commands {
use super::*; use super::*;
#[tokio::test] #[tokio::test]
async fn list() { async fn list_dump() {
//given //given
let mock_net = kxio::net::mock(); let mock_net = kxio::net::mock();
@ -121,30 +127,59 @@ mod commands {
// let fs = given::a_filesystem(); // let fs = given::a_filesystem();
let ctx = given::a_full_context(mock_net); let ctx = given::a_full_context(mock_net);
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
//when //when
let result = ctx Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::List {
.deck_client() dump: true,
.get_boards() }))
.await .execute(ctx)
.result .await
.expect("get boards"); .expect("execute");
let output = prt.output();
assert_eq!( assert_eq!(
result.first(), output.trim(),
Some(&Board { include_str!("../tests/responses/nextcloud-board-list.json").trim()
id: NextcloudBoardId::new(1), );
title: NextcloudBoardTitle::new("Personal Board"), }
owner: NextcloudBoardOwner {
primary_key: s!("pcampbell"), #[tokio::test]
uid: s!("pcampbell"), async fn list_no_dump() {
display_name: s!("Paul Campbell"), //given
}, let mock_net = kxio::net::mock();
color: NextcloudBoardColour::new("0087C5"),
archived: false, mock_net
labels: vec![], .on()
acl: vec![] .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")
); );
} }
} }
@ -457,7 +492,7 @@ mod commands {
json!({ json!({
"labelId":400, "labelId":400,
}) })
.to_string(), .to_string(),
) )
.respond(StatusCode::OK) .respond(StatusCode::OK)
.mock() .mock()
@ -482,58 +517,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(),
},
}
}
}

View file

@ -108,8 +108,15 @@ mod template {
} }
} }
mod given { pub(crate) mod given {
use super::*; 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::{ use kxio::{
fs::{FileSystem, TempFileSystem}, fs::{FileSystem, TempFileSystem},
net::{MockNet, Net}, net::{MockNet, Net},
@ -119,6 +126,22 @@ mod given {
pub(crate) fn a_context(fs: FileSystem, net: Net, prt: Printer) -> Ctx { pub(crate) fn a_context(fs: FileSystem, net: Net, prt: Printer) -> Ctx {
Ctx { fs, net, prt } 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 { pub(crate) fn a_filesystem() -> TempFileSystem {
kxio::fs::temp().expect("temp fs") kxio::fs::temp().expect("temp fs")
} }
@ -130,4 +153,25 @@ mod given {
pub(crate) fn a_printer() -> Printer { pub(crate) fn a_printer() -> Printer {
kxio::print::test() 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,
}
}
} }