@@ -146,38 +146,36 @@ test_that("We can call all the legitimate HATEOAS endpoints", {
146
146
})
147
147
148
148
test_that(" Shorthand specification of fields results in expected results" , {
149
-
149
+ skip_on_cran()
150
150
query <- TEST_QUERIES [[" patent" ]]
151
151
152
+ # We ask for all of assignee's nested fields (total of 9 fields currently).
153
+ # It gets turned into a shorthand request, however now 11 fields are returned.
154
+ # Returned but not requested: assignee and assignee_location_id
155
+ # Now the test is really that the shorthand notation was used and
156
+ # that we got back all of the requested fields, ignoring the extras
152
157
all_assn_flds <- get_fields(" patent" , groups = " assignees" )
153
- full_res <- search_pv(query , fields = all_assn_flds )
158
+ full_res <- search_pv(query , fields = all_assn_flds , method = " POST" )
159
+ api_request <- httr2 :: last_request()$ body $ data
160
+ expect_true(grepl(' "f":\\ ["assignees","patent_id"\\ ]' , api_request ))
161
+
162
+ unnested_requested_flds <- sub(" .*\\ .(.*)" , " \\ 1" , all_assn_flds )
163
+ returned_flds <- names(full_res $ data $ patents $ assignees [[1 ]])
164
+ expect_true(all(unnested_requested_flds %in% returned_flds ))
154
165
166
+ # Here we explicitly request 8 fields but we get 9 back. We get assignee_id back
167
+ # as well as assignee (that we didn't ask for). The opposite is not true,
168
+ # asking for just assignee doesn't return assignee or assignee_id
155
169
no_city <- all_assn_flds [all_assn_flds != " assignees.assignee_city" ]
156
170
no_city_res <- search_pv(query , fields = no_city )
157
171
158
- no_city_has_seven <- length(no_city_res $ data $ patents $ assignees [[1 ]]) == 7
159
- all_cols_has_nine <- length(full_res $ data $ patents $ assignees [[1 ]]) == 9
160
- expect_true(no_city_has_seven && all_cols_has_nine )
161
- })
162
-
163
- test_that(" nested shorthand produces the same results as fully qualified ones" , {
164
- skip_on_cran()
165
-
166
- # The API now allows you to use the `group` name in place of all the field
167
- # names belonging to that group when specifying which fields you want. The
168
- # group names are given in fieldsdf$group.
169
- # This is indirectly testing our parse of the OpenAPI object in
170
- # data-raw/fieldsdf.R
171
- all_qualified_fields <- fieldsdf [
172
- fieldsdf $ endpoint == " patent" & fieldsdf $ group == " application" ,
173
- " field"
174
- ]
172
+ unnested_requested_flds <- sub(" .*\\ .(.*)" , " \\ 1" , no_city )
173
+ returned_flds <- names(no_city_res $ data $ patents $ assignees [[1 ]])
175
174
176
- query <- TEST_QUERIES [[ " patent " ]]
177
- shorthand_res <- search_pv( query , fields = " application " )
178
- qualified_res <- search_pv( query , fields = all_qualified_fields )
175
+ # we request "assignee" but don't get "assignee" or "assignee_id" back
176
+ # so we can't expect_true TODO move to api-bugs?
177
+ expect_false(all( unnested_requested_flds %in% returned_flds ) )
179
178
180
- expect_equal(shorthand_res $ data , qualified_res $ data )
181
179
})
182
180
183
181
test_that(" The 'after' parameter works properly" , {
@@ -189,7 +187,6 @@ test_that("The 'after' parameter works properly", {
189
187
expect_gt(results $ query_results $ total_hits , 1000 )
190
188
191
189
after <- results $ data $ patents $ patent_id [[nrow(results $ data $ patents )]]
192
- after <- pad_patent_id(after )
193
190
subsequent <- search_pv(big_query , after = after , sort = sort )
194
191
195
192
expect_equal(nrow(subsequent $ data $ patents ), 1000 )
0 commit comments