From 6fa6849383dfcb8daae152ea0193276c4d2b54ed Mon Sep 17 00:00:00 2001 From: Philip Chase Date: Mon, 29 Sep 2025 15:00:08 -0400 Subject: [PATCH 1/2] Move test data out of package space and remove tests of schema files Move test data from package scope to test scope. Remove 9 man pages for test data that movwed to test scope. Remove tests that were only testing schema files. Remove helpers used only by the removed tests. Fix tests that needed the rescoped test data. --- .gitignore | 1 + DESCRIPTION | 1 - NAMESPACE | 1 - R/data.R | 179 ------------------ R/transform.R | 33 ---- data-raw/invoice_line_items.R | 31 --- data-raw/redcap_log_event_test_data.R | 57 ------ data-raw/redcap_user_information.R | 28 --- ...ice_line_item_communications_test_data.rda | Bin 2212 -> 0 bytes data/invoice_line_item_reasons.rda | Bin 526 -> 0 bytes data/invoice_line_item_statuses.rda | Bin 358 -> 0 bytes data/redcap_log_event_test_data.rda | Bin 1020 -> 0 bytes data/redcap_rights_test_data.rda | Bin 1954 -> 0 bytes data/redcap_user_information_test_data.rda | Bin 1028 -> 0 bytes data/service_instance_test_data.rda | Bin 395 -> 0 bytes data/service_type_test_data.rda | Bin 276 -> 0 bytes examples/ctsit_staff.R | 15 -- examples/invoice_line_item.R | 16 -- examples/invoice_line_item_communications.R | 16 -- examples/redcap_projects.R | 18 -- examples/service_instance.R | 16 -- examples/service_type.R | 16 -- man/fix_data_in_redcap_log_event.Rd | 23 --- ...oice_line_item_communications_test_data.Rd | 53 ------ man/invoice_line_item_reasons.Rd | 20 -- man/invoice_line_item_statuses.Rd | 23 --- man/redcap_log_event_test_data.Rd | 37 ---- man/redcap_rights_test_data.Rd | 24 --- man/redcap_user_information_test_data.Rd | 70 ------- man/service_instance_test_data.Rd | 25 --- man/service_type_test_data.Rd | 24 --- .../make_test_data.R | 22 ++- .../redcap_user_information.rds | Bin 0 -> 1051 bytes .../redcap_user_rights.rds | Bin 0 -> 770 bytes .../redcap_user_roles.rds | Bin 0 -> 683 bytes tests/testthat/helper-package-specific.R | 152 --------------- .../invoice_line_item_reasons.rds | Bin 0 -> 476 bytes .../invoice_line_item_statuses.rds | Bin 0 -> 320 bytes .../invoice_line_item/make_test_data.R | 42 ++++ .../redcap_user_information/make_test_data.R | 30 +++ .../service_instance/make_test_data.R | 6 +- .../service_instance/service_instance.rds | Bin 0 -> 360 bytes .../testthat/service_type/make_test_data.R | 10 +- tests/testthat/service_type/service_type.rds | Bin 0 -> 250 bytes tests/testthat/test-invoice_line_item.R | 31 --- .../test-invoice_line_item_communications.R | 29 --- tests/testthat/test-redcap_log_event.R | 27 --- tests/testthat/test-redcap_rights.R | 28 ++- tests/testthat/test-redcap_user_information.R | 20 -- tests/testthat/test-service_instance.R | 20 -- tests/testthat/test-service_type.R | 19 -- tests/testthat/test-transform.R | 21 +- 52 files changed, 148 insertions(+), 1036 deletions(-) delete mode 100644 data-raw/invoice_line_items.R delete mode 100644 data-raw/redcap_log_event_test_data.R delete mode 100644 data-raw/redcap_user_information.R delete mode 100644 data/invoice_line_item_communications_test_data.rda delete mode 100644 data/invoice_line_item_reasons.rda delete mode 100644 data/invoice_line_item_statuses.rda delete mode 100644 data/redcap_log_event_test_data.rda delete mode 100644 data/redcap_rights_test_data.rda delete mode 100644 data/redcap_user_information_test_data.rda delete mode 100644 data/service_instance_test_data.rda delete mode 100644 data/service_type_test_data.rda delete mode 100644 examples/ctsit_staff.R delete mode 100644 examples/invoice_line_item.R delete mode 100644 examples/invoice_line_item_communications.R delete mode 100644 examples/redcap_projects.R delete mode 100644 examples/service_instance.R delete mode 100644 examples/service_type.R delete mode 100644 man/fix_data_in_redcap_log_event.Rd delete mode 100644 man/invoice_line_item_communications_test_data.Rd delete mode 100644 man/invoice_line_item_reasons.Rd delete mode 100644 man/invoice_line_item_statuses.Rd delete mode 100644 man/redcap_log_event_test_data.Rd delete mode 100644 man/redcap_rights_test_data.Rd delete mode 100644 man/redcap_user_information_test_data.Rd delete mode 100644 man/service_instance_test_data.Rd delete mode 100644 man/service_type_test_data.Rd rename data-raw/redcap_rights_test_data.R => tests/testthat/get_user_rights_and_info_v1/make_test_data.R (54%) create mode 100644 tests/testthat/get_user_rights_and_info_v1/redcap_user_information.rds create mode 100644 tests/testthat/get_user_rights_and_info_v1/redcap_user_rights.rds create mode 100644 tests/testthat/get_user_rights_and_info_v1/redcap_user_roles.rds create mode 100644 tests/testthat/invoice_line_item/invoice_line_item_reasons.rds create mode 100644 tests/testthat/invoice_line_item/invoice_line_item_statuses.rds create mode 100644 tests/testthat/redcap_user_information/make_test_data.R rename data-raw/service_instance_test_data.R => tests/testthat/service_instance/make_test_data.R (81%) create mode 100644 tests/testthat/service_instance/service_instance.rds rename data-raw/service_type_test_data.R => tests/testthat/service_type/make_test_data.R (71%) create mode 100644 tests/testthat/service_type/service_type.rds delete mode 100644 tests/testthat/test-invoice_line_item.R delete mode 100644 tests/testthat/test-invoice_line_item_communications.R delete mode 100644 tests/testthat/test-redcap_log_event.R delete mode 100644 tests/testthat/test-redcap_user_information.R delete mode 100644 tests/testthat/test-service_instance.R delete mode 100644 tests/testthat/test-service_type.R diff --git a/.gitignore b/.gitignore index 86747a5f..e4676d16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vscode/ .Rproj.user .Rhistory .RData diff --git a/DESCRIPTION b/DESCRIPTION index 2304048a..ca1913f7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,7 +37,6 @@ License: Apache License (>= 2) Encoding: UTF-8 LazyData: true Imports: - bit64, dplyr, jsonlite, lubridate, diff --git a/NAMESPACE b/NAMESPACE index a78c225b..0c2f7d94 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,6 @@ export(connect_to_rcc_billing_db) export(draft_communication_record_from_line_item) export(fix_data_in_invoice_line_item) export(fix_data_in_invoice_line_item_communication) -export(fix_data_in_redcap_log_event) export(fix_data_in_redcap_projects) export(fix_data_in_redcap_user_information) export(get_bad_emails_from_log) diff --git a/R/data.R b/R/data.R index d2d19668..8f6f45f9 100644 --- a/R/data.R +++ b/R/data.R @@ -33,74 +33,6 @@ #' @source \url{https://github.com/ctsit/rcc.billing/issues/3} "invoice_line_item_test_data" -#' Sample data for service_instance table -#' -#' @format -#' \describe{ -#' \item{service_instance_id}{the primary key} -#' \item{service_type_code}{a numeric code that uniquely identifies the service_type} -#' \item{service_identifier}{either a redcap project ID, or redcap username} -#' \item{ctsi_study_id}{CSBT’s unique identifier for a service} -#' \item{active}{a boolean indicating if we expect to continue billing for this service} -#' } -#' -#' @source \url{https://github.com/ctsit/rcc.billing/issues/2} -"service_instance_test_data" - -#' Sample data for service_type table -#' -#' @format -#' \describe{ -#' \item{service_type_code}{a numeric code that uniquely identifies the service_type} -#' \item{service_type}{short name describing the service_type, in snake case} -#' \item{price}{price for one unit of the service, in US dollars} -#' \item{billing_frequency}{frequency at which this service ir billed, in months} -#' } -#' -#' @source \url{https://github.com/ctsit/rcc.billing/issues/1} -"service_type_test_data" - -#' @title invoice_line_item_communications_test_data -#' @description A test dataset for testing functions that write or read invoice_line_item_communications -#' @format A data frame with 26 rows and 32 variables: -#' \describe{ -#' \item{\code{id}}{double: the primary key} -#' \item{\code{service_identifier}}{character: either a redcap project ID, or redcap username} -#' \item{\code{service_type_code}}{double: a numeric code that uniquely identifies the service_type} -#' \item{\code{service_instance_id}}{character: a numeric code that uniquely identifies the service_instance} -#' \item{\code{ctsi_study_id}}{double: CSBT's unique identifier for a service} -#' \item{\code{name_of_service}}{character: name of the service} -#' \item{\code{name_of_service_instance}}{character: name of the study} -#' \item{\code{other_system_invoicing_comments}}{character: additional invoice information, either project url, or sponsor and pi} -#' \item{\code{price_of_service}}{double: price of the service, in US dollars} -#' \item{\code{qty_provided}}{double: quantity provided} -#' \item{\code{amount_due}}{double: amount due, in US dollars} -#' \item{\code{fiscal_year}}{character: fiscal year of the invoice} -#' \item{\code{month_invoiced}}{character: month of the invoice} -#' \item{\code{pi_last_name}}{character: last name of the person invoiced} -#' \item{\code{pi_first_name}}{character: first name of the person invoiced} -#' \item{\code{pi_email}}{character: email of the person invoiced} -#' \item{\code{gatorlink}}{character: gatorlink of the person invoiced} -#' \item{\code{crc_number}}{double: Clinical Research Center number} -#' \item{\code{ids_number}}{character: Investigational Drug Service number} -#' \item{\code{ocr_number}}{character: Office of Clinical Research study number} -#' \item{\code{invoice_number}}{double: invoice number} -#' \item{\code{je_number}}{character: journal entry number} -#' \item{\code{je_posting_date}}{POSIXct: journal entry posting date} -#' \item{\code{reason}}{character: reason for the invoice} -#' \item{\code{status}}{character: status of the invoice} -#' \item{\code{created}}{POSIXct: created at timestamp} -#' \item{\code{updated}}{POSIXct: updated at timestamp} -#' \item{\code{sender}}{character: message sender, typically an email address} -#' \item{\code{recipient}}{character: message recipient, typically an email address} -#' \item{\code{date_sent}}{POSIXct: date CTSI sent the message} -#' \item{\code{date_received}}{POSIXct: date CTSIT received the email} -#' \item{\code{script_name}}{character: the script that created this record} -#' } -#' -#' @source \url{https://github.com/ctsit/rcc.billing/issues/7} -"invoice_line_item_communications_test_data" - #' @title CTS-IT Staff #' @description usernames of CTS-IT staff #' @format A data frame with 6 rows and 1 variable: @@ -434,87 +366,6 @@ #' } "projects_table_fragment" -#' @title redcap_user_information_test_data -#' @description Test dataset for redcap_user_information -#' @format A data frame with 5 rows and 49 variables: -#' \describe{ -#' \item{\code{ui_id}}{integer primary key} -#' \item{\code{username}}{character redcap username} -#' \item{\code{user_email}}{character primary email address} -#' \item{\code{user_email2}}{character} -#' \item{\code{user_email3}}{character} -#' \item{\code{user_phone}}{character} -#' \item{\code{user_phone_sms}}{character} -#' \item{\code{user_firstname}}{character} -#' \item{\code{user_lastname}}{character} -#' \item{\code{user_inst_id}}{character} -#' \item{\code{super_user}}{integer} -#' \item{\code{account_manager}}{integer} -#' \item{\code{access_system_config}}{integer} -#' \item{\code{access_system_upgrade}}{integer} -#' \item{\code{access_external_module_install}}{integer} -#' \item{\code{admin_rights}}{integer} -#' \item{\code{access_admin_dashboards}}{integer} -#' \item{\code{user_creation}}{double} -#' \item{\code{user_firstvisit}}{double} -#' \item{\code{user_firstactivity}}{double} -#' \item{\code{user_lastactivity}}{double} -#' \item{\code{user_lastlogin}}{double} -#' \item{\code{user_suspended_time}}{double} -#' \item{\code{user_expiration}}{double} -#' \item{\code{user_access_dashboard_view}}{double} -#' \item{\code{user_access_dashboard_email_queued}}{character} -#' \item{\code{user_sponsor}}{character} -#' \item{\code{user_comments}}{character} -#' \item{\code{allow_create_db}}{integer} -#' \item{\code{email_verify_code}}{character} -#' \item{\code{email2_verify_code}}{character} -#' \item{\code{email3_verify_code}}{character} -#' \item{\code{datetime_format}}{character} -#' \item{\code{number_format_decimal}}{character} -#' \item{\code{number_format_thousands_sep}}{character} -#' \item{\code{csv_delimiter}}{character} -#' \item{\code{two_factor_auth_secret}}{character} -#' \item{\code{display_on_email_users}}{integer} -#' \item{\code{two_factor_auth_twilio_prompt_phone}}{integer} -#' \item{\code{two_factor_auth_code_expiration}}{integer} -#' \item{\code{api_token}}{character} -#' \item{\code{messaging_email_preference}}{character} -#' \item{\code{messaging_email_urgent_all}}{integer} -#' \item{\code{messaging_email_ts}}{double} -#' \item{\code{messaging_email_general_system}}{integer} -#' \item{\code{messaging_email_queue_time}}{double} -#' \item{\code{ui_state}}{character} -#' \item{\code{api_token_auto_request}}{integer} -#' \item{\code{fhir_data_mart_create_project}}{integer} -#' } -#' @details DETAILS -"redcap_user_information_test_data" - -#' @title redcap_log_event_test_data -#' @description a named list of redcap_log_event tables with project lifecycle test data -#' @format A named list of 10 dataframes each with a 0 or more rows of 15 variables. -#' Each dataframe is structured as described here. -#' \describe{ -#' \item{\code{log_event_id}}{integer primary key} -#' \item{\code{project_id}}{integer REDCap project_id} -#' \item{\code{ts}}{double a timestamp in the format YYYYMMDDHHMMSS in local time} -#' \item{\code{user}}{character the REDCap username who initiated this event} -#' \item{\code{ip}}{character IP address of that REDCap user} -#' \item{\code{page}}{character relative REDCap URL that initiated this event} -#' \item{\code{event}}{character the type of event. e.g DATA_EXPORT, DELETE, ERROR, INSERT, MANAGE, OTHER, UPDATE} -#' \item{\code{object_type}}{character a REDCap object type e.g., NA, redcap_arms, redcap_auth, redcap_data, redcap_docs, redcap_event_forms, redcap_events, redcap_events_metadata, redcap_metadata, redcap_metadata_temp, redcap_projects, redcap_user_rights} -#' \item{\code{sql_log}}{character the SQL code executed during this event} -#' \item{\code{pk}}{character the primary key of the effected object} -#' \item{\code{event_id}}{integer the REDCap event_id if relevant} -#' \item{\code{data_values}}{character} -#' \item{\code{description}}{character description of the event} -#' \item{\code{legacy}}{integer} -#' \item{\code{change_reason}}{character} -#' } -#' @details DETAILS -"redcap_log_event_test_data" - #' @title csbt_column_names #' @description Column names useful for CTSI-IT billing #' @format A data frame with 12 rows and 2 variables: @@ -524,25 +375,6 @@ #'} "csbt_column_names" -#' @title invoice_line_item_reasons -#' @description Provides text for new invoice line items -#' @format A data frame with 3 rows and 2 variables: -#' \describe{ -#' \item{\code{code}}{character: A short, static name for the string} -#' \item{\code{label}}{character: A friendly human-readable string} -#'} -"invoice_line_item_reasons" - -#' @title invoice_line_item_statuses -#' @description Describes valid invoice line item statuses -#' @format A data frame with 5 rows and 2 variables: -#' \describe{ -#' \item{\code{status}}{character: A short, static name for the status code} -#' \item{\code{description}}{character: A human-readable description of the status} -#'} -#' @details DETAILS -"invoice_line_item_statuses" - #' @title fiscal_years #' @description A dataframe of fiscal years and labels from 2019-2020 to 2039-2040 #' @format A data frame with 21 rows and 2 variables: @@ -558,14 +390,3 @@ #' @format A vector with 9 elements #' @details DETAILS "log_event_tables" - -#' @title redcap_rights_test_data -#' @description A named list of dataframes used to test the functions written for redcap_rights.R -#' @format A named list of 3 dataframes: -#' \describe{ -#' \item{\code{redcap_user_information}}{REDCap Core table} -#' \item{\code{redcap_user_rights}}{REDCap Core table} -#' \item{\code{redcap_user_roles}}{REDCap Core table} -#' } -#' @details DETAILS -"redcap_rights_test_data" diff --git a/R/transform.R b/R/transform.R index 83f267eb..a68caf32 100644 --- a/R/transform.R +++ b/R/transform.R @@ -175,39 +175,6 @@ fix_data_in_redcap_user_information <- function(data) { return(mutate_columns_to_posixct(data, time_columns)) } -#' fix_data_in_redcap_log_event -#' -#' Fixes column data types that can vary between MySQL/MariaDB and SQLite3. -#' This allows testing in SQLite3 while production is MariaDB -#' -#' @param data - a dataframe containing data from the redcap_log_event tables -#' -#' @return The input dataframe with revised data types -#' @export -#' -#' @examples -#' \dontrun{ -#' fix_data_in_redcap_log_event(redcap_log_event_test_data) -#' } -fix_data_in_redcap_log_event <- function(data) { - integer64_columns <- c( - "ts" - ) - if (nrow(data) == 0) { # zero-row SQLite3 tables get the wrong data type on ts - result <- data |> - dplyr::mutate( - dplyr::across( - dplyr::any_of(integer64_columns), - bit64::as.integer64 - ) - ) - } else { - result <- data - } - - return(result) -} - #' Renames columns of a dataframe from CTSIT format to CSBT format #' #' Excludes non-CSBT columns and renames CTSIT column names to the corresponding CSBT names. diff --git a/data-raw/invoice_line_items.R b/data-raw/invoice_line_items.R deleted file mode 100644 index 4fc49031..00000000 --- a/data-raw/invoice_line_items.R +++ /dev/null @@ -1,31 +0,0 @@ -library(dplyr) - -invoice_line_item_reasons <- tibble::tribble( - ~code, ~label, - "new_item", "New item to be invoiced", - "deleted", "Project deleted", - "reassigned", "PI reassigned", - "seeking_voucher", "seeking voucher", - # values from do not bill reason - "17", "17. Withdrawn/Canceled", - "21", "21. Duplicate Charge", - "24", "24. Project/Data deleted after invoice creation.", - "27", "27. PI no longer with UF", - "41", "41. Write-Off (True Write-Off, not billing issues)", - "45", "45. PI Left UF and project should have been sequestered/not invoiced.", - "46", "46. Did not meet billing criteria.", - "47", "47. Reassigned to new project owner who decided to delete within 30 days." -) - -usethis::use_data(invoice_line_item_reasons, overwrite = TRUE) - -invoice_line_item_statuses <- tribble( - ~status, ~description, - "draft", "draft invoices line items that have not yet been sent", - "sent", "the invoice line item has been sent to CSBT", - "canceled", "the invoice line item does not need to be paid", - "unreconciled", "CSBT says the line item is paid, but this has not yet been verified by CTS-IT", - "paid", "CTS-IT has verified the line item has been paid" -) - -usethis::use_data(invoice_line_item_statuses, overwrite = TRUE) diff --git a/data-raw/redcap_log_event_test_data.R b/data-raw/redcap_log_event_test_data.R deleted file mode 100644 index 9a2746bf..00000000 --- a/data-raw/redcap_log_event_test_data.R +++ /dev/null @@ -1,57 +0,0 @@ -# Create redcap_log_event_test_data with a subset of logged data -# that shows the entire logged project life-cycle across every -# redcap_log_event* table - -library(redcapcustodian) -library(rcc.billing) -library(tidyverse) -library(DBI) -library(RMariaDB) -library(dotenv) - -project_event_descriptions <- - c( - "Approve production project modifications (automatic)", - "Create project", - "Delete project", - "Request approval for production project modifications", - "Send request to move project to production status", - "Move project to production status", - "Permanently delete project", - "Copy project", - "Approve production project modifications", - "Create project using template", - "Archive project", - "Send request to create project", - "Set project as inactive", - "Reject production project modifications", - "Move project back to development status", - "Return project to production from inactive status", - "Reset production project modifications", - "Send request to copy project", - "Restore/undelete project", - "Create project (API)" - ) - -# run this once against a test redcap to extract the part we need -conn <- connect_to_redcap_db() - -base_table <- "redcap_log_event" -redcap_log_event_test_data <- list() -for (i in seq(1:9)) { - my_table <- if_else(i == 1, base_table, paste0(base_table, i)) - single_log_table <- - tbl(conn, my_table) %>% - filter(description %in% project_event_descriptions) %>% - collect() - redcap_log_event_test_data[[my_table]] <- single_log_table - - # write the schema - DBI::dbGetQuery(conn, paste("show create table", my_table))$`Create Table` %>% - write(file = paste0("inst/schema/", my_table, ".sql")) -} - -# write the test data -usethis::use_data(redcap_log_event_test_data, overwrite = T) - -dbDisconnect(conn) diff --git a/data-raw/redcap_user_information.R b/data-raw/redcap_user_information.R deleted file mode 100644 index 2fa4e0de..00000000 --- a/data-raw/redcap_user_information.R +++ /dev/null @@ -1,28 +0,0 @@ -## Create redcap_user_information from the database of a testing system - -library(redcapcustodian) -library(rcc.billing) -library(tidyverse) -library(lubridate) -library(DBI) -library(RMariaDB) -library(dotenv) - -my_table <- "redcap_user_information" - -# # run this once against a test redcap to extract the part we need -# conn <- connect_to_redcap_db() -# data <- tbl(conn, my_table) -# -# redcap_user_information_test_data <- data %>% -# collect() %>% -# filter(ui_id >= 3) -# -# # write the test data -# usethis::use_data(redcap_user_information_test_data, overwrite = T) -# -# # write the schema -# DBI::dbGetQuery(conn, paste("show create table", my_table))$`Create Table` %>% -# write(file = paste0("inst/schema/", my_table, ".sql")) -# -# dbDisconnect(conn) diff --git a/data/invoice_line_item_communications_test_data.rda b/data/invoice_line_item_communications_test_data.rda deleted file mode 100644 index ec22fabf3f840cd75d1e8467cdfc9a6099e148cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2212 zcmV;V2wV3;T4*^jL0KkKS>3Kf-T)AkfB*mg{q^r7D0F4QU3M7)=^s1|f;20E~?>3`_u-FaS)0MgRbe zm`s=gVHkrBQA5qPAF zIEXUHWD#IS5S3RcIh%a-#)9WXqtabuZuI(#%iT@)f2po1wDEH$;u+GTuok@Ji zn-C9W#*K)W5a-+)VcW&VjhTEFaSn$A8CI>TE#OY*8F-UPN`rk*e9ceqw)?$Ts5f@q zvk~5d3U57#If?TWA^w$sT;@|w?EHGMYO3Etsya>xFk|q=MAHbGeA!L20??Wu9Qztp zX_Vo=G6199!hjrqF)*$!ZoEDWOKlok*mZ>3wl{QGmx3r^wiHj6y?G{qB`t3RMG_T; z8k9yZp(R`@D!9vP)hsL;t(i7d#SPZ7yM$Iq#I96UV&hdJw2Wwic&{TaY=cT{= z;q;?6HMY#|w+_6v%@xC3IPdOFs!>XjS;*ev#l^FFxOjZ4>#j=Ae>~f~wiTvj&uFde ztv2p%UNF;PtIC|+9KANBWtLe+<6cadOf=h88B|qE&nr__%@S7TSo9+bBRj@<;VVU@ z)YTSAdx=$o<&>*$?ci?bVx>AO)nRO_M%O=;2pzISl87KgAh0X|EUd^!sxY9dCKVOc zQUFzaI7ME#eiBmr3GuKVQ3y~GB$V{+DxHX;8Bkt|QMRHc6@+@^uq{yqXFsj)PK&s% zl_=&#k;YE2=!vW**g61VOCV?~2Nhr0UBxB>75bapxlg%QS2DYg+B)O65!q0xr7huh z(d^Mb^h~)i4FQn%64TR(lz;bdCRU)cA zaZvMWNjVBB6j4b@B$0mwU{Fn6{0t%ppo$8t3M&dAt_7u}-&AReDJCf-M3$% zdz%!hMX67pJxIvpaS^I%hE%FmN<|&(fe-HHI6{oO=nmFaW<8@6)TV=;z=t^ zbeJA%C(QB5Y0v4%=_AW|!&+oF-_kOXc-SZ>bkjE9ICDhN0j1h?+phtH17DTOmb|?3 zO3~^>^)a@J^Bv_iOZEG@E*K)iE4@jp1k{XlSToh2C_QN>Rx~7R*{Ku94PI=rDChb@ zOyAg6X;Dg0q3az|W|Bbg=( z2{1+@7`%q&lL#=yC$gm0iQq>4^X(xT0Vtq^s>Fn#R&gRvQ}9xiFeW6N&n7W%2L*1( z*<7^dUX30L30hN2m}k?SspE%>B-j=bSB&GG1r9aNG~y(c%cL5sRe&J|6>~I`Ea66) zR61+!3kC-9&L>egLqx33IMmx~L9z~0;94~Xj5`dp;AbrEg&xpy(_4d506m2ROu zfg7q&f={mz1VmR@-$c(rP?nSziVp@ye`f1MW}NIHCXFo$(w@j;IDB6F#MaAbWwe+J z@`@31@=H`H6fluyh%lv6swqm5doVS|i4C#4B>ytW;~jj_!>VFVxa>%1BWTj=Y>x`M z2;1Nc+EK?O=7}#O_>&)doMlM(({bj`0!&H{h*C-C$n8krk&;++I(!Y_^n9NK`-eN2 zB=`v1-aN{6Bl^Y?9RSs@u_K#DE^i{zoAfPFfN|kxp>Jg)KNH3WH1&~S)Yc^9nS1w2 zs+UEWNYGsj30ZG<9Hi3`SKC}#oUoj6eKrmkoSOqNcU6# diff --git a/data/invoice_line_item_reasons.rda b/data/invoice_line_item_reasons.rda deleted file mode 100644 index 5f707b68ec3eefb06bcf05fb67e3025e3dd10a78..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 526 zcmV+p0`dJqT4*^jL0KkKS+viJ&Hw=T|G@wD&EQaH|9}rA*1*62|DZqs1OdPSylj>C$!XW#-SquCWrhH1YSeMNWB$=6zNRHvY}UXIA|F0?&~arlYn=xBrGbA zhg#l(!$%nx1Qa2dOX1jnl%YBy0ZTeo#rZ5`jd89q&sW*1C0ej9U%(m|(NQpswuxr> zuoGMasx*iv#z659lL3(f^N(>`a4-vIRcv9EBnKAT`&Yok*Ohc#V!ni51V&;Lp^|K? zoC;L|f{Ui1ne+;T%vF*s5nP6p8XI{`c2fbwI!Y`F9A-B6z;Fz;D^&1(klZ3btP{G$ z8!WhH3+R{}U$Pa}_Hh{`YJ^>q6+U&g8AxEp@ys%1EY1;HR);JhP|z Qph5o^az!{$khIT=&Qdz+2LJ#7 diff --git a/data/invoice_line_item_statuses.rda b/data/invoice_line_item_statuses.rda deleted file mode 100644 index e3446365642d9eb4684c3b2c57ee677551095de6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 358 zcmV-s0h#_nT4*^jL0KkKSsYw{H2?sg|G@u#NDx2|k^mec96-Nk-=IJM012=GSrP=P zlS*PXlT&JWH8c$XXnK01N0jvj00000Xfy$!8UZANWf?t5>VBxu8UXbHqfIo;BZ8E+ zj=F3(VH(u1c(r4`$Xpau{cjCmnuNQLm{NV_CS}vgMg(u zW|4{~bw6%xaM&X&fu4$&D#7CDNDBA7(%2HsiqVfADZ*S09h%GxBqE+t-*L9wjDb22 z%tCbCFugZ8c!n7|gikuAVMIqIa>j|V*%MQW)e}F~Yb+>dje%zvpckx#qoe1^fYzJv zDi<>%K=9OFWxP^1G~-vJLsXt>!4YyUO__q4AqfgWjFZAAHK6)#b#l_^OmpbcPsvTG z9c2#{Z@u)wDooj1RYc?;WYAHfaiXExuFYM&3C!;|J&1%^<8uD?5Kr-UBvXY60maAj EP!+bG{Qv*} diff --git a/data/redcap_log_event_test_data.rda b/data/redcap_log_event_test_data.rda deleted file mode 100644 index 7f0820f81bd4f40cfc725a70c296415c555c91ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1020 zcmV|M&m@{nB9L|MD(_P(c6x|DZqs0E8R>00aOO z03?D3&;-5VLIn^3A~Q+02%-TL7-^F002cI z0vboDw1=u?J))VZ>SV$I^#db8qeIC7wH_3ERLdO9*pxJzjST|^0|pA@f0ukh_2Lys zuz?~Nf_oOI><2m-(2%;vHPYstzliu+@Ejv*RF`NO+Y|}fIt9gg#mQk+bTM}H3ElzEQA4K zuPI*%KUyB7InebX#)qwbv=C&6 zT9r2D#9ZjAUE!oKj0OW0@x&<$)SytK7DRAB?-4?XfJ-4=I2YmkJvqE80~#MkOGd=W z(+x>>EO0Wiwd9J}Vy&tIx%p?DV(X122?sR7ub~I@ghN=(`h(68=(!C3B?%D0)lPBKHv;0+SLxQEJy?%7C%_f}MdAv~)@g9I@`)G@(_8B0u(kZ4D(5t$(j zP?8(7#&b6D!L@-u@ACx6o&T`D5CFryS91#i- zfM>>{7t}8g;)k?_bPPllA!POtuqBbrHxwa0sz$UoLx~KRuL2cRhj}xi5$Vc>XiF$w qT-s`{r|N6iH5EKvqL;w^( zKpEf&-hC7y0h=HcC<-Vj2n{4jrcYBLiJ-wW(Sl+C!eV4(WFCZOgFpGkkOz30000000#g8pa2;F003k(XaE2J00001zyN3f20#D+84Vf$00000001IL zh*Q+rDDz5UU`-lnwJ|V_3{08;000N5X_25b)5-}VXdpmFniTU>B6>9;>9kCy^-VGj zr~}jkYBV&^@{J9MnFsU!iZeOh3^&;Y$rQ3m6nB9_(ICY$tATlSVp$?VD3L(HAO)(G zW)|{8qGf~{fC@lTjPW5Y6$u1zOdta&riz)%CPiI1l^YAQWeW?f5Vh5aWk94zD8UV2 zaIi8R?u8&8^ixC-#K@sg6J5e7>%yVsWc; ze>J2Pc!?MMFF5I)94AkyeaLNA{MOQklN~1ha_qU4g2<8x@%WNSNL!Ju<0-4O>qXVu znz3^tqx3-6Mhb3V90?$Dt|@{OQ8#nww|q!h3mHx8rcwa0hyn*NG*Xo+0IR=%DaPW7 z$a0~Hh~>o8GWgU_u&7+mNBET&KA{{(0_>v=VlK=#Mn2^3&}vTG=ZT=1K)~dh~1K1!wZ>mV`r)G4uq63VRYjEfQiq}+8R@*b-4Mfr-=sXQzx z5(CgHhbM4~tg)Q5;0A1o&o%%)R8^$tuOKOP&vohj=GlG$axVdwSNI(yeqU_)81s4m zJrCNr4OKn_%r|;KW?NCQ3*{P0BvkQ>3$fM}RuSq(0B@M90YOIyjFBbX59oPn7A`d+ z;^ht^5y$8Olqn>aR)bZCBQW%Q13kTS z6*Pv(5O7BtO2@fh2#`(kObB4JP!}VqgAgI~5-KB!e`A<+**qc4spTk4=ZrE-+Td&kMmk0&(Wq`<-#WUnIsBIwkur?gA;E1Hq!SeYVN7G* zMkR4nZ18YxENx-jGzipt0C-I_)-_Y6O2<;2keSCAVT;0Ip}6*5;}9(&JzQZ_;Bhiy z86<9y53zWUIiRAdv0xd2k6i2xwVsm z4)vZZG$sLwzNe0b1XO?~ODchU^|EhpLkOT@eRInFfKn+@<^&Bl0&EPDP#yKwrEtj1 zUgZ<^)=@O~2<{G9!x|JBWFq}+MU#vuP6h+HRe8WV=}a|n0r4vye!rU#JRB(b#KpRd zqXCsV^R9BhRMK~F<{EljX8g(f{f}?!9Q|jx-S9o$4)j{jI}J~@u$GQs?JjYo(6$3_ z@|>Im1USufJ(WWP)VmGQ{JrR+Hrbb~*O);mbzwt#jhQU){3xWZNS^{nfa$1dO8LB3F z(&4pTs!BKjGGJ8EP$C#;j%a~$DFCrbDHtMA4k{TZ>9Wth)xiYu=McJK>)KN48YR56 z-k7CKWe5;pCr3YcIb1PvfA=Z|L?e`{(L8Zli8kKtE}s-ELuH5vI-;0hqa&|(xffAm zGYPhF9*<*y^NuVZNSOOXW2PEWkcQltu+sgA+wJswav{g?Nkqp$iqDmb2*wr!Z z^lIG`8mo(Jy(EA|a!3Fu0!qY*6d(@dHNgcW5LESPpq*AjUaDB71c)SwBx14)vICJD z{@mAxpg2Pb$Q>ZM`1TX_?FRSNh&Y7d4lQ|8tO?8<0mcdHOT@w^zC^~HfR(UHCqz#N zJCG9`3&33>$fv5aVpDx3uKF}J61x90*liu92DOg+D=47E#PB@Iri^|}3PFSBUY@ke3Q_4gwzwGO_;4vG66Fqyn zve{Fi#u^lR3Skc&#u;0_K1Q<*kwMLr+sFaRz?v?UZkv$&uiF?S?Wg$W7UVVl6d(XrwH diff --git a/data/service_instance_test_data.rda b/data/service_instance_test_data.rda deleted file mode 100644 index 4957a5a5d400482ce2a047a8b6dca15aa24228ed..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 395 zcmV;60d)RCT4*^jL0KkKS$AY5qyPab|MCBS{16~Rf1vCH5J128-{3$100RM(5CA}h zumM&ZZ3$H|iU0s;8UO$Q0ib9A4J648H1$13fB*mh0009gr~*kNL?%xPHlWaG0BCxK zO+6q3MuXB!__d``eSo5t^NGHQXCR;$1lfoQ5|}6s7!=eX;DhK55&-mW0h5hKB0N>* zfJtF#Yl;8>k%Vk8r>kU>21zZCd*OlkG$Zn-FTmftqcjkz@}s*u_go+ z_r=)_FK{y@X@Tt+-NhI|u_=P~Y0Q-cAwD~!Z{cbJ7;Xv9z7++Lf>Gi{#E1%WK!!Lt zB7#;4S+=^QusyOJrwgoC>wEg**NoUi}@ diff --git a/data/service_type_test_data.rda b/data/service_type_test_data.rda deleted file mode 100644 index 01614ad0b988643f1d4946c527783e4f750babb1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 276 zcmV+v0qg!kT4*^jL0KkKS*gp%1ONbp|G@t@X#ikB5CHB1P(c5;|DZqsKmo7-*t9fB zl+ZS#WeplM0BF&sgEB!8C#3Xf35@|6G{G1qm;}QTK?Vo_&;SO214ZAcTYLwlidP{k z(pYGqc%)MACiV^^% collect() redcap_user_rights <- tbl(conn, "redcap_user_rights") %>% collect() redcap_user_roles <- tbl(conn, "redcap_user_roles") %>% collect() -redcap_rights_test_data <- lst( +saveRDS( redcap_user_information, + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_information.rds" + ) +) + +saveRDS( redcap_user_rights, - redcap_user_roles + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_rights.rds" + ) ) -usethis::use_data(redcap_rights_test_data, overwrite = TRUE) +saveRDS( + redcap_user_roles, + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_roles.rds" + ) +) diff --git a/tests/testthat/get_user_rights_and_info_v1/redcap_user_information.rds b/tests/testthat/get_user_rights_and_info_v1/redcap_user_information.rds new file mode 100644 index 0000000000000000000000000000000000000000..a729bb1af9fc560d9fc53de5a051d499c3e20663 GIT binary patch literal 1051 zcmV+$1myc4iwFP!000001MOH(Zxcrp-`EZz0b&Rxl|Vq{UW=&%NXWSWEs!9gR1KEs zX*Aw_Yfrknvz?i>|a_c@~myu}TxPapfjs+a0MA)(_v7p8;CUeDF#(70D z1%x_23pBErCp>0@CdzHzHn>d%_YCgPpzzwOdmQSK1o0pgd=G3Tz_Dpq=c1z}sskQ9 zfPLzR9(;D#IA>YQNBGPzpDsOJk7qn9*Qcv>%+&+|NHPcd^k1#n~Eo3ah#SoQoXbcXP@8x{`OC#u`zc# zZ)c%C+oGWT&1{SLXq$|sjEhh2?QHKn+I{wPx3%@~@%Ftrbj-){OB2RCI$-H8+1hFS zxI0gBYGnV3bLTYpIIa`7XtU9L#hQ)#o5@Nx?>1{L7k!gy2^z1rPfSY4wcY>K)nPh%3@_~(UK_&HR;m)mMVZZ^y|_K;nSSd}_*kEzeY4 z9!VNF*g6oJcx>52Esx>xl6Bv@>T}{^g*YZEQeBkC*o?__hsn^R1HuEHwKyjx7he~3 zRiAl`lTdI!RJkp7vnU#ed%UE}G-O2apCPL;9tx6TmvprKP=E^pg6x-sV-k_*V7tP$VSwm7rpFELkAF03@UlSWbMC zaT~|Mc9@n8{T9B2Z|Ik>M=D%r;*2LsA5hAINFLkgT-*2M>v^{x1VKL-40=I-8Hd60 z+c&SDy+CXiCkNOzEr@L!+kI?1UJEO35DaZknc(@glYS&4hsRXO452MM`SRT!zxvhn zFVD}v*-;x0g256Fdd(&o)wE6xgI3=WvC)+g8_gm%YDa9;5wVet*zhNQULV$)w(-mQ+urG$dg~^hytDdp&3S)n z!(Hh4H@PtQtz58=NYCX^zs}$l6J>-Y?y16AJzQth(8EMg0j>9EsO0o8M_kwXEuG;H z9`U37P&pxc;DOt>Q1S>foN!hnYo!KdMV$nk6kJhz2Wn&$A5HKUq)L{>e10#J@v*&b zQaR{>2N8i+j3-iwE;26hZVLX{ogP}d394W(qmk12W8cSlu8k@M~1*@v#R~TrXI)AUB9OR5DKNkpE+vqc-1xHhk!7W+0z|1>7GINMSgp90p zv?$!`K1T?X(>#-u`8IC4AStkaZx%rXUeY*_Vfkz%`>Zi=!z-AC)(Zox(+j(Z@o}HJSJ6=wbq?NSW3rTAc|0at^pAUBW zh;5*-jcX0p16&JXkMeq0-BNBR9o&~Wb(9F@%w<4UOC+a?rouF=SC4ky^!Gk|?C*a$ zIG$o}_xgwX@A~gQ9oE?5b0_%!#Amvx?T?EpSBfK4EIq|pY> zu(DI6QyLVm0qA-q&pkFy17FF2eJk1tO!R$PgGi1oB!^(~c}nK7_j388BAJZN3tcpu z1BhwZs^d~wXMBzW*3P)eyy>=C;tX=U2-1S8>n1ZfgEW;Y4cL>REU$(JEAdXm@x8*q z4^UBfM95oVh>_{2I>dVULdux1mZS!}j+#zts2)j1vnuJUzaYoCwVrmx%Xuc0pLvcYtxoz(TsUDA%}5U1W1bnP Rp-fS8{R_d paste(collapse = "") - return(result) -} - -#' converts an in-memory schema to a sqlite schema -#' and returns that schema. -#' -#' @param schema, a MySQL/MariaDB Schema -#' -#' @returns sqlite schema for `schema` -#' -#' @examples -#' \dontrun{ -#' mysql_schema_to_sqlite(schema) -#' } -#' @export -mysql_schema_to_sqlite <- function(schema) { - # find the perl script that does the conversion - pl_to_sqlite <- system.file("", "to_sqlite.pl", package = "rcc.billing") - - # construct conversion command - cmd <- paste("perl", pl_to_sqlite) - - result <- system(cmd, input = schema, intern = TRUE) |> paste(collapse = "") - return(result) -} - -#' Creates a table based on a schema. -#' -#' @param conn, a DBI connection object -#' @param schema, the ddl to execute against conn -#' -#' @examples -#' \dontrun{ -#' table_name <- "service_type" -#' conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") -#' -#' schema <- convert_schema_to_sqlite(table_name) -#' create_table(conn = conn, schema = schema) -#' } -#' @export -create_table <- function(conn, schema) { - schemata <- stringr::str_split(schema, pattern = ";\n+")[[1]] - schemata <- schemata[schemata != ""] - - for (schema in schemata) { - # create table - result <- DBI::dbSendQuery(conn, schema) - # close result set to avoid warning - DBI::dbClearResult(result) - } -} - -#' Populates table_name with the corresponding test data found in /data. -#' -#' @param conn, a DBI connection object -#' @param table_name, the table to populate with test data -#' @param use_test_data, whether to use "_test_data" -#' -#' @examples -#' \dontrun{ -#' conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") -#' populate_table(conn = conn, table_name = "service_type") -#' } -#' @export -populate_table <- function(conn, table_name, use_test_data = FALSE) { - data_ref <- table_name - - if (isTRUE(use_test_data)) { - data_ref <- paste0(data_ref, "_test_data") - } - - # get test data - data <- get0(data_ref) - - # write sample data - result <- DBI::dbAppendTable( - conn = conn, - name = table_name, - value = data, - overwrite = TRUE - ) - - result <- DBI::dbGetQuery(conn, paste("select * from", table_name)) - return(result) -} - -#' create_and_load_test_table -#' -#' Create a named table for which we have stored schema and optionally load the stored test data into it -#' -#' @param conn, a DBI Connection object -#' @param table_name, the name of the table -#' @param load_test_data, a logical to indicate if test data should be loaded -#' @param is_sqllite, a logical to indicate if the DBI object is a a SQLLite DB -#' -#' @return The test data as read back from the new table or NULL -#' @export -#' -#' @examples -#' conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") -#' result <- create_and_load_test_table( -#' conn = conn, -#' table_name = "invoice_line_item_communications", -#' is_sqllite = TRUE -#' ) -create_and_load_test_table <- function(conn, table_name, load_test_data = TRUE, is_sqllite = FALSE) { - schema_file_name <- paste0(table_name, ".sql") - original_schema_file <- system.file("schema", schema_file_name, package = "rcc.billing") - schema <- dplyr::if_else(is_sqllite, - convert_schema_to_sqlite(table_name = table_name), - readr::read_file(original_schema_file) - ) - create_table( - conn = conn, - schema = schema - ) - if (load_test_data) { - populate_table( - conn = conn, - table_name = table_name, - use_test_data = T - ) - } -} diff --git a/tests/testthat/invoice_line_item/invoice_line_item_reasons.rds b/tests/testthat/invoice_line_item/invoice_line_item_reasons.rds new file mode 100644 index 0000000000000000000000000000000000000000..5b9b3602a2b6564efe4171e6f0a3eda862588584 GIT binary patch literal 476 zcmV<20VDn&iwFP!0000019el~Z__Xk_tq4)iHS)d#^Z@6kXX8A*~(I>LKB4wM- z0i72tVY~F-G1!ci$63&yOVsF526fLNuPQY)o#kbP_*0qbcy4P^q6_Bj;V4Sku#@sm z>b!a9%}+b&tdm9?{0_fh11&%B7A6SF%&ih@HaE`xK;hvj?fsi;_%CyK%KXi6l)}C8 zrF6V8gL7^KVa24^*)WBR`avtfJ;Hg(-4uiGILlKA1O^w}^T+~t;n78|Ac%@r)}$ft zZAKM|p|PN?nNnm!<>Brs__Lg9-aG30=xb5H`&(DzTK`CS9wtibwii`ZHC7)&=4F1m zME;D0Cp_Rr!b6x)RoYrhDES;|kZ7R7UzAEjQ4U(jINC__U4BNbE4i#ULtGaXEf=SF zjJ(dNp>N&1+pD6r>MGmDv^|!V<|C9`1*}H3>|7Z*IR?ppS1DsjyP;bFxGyw;hLz|A z<1;_eV_5{PM_OD~Nq3MIj?ZudXV=*#HDqtG_S;4KL!ZTB@prRe3_4i8m6b6OR>nK; SYd%3u!oNq7gyybj0{{U19q&{C literal 0 HcmV?d00001 diff --git a/tests/testthat/invoice_line_item/invoice_line_item_statuses.rds b/tests/testthat/invoice_line_item/invoice_line_item_statuses.rds new file mode 100644 index 0000000000000000000000000000000000000000..986c61160c19107480cd50e4d0f8756a07f6c74b GIT binary patch literal 320 zcmV-G0l)qqiwFP!0000018q`GOT$1A-I`QvRVere=B}+L!LtRygQr&LO*Xp|vXJhU z?4**L|64H5rkj4@A)9%RdGAejvKk8^5|O3@kqo&M!;j_b^qILk1{eHH0x4243U6J> zoFYg)+P=P0(kd)bM|@M;3YD|U9Jq8NjXpDc>I}iytuqQel*S?$!nFq~Btap!2-Xoa zNRS~~I10U|0(x}Q( z9w4hZsbCnwPv+fXWpcx=Sp)OsV*1vP^0-5tV&8OXzyFfm&81--gMJmNl-|edOd@$n zS^25+h!RGz9BWB(mRE9(XFj9Kea$TM!Rt2c{F{%qZGX-K`=&|vW5hsDl4>8(wMMTh SvmxUw!{0xB-*H1-0ssI*ft4Bn literal 0 HcmV?d00001 diff --git a/tests/testthat/invoice_line_item/make_test_data.R b/tests/testthat/invoice_line_item/make_test_data.R index 5c077144..978bd617 100644 --- a/tests/testthat/invoice_line_item/make_test_data.R +++ b/tests/testthat/invoice_line_item/make_test_data.R @@ -36,3 +36,45 @@ saveRDS( "invoice_line_item.rds" ) ) + +invoice_line_item_reasons <- tibble::tribble( + ~code, ~label, + "new_item", "New item to be invoiced", + "deleted", "Project deleted", + "reassigned", "PI reassigned", + "seeking_voucher", "seeking voucher", + # values from do not bill reason + "17", "17. Withdrawn/Canceled", + "21", "21. Duplicate Charge", + "24", "24. Project/Data deleted after invoice creation.", + "27", "27. PI no longer with UF", + "41", "41. Write-Off (True Write-Off, not billing issues)", + "45", "45. PI Left UF and project should have been sequestered/not invoiced.", + "46", "46. Did not meet billing criteria.", + "47", "47. Reassigned to new project owner who decided to delete within 30 days." +) + +saveRDS( + invoice_line_item_reasons, + testthat::test_path( + "invoice_line_item", + "invoice_line_item_reasons.rds" + ) +) + +invoice_line_item_statuses <- tribble( + ~status, ~description, + "draft", "draft invoices line items that have not yet been sent", + "sent", "the invoice line item has been sent to CSBT", + "canceled", "the invoice line item does not need to be paid", + "unreconciled", "CSBT says the line item is paid, but this has not yet been verified by CTS-IT", + "paid", "CTS-IT has verified the line item has been paid" +) + +saveRDS( + invoice_line_item_statuses, + testthat::test_path( + "invoice_line_item", + "invoice_line_item_statuses.rds" + ) +) diff --git a/tests/testthat/redcap_user_information/make_test_data.R b/tests/testthat/redcap_user_information/make_test_data.R new file mode 100644 index 00000000..ce805016 --- /dev/null +++ b/tests/testthat/redcap_user_information/make_test_data.R @@ -0,0 +1,30 @@ +## Create redcap_user_information from the database of a testing system +library(redcapcustodian) +library(rcc.billing) +library(tidyverse) +library(lubridate) +library(DBI) +library(RMariaDB) +library(dotenv) + +my_table <- "redcap_user_information" + +# run this once against a test redcap to extract the part we need +conn <- connect_to_redcap_db() +data <- tbl(conn, my_table) + +redcap_user_information <- data |> + dplyr::collect() |> + dplyr::filter(ui_id >= 3) + +# write the test data +saveRDS( + redcap_user_information, + testthat::test_path("redcap_user_information", "redcap_user_information.rds") +) + +# write the schema +DBI::dbGetQuery(conn, paste("show create table", my_table))$`Create Table` |> + write(file = paste0("inst/schema/", my_table, ".sql")) + +dbDisconnect(conn) diff --git a/data-raw/service_instance_test_data.R b/tests/testthat/service_instance/make_test_data.R similarity index 81% rename from data-raw/service_instance_test_data.R rename to tests/testthat/service_instance/make_test_data.R index 627fff4f..0ed971ef 100644 --- a/data-raw/service_instance_test_data.R +++ b/tests/testthat/service_instance/make_test_data.R @@ -1,4 +1,3 @@ -## code to prepare `service_instance` dataset goes here library(tibble) library(usethis) @@ -19,4 +18,7 @@ service_instance_test_data <- tribble( "5-2345", 5, "2345", 787878, T ) -usethis::use_data(service_instance_test_data, overwrite = TRUE) +saveRDS( + service_instance_test_data, + testthat::test_path("service_instance", "service_instance.rds") +) diff --git a/tests/testthat/service_instance/service_instance.rds b/tests/testthat/service_instance/service_instance.rds new file mode 100644 index 0000000000000000000000000000000000000000..42e3af7e95ac0c0d243233824d522582073f552c GIT binary patch literal 360 zcmV-u0hj(CiwFP!0000019ehOPlG@Z-Ik@X*w&Bw2fTTKRQsWx#F%*UsEIeSvWu>1 zp<%bJz4=GYSfkTW2MinY4tJ@J{%#KdBBQc#0Czoc$~%11VPAfxe+ zSwVQ4wd^kp@2A6|O}yaACrZvLwAWVP&LWl!m<0hexd9ciM{kxN>S2qHNkWr-5nAk)ceu0 zuOM%R4)qk%fT`4=L=wvj$%vKu)WcwA`Jl(Wnh@1TxI|I(RUVk#6c5yu*cL3Da+f*W z7n1mKLbD$yE6MqoIc`9iDs2BfLzyqR$62T04)o< z96C-gl3J9d`%d7%E4$W7nz=6E&XxUCSTW9w_`;S>&*VR2V!YA1ZU+BysO$RB9_UHK z<9*y(C7N#~F|oS>6Pc%e-@*R}uTU6uImlXR&1Xn5gWC#8?if7$0dH?9ZI%H505%(T A^#A|> literal 0 HcmV?d00001 diff --git a/tests/testthat/test-invoice_line_item.R b/tests/testthat/test-invoice_line_item.R deleted file mode 100644 index 60be6624..00000000 --- a/tests/testthat/test-invoice_line_item.R +++ /dev/null @@ -1,31 +0,0 @@ -testthat::test_that("service_type sqlite schema is created and correct test data is returned", { - table_name <- "invoice_line_item" - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - test_data <- readRDS( - testthat::test_path( - table_name, paste0(table_name, ".rds") - ) - ) - test_data <- dplyr::mutate(test_data, - je_posting_date = as.POSIXct(je_posting_date, tz = "UTC"), - created = as.POSIXct(created, tz = "UTC"), - updated = as.POSIXct(updated, tz = "UTC"), - date_sent = as.POSIXct(date_sent, tz = "UTC"), - date_received = as.POSIXct(date_received, tz = "UTC") - ) - - sqlite_schema <- convert_schema_to_sqlite(table_name) - create_table( - conn = conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE - ) |> fix_data_in_invoice_line_item() - - expect_identical(test_data, dplyr::as_tibble(results)) - DBI::dbDisconnect(conn) -}) - diff --git a/tests/testthat/test-invoice_line_item_communications.R b/tests/testthat/test-invoice_line_item_communications.R deleted file mode 100644 index 977ada8c..00000000 --- a/tests/testthat/test-invoice_line_item_communications.R +++ /dev/null @@ -1,29 +0,0 @@ -testthat::test_that("service_type sqlite schema is created and correct test data is returned", { - table_name <- "invoice_line_item_communications" - mem_conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - test_data <- readRDS( - testthat::test_path( - table_name, paste0(table_name, ".rds") - ) - ) - test_data <- dplyr::mutate(test_data, - je_posting_date = as.POSIXct(je_posting_date, tz = "UTC"), - created = as.POSIXct(created, tz = "UTC"), - updated = as.POSIXct(updated, tz = "UTC"), - date_sent = as.POSIXct(date_sent, tz = "UTC"), - date_received = as.POSIXct(date_received, tz = "UTC") - ) - sqlite_schema <- convert_schema_to_sqlite(table_name) - create_table( - conn = mem_conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = mem_conn, - table_name = table_name, - use_test_data = T - ) %>% fix_data_in_invoice_line_item_communication() - - expect_identical(test_data, dplyr::as_tibble(results)) - DBI::dbDisconnect(mem_conn) -}) diff --git a/tests/testthat/test-redcap_log_event.R b/tests/testthat/test-redcap_log_event.R deleted file mode 100644 index 50642dd5..00000000 --- a/tests/testthat/test-redcap_log_event.R +++ /dev/null @@ -1,27 +0,0 @@ -test_that("redcap_log_event sqlite schemata are created and correct test data is returned", { - table_name <- "redcap_log_event" - test_data <- get0(paste0(table_name, "_test_data")) - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - - for (log_table in names(redcap_log_event_test_data)) { - sqlite_schema <- convert_schema_to_sqlite(table_name = log_table) - create_table( - conn = conn, - schema = sqlite_schema - ) - - result <- DBI::dbAppendTable( - conn = conn, - name = log_table, - value = test_data[[log_table]], - overwrite = TRUE - ) - - results <- DBI::dbGetQuery(conn, paste("select * from", log_table)) %>% - fix_data_in_redcap_log_event() - - testthat::expect_equal(dplyr::as_tibble(results), test_data[[log_table]]) - } - - DBI::dbDisconnect(conn) -}) diff --git a/tests/testthat/test-redcap_rights.R b/tests/testthat/test-redcap_rights.R index 52e9b418..1eb92944 100644 --- a/tests/testthat/test-redcap_rights.R +++ b/tests/testthat/test-redcap_rights.R @@ -1,8 +1,30 @@ testthat::test_that("get_user_rights_and_info_v1 works", { + +redcap_user_information <- readRDS( + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_information.rds" + ) +) + +redcap_user_rights <- readRDS( + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_rights.rds" + ) +) + +redcap_user_roles <- readRDS( + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_roles.rds" + ) +) + result <- get_user_rights_and_info_v1( - redcap_user_rights = redcap_rights_test_data$redcap_user_rights, - redcap_user_roles = redcap_rights_test_data$redcap_user_roles, - redcap_user_information = redcap_rights_test_data$redcap_user_information + redcap_user_rights = redcap_user_rights, + redcap_user_roles = redcap_user_roles, + redcap_user_information = redcap_user_information ) limited_result <- result %>% diff --git a/tests/testthat/test-redcap_user_information.R b/tests/testthat/test-redcap_user_information.R deleted file mode 100644 index 2fc10c57..00000000 --- a/tests/testthat/test-redcap_user_information.R +++ /dev/null @@ -1,20 +0,0 @@ -test_that("redcap_user_information sqlite schema is created and correct test data is returned", { - table_name <- "redcap_user_information" - test_data <- get0(paste0(table_name, "_test_data")) - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - - sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) - create_table( - conn = conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = T - ) %>% - fix_data_in_redcap_user_information() - - DBI::dbDisconnect(conn) - testthat::expect_equal(dplyr::as_tibble(results), test_data) -}) diff --git a/tests/testthat/test-service_instance.R b/tests/testthat/test-service_instance.R deleted file mode 100644 index ef798f3a..00000000 --- a/tests/testthat/test-service_instance.R +++ /dev/null @@ -1,20 +0,0 @@ -test_that("service_type sqlite schema is created and correct test data is returned", { - table_name <- "service_instance" - test_data <- get0(paste0(table_name, "_test_data")) - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - - sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) - create_table( - conn = conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE - ) - results$active <- as.logical(results$active) - - DBI::dbDisconnect(conn) - expect_identical(test_data, dplyr::as_tibble(results)) -}) diff --git a/tests/testthat/test-service_type.R b/tests/testthat/test-service_type.R deleted file mode 100644 index 80ac5885..00000000 --- a/tests/testthat/test-service_type.R +++ /dev/null @@ -1,19 +0,0 @@ -test_that("service_type sqlite schema is created and correct test data is returned", { - table_name <- "service_type" - test_data <- get0(paste0(table_name, "_test_data")) - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - - sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) - create_table( - conn = conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE - ) - - DBI::dbDisconnect(conn) - expect_identical(test_data, dplyr::as_tibble(results)) -}) diff --git a/tests/testthat/test-transform.R b/tests/testthat/test-transform.R index 23dc17c6..2bf06927 100644 --- a/tests/testthat/test-transform.R +++ b/tests/testthat/test-transform.R @@ -1,11 +1,28 @@ test_that("invoice_line_item_df_from invoice_line_item_communications works properly", { + + invoice_line_item_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item", + "invoice_line_item.rds" + )) + + invoice_line_item_communications_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item_communications", + "invoice_line_item_communications.rds" + )) |> + dplyr::mutate(dplyr::across(c( + "je_posting_date", + "date_sent", + "date_received", + "created", + "updated" + ), lubridate::ymd_hms)) + expect_identical( invoice_line_item_test_data, invoice_line_item_df_from(invoice_line_item_communications_test_data) ) }) - test_that("transform_invoice_line_items_for_csbt correctly converts all column names in CTSIT to CSBT format", { initial_colnames <- invoice_line_item_test_data %>% @@ -62,7 +79,7 @@ test_that("draft_communication_record_from_line_item correctly adds requisite co redcapcustodian::set_script_run_time() expect_true( - all( added_columns %in% colnames(communication_records) ) + all(added_columns %in% colnames(communication_records)) ) }) From 711d18115db1bde0e0d4f79aadb2f791df83a2de Mon Sep 17 00:00:00 2001 From: Philip Chase Date: Mon, 29 Sep 2025 15:32:37 -0400 Subject: [PATCH 2/2] Update test-transform.R Initialize invoice_line_item_test_data in each test. --- tests/testthat/test-transform.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/testthat/test-transform.R b/tests/testthat/test-transform.R index 2bf06927..a5656c09 100644 --- a/tests/testthat/test-transform.R +++ b/tests/testthat/test-transform.R @@ -25,6 +25,11 @@ test_that("invoice_line_item_df_from invoice_line_item_communications works prop test_that("transform_invoice_line_items_for_csbt correctly converts all column names in CTSIT to CSBT format", { + invoice_line_item_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item", + "invoice_line_item.rds" + )) + initial_colnames <- invoice_line_item_test_data %>% colnames() %>% sort() @@ -41,6 +46,11 @@ test_that("transform_invoice_line_items_for_csbt correctly converts all column n test_that("transform_invoice_line_items_for_ctsit correctly converts all column names in CSBT to CTSIT format", { + invoice_line_item_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item", + "invoice_line_item.rds" + )) + csbt_test_data <- invoice_line_item_test_data %>% transform_invoice_line_items_for_csbt() @@ -60,6 +70,12 @@ test_that("transform_invoice_line_items_for_ctsit correctly converts all column test_that("draft_communication_record_from_line_item correctly adds requisite columns", { + + invoice_line_item_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item", + "invoice_line_item.rds" + )) + csbt_line_items <- invoice_line_item_test_data %>% transform_invoice_line_items_for_csbt()