Skip to content

Commit b71df3c

Browse files
committed
Fix test errors (closes #43)
Errors arose after upgrading to latest version of httr
1 parent b33d748 commit b71df3c

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

tests/testthat/setup.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
library(httptest2)
2+
library(httr2)
23
library(withr)
34

45
withr::local_envvar(

tests/testthat/test-objr.R

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ test_that("Success if valid token exists", {
5151
class = c("POSIXct", "POSIXt"))
5252
)
5353

54-
expect_s3_class(objr_auth(req), "httr2_request")
55-
# expect_equal(objr_auth(req)$headers$Authorization, "test")
54+
x <- objr_auth(req)
55+
expect_s3_class(x, "httr2_request")
56+
expect_equal(req_get_headers(x, redacted = "reveal")$Authorization, "test")
5657

5758
rm(token, pos = .GlobalEnv)
5859

@@ -68,38 +69,49 @@ test_that("Uses usr/pwd if token exists but is expired", {
6869

6970
req_auth <- suppressMessages(objr_auth(req))
7071

71-
# expect_true(
72-
# grepl("^Basic", req_auth$headers$Authorization)
73-
# )
72+
expect_true(
73+
grepl("^Basic",
74+
req_get_headers(req_auth, redacted = "reveal")$Authorization)
75+
)
7476

7577
expect_false(
7678
exists("token", where = .GlobalEnv)
7779
)
7880

7981
})
8082

81-
# test_that("Correct authentication used", {
82-
#
83-
# expect_true(grepl("^Basic ", objr_auth(req)$headers$Authorization))
84-
#
85-
# .GlobalEnv$token <- "test" # nolint: object_name_linter
86-
#
87-
# exp_token1 <- objr_auth(req)
88-
# expect_equal(exp_token1$headers$Authorization, "test")
89-
#
90-
# # Token used even when no username and password supplied
91-
# with_envvar(
92-
# new = c("OBJR_USR" = "",
93-
# "OBJR_PWD" = ""),
94-
# code = {
95-
# exp_token2 <- objr_auth(req)
96-
# expect_equal(exp_token2$headers$Authorization, "test")
97-
# }
98-
# )
99-
#
100-
# rm(token, pos = .GlobalEnv)
101-
#
102-
# })
83+
test_that("Correct authentication used", {
84+
85+
req1 <- objr_auth(req)
86+
expect_true(grepl("^Basic ",
87+
req_get_headers(req1, redacted = "reveal")$Authorization))
88+
89+
.GlobalEnv$token <- list( # nolint: object_name_linter
90+
value = "test",
91+
expiry = structure(Sys.time() + 60,
92+
class = c("POSIXct", "POSIXt"))
93+
)
94+
95+
exp_token1 <- objr_auth(req)
96+
expect_equal(req_get_headers(exp_token1, redacted = "reveal")$Authorization,
97+
"test")
98+
99+
# Token used even when no username and password supplied
100+
with_envvar(
101+
new = c("OBJR_USR" = "",
102+
"OBJR_PWD" = ""),
103+
code = {
104+
exp_token2 <- objr_auth(req)
105+
expect_equal(
106+
req_get_headers(exp_token2, redacted = "reveal")$Authorization,
107+
"test"
108+
)
109+
}
110+
)
111+
112+
rm(token, pos = .GlobalEnv)
113+
114+
})
103115

104116

105117
# store_token ----
@@ -150,11 +162,11 @@ test_that("Expect character value returned", {
150162
"character"
151163
)
152164

153-
# expect_type(
154-
# error(httr2::response(status_code = 403,
155-
# body = list(description = "x"))),
156-
# "character"
157-
# )
165+
expect_type(
166+
error(httr2::response_json(status_code = 403,
167+
body = list(description = "x"))),
168+
"character"
169+
)
158170

159171
expect_type(
160172
error(httr2::response_json(

0 commit comments

Comments
 (0)