tests: add tests for commnad 'trello attachment get'
This commit is contained in:
parent
6c986fa5b9
commit
c8eb0e5f0e
4 changed files with 126 additions and 0 deletions
107
src/trello/tests/attachment/get.rs
Normal file
107
src/trello/tests/attachment/get.rs
Normal file
|
@ -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")
|
||||||
|
);
|
||||||
|
}
|
5
src/trello/tests/attachment/mod.rs
Normal file
5
src/trello/tests/attachment/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
mod get;
|
||||||
|
// mod save;
|
|
@ -25,6 +25,7 @@ use crate::{
|
||||||
AppConfig, Command, FullCtx,
|
AppConfig, Command, FullCtx,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mod attachment;
|
||||||
mod board;
|
mod board;
|
||||||
mod card;
|
mod card;
|
||||||
mod member;
|
mod member;
|
||||||
|
|
13
src/trello/tests/responses/trello-attachment-get.json
Normal file
13
src/trello/tests/responses/trello-attachment-get.json
Normal file
|
@ -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"
|
||||||
|
}
|
Loading…
Reference in a new issue