Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparing comprehensive unit and integration tests #51

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8462a13
Moved to version 2.1.0; Prepared testing for getStudyData
reiniervlinschoten Jun 23, 2024
494efe5
Testing of getStudyData runs
reiniervlinschoten Jun 23, 2024
a4b2bea
Changed testing folder structure; added tests for parametrised getStu…
reiniervlinschoten Jun 23, 2024
c375fb3
Added getStudyData tests for not translating checkbox values
reiniervlinschoten Jun 23, 2024
a3c1adf
Added tests for getParticipants
reiniervlinschoten Jun 23, 2024
15615a9
Merge branch 'field_info' into prepare_testing
reiniervlinschoten Jun 30, 2024
51cf996
Added field tests
reiniervlinschoten Jun 30, 2024
e1d17b1
Switched to 1 study for all tests
reiniervlinschoten Jun 30, 2024
7df1e0a
Switched to 1 study for all tests
reiniervlinschoten Jun 30, 2024
7568ce0
Added tests for getStudyDataBulk
reiniervlinschoten Jun 30, 2024
ab276f4
Small bugfixes so getStudyDataBulk and getFields tests run
reiniervlinschoten Jun 30, 2024
42a2f5c
Add getStudyDataPoints tests
reiniervlinschoten Jun 30, 2024
10fe551
Naming convention of test files
reiniervlinschoten Jun 30, 2024
81712ca
Moved to version 2.1.0; Prepared testing for getStudyData
reiniervlinschoten Jun 23, 2024
91112f7
Testing of getStudyData runs
reiniervlinschoten Jun 23, 2024
7ff04ad
Changed testing folder structure; added tests for parametrised getStu…
reiniervlinschoten Jun 23, 2024
3acd48e
Added getStudyData tests for not translating checkbox values
reiniervlinschoten Jun 23, 2024
eae31e1
Added tests for getParticipants
reiniervlinschoten Jun 23, 2024
248d6db
Added field tests
reiniervlinschoten Jun 30, 2024
8345a2b
Switched to 1 study for all tests
reiniervlinschoten Jun 30, 2024
8a122f1
Switched to 1 study for all tests
reiniervlinschoten Jun 30, 2024
3aedf8d
Added tests for getStudyDataBulk
reiniervlinschoten Jun 30, 2024
ecfd48a
Small bugfixes so getStudyDataBulk and getFields tests run
reiniervlinschoten Jun 30, 2024
a329be9
Add getStudyDataPoints tests
reiniervlinschoten Jun 30, 2024
53bb7b2
Naming convention of test files
reiniervlinschoten Jun 30, 2024
e3f7f62
Merge branch 'prepare_testing' of https://github.com/castoredc/castoR…
reiniervlinschoten Jul 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: castoRedc
Title: Wraps Castor API for easy data access
Version: 2.0.1
Version: 2.1.0
Authors@R: c(
person("Thomas", "Johnson", role = "aut"),
person("Reinier", "van Linschoten",
Expand All @@ -26,10 +26,11 @@ Imports:
glue
Suggests:
knitr,
testthat
testthat (>= 3.0.0)
RoxygenNote: 7.3.0
Collate:
'imports.R'
'utils.R'
'CastorData.R'
'CastorAPIWrapper.R'
Config/testthat/edition: 3
4 changes: 2 additions & 2 deletions create_testing_credentials.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
creds = list(
client_id = "",
client_secret = "",
example_study = "",
output_study = "",
base_url = "https://data.castoredc.com",
example_field = "",
example_visit = "",
Expand All @@ -14,7 +14,7 @@ creds = list(
)

castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url)
entire_study <- castor_api$getStudyData(creds$example_study)
entire_study <- castor_api$getStudyData(creds$output_study)
study_hash <- digest::digest(entire_study)

creds$study_hash <- study_hash
Expand Down
1 change: 1 addition & 0 deletions tests/test_files/files_output/.~lock.CastorStudy.csv#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,reinier,Reinier-PC,30.06.2024 12:37,file:///home/reinier/.config/libreoffice/4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
participant_id,institute,created_on,custom_name,parent,archived,AE_type,AE_startdate,AE_stopdate,AE_severity,AE_relation,AE_action,AE_outcome,AE_expected,AE_SAE
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:58:13,Adverse event - 22-06-2021 09:58:12,No parent,FALSE,,,,,,,,,
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:55:13,Adverse event - 22-06-2021 09:55:12,Follow-up Visit,FALSE,A bug in the API,23-06-2021,24-06-2021,4,4,2,1,1,1
3 changes: 3 additions & 0 deletions tests/test_files/files_output/CastorAdverseEvent.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
participant_id,institute,created_on,custom_name,parent,archived,AE_type,AE_startdate,AE_stopdate,AE_severity,AE_relation,AE_action,AE_outcome,AE_expected,AE_SAE
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:58:13,Adverse event - 22-06-2021 09:58:12,No parent,FALSE,,,,,,,,,
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:55:13,Adverse event - 22-06-2021 09:55:12,Follow-up Visit,FALSE,A bug in the API,23-06-2021,24-06-2021,Life-threatening,Definitely related,Medical intervention,Resolved,Yes,Yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
participant_id,institute,created_on,custom_name,parent,archived,comorbidities
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:56:07,Comorbidities - 22-06-2021 09:56:06,No parent,FALSE,-- Uploaded File: comorbidities.txt --
2 changes: 2 additions & 0 deletions tests/test_files/files_output/CastorComorbidities.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
participant_id,institute,created_on,custom_name,parent,archived,comorbidities
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:56:07,Comorbidities - 22-06-2021 09:56:06,No parent,FALSE,-- Uploaded File: comorbidities.txt --
3 changes: 3 additions & 0 deletions tests/test_files/files_output/CastorMedication (noLabel).csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
participant_id,institute,created_on,custom_name,parent,archived,med_name,med_start,med_stop,med_dose,med_units,med_other_unit
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:54:28,Medication - 22-06-2021 09:54:28,Unscheduled visits and Medication,FALSE,Diclofenac,25-06-2021,28-06-2021,150,2,
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:58:27,Medication - 22-06-2021 09:58:26,No parent,FALSE,,,,,,
3 changes: 3 additions & 0 deletions tests/test_files/files_output/CastorMedication.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
participant_id,institute,created_on,custom_name,parent,archived,med_name,med_start,med_stop,med_dose,med_units,med_other_unit
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:54:28,Medication - 22-06-2021 09:54:28,Unscheduled visits and Medication,FALSE,Diclofenac,25-06-2021,28-06-2021,150,mg/day,
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:58:27,Medication - 22-06-2021 09:58:26,No parent,FALSE,,,,,,
3 changes: 3 additions & 0 deletions tests/test_files/files_output/CastorQOLSurvey (noLabel).csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
participant_id,institute,survey_name,survey_instance_id,created_on,sent_on,progress,completed_on,package_id,package_name,archived,SF12_1,SF12_2,SF12_3,SF12_12,VAS
110001,Franciscus Gasthuis & Vlietland,QOL Survey,4FF130AD-274C-4C8F-A4A0-A7816A5A88E9,22-06-2021 10:12:19,22-06-2021 10:12:19,100,22-06-2021 10:12:44,0761A9BA-9802-483D-8EB3-D07233A56F2B,My first survey package,FALSE,5,2,2,5,85
110001,Franciscus Gasthuis & Vlietland,QOL Survey,B99F0082-1B20-456B-8D4D-47D16867B211,22-06-2021 10:13:01,22-06-2021 10:13:01,0,,5B3FE56F-89FA-4C6D-A638-E8FA46113EB0,My first survey package,FALSE,,,,,
3 changes: 3 additions & 0 deletions tests/test_files/files_output/CastorQOLSurvey.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
participant_id,institute,survey_name,survey_instance_id,created_on,sent_on,progress,completed_on,package_id,package_name,archived,SF12_1,SF12_2,SF12_3,SF12_12,VAS
110001,Franciscus Gasthuis & Vlietland,QOL Survey,4FF130AD-274C-4C8F-A4A0-A7816A5A88E9,22-06-2021 10:12:19,22-06-2021 10:12:19,100,22-06-2021 10:12:44,0761A9BA-9802-483D-8EB3-D07233A56F2B,My first survey package,FALSE,Excellent,Mostly,Mostly,Rarely,85
110001,Franciscus Gasthuis & Vlietland,QOL Survey,B99F0082-1B20-456B-8D4D-47D16867B211,22-06-2021 10:13:01,22-06-2021 10:13:01,0,,5B3FE56F-89FA-4C6D-A638-E8FA46113EB0,My first survey package,FALSE,,,,,
3 changes: 3 additions & 0 deletions tests/test_files/files_output/CastorStudy (noLabel).csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
participant_id,archived,institute,randomisation_group,randomisation_datetime,ic_date,ic_versions#Main study CF,ic_versions#Other,ic_main_version,ic_other_version,ic_language#English,ic_language#Dutch,ic_language#French,ic_language#Other,inc_ic,inc_trials,inc_age,inc_dx,inc_criteria,pat_birth_year,pat_sex,pat_race,pat_height,his_cvd,his_diabetes,his_smoke,his_smoke_start,his_smoke_dose,his_family#None,his_family#Unknown,his_family#Deafness,his_family#(Cardio)myopathy,his_family#Encephalopathy,his_family#Diabetes Mellitus,his_family#Hypertension/Cardiovascular disease,his_family#Thrombosis,his_family#Malignancy,randalloc,randdisp,disp_datetime,base_date,onset_stroke,onset_trombectomy,base_weight,base_bmi,base_sbp,base_dbp,base_hr,base_bl_date,base_hb,base_ht,base_leucoc,base_tromboc,base_urea,base_creat,base_CRP,fac_V_leiden_number,fac_V_leiden_date,base_gluc,fu_date,fu_weight,fu_bmi,fu_sbp,fu_dbp,fu_hr,fu_bl_date,fu_hb,fu_ht,fu_leucoc,fu_tromboc,fu_urea,fu_creat,fu_CRP,fu_gluc,unscheduled,conc_med
110001,FALSE,Franciscus Gasthuis & Vlietland,,,22-06-2021,TRUE,FALSE,2.5,,FALSE,FALSE,TRUE,FALSE,1,0,1,0,Yes,1996,0,2,1.75,1,0,0,,,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,22-06-2021,21-06-2021 01:15,01:30,88,28.7,120,65,66,22-06-2021,7.4,0.23,4.1,252,4.6,88,2.1,55,22-06-2021,5.4,29-06-2021,66,21.6,132,72,69,29-06-2021,8.1,0.36,9.5,366,8.2,99,4.4,3.1,1,1
110002,FALSE,Franciscus Gasthuis & Vlietland,,,,FALSE,FALSE,,,-99,-99,-99,-99,,,,,,,,,-95,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,31-12-2999,,,,,,,,,,,,,,,,-96,01-01-2996,,,,,,,,,,,,,,,,,,
3 changes: 3 additions & 0 deletions tests/test_files/files_output/CastorStudy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
participant_id,archived,institute,randomisation_group,randomisation_datetime,ic_date,ic_versions#Main study CF,ic_versions#Other,ic_main_version,ic_other_version,ic_language#English,ic_language#Dutch,ic_language#French,ic_language#Other,inc_ic,inc_trials,inc_age,inc_dx,inc_criteria,pat_birth_year,pat_sex,pat_race,pat_height,his_cvd,his_diabetes,his_smoke,his_smoke_start,his_smoke_dose,his_family#None,his_family#Unknown,his_family#Deafness,his_family#(Cardio)myopathy,his_family#Encephalopathy,his_family#Diabetes Mellitus,his_family#Hypertension/Cardiovascular disease,his_family#Thrombosis,his_family#Malignancy,randalloc,randdisp,disp_datetime,base_date,onset_stroke,onset_trombectomy,base_weight,base_bmi,base_sbp,base_dbp,base_hr,base_bl_date,base_hb,base_ht,base_leucoc,base_tromboc,base_urea,base_creat,base_CRP,fac_V_leiden_number,fac_V_leiden_date,base_gluc,fu_date,fu_weight,fu_bmi,fu_sbp,fu_dbp,fu_hr,fu_bl_date,fu_hb,fu_ht,fu_leucoc,fu_tromboc,fu_urea,fu_creat,fu_CRP,fu_gluc,unscheduled,conc_med
110001,FALSE,Franciscus Gasthuis & Vlietland,,,22-06-2021,TRUE,FALSE,2.5,,FALSE,FALSE,TRUE,FALSE,Yes,No,Yes,No,Yes,1996,Female,African/black,1.75,Yes,No,No,,,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,22-06-2021,21-06-2021 01:15,01:30,88,28.7,120,65,66,22-06-2021,7.4,0.23,4.1,252,4.6,88,2.1,55,22-06-2021,5.4,29-06-2021,66,21.6,132,72,69,29-06-2021,8.1,0.36,9.5,366,8.2,99,4.4,3.1,Yes,Yes
110002,FALSE,Franciscus Gasthuis & Vlietland,,,,FALSE,FALSE,,,-99,-99,-99,-99,,,,,,,,,-95,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,31-12-2999,,,,,,,,,,,,,,,,-96,01-01-2996,,,,,,,,,,,,,,,,,,
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
participant_id,institute,created_on,custom_name,parent,archived,unsvis_type,unsvis_date,unsvis_weight,unsvis_sbp,unsvis_dbp,unsvis_hr,unslab_date,unslab_s_hb,unslab_ht,unslab_leucoc,unslab_tromboc,unslab_urea,unslab_creat,unslab_CRP,unslab_gluc
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:57:38,Unscheduled visit - 22-06-2021 09:57:36,Unscheduled visits and Medication,FALSE,3,24-06-2021,98.3,233,156,112,,,,,,,,,
2 changes: 2 additions & 0 deletions tests/test_files/files_output/CastorUnscheduledVisit.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
participant_id,institute,created_on,custom_name,parent,archived,unsvis_type,unsvis_date,unsvis_weight,unsvis_sbp,unsvis_dbp,unsvis_hr,unslab_date,unslab_s_hb,unslab_ht,unslab_leucoc,unslab_tromboc,unslab_urea,unslab_creat,unslab_CRP,unslab_gluc
110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:57:38,Unscheduled visit - 22-06-2021 09:57:36,Unscheduled visits and Medication,FALSE,admission to day-care,24-06-2021,98.3,233,156,112,,,,,,,,,
57 changes: 39 additions & 18 deletions tests/testthat/test_fields.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
context("Test Field related methods.")

creds <- readRDS("testing_credentials.Rds")
castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url)

test_that("getField returns an appropriate object.", {
field <- castor_api$getField(creds$example_study, creds$example_field)
field <- castor_api$getField(creds$output_study, creds$example_field)

expect_is(field, "list")
expect_type(field, "list")
expect_equal(field$field_id, creds$example_field)
expect_gt(length(field), 0)
})

test_that("getField fails appropriately", {
error <- expect_error(castor_api$getField(creds$output_study, creds$fail_field))
expect_match(error$message, "Error code: 404")
})


test_that("getFieldsPages returns an appropriate object.", {
fields <- castor_api$getFieldsPages(creds$example_study)
one_field <- castor_api$getFieldsPages(creds$example_study, page = 1)

expect_is(fields, "list")
expect_is(one_field, "list")
expect_true(length(one_field) == 1)
expect_error(castor_api$getFieldsPages(creds$example_study, page = -1))
expect_error(castor_api$getFieldsPages(creds$example_study, page = 100000000))
expect_error(castor_api$getFieldsPages(creds$example_study, page = pi))
fields <- castor_api$getFieldsPages(creds$output_study)
expect_type(fields, "list")
})

test_that("getFieldPages returns an appropriate object when retrieving a single page.", {
one_page <- castor_api$getFieldsPages(creds$output_study, page = 1)
expect_type(one_page, "list")
expect_true(length(one_page) == 1)
})

test_that("getFieldPages fails appropriately", {
error1 <- expect_error(castor_api$getFieldsPages(creds$output_study, page = -1))
expect_match(error1$message, "Error code: 400")

error2 <- expect_error(castor_api$getFieldsPages(creds$output_study, page = 100000000))
expect_match(error2$message, "Error code: 409")

error3 <- expect_error(castor_api$getFieldsPages(creds$output_study, page = pi))
expect_match(error3$message, "page must be an integer")
})



test_that("getFields returns an appropriate object.", {
field_data <- castor_api$getFields(creds$example_study)
field_data <- castor_api$getFields(creds$output_study)

expect_is(field_data, "data.frame")
expect_gt(nrow(field_data), 0)
expect_gt(ncol(field_data), 0)
expect_error(castor_api$getFields("this is not a study id"))
expect_s3_class(field_data, "data.frame")
expect_equal(nrow(field_data), 115)
expect_equal(ncol(field_data), 37)
})

test_that("getFields fails appropriately", {
error <- expect_error(castor_api$getFields("THISISNOTASTUDYID"))
expect_match(error$message, "Error code: 404")
})

15 changes: 8 additions & 7 deletions tests/testthat/test_forms.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
# TODO: Needs updates to tests
context("Test Form related methods.")

creds <- readRDS("testing_credentials.Rds")
castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url)

test_that("getForm returns an appropriate object.", {
form <- castor_api$getForm(creds$example_study, creds$example_form)
form <- castor_api$getForm(creds$output_study, creds$example_form)

expect_is(form, "list")
expect_equal(form$form_id, creds$example_form)
expect_gt(length(form), 0)
})

test_that("getFormsPages returns an appropriate object.", {
forms <- castor_api$getFormsPages(creds$example_study)
one_form <- castor_api$getFormsPages(creds$example_study, page = 1)
forms <- castor_api$getFormsPages(creds$output_study)
one_form <- castor_api$getFormsPages(creds$output_study, page = 1)

expect_is(forms, "list")
expect_is(one_form, "list")
expect_true(length(one_form) == 1)
expect_error(castor_api$getFormsPages(creds$example_study, page = -1))
expect_error(castor_api$getFormsPages(creds$example_study, page = 100000000))
expect_error(castor_api$getFormsPages(creds$example_study, page = pi))
expect_error(castor_api$getFormsPages(creds$output_study, page = -1))
expect_error(castor_api$getFormsPages(creds$output_study, page = 100000000))
expect_error(castor_api$getFormsPages(creds$output_study, page = pi))
})

test_that("getForms returns an appropriate object.", {
form_data <- castor_api$getForms(creds$example_study)
form_data <- castor_api$getForms(creds$output_study)

expect_is(form_data, "data.frame")
expect_gt(nrow(form_data), 0)
Expand Down
10 changes: 0 additions & 10 deletions tests/testthat/test_getStudyData.R

This file was deleted.

39 changes: 39 additions & 0 deletions tests/testthat/test_getStudyData/test_getStudyData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
creds <- readRDS("../testing_credentials.Rds")
castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url)
complete_study_output <- castor_api$getStudyData(creds$output_study)

test_that("getStudyData returns the expected study data.", {
actual <- complete_study_output$Study
expected <- read.csv("../../test_files/files_output/CastorStudy.csv", check.names=F)
expect_identical(actual, expected)
})

test_that("getStudyData returns the expected data for the repeated measure Unscheduled Visit", {
actual <- complete_study_output$`Repeating data`$`Unscheduled visit`
expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F)
expect_identical(actual, expected)
})

test_that("getStudyData returns the expected data for the repeated measure Medication", {
actual <- complete_study_output$`Repeating data`$Medication
expected <- read.csv("../../test_files/files_output/CastorMedication.csv", check.names=F)
expect_identical(actual, expected)
})

test_that("getStudyData returns the expected data for the repeated measure Comorbidities", {
actual <- complete_study_output$`Repeating data`$Comorbidities
expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F)
expect_identical(actual, expected)
})

test_that("getStudyData returns the expected data for the repeated measure Adverse Events", {
actual <- complete_study_output$`Repeating data`$`Adverse event`
expected <- read.csv("../../test_files/files_output/CastorAdverseEvent.csv", check.names=F)
expect_identical(actual, expected)
})

test_that("getStudyData returns the expected data for the survey Quality of Life", {
actual <- complete_study_output$Surveys$`QOL Survey`
expected <- read.csv("../../test_files/files_output/CastorQOLSurvey.csv", check.names=F)
expect_identical(actual, expected)
})
Loading