From fc8e4e2ad0b30991d451b1e4ba32e2f4cc511bfd Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 31 Jan 2024 11:10:37 +0100 Subject: [PATCH] test(app): #14 Add test for validity of output files --- tests/testthat/test-process_directory.R | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-process_directory.R b/tests/testthat/test-process_directory.R index d4cfc42..c7d9429 100644 --- a/tests/testthat/test-process_directory.R +++ b/tests/testthat/test-process_directory.R @@ -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" @@ -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.", { @@ -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 + )) })