diff --git a/src/nextcloud/tests/card/add_label.rs b/src/nextcloud/tests/card/add_label.rs new file mode 100644 index 0000000..969aa62 --- /dev/null +++ b/src/nextcloud/tests/card/add_label.rs @@ -0,0 +1,101 @@ +use super::*; + +#[rstest::fixture] +fn stack_id() -> NextcloudStackId { + NextcloudStackId::new(1) +} + +#[rstest::fixture] +fn card_id() -> NextcloudCardId { + NextcloudCardId::new(1) +} + +#[rstest::fixture] +fn label_id() -> NextcloudLabelId { + NextcloudLabelId::new(1) +} + +#[rstest::fixture] +fn ctx() -> FullCtx { + let fs = given::a_filesystem(); + let nextcloud_config = given::a_nextcloud_config(); + + let mock_net = given::a_network(); + mock_net + .on() + .put(crate::f!( + "https://{}/index.php/apps/deck/api/v1.0/boards/{}/stacks/1/cards/1/assignLabel", + nextcloud_config.hostname, + nextcloud_config.board_id + )) + .body(json!({ "labelId": 1 }).to_string()) + .respond(StatusCode::OK) + .mock() + .expect("mock request"); + + FullCtx { + fs: fs.as_real(), + net: mock_net.into(), + prt: given::a_printer(), + cfg: AppConfig { + trello: given::a_trello_config(), + nextcloud: nextcloud_config, + }, + } +} + +#[rstest::rstest] +#[test_log::test(tokio::test)] +async fn dump( + ctx: FullCtx, + stack_id: NextcloudStackId, + card_id: NextcloudCardId, + label_id: NextcloudLabelId, +) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel { + dump: true, + stack_id: stack_id.into(), + card_id: card_id.into(), + label_id: label_id.into(), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_peq!(output.trim(), "null"); +} + +#[rstest::rstest] +#[test_log::test(tokio::test)] +async fn no_dump( + ctx: FullCtx, + stack_id: NextcloudStackId, + card_id: NextcloudCardId, + label_id: NextcloudLabelId, +) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel { + dump: false, + stack_id: stack_id.into(), + card_id: card_id.into(), + label_id: label_id.into(), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_eq!(output, ""); +} diff --git a/src/nextcloud/tests/card/create.rs b/src/nextcloud/tests/card/create.rs new file mode 100644 index 0000000..83911e5 --- /dev/null +++ b/src/nextcloud/tests/card/create.rs @@ -0,0 +1,86 @@ +// +use super::*; + +#[rstest::fixture] +fn stack_id() -> NextcloudStackId { + NextcloudStackId::new(1) +} + +#[rstest::fixture] +fn ctx() -> FullCtx { + let fs = given::a_filesystem(); + let nextcloud_config = given::a_nextcloud_config(); + + let mock_net = given::a_network(); + mock_net + .on() + .post(crate::f!( + "https://{}/index.php/apps/deck/api/v1.0/boards/{}/stacks/1/cards", + nextcloud_config.hostname, + nextcloud_config.board_id + )) + .respond(StatusCode::OK) + .body(include_str!( + "../../../tests/responses/nextcloud-card-create.json" + )) + .expect("mock request"); + + FullCtx { + fs: fs.as_real(), + net: mock_net.into(), + prt: given::a_printer(), + cfg: AppConfig { + trello: given::a_trello_config(), + nextcloud: nextcloud_config, + }, + } +} + +#[rstest::rstest] +#[test_log::test(tokio::test)] +async fn dump(ctx: FullCtx, stack_id: NextcloudStackId) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Create { + dump: true, + stack_id: stack_id.into(), + title: "my new card".to_string(), + description: Some("my new description".to_string()), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_peq!( + output.trim(), + include_str!("../../../tests/responses/nextcloud-card-create.json").trim() + ); +} + +#[rstest::rstest] +#[test_log::test(tokio::test)] +async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Create { + dump: false, + stack_id: stack_id.into(), + title: "my new card".to_string(), + description: Some("my new description".to_string()), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_peq!(output.trim(), "331:my new card"); +} diff --git a/src/nextcloud/tests/card/get.rs b/src/nextcloud/tests/card/get.rs new file mode 100644 index 0000000..f5ae7c9 --- /dev/null +++ b/src/nextcloud/tests/card/get.rs @@ -0,0 +1,89 @@ +// +use super::*; + +#[rstest::fixture] +fn stack_id() -> NextcloudStackId { + NextcloudStackId::new(1) +} + +#[rstest::fixture] +fn card_id() -> NextcloudCardId { + NextcloudCardId::new(321) +} + +#[rstest::fixture] +fn ctx() -> FullCtx { + let fs = given::a_filesystem(); + let nextcloud_config = given::a_nextcloud_config(); + + let mock_net = given::a_network(); + mock_net + .on() + .get(crate::f!( + "https://{}/index.php/apps/deck/api/v1.0/boards/{}/stacks/1/cards/321", + nextcloud_config.hostname, + nextcloud_config.board_id + )) + .respond(StatusCode::OK) + .body(include_str!( + "../../../tests/responses/nextcloud-card-get.json" + )) + .expect("mock request"); + + FullCtx { + fs: fs.as_real(), + net: mock_net.into(), + prt: given::a_printer(), + cfg: AppConfig { + trello: given::a_trello_config(), + nextcloud: nextcloud_config, + }, + } +} + +#[rstest::rstest] +#[test_log::test(tokio::test)] +async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCardId) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get { + dump: true, + stack_id: stack_id.into(), + card_id: card_id.into(), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_peq!( + output.trim(), + include_str!("../../../tests/responses/nextcloud-card-get.json").trim() + ); +} + +#[rstest::rstest] +#[test_log::test(tokio::test)] +async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCardId) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get { + dump: false, + stack_id: stack_id.into(), + card_id: card_id.into(), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_peq!(output.trim(), "321:Breakfast: Cereal"); +} diff --git a/src/nextcloud/tests/card/list.rs b/src/nextcloud/tests/card/list.rs new file mode 100644 index 0000000..69f11ee --- /dev/null +++ b/src/nextcloud/tests/card/list.rs @@ -0,0 +1,82 @@ +// +use super::*; + +#[rstest::fixture] +fn stack_id() -> NextcloudStackId { + NextcloudStackId::new(1) +} + +#[rstest::fixture] +fn ctx() -> FullCtx { + let fs = given::a_filesystem(); + let nextcloud_config = given::a_nextcloud_config(); + + let mock_net = given::a_network(); + mock_net + .on() + .get(crate::f!( + "https://{}/index.php/apps/deck/api/v1.0/boards/{}/stacks/1", + nextcloud_config.hostname, + nextcloud_config.board_id + )) + .respond(StatusCode::OK) + .body(include_str!( + "../../../tests/responses/nextcloud-card-list.json" + )) + .expect("mock request"); + + FullCtx { + fs: fs.as_real(), + net: mock_net.into(), + prt: given::a_printer(), + cfg: AppConfig { + trello: given::a_trello_config(), + nextcloud: nextcloud_config, + }, + } +} + +#[rstest::rstest] +#[test_log::test(tokio::test)] +async fn dump(ctx: FullCtx, stack_id: NextcloudStackId) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::List { + dump: true, + stack_id: stack_id.into(), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_peq!( + output.trim(), + include_str!("../../../tests/responses/nextcloud-card-list.json").trim() + ); +} + +#[rstest::rstest] +#[test_log::test(tokio::test)] +async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId) { + //given + let prt = ctx.prt.clone(); + let prt = prt.as_test().unwrap(); + + //when + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::List { + dump: false, + stack_id: stack_id.into(), + })) + .execute(ctx) + .await + .expect("execute"); + + //then + let output = prt.output(); + assert_peq!(output.trim(), ["322:Lunch: Soup & Toast"].join("\n")); +} diff --git a/src/nextcloud/tests/card/mod.rs b/src/nextcloud/tests/card/mod.rs new file mode 100644 index 0000000..6568867 --- /dev/null +++ b/src/nextcloud/tests/card/mod.rs @@ -0,0 +1,7 @@ +// +use super::*; + +mod add_label; +mod create; +mod get; +mod list; diff --git a/src/nextcloud/tests/mod.rs b/src/nextcloud/tests/mod.rs new file mode 100644 index 0000000..8e404e8 --- /dev/null +++ b/src/nextcloud/tests/mod.rs @@ -0,0 +1,33 @@ +#![allow(dead_code)] +#![allow(unused_imports)] +// +use kxio::{ + net::{MockNet, StatusCode}, + print::Printer, +}; +use pretty_assertions::assert_eq as assert_peq; +use serde_json::json; + +use crate::execute::Execute; +use crate::nextcloud::card::NextcloudCardCommand; +use crate::nextcloud::deck::NextcloudDeckCommand; +use crate::nextcloud::NextcloudCommand; +use crate::Command; +use crate::{ + nextcloud::{ + card::{AddLabel, Create}, + model::{ + Card, Label, NextcloudBoardId, NextcloudCardId, NextcloudCardTitle, NextcloudETag, + NextcloudHostname, NextcloudLabelId, NextcloudOrder, NextcloudPassword, + NextcloudStackId, NextcloudStackTitle, NextcloudUsername, Stack, + }, + NextcloudConfig, + }, + s, + tests::given, + trello::TrelloConfig, + AppConfig, FullCtx, +}; + +mod card; +mod stack; diff --git a/src/nextcloud/tests/stack/list.rs b/src/nextcloud/tests/stack/list.rs index 71338bf..7b4e1aa 100644 --- a/src/nextcloud/tests/stack/list.rs +++ b/src/nextcloud/tests/stack/list.rs @@ -1,3 +1,8 @@ +use crate::execute::Execute; +use crate::nextcloud::card::NextcloudCardCommand; +use crate::nextcloud::stack::NextcloudStackCommand; +use crate::nextcloud::NextcloudCommand; +use crate::Command; // use super::*; @@ -52,9 +57,12 @@ async fn no_dump(ctx: FullCtx) { let prt = prt.as_test().unwrap(); //when - crate::nextcloud::stack::list(ctx, false) - .await - .expect("execute"); + Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::List { + dump: false, + })) + .execute(ctx) + .await + .expect("execute"); //then let output = prt.output();