Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Sep 25, 2024
1 parent 8155494 commit e94f3e0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion R/remotebmi/tests/testthat/test-route.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Poor mans mock
bmi_initialize_called_with <<- ""
bmi_get_var_units_called_with <<- ""
# Mock model object
mock_model <- list(
bmi_initialize = function(config_file) {
bmi_initialize_called_with <<- config_file
},
getComponentName = function() "Mock Component",
getOutputVarNames = function() c("var1", "var2")
getOutputVarNames = function() c("var1", "var2"),
getVarUnits = function(name) {
bmi_get_var_units_called_with <<- name
return("unit1")
}
)

route <- create_route(mock_model)
Expand Down Expand Up @@ -42,3 +47,13 @@ test_that("/initialize", {
expect_equal(res$status, 201)
expect_equal(bmi_initialize_called_with, "some_config")
})

test_that("/get_var_units", {
fake_rook <- fiery::fake_request("/get_var_units/Q")
req <- reqres::Request$new(fake_rook)
res <- req$respond()
route$dispatch(req)
expect_equal(res$status, 200)
expect_equal(res$body, formatter(list(units = "unit1")))
expect_equal(bmi_get_var_units_called_with, "Q")
})

0 comments on commit e94f3e0

Please sign in to comment.