Skip to content

Commit

Permalink
Mock github search response, rename some test files.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekbanas committed Sep 27, 2024
1 parent 292053e commit 22278eb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 5 deletions.
49 changes: 49 additions & 0 deletions tests/testthat/helper-fixtures.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,52 @@ test_fixtures$gitlab_search_response <- list(
"project_id" = 43400864
)
)

test_fixtures$github_search_response <- list(
"total_count" = 3,
"incomplete_results" = FALSE,
"items" = list(
list(
"name" = "test1.R",
"path" = "examples/test1.R",
"sha" = "0d42b9d23ddfc0bca1",
"url" = "test_url",
"git_url" = "test_git_url",
"html_url" = "test_html_url",
"repository" = list(
"id" = 627452680,
"url" = "https://api.github.com/repos/r-world-devs/GitStats",
"html" = "https://github.com/r-world-devs/GitStats"
),
"score" = 1
),
list(
"name" = "test2.R",
"path" = "tests/test2.R",
"sha" = "01238xb",
"url" = "test_url",
"git_url" = "test_git_url",
"html_url" = "test_html_url",
"repository" = list(
"id" = 604718884,
"url" = "https://api.github.com/repos/r-world-devs/GitStats",
"html" = "https://github.com/r-world-devs/GitStats"
),
"score" = 1
),
list(
"name" = "test3.R",
"path" = "R/test3.R",
"sha" = "20e19af2dda26d04f6",
"url" = "test_url",
"git_url" = "test_git_url",
"html_url" = "test_html_url",
"repository" = list(
"id" = 495151911,
"url" = "https://api.github.com/repos/r-world-devs/GitStats",
"html" = "https://github.com/r-world-devs/GitStats"
),
"score" = 1
)
)
)
2 changes: 1 addition & 1 deletion tests/testthat/test-get_files_content-GitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test_that("`get_files_content()` pulls files in the table format", {
test_mocker$use("gh_files_table")
)
gh_files_table <- github_testhost$get_files_content(
file_path = "LICENSE"
file_path = "DESCRIPTION"
)
expect_files_table(gh_files_table, with_cols = "api_url")
test_mocker$cache(gh_files_table)
Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/test-get_repos-GitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ test_that("`get_repos_from_org()` prepares formatted list", {
# REST Engine search repos by code

test_that("`response()` returns search response from GitHub's REST API", {
search_endpoint <- "https://api.github.com/search/code?q=shiny+user:openpharma"
test_mocker$cache(search_endpoint)
gh_search_response_raw <- test_rest_github$response(search_endpoint)
# search_endpoint <- "https://api.github.com/search/code?q=shiny+user:r-world-devs"
# test_mocker$cache(search_endpoint)
# gh_search_response_raw <- test_rest_github$response(search_endpoint)
gh_search_response_raw <- test_fixtures$github_search_response
expect_gh_search_response(gh_search_response_raw[["items"]])
test_mocker$cache(gh_search_response_raw)
})
Expand All @@ -74,7 +75,7 @@ test_that("`search_response()` performs search with limit under 100", {
total_n <- test_mocker$use("gh_search_response_raw")[["total_count"]]
mockery::stub(
test_rest_github_priv$search_response,
"private$rest_response",
"self$response",
test_mocker$use("gh_search_response_raw")
)
gh_search_repos_response <- test_rest_github_priv$search_response(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 22278eb

Please sign in to comment.