Skip to content

Commit

Permalink
tests(cli): add basic integration tests for the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Rolv-Apneseth committed Nov 13, 2024
1 parent 9a51961 commit 84570ff
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 0 deletions.
139 changes: 139 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ termcolor = { version = "1.4.1" }
is-terminal = { version = "0.4.13" }
comfy-table = "7.1.1"
anyhow = "1.0.91"

[dev-dependencies]
assert_cmd = "2.0.16"
predicates = "3.1.2"
117 changes: 117 additions & 0 deletions cli/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use assert_cmd::Command;
use predicates::{
prelude::PredicateBooleanExt,
str::{contains, ends_with, is_match, starts_with},
};

fn get_cmd() -> Command {
let mut cmd = Command::cargo_bin("frs").unwrap();
cmd.arg("--url=http://localhost:8080");
cmd
}

#[test]
fn test_currencies_basic() {
get_cmd()
.arg("currencies")
.assert()
.stdout(
contains("AUD")
.and(contains("USD"))
.and(contains("GBP"))
.and(contains("United States Dollar"))
.and(is_match("\\d").unwrap().not()),
)
.success();
}

#[test]
fn test_currencies_json() {
get_cmd()
.arg("currencies")
.arg("--json")
.assert()
.stdout(
starts_with("{")
.and(ends_with("}\n"))
.and(contains("\"EUR\": \"Euro\"")),
)
.success();
}

#[test]
fn test_currencies_raw() {
get_cmd()
.arg("currencies")
.arg("--raw")
.assert()
.stdout(starts_with("AUD\tAustralian Dollar").and(contains("EUR\tEuro")))
.success();
}

#[test]
fn test_convert_basic() {
get_cmd()
.arg("convert")
.assert()
.stdout(
contains("AUD")
.and(contains("USD"))
.and(contains("GBP"))
.and(is_match("\\d").unwrap()),
)
.success();
}

#[test]
fn test_convert_targets() {
get_cmd()
.args(["convert", "USD", "EUR,GBP"])
.assert()
.stdout(
contains("EUR")
.and(contains("GBP"))
.and(is_match("\\d").unwrap())
.and(contains("USD").not()),
)
.success();
}

#[test]
fn test_convert_amount() {
get_cmd()
.args(["convert", "-a", "1000", "--json"])
.assert()
.stdout(contains("1000").and(is_match("\\d").unwrap()))
.success();
}

#[test]
fn test_period_basic() {
get_cmd()
.args(["period", "EUR", "2024-10-10"])
.assert()
.stdout(
contains("2024-10-10")
.and(contains("2024-10-11"))
.and(contains("2024-11-05"))
.and(contains("AUD"))
.and(contains("USD"))
.and(contains("GBP")),
)
.success();
}

#[test]
fn test_period_end_date() {
get_cmd()
.args(["period", "EUR", "2020-5-12", "2020-5-13"])
.assert()
.stdout(
contains("2020-05-12")
.and(contains("2020-05-13"))
.and(contains("2024-05-11").not())
.and(contains("2024-05-14").not()),
)
.success();
}

0 comments on commit 84570ff

Please sign in to comment.