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

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

View file

@ -0,0 +1,93 @@
//
use super::*;
#[rstest::fixture]
fn card_id() -> TrelloCardId {
s!("65ad94865aed24f70ecdcebb").into()
}
#[rstest::fixture]
fn ctx() -> FullCtx {
let fs = given::a_filesystem();
let trello_config = given::a_trello_config();
let card_id = card_id();
let mock_net = given::a_network();
mock_net
.on()
.get("https://api.trello.com/1/cards/65ad94865aed24f70ecdcebb")
.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-card-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, card_id: TrelloCardId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
//when
Command::Trello(TrelloCommand::Card(TrelloCardCommand::Get {
dump: true,
card_id: card_id.into(),
}))
.execute(ctx)
.await
.expect("execute");
//then
let output = prt.output();
assert_eq!(
output.trim(),
include_str!("../../../tests/responses/trello-card-get.json").trim()
);
}
#[rstest::rstest]
#[tokio::test]
async fn no_dump(ctx: FullCtx, card_id: TrelloCardId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
//when
Command::Trello(TrelloCommand::Card(TrelloCardCommand::Get {
dump: false,
card_id: card_id.into(),
}))
.execute(ctx)
.await
.expect("execute");
//then
let output = prt.output();
assert_peq!(
output.trim(),
["65ad94875aed24f70ecdd037:Backlog.png"].join("\n")
);
}

View file

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

View file

@ -25,4 +25,5 @@ use crate::{
}; };
mod board; mod board;
mod card;
mod member; mod member;