test(nextcloud): add new tests
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 1m43s
Test / build (map[name:stable]) (push) Successful in 2m5s
Release Please / Release-plz (push) Failing after 17s

This commit is contained in:
Paul Campbell 2024-12-11 20:46:10 +00:00
parent 6e39f94a31
commit 89862e9cb0
7 changed files with 409 additions and 3 deletions

View file

@ -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, "");
}

View file

@ -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");
}

View file

@ -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");
}

View file

@ -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"));
}

View file

@ -0,0 +1,7 @@
//
use super::*;
mod add_label;
mod create;
mod get;
mod list;

View file

@ -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;

View file

@ -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::*; use super::*;
@ -52,7 +57,10 @@ async fn no_dump(ctx: FullCtx) {
let prt = prt.as_test().unwrap(); let prt = prt.as_test().unwrap();
//when //when
crate::nextcloud::stack::list(ctx, false) Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::List {
dump: false,
}))
.execute(ctx)
.await .await
.expect("execute"); .expect("execute");