@@ -7,7 +7,10 @@ test_that("ids_bulk handles custom file paths", {
7
7
skip_if_not_installed(" jsonlite" )
8
8
skip_if_not_installed(" readxl" )
9
9
10
- test_url <- ids_bulk_files()$ file_url [1 ]
10
+ test_url <- paste0(
11
+ " https://datacatalogfiles.worldbank.org/ddh-published/0038015/DR0092201/" ,
12
+ " A_D.xlsx?versionId=2024-12-04T18:30:10.8890786Z"
13
+ )
11
14
temp_path <- tempfile(fileext = " .xlsx" )
12
15
13
16
local_mocked_bindings(
@@ -22,7 +25,10 @@ test_that("ids_bulk handles custom file paths", {
22
25
tibble :: tibble()
23
26
},
24
27
get_response_headers = function (... ) {
25
- list (`content-length` = 1000 )
28
+ list (
29
+ `content-type` = mime :: guess_type(temp_path ),
30
+ `content-length` = 1000
31
+ )
26
32
}
27
33
)
28
34
@@ -40,9 +46,17 @@ test_that("ids_bulk handles custom file paths", {
40
46
})
41
47
42
48
test_that(" ids_bulk fails gracefully with invalid URL" , {
49
+ local_mocked_bindings(
50
+ get_response_headers = function (file_url ) {
51
+ list (
52
+ `content-type` = " text/html; charset=utf-8"
53
+ )
54
+ }
55
+ )
56
+
43
57
expect_error(
44
58
ids_bulk(" https://invalid-url.com/file.xlsx" ),
45
- " cannot open URL|download failed|Could not resolve host|SSL certificate problem " # nolint
59
+ " Request returned an invalid file type. Please check the URL and try again. "
46
60
)
47
61
})
48
62
@@ -63,7 +77,10 @@ test_that("ids_bulk handles message parameter correctly", {
63
77
skip_if_not_installed(" jsonlite" )
64
78
skip_if_not_installed(" readxl" )
65
79
66
- test_url <- ids_bulk_files()$ file_url [1 ]
80
+ test_url <- paste0(
81
+ " https://datacatalogfiles.worldbank.org/ddh-published/0038015/DR0092201/" ,
82
+ " A_D.xlsx?versionId=2024-12-04T18:30:10.8890786Z"
83
+ )
67
84
68
85
mock_data <- tibble :: tibble(
69
86
" Country Code" = " ABC" ,
@@ -123,7 +140,12 @@ test_that("ids_bulk handles timeout parameter correctly", {
123
140
}
124
141
stop(" Unexpected timeout value" , call. = FALSE )
125
142
},
126
- get_response_headers = function (... ) list (" content-length" = " 1000" )
143
+ get_response_headers = function (... ) {
144
+ list (
145
+ `content-type` = mime :: guess_type(" file.xlsx" ),
146
+ `content-length` = " 1000"
147
+ )
148
+ }
127
149
)
128
150
129
151
expect_error(
@@ -138,31 +160,27 @@ test_that("ids_bulk handles warn_size parameter", {
138
160
skip_if_not_installed(" jsonlite" )
139
161
skip_if_not_installed(" readxl" )
140
162
141
- test_url <- ids_bulk_files()$ file_url [1 ]
142
-
143
- local_mocked_bindings(
144
- download_file = function (... ) TRUE
145
- )
146
-
147
- local_mocked_bindings(
148
- validate_file = function (... ) TRUE
163
+ test_url <- paste0(
164
+ " https://datacatalogfiles.worldbank.org/ddh-published/0038015/DR0092201/" ,
165
+ " A_D.xlsx?versionId=2024-12-04T18:30:10.8890786Z"
149
166
)
150
167
151
168
local_mocked_bindings(
169
+ download_file = function (... ) TRUE ,
170
+ validate_file = function (... ) TRUE ,
152
171
check_interactive = function () FALSE
153
172
)
154
173
155
174
expect_warning(
156
175
download_bulk_file(
157
- test_url , tempfile(), 60 , warn_size = TRUE , quiet = TRUE
176
+ test_url , tempfile(fileext = " .xlsx " ), 60 , warn_size = TRUE , quiet = TRUE
158
177
),
159
- " may take several minutes to download" ,
160
- fixed = FALSE
178
+ " may take several minutes to download"
161
179
)
162
180
163
181
expect_no_warning(
164
182
download_bulk_file(
165
- test_url , tempfile(), 60 , warn_size = FALSE , quiet = TRUE
183
+ test_url , tempfile(fileext = " .xlsx " ), 60 , warn_size = FALSE , quiet = TRUE
166
184
)
167
185
)
168
186
})
@@ -186,7 +204,10 @@ test_that("download_bulk_file downloads files correctly", {
186
204
skip_if_offline()
187
205
skip_on_cran()
188
206
189
- test_url <- ids_bulk_files()$ file_url [1 ]
207
+ test_url <- paste0(
208
+ " https://datacatalogfiles.worldbank.org/ddh-published/0038015/DR0092201/" ,
209
+ " A_D.xlsx?versionId=2024-12-04T18:30:10.8890786Z"
210
+ )
190
211
test_path <- tempfile(fileext = " .xlsx" )
191
212
192
213
local_mocked_bindings(
@@ -325,15 +346,26 @@ test_that("warn_size warning is triggered & user prompt is handled correctly", {
325
346
skip_if_not_installed(" jsonlite" )
326
347
skip_if_not_installed(" readxl" )
327
348
349
+ test_url <- paste0(
350
+ " https://datacatalogfiles.worldbank.org/ddh-published/0038015/DR0092201/" ,
351
+ " A_D.xlsx?versionId=2024-12-04T18:30:10.8890786Z"
352
+ )
353
+ temp_file <- tempfile(fileext = " .xlsx" )
354
+
328
355
with_mocked_bindings(
329
- get_response_headers = function (... ) list (`content-length` = 150 * 1024 ^ 2 ),
356
+ get_response_headers = function (... ) {
357
+ list (
358
+ `content-type` = mime :: guess_type(temp_file ),
359
+ `content-length` = 150 * 1024 ^ 2
360
+ )
361
+ },
330
362
check_interactive = function (... ) TRUE ,
331
363
prompt_user = function (... ) " n" ,
332
364
{
333
365
expect_error(
334
366
expect_warning(
335
367
download_bulk_file(
336
- test_url , tempfile( fileext = " .xlsx " ) ,
368
+ test_url , temp_file ,
337
369
timeout = 30 , warn_size = TRUE , quiet = TRUE
338
370
),
339
371
regexp = " may take several minutes to download."
0 commit comments