From ff042181727f6bf569011d89efc1a84fd383ba9e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 14 Dec 2024 17:27:44 +0000 Subject: [PATCH] tests: add tests for 'trello card get' --- src/trello/tests/card/get.rs | 93 ++++++++++++++++++++++++++++++++++++ src/trello/tests/card/mod.rs | 4 ++ src/trello/tests/mod.rs | 1 + 3 files changed, 98 insertions(+) create mode 100644 src/trello/tests/card/get.rs create mode 100644 src/trello/tests/card/mod.rs diff --git a/src/trello/tests/card/get.rs b/src/trello/tests/card/get.rs new file mode 100644 index 0000000..4e371a4 --- /dev/null +++ b/src/trello/tests/card/get.rs @@ -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") + ); +} diff --git a/src/trello/tests/card/mod.rs b/src/trello/tests/card/mod.rs new file mode 100644 index 0000000..2563f63 --- /dev/null +++ b/src/trello/tests/card/mod.rs @@ -0,0 +1,4 @@ +// +use super::*; + +mod get; diff --git a/src/trello/tests/mod.rs b/src/trello/tests/mod.rs index c6a1d47..0311dc2 100644 --- a/src/trello/tests/mod.rs +++ b/src/trello/tests/mod.rs @@ -25,4 +25,5 @@ use crate::{ }; mod board; +mod card; mod member;