You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During #317 I noticed 9 functions return a different result between the API and a local SQL query.
Add tests all exported functions to see if API and local queries match
Create custom expectation for comparing api to sql query
find why there is a mismatch, and fix it!
Some of these differences might be fixed, or at least different after merging #328
API - SQL mismatch
mismatches for:
get_cpod_projects
list_animal_project_codes
list_acoustic_project_codes
get_animals
list_receiver_ids
get_tags
get_animal_projects
list_scientific_names
get_acoustic_projects
Maybe this is a good use case for a [custom expectation](https://testthat.r-lib.org/articles/custom-expectation.html).
For example, you could create a expect_call_agnostic(), with one argument: a function call. The helper could grab the function call (and its arguments), run it locally and over API and expect the result to be the same.
It could then be called as part of a regular test-function.R file:
testthat("get_animals() returns same result locally and via API", {
expect_call_agnostic(get_animals(animal_id="5"))
})
_Originallypostedby@peterdesmetinhttps://github.com/inbo/etn/issues/317#issuecomment-2421841943_
The text was updated successfully, but these errors were encountered:
for(function_to_testin getNamespaceExports("etnservice")) {
test_that(paste(
function_to_test,
"returns same result over api as over local db connection"
),
{
skip_if_offline()
skip("not all functions work with no arguments")
api_result<- do.call(function_to_test, list(api=TRUE))
sql_result<- do.call(function_to_test, list(api=FALSE))
expect_identical(api_result, sql_result, label=function_to_test)
})
}
for(function_to_testin getNamespaceExports("etnservice")){
print(function_to_test)
api_result<- do.call(function_to_test, list(api=TRUE))
sql_result<- do.call(function_to_test, list(api=FALSE))
expect_identical(api_result, sql_result, label=function_to_test)
}
test_result<-purrr::map(
getNamespaceExports("etnservice"),
purrr::safely(function(function_to_test){
api_result<- do.call(function_to_test, list(api=TRUE))
sql_result<- do.call(function_to_test, list(api=FALSE))
expect_identical(api_result, sql_result)
}
)) %>% purrr::set_names(getNamespaceExports("etnservice"))
# only keep those with errorstest_result[purrr::map_lgl(test_result, ~!is.null(purrr::pluck(.x,"error")))]
During #317 I noticed 9 functions return a different result between the API and a local SQL query.
Some of these differences might be fixed, or at least different after merging #328
API - SQL mismatch
mismatches for:
For example, you could create a
expect_call_agnostic()
, with one argument: a function call. The helper could grab the function call (and its arguments), run it locally and over API and expect the result to be the same.It could then be called as part of a regular test-function.R file:
The text was updated successfully, but these errors were encountered: