tests: add tests for 'trello stack get'
Some checks failed
Test / build (map[name:stable]) (push) Successful in 2m12s
Test / build (map[name:nightly]) (push) Successful in 5m26s
Release Please / Release-plz (push) Failing after 1m51s

This commit is contained in:
Paul Campbell 2024-12-14 22:08:30 +00:00
parent 9824aa6374
commit 6c986fa5b9
4 changed files with 234 additions and 0 deletions

View file

@ -0,0 +1,130 @@
[
{
"id": "65ad94865aed24f70ecdcebb",
"badges": {
"attachmentsByType": {
"trello": {
"board": 0,
"card": 0
}
},
"externalSource": null,
"location": false,
"votes": 0,
"viewingMemberVoted": false,
"subscribed": false,
"fogbugz": "",
"checkItems": 0,
"checkItemsChecked": 0,
"checkItemsEarliestDue": null,
"comments": 0,
"attachments": 1,
"description": true,
"due": null,
"dueComplete": false,
"start": null,
"lastUpdatedByAi": false
},
"checkItemStates": [],
"closed": false,
"dueComplete": false,
"dateLastActivity": "2024-01-21T22:02:47.582Z",
"desc": "A list of the things we think we want to do, maybe not quite ready for work, but high likelihood of being worked on.\n\nThis is the staging area where specs should get fleshed out.\n\nNo limit on the list size, but we should reconsider if it gets long.",
"descData": null,
"due": null,
"dueReminder": null,
"email": null,
"idBoard": "65ad94865aed24f70ecdce4b",
"idChecklists": [],
"idList": "65ad94865aed24f70ecdce4c",
"idMembers": [],
"idMembersVoted": [],
"idShort": 1,
"idAttachmentCover": "65ad94875aed24f70ecdd037",
"labels": [],
"idLabels": [],
"manualCoverAttachment": false,
"name": "Backlog",
"pinned": false,
"pos": 16384,
"shortLink": "Z7CTyW2I",
"shortUrl": "https://trello.com/c/Z7CTyW2I",
"start": null,
"subscribed": false,
"url": "https://trello.com/c/Z7CTyW2I/1-backlog",
"cover": {
"idAttachment": "65ad94875aed24f70ecdd037",
"color": null,
"idUploadedBackground": null,
"size": "normal",
"brightness": "light",
"idPlugin": null
},
"isTemplate": false,
"cardRole": null
},
{
"id": "65ad94865aed24f70ecdced1",
"badges": {
"attachmentsByType": {
"trello": {
"board": 0,
"card": 0
}
},
"externalSource": null,
"location": false,
"votes": 0,
"viewingMemberVoted": false,
"subscribed": false,
"fogbugz": "",
"checkItems": 0,
"checkItemsChecked": 0,
"checkItemsEarliestDue": null,
"comments": 0,
"attachments": 0,
"description": false,
"due": null,
"dueComplete": false,
"start": null,
"lastUpdatedByAi": false
},
"checkItemStates": [],
"closed": false,
"dueComplete": false,
"dateLastActivity": "2024-01-21T22:02:47.112Z",
"desc": "",
"descData": null,
"due": null,
"dueReminder": null,
"email": null,
"idBoard": "65ad94865aed24f70ecdce4b",
"idChecklists": [],
"idList": "65ad94865aed24f70ecdce4c",
"idMembers": [],
"idMembersVoted": [],
"idShort": 12,
"idAttachmentCover": null,
"labels": [],
"idLabels": [],
"manualCoverAttachment": false,
"name": "[Example task]",
"pinned": false,
"pos": 81920,
"shortLink": "kqHXwwev",
"shortUrl": "https://trello.com/c/kqHXwwev",
"start": null,
"subscribed": false,
"url": "https://trello.com/c/kqHXwwev/12-example-task",
"cover": {
"idAttachment": null,
"color": null,
"idUploadedBackground": null,
"size": "normal",
"brightness": "light",
"idPlugin": null
},
"isTemplate": false,
"cardRole": null
}
]

View file

@ -19,6 +19,7 @@ use crate::{
card::TrelloCardCommand, card::TrelloCardCommand,
member::TrelloMemberCommand, member::TrelloMemberCommand,
model::{TrelloBoardId, TrelloCardId}, model::{TrelloBoardId, TrelloCardId},
stack::TrelloStackCommand,
TrelloCommand, TrelloConfig, TrelloCommand, TrelloConfig,
}, },
AppConfig, Command, FullCtx, AppConfig, Command, FullCtx,
@ -27,3 +28,4 @@ use crate::{
mod board; mod board;
mod card; mod card;
mod member; mod member;
mod stack;

View file

@ -0,0 +1,98 @@
use crate::trello::model::TrelloListId;
//
use super::*;
#[rstest::fixture]
fn list_id() -> TrelloListId {
s!("65ad94865aed24f70ecdcebb").into()
}
#[rstest::fixture]
fn ctx() -> FullCtx {
let fs = given::a_filesystem();
let trello_config = given::a_trello_config();
let list_id = list_id();
let mock_net = given::a_network();
mock_net
.on()
.get(f!("https://api.trello.com/1/lists/{list_id}/cards"))
.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-list-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, list_id: TrelloListId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
//when
Command::Trello(TrelloCommand::Stack(TrelloStackCommand::Get {
dump: true,
list_id: list_id.into(),
}))
.execute(ctx)
.await
.expect("execute");
//then
let output = prt.output();
assert_eq!(
output.trim(),
include_str!("../../../tests/responses/trello-list-get.json").trim()
);
}
#[rstest::rstest]
#[tokio::test]
async fn no_dump(ctx: FullCtx, list_id: TrelloListId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
//when
Command::Trello(TrelloCommand::Stack(TrelloStackCommand::Get {
dump: false,
list_id: list_id.into(),
}))
.execute(ctx)
.await
.expect("execute");
//then
let output = prt.output();
assert_peq!(
output.trim(),
[
"65ad94865aed24f70ecdcebb:Backlog",
"65ad94865aed24f70ecdced1:[Example task]"
]
.join("\n")
);
}

View file

@ -0,0 +1,4 @@
//
use super::*;
mod get;