Skip to content

Commit

Permalink
fix(search_games): support new game_id
Browse files Browse the repository at this point in the history
See also ropensci/tarchetypes#94. The `game_id` is now converted to `character` class in `search_games()` as a workaround.

Signed-off-by: Liang Zhang <[email protected]>
  • Loading branch information
psychelzh committed May 22, 2022
1 parent 90f7a86 commit 62b7006
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 28 deletions.
30 changes: 14 additions & 16 deletions R/search_games.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@ search_games <- function(config_where, known_only = TRUE, query_file = NULL) {
if (is.null(query_file)) query_file <- "sql/games.tmpl.sql"
if (!file.exists(query_file)) abort("Query file missing.", "query_file_miss")
games <- pickup(query_file, config_where)
if (bit64::is.integer64(games$game_id)) {
games$game_id <- bit64::as.character.integer64(games$game_id)
}
if (known_only) {
games |>
dplyr::inner_join(data.iquizoo::game_info, by = "game_id") |>
dplyr::mutate(
prep_fun = syms(.data[["prep_fun_name"]]),
dplyr::across(
dplyr::all_of(c("input", "extra")),
parse_exprs
)
join_method <- if (known_only) dplyr::inner_join else dplyr::left_join
games |>
join_method(data.iquizoo::game_info, by = names(games)) |>
dplyr::mutate(
# https://github.com/ropensci/tarchetypes/issues/94
game_id = bit64::as.character.integer64(game_id),
prep_fun = purrr::map(
.data[["prep_fun_name"]],
purrr::possibly(sym, NA)
),
dplyr::across(
dplyr::all_of(c("input", "extra")),
parse_exprs
)
} else {
games |>
dplyr::left_join(data.iquizoo::game_info, by = "game_id")
}
)
}

#' @describeIn search_games Cached version using
Expand Down
54 changes: 45 additions & 9 deletions tests/testthat/_snaps/search_games.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@
{
"type": "list",
"attributes": {
"class": {
"names": {
"type": "character",
"attributes": {},
"value": ["tbl_df", "tbl", "data.frame"]
"value": ["game_id", "game_name", "game_name_en", "game_name_abbr", "prep_fun_name", "input", "extra", "prep_fun"]
},
"row.names": {
"type": "integer",
"attributes": {},
"value": [1, 2]
},
"names": {
"class": {
"type": "character",
"attributes": {},
"value": ["game_id", "game_name", "game_name_en", "game_name_abbr", "prep_fun_name", "input", "extra"]
"value": ["tbl_df", "tbl", "data.frame"]
}
},
"value": [
{
"type": "character",
"attributes": {},
"value": ["225528186135045", "test"]
"value": ["225528186135045", "225528186135046"]
},
{
"type": "character",
Expand All @@ -127,14 +127,50 @@
"value": ["span", null]
},
{
"type": "character",
"type": "list",
"attributes": {},
"value": ["list(name_acc = \"accarrow\")", null]
"value": [
{
"type": "language",
"attributes": {},
"value": ["list(name_acc = \"accarrow\")"]
},
{
"type": "logical",
"attributes": {},
"value": [null]
}
]
},
{
"type": "character",
"type": "list",
"attributes": {},
"value": ["NULL", null]
"value": [
{
"type": "NULL"
},
{
"type": "logical",
"attributes": {},
"value": [null]
}
]
},
{
"type": "list",
"attributes": {},
"value": [
{
"type": "symbol",
"attributes": {},
"value": ["span"]
},
{
"type": "logical",
"attributes": {},
"value": [null]
}
]
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/dummy/test.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
game_id
225528186135045
test
225528186135046
7 changes: 5 additions & 2 deletions tests/testthat/test-search_games.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
test_that("Correctly combine `game_info`", {
mockery::stub(
search_games, "pickup",
function(query_file, ...) tibble::tibble(read.csv(query_file))
function(query_file, ...) {
tibble::tibble(read.csv(query_file)) |>
dplyr::mutate(game_id = bit64::as.integer64(game_id))
}
)
expect_snapshot_value(
search_games(query_file = "dummy/test.sql"),
Expand All @@ -17,7 +20,7 @@ test_that("Support `integer64`", {
mockery::stub(
search_games, "pickup",
function(query_file, ...)
tibble::tibble(game_id = bit64::as.integer64.double(225528186135045))
tibble::tibble(game_id = bit64::as.integer64(225528186135045))
)
expect_snapshot_value(
search_games(query_file = "dummy/test.sql"),
Expand Down

0 comments on commit 62b7006

Please sign in to comment.