diff --git a/tests/fixtures/ebirdgeo.yml b/tests/fixtures/ebirdgeo.yml new file mode 100644 index 0000000..0d12130 --- /dev/null +++ b/tests/fixtures/ebirdgeo.yml @@ -0,0 +1,83 @@ +http_interactions: +- request: + method: get + uri: https://ebird.org/ws2.0/data/obs/geo/recent/amegfi?speciesCode=amegfi&lat=42.45&lng=-76.5&dist=50&maxResults=2 + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + X-eBirdApiToken: <<>> + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + cache-control: no-cache, no-store, max-age=0, must-revalidate + content-encoding: gzip + content-length: '322' + content-type: application/json;charset=utf-8 + date: Sat, 09 Mar 2024 06:43:48 GMT + expires: '0' + pragma: no-cache + server: Apache + strict-transport-security: max-age=31536000 ; includeSubDomains + vary: + - Accept-Encoding + - Accept-Encoding,Origin,Access-Control-Request-Method,Access-Control-Request-Headers + x-content-type-options: nosniff + x-frame-options: DENY + x-xss-protection: 1; mode=block + body: + encoding: '' + file: no + string: '[{"speciesCode":"amegfi","comName":"American Goldfinch","sciName":"Spinus + tristis","locId":"L12963789","locName":"380 Snyder Hill Road Yard","obsDt":"2024-03-08 + 16:01","howMany":1,"lat":42.422177,"lng":-76.438978,"obsValid":true,"obsReviewed":false,"locationPrivate":true,"subId":"S164133162"},{"speciesCode":"amegfi","comName":"American + Goldfinch","sciName":"Spinus tristis","locId":"L22710256","locName":"Fall + Creek-West Campus loop","obsDt":"2024-03-08 15:31","howMany":7,"lat":42.446819,"lng":-76.495329,"obsValid":true,"obsReviewed":false,"locationPrivate":true,"subId":"S164139574"}]' + recorded_at: 2024-03-09 06:47:26 GMT + recorded_with: vcr/1.2.2, webmockr/0.9.0 +- request: + method: get + uri: https://ebird.org/ws2.0/data/obs/geo/recent?lat=42.45&lng=-76.5&back=30&maxResults=2&includeProvisional=true&hotspot=true + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + X-eBirdApiToken: <<>> + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + cache-control: no-cache, no-store, max-age=0, must-revalidate + content-encoding: gzip + content-length: '286' + content-type: application/json;charset=utf-8 + date: Sat, 09 Mar 2024 06:43:48 GMT + expires: '0' + pragma: no-cache + server: Apache + strict-transport-security: max-age=31536000 ; includeSubDomains + vary: + - Accept-Encoding + - Accept-Encoding,Origin,Access-Control-Request-Method,Access-Control-Request-Headers + x-content-type-options: nosniff + x-frame-options: DENY + x-xss-protection: 1; mode=block + body: + encoding: '' + file: no + string: '[{"speciesCode":"haiwoo","comName":"Hairy Woodpecker","sciName":"Dryobates + villosus","locId":"L99398","locName":"Ithaca City Cemetery","obsDt":"2024-03-08 + 17:21","howMany":1,"lat":42.4447668,"lng":-76.4912709,"obsValid":true,"obsReviewed":false,"locationPrivate":false,"subId":"S164140884"},{"speciesCode":"blujay","comName":"Blue + Jay","sciName":"Cyanocitta cristata","locId":"L99398","locName":"Ithaca City + Cemetery","obsDt":"2024-03-08 17:21","howMany":1,"lat":42.4447668,"lng":-76.4912709,"obsValid":true,"obsReviewed":false,"locationPrivate":false,"subId":"S164140884"}]' + recorded_at: 2024-03-09 06:47:26 GMT + recorded_with: vcr/1.2.2, webmockr/0.9.0 diff --git a/tests/testthat/test-ebirdgeo.R b/tests/testthat/test-ebirdgeo.R index dc7a682..8c01a23 100644 --- a/tests/testthat/test-ebirdgeo.R +++ b/tests/testthat/test-ebirdgeo.R @@ -1,16 +1,18 @@ -context("ebirdgeo") - -test_that("ebirdgeo works correctly", { - skip_on_cran() - skip_on_ci() - - egeo <- ebirdgeo('amegfi',42,-76) - expect_is(egeo, "data.frame") - expect_gt(NCOL(egeo), 10) - expect_is(egeo$locName, "character") - expect_is(egeo$howMany, "integer") - expect_is(ebirdgeo(lat = 42, lng = -76, max=10, provisional=TRUE, hotspot=TRUE), "data.frame") - expect_equal(NROW(ebirdgeo(lat = 42, lng = -76, max=10, provisional=TRUE, hotspot=TRUE)), 10) - expect_silent(ebirdgeo(lat = 40, lng = -120, dist = 50)) - expect_warning(ebirdgeo(lat = 30, lng = -120, dist = 100), "Distance supplied was >50km") +vcr::use_cassette("ebirdgeo", { + test_that("ebirdgeo works correctly", { + expect_warning(egeo <- ebirdgeo('amegfi', 42.45, -76.50, dist = 51, max = 2), + "Distance supplied was >50km") + expect_true(inherits(egeo, "data.frame")) + expect_gt(NCOL(egeo), 10) + expect_equal(nrow(egeo), 2) + expect_true(inherits(egeo$locName, "character")) + expect_true(inherits(egeo$howMany, "integer")) + expect_warning( + prov <- ebirdgeo( + lat = 42.45, lng = -76.50, max=2, + provisional=TRUE, hotspot=TRUE, back = 31.5), + "using 30 days" + ) + expect_true(inherits(prov, "data.frame")) + }) })