From 6c986fa5b9f8a4a57d6d31fb2c3842b0b5210b60 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 14 Dec 2024 22:08:30 +0000 Subject: [PATCH] tests: add tests for 'trello stack get' --- src/tests/responses/trello-list-get.json | 130 +++++++++++++++++++++++ src/trello/tests/mod.rs | 2 + src/trello/tests/stack/get.rs | 98 +++++++++++++++++ src/trello/tests/stack/mod.rs | 4 + 4 files changed, 234 insertions(+) create mode 100644 src/tests/responses/trello-list-get.json create mode 100644 src/trello/tests/stack/get.rs create mode 100644 src/trello/tests/stack/mod.rs diff --git a/src/tests/responses/trello-list-get.json b/src/tests/responses/trello-list-get.json new file mode 100644 index 0000000..308d3d1 --- /dev/null +++ b/src/tests/responses/trello-list-get.json @@ -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 + } +] diff --git a/src/trello/tests/mod.rs b/src/trello/tests/mod.rs index 0311dc2..fc8ae38 100644 --- a/src/trello/tests/mod.rs +++ b/src/trello/tests/mod.rs @@ -19,6 +19,7 @@ use crate::{ card::TrelloCardCommand, member::TrelloMemberCommand, model::{TrelloBoardId, TrelloCardId}, + stack::TrelloStackCommand, TrelloCommand, TrelloConfig, }, AppConfig, Command, FullCtx, @@ -27,3 +28,4 @@ use crate::{ mod board; mod card; mod member; +mod stack; diff --git a/src/trello/tests/stack/get.rs b/src/trello/tests/stack/get.rs new file mode 100644 index 0000000..1ba4705 --- /dev/null +++ b/src/trello/tests/stack/get.rs @@ -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") + ); +} diff --git a/src/trello/tests/stack/mod.rs b/src/trello/tests/stack/mod.rs new file mode 100644 index 0000000..2563f63 --- /dev/null +++ b/src/trello/tests/stack/mod.rs @@ -0,0 +1,4 @@ +// +use super::*; + +mod get;