test: rewrite nextcloud board list tests
This commit is contained in:
parent
570fadbfdd
commit
8692bb2be4
2 changed files with 107 additions and 83 deletions
|
@ -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 {
|
||||
|
@ -107,7 +113,7 @@ mod commands {
|
|||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn list() {
|
||||
async fn list_dump() {
|
||||
//given
|
||||
let mock_net = kxio::net::mock();
|
||||
|
||||
|
@ -121,30 +127,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()
|
||||
Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::List {
|
||||
dump: true,
|
||||
}))
|
||||
.execute(ctx)
|
||||
.await
|
||||
.result
|
||||
.expect("get boards");
|
||||
.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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,8 +108,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},
|
||||
|
@ -119,6 +126,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")
|
||||
}
|
||||
|
@ -130,4 +153,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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue