@@ -161,3 +161,186 @@ test_that("hierarchy$descendants includes optional params", {
161161 expect_equal(called_with $ query $ include_invalid , " true" )
162162 expect_equal(called_with $ query $ domain_ids , " Condition" )
163163})
164+
165+ # ==============================================================================
166+ # get() method
167+ # ==============================================================================
168+
169+ test_that(" hierarchy$get validates concept_id" , {
170+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
171+ resource <- HierarchyResource $ new(base_req )
172+
173+ expect_error(resource $ get(" invalid" ))
174+ expect_error(resource $ get(- 1 ))
175+ expect_error(resource $ get(0 ))
176+ })
177+
178+ test_that(" hierarchy$get calls correct endpoint" , {
179+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
180+ resource <- HierarchyResource $ new(base_req )
181+
182+ called_with <- NULL
183+ local_mocked_bindings(
184+ perform_get = function (req , path , query = NULL ) {
185+ called_with <<- list (path = path , query = query )
186+ list (ancestors = list (), descendants = list ())
187+ }
188+ )
189+
190+ resource $ get(201826 )
191+
192+ expect_equal(called_with $ path , " concepts/201826/hierarchy" )
193+ })
194+
195+ test_that(" hierarchy$get includes format parameter" , {
196+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
197+ resource <- HierarchyResource $ new(base_req )
198+
199+ called_with <- NULL
200+ local_mocked_bindings(
201+ perform_get = function (req , path , query = NULL ) {
202+ called_with <<- list (query = query )
203+ list ()
204+ }
205+ )
206+
207+ resource $ get(201826 , format = " graph" )
208+
209+ expect_equal(called_with $ query $ format , " graph" )
210+ })
211+
212+ test_that(" hierarchy$get defaults format to flat" , {
213+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
214+ resource <- HierarchyResource $ new(base_req )
215+
216+ called_with <- NULL
217+ local_mocked_bindings(
218+ perform_get = function (req , path , query = NULL ) {
219+ called_with <<- list (query = query )
220+ list ()
221+ }
222+ )
223+
224+ resource $ get(201826 )
225+
226+ expect_equal(called_with $ query $ format , " flat" )
227+ })
228+
229+ test_that(" hierarchy$get joins vocabulary_ids correctly" , {
230+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
231+ resource <- HierarchyResource $ new(base_req )
232+
233+ called_with <- NULL
234+ local_mocked_bindings(
235+ perform_get = function (req , path , query = NULL ) {
236+ called_with <<- list (query = query )
237+ list ()
238+ }
239+ )
240+
241+ resource $ get(201826 , vocabulary_ids = c(" SNOMED" , " ICD10CM" ))
242+
243+ expect_equal(called_with $ query $ vocabulary_ids , " SNOMED,ICD10CM" )
244+ })
245+
246+ test_that(" hierarchy$get joins domain_ids correctly" , {
247+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
248+ resource <- HierarchyResource $ new(base_req )
249+
250+ called_with <- NULL
251+ local_mocked_bindings(
252+ perform_get = function (req , path , query = NULL ) {
253+ called_with <<- list (query = query )
254+ list ()
255+ }
256+ )
257+
258+ resource $ get(201826 , domain_ids = c(" Condition" , " Drug" ))
259+
260+ expect_equal(called_with $ query $ domain_ids , " Condition,Drug" )
261+ })
262+
263+ test_that(" hierarchy$get caps max_levels at 20" , {
264+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
265+ resource <- HierarchyResource $ new(base_req )
266+
267+ called_with <- NULL
268+ local_mocked_bindings(
269+ perform_get = function (req , path , query = NULL ) {
270+ called_with <<- list (query = query )
271+ list ()
272+ }
273+ )
274+
275+ resource $ get(201826 , max_levels = 50 ) # Request 50
276+
277+ expect_equal(called_with $ query $ max_levels , 20L ) # Capped at 20
278+ })
279+
280+ test_that(" hierarchy$get includes max_results parameter" , {
281+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
282+ resource <- HierarchyResource $ new(base_req )
283+
284+ called_with <- NULL
285+ local_mocked_bindings(
286+ perform_get = function (req , path , query = NULL ) {
287+ called_with <<- list (query = query )
288+ list ()
289+ }
290+ )
291+
292+ resource $ get(201826 , max_results = 100 )
293+
294+ expect_equal(called_with $ query $ max_results , 100L )
295+ })
296+
297+ test_that(" hierarchy$get joins relationship_types correctly" , {
298+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
299+ resource <- HierarchyResource $ new(base_req )
300+
301+ called_with <- NULL
302+ local_mocked_bindings(
303+ perform_get = function (req , path , query = NULL ) {
304+ called_with <<- list (query = query )
305+ list ()
306+ }
307+ )
308+
309+ resource $ get(201826 , relationship_types = c(" Is a" , " Subsumes" ))
310+
311+ expect_equal(called_with $ query $ relationship_types , " Is a,Subsumes" )
312+ })
313+
314+ test_that(" hierarchy$get adds include_invalid when TRUE" , {
315+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
316+ resource <- HierarchyResource $ new(base_req )
317+
318+ called_with <- NULL
319+ local_mocked_bindings(
320+ perform_get = function (req , path , query = NULL ) {
321+ called_with <<- list (query = query )
322+ list ()
323+ }
324+ )
325+
326+ resource $ get(201826 , include_invalid = TRUE )
327+
328+ expect_equal(called_with $ query $ include_invalid , " true" )
329+ })
330+
331+ test_that(" hierarchy$get does not add include_invalid when FALSE" , {
332+ base_req <- httr2 :: request(" https://api.omophub.com/v1" )
333+ resource <- HierarchyResource $ new(base_req )
334+
335+ called_with <- NULL
336+ local_mocked_bindings(
337+ perform_get = function (req , path , query = NULL ) {
338+ called_with <<- list (query = query )
339+ list ()
340+ }
341+ )
342+
343+ resource $ get(201826 , include_invalid = FALSE )
344+
345+ expect_null(called_with $ query $ include_invalid )
346+ })
0 commit comments