Skip to content

Commit

Permalink
tests and upstream integration
Browse files Browse the repository at this point in the history
  • Loading branch information
lwalejko committed Feb 26, 2024
1 parent d8cc29d commit 2f52bf3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
10 changes: 3 additions & 7 deletions R/api_get_randomization_list.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
api_get_rand_list <- function(study_id, req, res) {
audit_log_event_type("get_rand_list", req)
db_connection_pool <- get("db_connection_pool")

study_id <- req$args$study_id

is_study <-
checkmate::test_true(
dplyr::tbl(db_connection_pool, "study") |>
dplyr::filter(id == study_id) |>
dplyr::collect() |>
nrow() > 0
)
is_study <- check_study_exist(study_id = study_id)

if (!is_study) {
res$status <- 404
return(list(
error = "Study not found"
))
}
audit_log_study_id(study_id, req)

patients <-
dplyr::tbl(db_connection_pool, "patient") |>
Expand Down
10 changes: 6 additions & 4 deletions R/audit-trail.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ AuditLog <- R6::R6Class( # nolint: object_name_linter.
private$request_body <- request_body
},
set_response_body = function(response_body) {
if (typeof(response_body) == "list") {
response_body <- jsonlite::toJSON(response_body, auto_unbox = TRUE) |> as.character()
}
checkmate::assert_false(
typeof(response_body) == "list"
)
private$response_body <- response_body
},
set_event_type = function(event_type) {
Expand Down Expand Up @@ -149,7 +149,9 @@ setup_audit_trail <- function(pr, endpoints = list()) {
audit_log$set_request_body(req$body)
audit_log$set_response_body(res$body)

if (audit_log$validate_log()) {
log_valid <- audit_log$validate_log()

if (log_valid) {
audit_log$persist()
}
})
Expand Down
2 changes: 1 addition & 1 deletion inst/plumber/unbiased_api/study.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ unbiased:::wrap_endpoint(function(study_id, req, res) {
#* @serializer unboxedJSON
#*

sentryR::with_captured_calls(function(study_id, req, res) {
unbiased:::wrap_endpoint(function(study_id, req, res) {
return(
unbiased:::api_get_rand_list(study_id, req, res)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-E2E-study-minimisation-pocock.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("correct request with the structure of the returned result", {
source("./test-helpers.R")
source("./audit-log-test-helpers.R")
with_db_fixtures("fixtures/example_study.yml")
with_db_fixtures("fixtures/example_db.yml")
assert_audit_trail_for_test(c(
"study_create",
"randomize_patient"
Expand Down

0 comments on commit 2f52bf3

Please sign in to comment.