test: rewrite nextcloud board list tests
This commit is contained in:
parent
7914e86c62
commit
74862f278c
2 changed files with 107 additions and 83 deletions
|
@ -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 {
|
||||||
|
@ -99,7 +105,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();
|
||||||
|
|
||||||
|
@ -113,30 +119,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()
|
}))
|
||||||
|
.execute(ctx)
|
||||||
.await
|
.await
|
||||||
.result
|
.expect("execute");
|
||||||
.expect("get boards");
|
|
||||||
|
|
||||||
|
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")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -115,8 +115,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},
|
||||||
|
@ -126,6 +133,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")
|
||||||
}
|
}
|
||||||
|
@ -137,4 +160,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,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue