diff --git a/src/trello/tests/board/get.rs b/src/trello/tests/board/get.rs new file mode 100644 index 0000000..b242fa0 --- /dev/null +++ b/src/trello/tests/board/get.rs @@ -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") + ); +} diff --git a/src/trello/tests/board/mod.rs b/src/trello/tests/board/mod.rs new file mode 100644 index 0000000..2563f63 --- /dev/null +++ b/src/trello/tests/board/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 a746b37..c6a1d47 100644 --- a/src/trello/tests/mod.rs +++ b/src/trello/tests/mod.rs @@ -24,4 +24,5 @@ use crate::{ AppConfig, Command, FullCtx, }; +mod board; mod member;