Skip to content

Commit

Permalink
test(app): #14 Add test for validity of output files
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAxthelm committed Jan 31, 2024
1 parent f7296ec commit fc8e4e2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/testthat/test-process_directory.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ simple_groups <- tibble::tribble(
"Simple Investor", "Simple Portfolio"
)

json_validator <- jsonvalidate::json_schema[["new"]](
schema = system.file(
"extdata", "schema", "metadata.json",
package = "workflow.portfolio.parsing"
),
strict = TRUE,
engine = "ajv"
)

test_that("Processing a directory with a single file works.", {
test_file <- testthat::test_path(
"testdata", "portfolios", "simple.csv"
Expand Down Expand Up @@ -40,7 +49,12 @@ test_that("Processing a directory with a single file works.", {
input_filename = "foo.csv",
input_entries = 1L
)
expect_true(file.exists(file.path(output_dir, "processed_portfolios.json")))
metadata_file <- file.path(output_dir, "processed_portfolios.json")
expect_true(file.exists(metadata_file))
expect_true(json_validator[["validate"]](
json = metadata_file,
verbose = TRUE
))
})

test_that("Processing a directory with a multiple files works.", {
Expand Down Expand Up @@ -86,5 +100,10 @@ test_that("Processing a directory with a multiple files works.", {
input_filename = "foo2.csv",
input_entries = 1L
)
metadata_file <- file.path(output_dir, "processed_portfolios.json")
expect_true(file.exists(file.path(output_dir, "processed_portfolios.json")))
expect_true(json_validator[["validate"]](
json = metadata_file,
verbose = TRUE
))
})

0 comments on commit fc8e4e2

Please sign in to comment.