tests: add tests for 'trello card get'
This commit is contained in:
parent
7e65cdd415
commit
ff04218172
3 changed files with 98 additions and 0 deletions
93
src/trello/tests/card/get.rs
Normal file
93
src/trello/tests/card/get.rs
Normal 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")
|
||||
);
|
||||
}
|
4
src/trello/tests/card/mod.rs
Normal file
4
src/trello/tests/card/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
//
|
||||
use super::*;
|
||||
|
||||
mod get;
|
|
@ -25,4 +25,5 @@ use crate::{
|
|||
};
|
||||
|
||||
mod board;
|
||||
mod card;
|
||||
mod member;
|
||||
|
|
Loading…
Reference in a new issue