@@ -200,4 +200,123 @@ describe('Search Worker', () => {
200200 }
201201 } ) ;
202202 } ) ;
203+ describe ( '_summary parameter' , ( ) => {
204+ test ( 'should return only summary elements with _summary=true' , async ( ) => {
205+ const response = await request ( app )
206+ . get ( '/tx/r5/CodeSystem' )
207+ . query ( { _summary : 'true' , _count : 5 } )
208+ . set ( 'Accept' , 'application/json' ) ;
209+
210+ expect ( response . status ) . toBe ( 200 ) ;
211+ expect ( response . body . resourceType ) . toBe ( 'Bundle' ) ;
212+
213+ if ( response . body . entry && response . body . entry . length > 0 ) {
214+ const resource = response . body . entry [ 0 ] . resource ;
215+ // Summary elements should be present
216+ expect ( resource . resourceType ) . toBe ( 'CodeSystem' ) ;
217+ expect ( resource . id ) . toBeDefined ( ) ;
218+ // Non-summary elements should be absent
219+ expect ( resource . concept ) . toBeUndefined ( ) ;
220+ expect ( resource . property ) . toBeUndefined ( ) ;
221+ }
222+ } ) ;
223+
224+ test ( 'should return only count with _summary=count' , async ( ) => {
225+ const response = await request ( app )
226+ . get ( '/tx/r5/CodeSystem' )
227+ . query ( { _summary : 'count' } )
228+ . set ( 'Accept' , 'application/json' ) ;
229+
230+ expect ( response . status ) . toBe ( 200 ) ;
231+ expect ( response . body . resourceType ) . toBe ( 'Bundle' ) ;
232+ expect ( response . body . type ) . toBe ( 'searchset' ) ;
233+ expect ( response . body . total ) . toBeGreaterThan ( 0 ) ;
234+ // No entries when _summary=count
235+ expect ( response . body . entry ) . toBeUndefined ( ) ;
236+ expect ( response . body . link ) . toBeUndefined ( ) ;
237+ } ) ;
238+
239+ test ( 'should return full resources with _summary=false' , async ( ) => {
240+ const response = await request ( app )
241+ . get ( '/tx/r5/CodeSystem' )
242+ . query ( { _summary : 'false' , url : 'http://hl7.org/fhir/administrative-gender' } )
243+ . set ( 'Accept' , 'application/json' ) ;
244+
245+ expect ( response . status ) . toBe ( 200 ) ;
246+
247+ if ( response . body . entry && response . body . entry . length > 0 ) {
248+ const resource = response . body . entry [ 0 ] . resource ;
249+ expect ( resource . resourceType ) . toBe ( 'CodeSystem' ) ;
250+ // Full resource should include concept
251+ expect ( resource . concept ) . toBeDefined ( ) ;
252+ }
253+ } ) ;
254+ } ) ;
255+
256+ describe ( '_total parameter' , ( ) => {
257+ test ( 'should include total with _total=accurate (default)' , async ( ) => {
258+ const response = await request ( app )
259+ . get ( '/tx/r5/CodeSystem' )
260+ . query ( { _count : 5 } )
261+ . set ( 'Accept' , 'application/json' ) ;
262+
263+ expect ( response . status ) . toBe ( 200 ) ;
264+ expect ( response . body . total ) . toBeDefined ( ) ;
265+ expect ( typeof response . body . total ) . toBe ( 'number' ) ;
266+ } ) ;
267+
268+ test ( 'should not include total with _total=none' , async ( ) => {
269+ const response = await request ( app )
270+ . get ( '/tx/r5/CodeSystem' )
271+ . query ( { _total : 'none' , _count : 5 } )
272+ . set ( 'Accept' , 'application/json' ) ;
273+
274+ expect ( response . status ) . toBe ( 200 ) ;
275+ expect ( response . body . resourceType ) . toBe ( 'Bundle' ) ;
276+ expect ( response . body . total ) . toBeUndefined ( ) ;
277+ } ) ;
278+ } ) ;
279+
280+ describe ( '_format parameter' , ( ) => {
281+ test ( 'should return JSON with _format=json' , async ( ) => {
282+ const response = await request ( app )
283+ . get ( '/tx/r5/CodeSystem' )
284+ . query ( { _format : 'json' , _count : 2 } ) ;
285+
286+ expect ( response . status ) . toBe ( 200 ) ;
287+ expect ( response . headers [ 'content-type' ] ) . toContain ( 'application/fhir+json' ) ;
288+ expect ( response . body . resourceType ) . toBe ( 'Bundle' ) ;
289+ } ) ;
290+
291+ test ( 'should return XML with _format=xml' , async ( ) => {
292+ const response = await request ( app )
293+ . get ( '/tx/r5/CodeSystem' )
294+ . query ( { _format : 'xml' , _count : 2 } ) ;
295+
296+ expect ( response . status ) . toBe ( 200 ) ;
297+ expect ( response . headers [ 'content-type' ] ) . toContain ( 'application/fhir+xml' ) ;
298+ expect ( response . text ) . toContain ( '<Bundle' ) ;
299+ expect ( response . text ) . toContain ( 'xmlns="http://hl7.org/fhir"' ) ;
300+ } ) ;
301+
302+ test ( 'should return JSON with _format=application/fhir+json' , async ( ) => {
303+ const response = await request ( app )
304+ . get ( '/tx/r5/CodeSystem' )
305+ . query ( { _format : 'application/fhir+json' , _count : 2 } ) ;
306+
307+ expect ( response . status ) . toBe ( 200 ) ;
308+ expect ( response . headers [ 'content-type' ] ) . toContain ( 'application/fhir+json' ) ;
309+ } ) ;
310+
311+ test ( '_format should override Accept header' , async ( ) => {
312+ const response = await request ( app )
313+ . get ( '/tx/r5/CodeSystem' )
314+ . query ( { _format : 'xml' , _count : 2 } )
315+ . set ( 'Accept' , 'application/fhir+json' ) ;
316+
317+ expect ( response . status ) . toBe ( 200 ) ;
318+ // _format=xml should override Accept: application/fhir+json
319+ expect ( response . headers [ 'content-type' ] ) . toContain ( 'application/fhir+xml' ) ;
320+ } ) ;
321+ } ) ;
203322} ) ;
0 commit comments