diff --git a/src/trello/tests/attachment/get.rs b/src/trello/tests/attachment/get.rs new file mode 100644 index 0000000..b86726f --- /dev/null +++ b/src/trello/tests/attachment/get.rs @@ -0,0 +1,107 @@ +use crate::trello::attachment::TrelloAttachmentCommand; +use crate::trello::model::TrelloAttachmentId; +// +use super::*; + +#[rstest::fixture] +fn card_id() -> TrelloCardId { + s!("65ad94865aed24f70ecdcebb").into() +} + +#[rstest::fixture] +fn attachment_id() -> TrelloAttachmentId { + s!("65ad94865aed24f70ecdcebc").into() +} + +#[rstest::fixture] +fn ctx() -> FullCtx { + let fs = given::a_filesystem(); + let trello_config = given::a_trello_config(); + let card_id = card_id(); + let attachment_id = attachment_id(); + + let mock_net = given::a_network(); + mock_net + .on() + .get(&format!( + "https://api.trello.com/1/cards/{}/attachments/{}", + card_id.as_ref(), + attachment_id.as_ref() + )) + .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-attachment-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, attachment_id: TrelloAttachmentId) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Trello(TrelloCommand::Attachment(TrelloAttachmentCommand::Get { + dump: true, + card_id: card_id.into(), + attachment_id: attachment_id.into(), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_eq!( + output.trim(), + include_str!("../../../tests/responses/trello-attachment-get.json").trim() + ); +} + +#[rstest::rstest] +#[tokio::test] +async fn no_dump(ctx: FullCtx, card_id: TrelloCardId, attachment_id: TrelloAttachmentId) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Trello(TrelloCommand::Attachment(TrelloAttachmentCommand::Get { + dump: false, + card_id: card_id.into(), + attachment_id: attachment_id.into(), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_peq!( + output.trim(), + ["Backlog.png:https://trello.com/1/cards/65ad94865aed24f70ecdcebb/attachments/65ad94875aed24f70ecdd037/download/Backlog.png"].join("\n") + ); +} diff --git a/src/trello/tests/attachment/mod.rs b/src/trello/tests/attachment/mod.rs new file mode 100644 index 0000000..399e273 --- /dev/null +++ b/src/trello/tests/attachment/mod.rs @@ -0,0 +1,5 @@ +// +use super::*; + +mod get; +// mod save; \ No newline at end of file diff --git a/src/trello/tests/mod.rs b/src/trello/tests/mod.rs index fc8ae38..bb87df8 100644 --- a/src/trello/tests/mod.rs +++ b/src/trello/tests/mod.rs @@ -25,6 +25,7 @@ use crate::{ AppConfig, Command, FullCtx, }; +mod attachment; mod board; mod card; mod member; diff --git a/src/trello/tests/responses/trello-attachment-get.json b/src/trello/tests/responses/trello-attachment-get.json new file mode 100644 index 0000000..7320318 --- /dev/null +++ b/src/trello/tests/responses/trello-attachment-get.json @@ -0,0 +1,13 @@ +{ + "id": "65ad94865aed24f70ecdcebc", + "bytes": 12345, + "date": "2024-01-21T14:30:00.000Z", + "edgeColor": null, + "idMember": "65ad94865aed24f70ecdcebd", + "isUpload": true, + "mimeType": "application/pdf", + "name": "sample_document.pdf", + "pos": 1000, + "previews": [], + "url": "https://trello.com/1/cards/65ad94865aed24f70ecdcebb/attachments/65ad94865aed24f70ecdcebc/download/sample_document.pdf" +} \ No newline at end of file