Skip to content

Commit aca84bd

Browse files
committed
added tests for newly reported API bugs
1 parent 9d64bda commit aca84bd

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

tests/testthat/test-api-bugs.R

+58-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,69 @@
11

22
# Tests from the other files in this directory that are masking API errors
3-
# This file will be submitted to the API team
3+
# This file was submitted to the API team as PVS-1125
44

55
eps <- (get_endpoints())
66

77
add_base_url <- function(x) {
88
paste0("https://search.patentsview.org/api/v1/", x)
99
}
1010

11+
test_that("there is case sensitivity on string equals", {
12+
skip_on_cran()
13+
skip_on_ci()
14+
15+
# reported to the API team PVS-1147
16+
# not sure if this is a bug or feature - original API was case insensitive
17+
# using both forms of equals, impied and explicit
18+
19+
assignee <- "Johnson & Johnson International"
20+
query1 <- sprintf('{"assignee_organization": \"%s\"}', assignee)
21+
a <- search_pv(query1, endpoint = "assignee")
22+
query2 <- qry_funs$eq(assignee_organization = assignee)
23+
b <- search_pv(query2, endpoint = "assignee")
24+
expect_equal(a$query_results$total_hits, 1)
25+
expect_equal(b$query_results$total_hits, 1)
26+
27+
assignee <- tolower(assignee)
28+
query1 <- sprintf('{"assignee_organization": \"%s\"}', assignee)
29+
c <- search_pv(query1, endpoint = "assignee")
30+
query2 <- qry_funs$eq(assignee_organization = assignee)
31+
d <- search_pv(query2, endpoint = "assignee")
32+
expect_equal(c$query_results$total_hits, 0)
33+
expect_equal(d$query_results$total_hits, 0)
34+
})
35+
36+
test_that("string vs text operators behave differently", {
37+
# # reported to the API team PVS-1147
38+
query <- qry_funs$begins(assignee_organization = "johnson")
39+
a <- search_pv(query, endpoint = "assignee")
40+
41+
query <- qry_funs$text_any(assignee_organization = "johnson")
42+
b <- search_pv(query, endpoint = "assignee")
43+
44+
expect_failure(
45+
expect_equal(a$query_results$total_hits, b$query_results$total_hits)
46+
)
47+
})
48+
49+
test_that("the otherreferences endpoint is still broken", {
50+
skip_on_cran()
51+
skip_on_ci()
52+
53+
query <- '{"_gte":{"patent_id":"1"}}'
54+
55+
# reported to the API team PVS-1109
56+
# otherreferences is listed in the OpenAPI object. It isn't in get_endpoints()
57+
# as it only throws errors.
58+
# This test will fail when the API does not throw an error
59+
60+
# Currently throws a 404
61+
expect_error(
62+
result <- retrieve_linked_data(add_base_url(paste0("patent/otherreference/?q=", query)))
63+
)
64+
})
65+
66+
1167
# from test-api-returns.R
1268
test_that("API returns all requested groups", {
1369
skip_on_cran()
@@ -98,8 +154,7 @@ test_that("API returns all requested groups", {
98154
# in an entity matching the plural form of the unnested endpoint
99155
expected_groups <- replace(expected_groups, expected_groups == "", to_plural(x))
100156

101-
# better way to do this? want to expect_set_not_equal
102-
expect_error(
157+
expect_failure(
103158
expect_setequal(actual_groups, expected_groups)
104159
)
105160
})

0 commit comments

Comments
 (0)