tests: add tests for 'trello board get'
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 2m10s
Test / build (map[name:stable]) (push) Successful in 2m8s
Release Please / Release-plz (push) Failing after 16s

This commit is contained in:
Paul Campbell 2024-12-14 17:27:44 +00:00
parent 959613919e
commit 7e65cdd415
3 changed files with 103 additions and 0 deletions

View file

@ -0,0 +1,98 @@
//
use super::*;
#[rstest::fixture]
fn board_id() -> TrelloBoardId {
s!("65ad94865aed24f70ecdce4b").into()
}
#[rstest::fixture]
fn ctx() -> FullCtx {
let fs = given::a_filesystem();
let trello_config = given::a_trello_config();
let board_id = board_id();
let mock_net = given::a_network();
mock_net
.on()
.get("https://api.trello.com/1/boards/65ad94865aed24f70ecdce4b")
.header("content-type", "application/json")
.header("accept", "application/json")
.headers(HashMap::from([(
s!("authorization"),
f!(
"OAuth oauth_consumer_key=\"{}\", oauth_token=\"{}\"",
trello_config.api_key,
trello_config.api_secret
),
)]))
.respond(StatusCode::OK)
.header("content-type", "application/json")
.body(include_str!(
"../../../tests/responses/trello-board-get.json"
))
.expect("mock request");
FullCtx {
fs: fs.as_real(),
net: mock_net.into(),
prt: given::a_printer(),
cfg: AppConfig {
trello: trello_config,
nextcloud: given::a_nextcloud_config(),
},
}
}
#[rstest::rstest]
#[test_log::test(tokio::test)]
async fn dump(ctx: FullCtx, board_id: TrelloBoardId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
//when
Command::Trello(TrelloCommand::Board(TrelloBoardCommand::Get {
dump: true,
board_id: board_id.into(),
}))
.execute(ctx)
.await
.expect("execute");
//then
let output = prt.output();
assert_eq!(
output.trim(),
include_str!("../../../tests/responses/trello-board-get.json").trim()
);
}
#[rstest::rstest]
#[tokio::test]
async fn no_dump(ctx: FullCtx, board_id: TrelloBoardId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
//when
Command::Trello(TrelloCommand::Board(TrelloBoardCommand::Get {
dump: false,
board_id: board_id.into(),
}))
.execute(ctx)
.await
.expect("execute");
//then
let output = prt.output();
assert_peq!(
output.trim(),
[
"65ad94865aed24f70ecdce4c:Backlog",
"65ad94865aed24f70ecdce52:Done 🎉",
"65ad94865aed24f70ecdce4e:To Do"
]
.join("\n")
);
}

View file

@ -0,0 +1,4 @@
//
use super::*;
mod get;

View file

@ -24,4 +24,5 @@ use crate::{
AppConfig, Command, FullCtx, AppConfig, Command, FullCtx,
}; };
mod board;
mod member; mod member;