diff --git a/tests/testthat/_snaps/01-get_repos-GitHub.md b/tests/testthat/_snaps/01-get_repos-GitHub.md index 42efdf6..043a672 100644 --- a/tests/testthat/_snaps/01-get_repos-GitHub.md +++ b/tests/testthat/_snaps/01-get_repos-GitHub.md @@ -33,7 +33,7 @@ i [Host:GitHub][Engine:REST][Scope:] Pulling repositories... i Preparing repositories table... -# `get_repos_with_code_from_orgs()` pulls minimum version of table +# `get_repos_with_code_from_repos()` pulls minimum version of table Code repos_with_code_from_repos_min <- github_testhost_priv$ @@ -52,6 +52,14 @@ Message i [Host:GitHub][Engine:REST] Pulling repositories... +# get_repos_from_repos works + + Code + gh_repos_individual <- github_testhost_priv$get_repos_from_repos(verbose = TRUE, + progress = FALSE) + Message + i [Host:GitHub][Engine:GraphQl][Scope:test_org] Pulling repositories... + # `get_all_repos()` is set to scan whole git host Code @@ -59,3 +67,12 @@ Message i [Host:GitHub][Engine:GraphQl] Pulling all organizations... +# `get_repos_contributors()` works on GitHost level + + Code + gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors( + repos_table = test_mocker$use("gh_repos_table_with_platform"), verbose = TRUE, + progress = FALSE) + Message + i [Host:GitHub][Engine:REST] Pulling contributors... + diff --git a/tests/testthat/_snaps/01-get_repos-GitLab.md b/tests/testthat/_snaps/01-get_repos-GitLab.md index d84ced0..f13ca20 100644 --- a/tests/testthat/_snaps/01-get_repos-GitLab.md +++ b/tests/testthat/_snaps/01-get_repos-GitLab.md @@ -5,6 +5,22 @@ Output [1] "\n query GetReposByOrg($org: ID! $repo_cursor: String!) {\n group(fullPath: $org) {\n projects(first: 100 after: $repo_cursor) {\n \n count\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n repo_id: id\n repo_name: name\n repo_path: path\n ... on Project {\n repository {\n rootRef\n }\n }\n stars: starCount\n forks: forksCount\n created_at: createdAt\n last_activity_at: lastActivityAt\n languages {\n name\n }\n issues: issueStatusCounts {\n all\n closed\n opened\n }\n namespace {\n path: fullPath\n }\n repo_url: webUrl\n }\n }\n }\n }\n }" +# `search_for_code()` works + + Code + gl_search_repos_by_code <- test_rest_gitlab_priv$search_for_code(code = "test", + filename = "TESTFILE", verbose = TRUE, page_max = 2) + Message + i Searching for code [test]... + +# `search_repos_for_code()` works + + Code + gl_search_repos_by_code <- test_rest_gitlab_priv$search_repos_for_code(code = "test", + repos = "TestRepo", filename = "TESTFILE", verbose = TRUE, page_max = 2) + Message + i Searching for code [test]... + # get_repos_from_org prints proper message Code diff --git a/tests/testthat/_snaps/02-get_commits-GitLab.md b/tests/testthat/_snaps/02-get_commits-GitLab.md new file mode 100644 index 0000000..13418dd --- /dev/null +++ b/tests/testthat/_snaps/02-get_commits-GitLab.md @@ -0,0 +1,16 @@ +# get_commits_from_orgs works + + Code + gl_commits_table <- gitlab_testhost_priv$get_commits_from_orgs(since = "2023-03-01", + until = "2023-04-01", verbose = TRUE, progress = FALSE) + Message + i [Host:GitLab][Engine:REST][Scope:mbtests] Pulling commits... + +# get_commits_from_repos works + + Code + gl_commits_table <- gitlab_testhost_priv$get_commits_from_repos(since = "2023-03-01", + until = "2023-04-01", verbose = TRUE, progress = FALSE) + Message + i [Host:GitLab][Engine:REST][Scope:test_org/TestRepo] Pulling commits... + diff --git a/tests/testthat/_snaps/get_release-GitLab.md b/tests/testthat/_snaps/get_release-GitLab.md index 7c4fb7a..b456d7c 100644 --- a/tests/testthat/_snaps/get_release-GitLab.md +++ b/tests/testthat/_snaps/get_release-GitLab.md @@ -5,3 +5,11 @@ Output [1] "query GetReleasesFromRepo($project_path: ID!) {\n project(fullPath: $project_path) {\n name\n webUrl\n \t\t\t\t\t\treleases {\n nodes{\n name\n tagName\n releasedAt\n links {\n selfUrl\n }\n description\n }\n }\n }\n }" +# `get_release_logs_from_repos()` works + + Code + releases_from_repos <- gitlab_testhost_priv$get_release_logs_from_repos(since = "2023-05-01", + until = "2023-09-30", verbose = TRUE, progress = FALSE) + Message + i [Host:GitLab][Engine:GraphQl][Scope:test_org/TestRepo] Pulling release logs... + diff --git a/tests/testthat/_snaps/get_urls_repos-GitHub.md b/tests/testthat/_snaps/get_urls_repos-GitHub.md index aeb16a3..3436548 100644 --- a/tests/testthat/_snaps/get_urls_repos-GitHub.md +++ b/tests/testthat/_snaps/get_urls_repos-GitHub.md @@ -6,3 +6,16 @@ Message i [Host:GitHub][Engine:REST][Scope:test_org] Pulling repositories (URLs)... +# get_repos_urls_from_repos prepares web repo_urls vector + + Code + gh_repos_urls <- github_testhost_priv$get_repos_urls_from_repos(type = "web", + verbose = TRUE, progress = FALSE) + Message + i [Host:GitHub][Engine:REST][Scope:test_org] Pulling repositories (URLs)... + +# get_all_repos_urls prepares web repo_urls vector + + Code + gh_repos_urls <- github_testhost_priv$get_all_repos_urls(type = "web", verbose = TRUE) + diff --git a/tests/testthat/helper-expect-responses.R b/tests/testthat/helper-expect-responses.R index 32dba11..acffaad 100644 --- a/tests/testthat/helper-expect-responses.R +++ b/tests/testthat/helper-expect-responses.R @@ -96,7 +96,7 @@ expect_gl_commit_rest_response <- function(object) { "list" ) expect_list_contains( - object[[1]], + object, c( "id", "short_id", "created_at", "parent_ids", "title", "message", "author_name", "author_email", "authored_date", "committer_name", diff --git a/tests/testthat/helper-fixtures.R b/tests/testthat/helper-fixtures.R index 8d7e1ee..a464927 100644 --- a/tests/testthat/helper-fixtures.R +++ b/tests/testthat/helper-fixtures.R @@ -311,9 +311,7 @@ gitlab_commit <- list( ) ) -test_fixtures$gitlab_commits_response <- list( - rep(gitlab_commit, 5) -) +test_fixtures$gitlab_commits_response <- rep(list(gitlab_commit), 5) test_fixtures$github_file_response <- list( "data" = list( diff --git a/tests/testthat/test-01-get_repos-GitHub.R b/tests/testthat/test-01-get_repos-GitHub.R index 3036fb2..ee7798f 100644 --- a/tests/testthat/test-01-get_repos-GitHub.R +++ b/tests/testthat/test-01-get_repos-GitHub.R @@ -578,9 +578,11 @@ test_that("get_repos_from_repos works", { ) github_testhost_priv$searching_scope <- c("org", "repo") github_testhost_priv$orgs_repos <- list("test_org" = "TestRepo") - gh_repos_individual <- github_testhost_priv$get_repos_from_repos( - verbose = FALSE, - progress = FALSE + expect_snapshot( + gh_repos_individual <- github_testhost_priv$get_repos_from_repos( + verbose = TRUE, + progress = FALSE + ) ) expect_repos_table( gh_repos_individual @@ -679,7 +681,7 @@ test_that("`get_repos_contributors()` adds contributors to repos table", { ) gh_repos_with_contributors <- test_rest_github$get_repos_contributors( repos_table = test_mocker$use("gh_repos_table_with_platform"), - progress = FALSE + progress = FALSE ) expect_repos_table( gh_repos_with_contributors, @@ -698,10 +700,12 @@ test_that("`get_repos_contributors()` works on GitHost level", { "rest_engine$get_repos_contributors", test_mocker$use("gh_repos_with_contributors") ) - gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors( - repos_table = test_mocker$use("gh_repos_table_with_platform"), - verbose = FALSE, - progress = FALSE + expect_snapshot( + gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors( + repos_table = test_mocker$use("gh_repos_table_with_platform"), + verbose = TRUE, + progress = FALSE + ) ) expect_repos_table( gh_repos_with_contributors, diff --git a/tests/testthat/test-01-get_repos-GitLab.R b/tests/testthat/test-01-get_repos-GitLab.R index f4c4089..695eb38 100644 --- a/tests/testthat/test-01-get_repos-GitLab.R +++ b/tests/testthat/test-01-get_repos-GitLab.R @@ -119,6 +119,39 @@ test_that("`get_repos_from_org()` does not fail when GraphQL response is not com ) }) +test_that("`search_for_code()` works", { + mockery::stub( + test_rest_gitlab_priv$search_for_code, + "self$response", + list() + ) + expect_snapshot( + gl_search_repos_by_code <- test_rest_gitlab_priv$search_for_code( + code = "test", + filename = "TESTFILE", + verbose = TRUE, + page_max = 2 + ) + ) +}) + +test_that("`search_repos_for_code()` works", { + mockery::stub( + test_rest_gitlab_priv$search_repos_for_code, + "self$response", + list() + ) + expect_snapshot( + gl_search_repos_by_code <- test_rest_gitlab_priv$search_repos_for_code( + code = "test", + repos = "TestRepo", + filename = "TESTFILE", + verbose = TRUE, + page_max = 2 + ) + ) +}) + test_that("`map_search_into_repos()` works", { gl_search_response <- test_fixtures$gitlab_search_response test_mocker$cache(gl_search_response) @@ -132,7 +165,7 @@ test_that("`map_search_into_repos()` works", { test_mocker$cache(gl_search_repos_by_code) }) -test_that("`get_repos_languages` works", { +test_that("`get_repos_languages()` works", { repos_list <- test_mocker$use("gl_search_repos_by_code") repos_list[[1]]$id <- "45300912" mockery::stub( @@ -140,12 +173,63 @@ test_that("`get_repos_languages` works", { "self$response", test_fixtures$gitlab_languages_response ) - repos_list_with_languages <- test_rest_gitlab_priv$get_repos_languages( + gl_repos_list_with_languages <- test_rest_gitlab_priv$get_repos_languages( repos_list = repos_list, progress = FALSE ) - purrr::walk(repos_list_with_languages, ~ expect_list_contains(., "languages")) - expect_equal(repos_list_with_languages[[1]]$languages, c("Python", "R")) + purrr::walk(gl_repos_list_with_languages, ~ expect_list_contains(., "languages")) + expect_equal(gl_repos_list_with_languages[[1]]$languages, c("Python", "R")) + test_mocker$cache(gl_repos_list_with_languages) +}) + +test_that("`get_repos_by_code()` works", { + mockery::stub( + test_rest_gitlab$get_repos_by_code, + "private$search_for_code", + test_fixtures$gitlab_search_response + ) + mockery::stub( + test_rest_gitlab$get_repos_by_code, + "private$map_search_into_repos", + test_mocker$use("gl_search_repos_by_code") + ) + mockery::stub( + test_rest_gitlab$get_repos_by_code, + "private$get_repos_languages", + test_mocker$use("gl_repos_list_with_languages") + ) + gl_repos_by_code <- test_rest_gitlab$get_repos_by_code( + code = "test", + org = "test_org" + ) + expect_gl_repos_rest_response( + gl_repos_by_code + ) +}) + +test_that("`get_repos_by_code()` works", { + mockery::stub( + test_rest_gitlab$get_repos_by_code, + "private$search_repos_for_code", + test_fixtures$gitlab_search_response + ) + mockery::stub( + test_rest_gitlab$get_repos_by_code, + "private$map_search_into_repos", + test_mocker$use("gl_search_repos_by_code") + ) + mockery::stub( + test_rest_gitlab$get_repos_by_code, + "private$get_repos_languages", + test_mocker$use("gl_repos_list_with_languages") + ) + gl_repos_by_code <- test_rest_gitlab$get_repos_by_code( + code = "test", + repos = c("TestRepo1", "TestRepo2") + ) + expect_gl_repos_rest_response( + gl_repos_by_code + ) }) test_that("`prepare_repos_table()` prepares repos table", { @@ -186,7 +270,10 @@ test_that("GitHost adds `repo_api_url` column to GitLab repos table", { test_that("`tailor_repos_response()` tailors precisely `repos_list`", { gl_repos_by_code <- test_mocker$use("gl_search_repos_by_code") gl_repos_by_code_tailored <- - test_rest_gitlab$tailor_repos_response(gl_repos_by_code) + test_rest_gitlab$tailor_repos_response( + repos_response = gl_repos_by_code, + output = "table_full" + ) gl_repos_by_code_tailored %>% expect_type("list") %>% expect_length(length(gl_repos_by_code)) @@ -206,6 +293,27 @@ test_that("`tailor_repos_response()` tailors precisely `repos_list`", { test_mocker$cache(gl_repos_by_code_tailored) }) +test_that("`tailor_repos_response()` tailors precisely to minimal `repos_list`", { + gl_repos_by_code <- test_mocker$use("gl_search_repos_by_code") + gl_repos_by_code_tailored <- + test_rest_gitlab$tailor_repos_response( + repos_response = gl_repos_by_code, + output = "table_min" + ) + gl_repos_by_code_tailored %>% + expect_type("list") %>% + expect_length(length(gl_repos_by_code)) + + expect_list_contains_only( + gl_repos_by_code_tailored[[1]], + c("repo_id", "repo_name", "created_at", "default_branch", "organization") + ) + expect_lt( + length(gl_repos_by_code_tailored[[1]]), + length(gl_repos_by_code[[1]]) + ) +}) + test_that("REST client prepares table from GitLab repositories response", { gl_repos_by_code_table <- test_rest_gitlab$prepare_repos_table( repos_list = test_mocker$use("gl_repos_by_code_tailored"), diff --git a/tests/testthat/test-02-get_commits-GitLab.R b/tests/testthat/test-02-get_commits-GitLab.R index e3e45d3..8ee44a3 100644 --- a/tests/testthat/test-02-get_commits-GitLab.R +++ b/tests/testthat/test-02-get_commits-GitLab.R @@ -1,17 +1,34 @@ -test_that("`get_commits_from_repos()` pulls commits from repo", { +test_that("`get_commits_from_one_repo()` pulls commits from repository", { + mockery::stub( + test_rest_gitlab_priv$get_commits_from_one_repo, + "private$paginate_results", + test_fixtures$gitlab_commits_response + ) + gl_commits_repo <- test_rest_gitlab_priv$get_commits_from_one_repo( + repo_path = "TestRepo", + since = "2023-01-01", + until = "2023-04-20" + ) + expect_gt(length(gl_commits_repo), 1) + purrr::walk(gl_commits_repo, ~ expect_gl_commit_rest_response(.)) + test_mocker$cache(gl_commits_repo) +}) + +test_that("`get_commits_from_repos()` pulls commits from repositories", { mockery::stub( test_rest_gitlab$get_commits_from_repos, "private$get_commits_from_one_repo", - test_fixtures$gitlab_commits_response + test_mocker$use("gl_commits_repo") ) - repos_names <- c("mbtests%2Fgitstatstesting", "mbtests%2Fgitstats-testing-2") + repos_names <- c("test_org/TestRepo1", "test_org/TestRepo2") gl_commits_org <- test_rest_gitlab$get_commits_from_repos( repos_names = repos_names, since = "2023-01-01", until = "2023-04-20", progress = FALSE ) - purrr::walk(gl_commits_org, ~ expect_gl_commit_rest_response(.)) + expect_equal(names(gl_commits_org), c("test_org/TestRepo1", "test_org/TestRepo2")) + purrr::walk(gl_commits_org[[1]], ~ expect_gl_commit_rest_response(.)) test_mocker$cache(gl_commits_org) }) @@ -126,11 +143,11 @@ test_that("get_commits_from_orgs works", { "rest_engine$get_commits_authors_handles_and_names", test_mocker$use("gl_commits_table") ) - suppressMessages( + expect_snapshot( gl_commits_table <- gitlab_testhost_priv$get_commits_from_orgs( since = "2023-03-01", until = "2023-04-01", - verbose = FALSE, + verbose = TRUE, progress = FALSE ) ) @@ -139,3 +156,35 @@ test_that("get_commits_from_orgs works", { ) test_mocker$cache(gl_commits_table) }) + +test_that("get_commits_from_repos works", { + gitlab_testhost_priv <- create_gitlab_testhost( + repos = "TestRepo", + mode = "private" + ) + test_org <- "test_org" + attr(test_org, "type") <- "organization" + mockery::stub( + gitlab_testhost_priv$get_repos_from_repos, + "private$set_owner_type", + test_org + ) + mockery::stub( + gitlab_testhost_priv$get_commits_from_repos, + "rest_engine$get_commits_authors_handles_and_names", + test_mocker$use("gl_commits_table") + ) + gitlab_testhost_priv$searching_scope <- "repo" + gitlab_testhost_priv$orgs_repos <- list("test_org" = "TestRepo") + expect_snapshot( + gl_commits_table <- gitlab_testhost_priv$get_commits_from_repos( + since = "2023-03-01", + until = "2023-04-01", + verbose = TRUE, + progress = FALSE + ) + ) + expect_commits_table( + gl_commits_table + ) +}) diff --git a/tests/testthat/test-get_release-GitLab.R b/tests/testthat/test-get_release-GitLab.R index 06e73b5..05d8eb4 100644 --- a/tests/testthat/test-get_release-GitLab.R +++ b/tests/testthat/test-get_release-GitLab.R @@ -80,11 +80,13 @@ test_that("`get_release_logs_from_repos()` works", { ) gitlab_testhost_priv$searching_scope <- "repo" gitlab_testhost_priv$orgs_repos <- list("test_org" = "TestRepo") - releases_from_repos <- gitlab_testhost_priv$get_release_logs_from_repos( - since = "2023-05-01", - until = "2023-09-30", - verbose = FALSE, - progress = FALSE + expect_snapshot( + releases_from_repos <- gitlab_testhost_priv$get_release_logs_from_repos( + since = "2023-05-01", + until = "2023-09-30", + verbose = TRUE, + progress = FALSE + ) ) expect_releases_table(releases_from_repos) test_mocker$cache(releases_from_repos) diff --git a/tests/testthat/test-get_urls_repos-GitHub.R b/tests/testthat/test-get_urls_repos-GitHub.R index 0a9c008..e474b44 100644 --- a/tests/testthat/test-get_urls_repos-GitHub.R +++ b/tests/testthat/test-get_urls_repos-GitHub.R @@ -88,10 +88,12 @@ test_that("get_repos_urls_from_repos prepares web repo_urls vector", { ) github_testhost_priv$searching_scope <- c("repo") github_testhost_priv$orgs_repos <- list("test_org" = "TestRepo") - gh_repos_urls <- github_testhost_priv$get_repos_urls_from_repos( - type = "web", - verbose = FALSE, - progress = FALSE + expect_snapshot( + gh_repos_urls <- github_testhost_priv$get_repos_urls_from_repos( + type = "web", + verbose = TRUE, + progress = FALSE + ) ) expect_gt(length(gh_repos_urls), 0) expect_true(any(grepl("test-org", gh_repos_urls))) @@ -110,9 +112,11 @@ test_that("get_all_repos_urls prepares web repo_urls vector", { "private$get_repos_urls_from_repos", test_mocker$use("gh_repos_urls") ) - gh_repos_urls <- github_testhost_priv$get_all_repos_urls( - type = "web", - verbose = FALSE + expect_snapshot( + gh_repos_urls <- github_testhost_priv$get_all_repos_urls( + type = "web", + verbose = TRUE + ) ) expect_gt(length(gh_repos_urls), 0) expect_true(any(grepl("test-org", gh_repos_urls)))