'use strict'

const buildPatientQuery = require('../../lib/builders/patient-query')
const tap = require('tap')

tap.test('Patient query builder', async t => {
  tap.test('should match on resource when there are no parameters', async t => {
    const expectedQuery = {
      resourceType: 'Patient'
    }
    const query = buildPatientQuery({}, 'Patient')
    t.deepEqual(query, expectedQuery)
  })

  tap.test(
    'should add a filter for the identifier query parameter',
    async t => {
      const expectedQuery = {
        resourceType: 'Patient',
        identifier: {
          $elemMatch: {
            value: '123'
          }
        }
      }
      const query = buildPatientQuery({
        identifier: '123'
      })
      t.deepEqual(query, expectedQuery)
    }
  )

  tap.test(
    'should add a filter for the identifier query parameter with a namespace',
    async t => {
      const expectedQuery = {
        resourceType: 'Patient',
        identifier: {
          $elemMatch: {
            value: '123',
            system: 'http://acme.org/patient'
          }
        }
      }
      const query = buildPatientQuery({
        identifier: 'http://acme.org/patient|123'
      })
      t.deepEqual(query, expectedQuery)
    }
  )

  tap.test(
    'should add filters for multiple identifier query parameters',
    async t => {
      const expectedQuery = {
        resourceType: 'Patient',
        $and: [
          {
            identifier: {
              $elemMatch: {
                value: '123'
              }
            }
          },
          {
            identifier: {
              $elemMatch: {
                value: '456'
              }
            }
          }
        ]
      }
      const query = buildPatientQuery({
        identifier: ['123', '456']
      })
      t.deepEqual(query, expectedQuery)
    }
  )

  tap.test(
    'should add filters for multiple identifier query parameters with a namespace',
    async t => {
      const expectedQuery = {
        resourceType: 'Patient',
        $and: [
          {
            identifier: {
              $elemMatch: {
                value: '123',
                system: 'http://acme.org/patient'
              }
            }
          },
          {
            identifier: {
              $elemMatch: {
                value: '456',
                system: 'http://acme.org/patient2'
              }
            }
          }
        ]
      }
      const query = buildPatientQuery({
        identifier: [
          'http://acme.org/patient|123',
          'http://acme.org/patient2|456'
        ]
      })
      t.deepEqual(query, expectedQuery)
    }
  )
})

@@ -151,26 +151,24 @@
 c t =%3E %7B%0A  t
-ap
 .test('shoul
@@ -389,37 +389,30 @@
 y)%0A  %7D)%0A%0A  t
-ap
 .test(
-%0A    
 'should add 
@@ -456,20 +456,16 @@
 ameter',
-%0A   
  async t
@@ -466,34 +466,32 @@
 sync t =%3E %7B%0A    
-  
 const expectedQu
@@ -490,34 +490,32 @@
 pectedQuery = %7B%0A
-  
       resourceTy
@@ -527,34 +527,32 @@
 Patient',%0A      
- 
- 
 identifier: %7B%0A  
@@ -541,34 +541,32 @@
   identifier: %7B%0A
-  
         $elemMat
@@ -563,34 +563,32 @@
   $elemMatch: %7B%0A
-  
           value:
@@ -598,38 +598,34 @@
 23'%0A        
-  %7D%0A  
+%7D%0A
       %7D%0A
       %7D%0A    
@@ -604,34 +604,32 @@
       %7D%0A      %7D%0A
-  
     %7D%0A      cons
@@ -614,34 +614,32 @@
     %7D%0A    %7D%0A    
-  
 const query = bu
@@ -654,34 +654,32 @@
 ntQuery(%7B%0A      
-  
 identifier: '123
@@ -676,39 +676,35 @@
 fier: '123'%0A    
- 
- 
 %7D)%0A
-  
     t.deepEqual(
@@ -723,38 +723,31 @@
 tedQuery)%0A  
-  %7D%0A  
+%7D
 )%0A%0A  t
-ap
 .test(%0A    '
@@ -1193,34 +1193,32 @@
 )%0A    %7D%0A  )%0A%0A  t
-ap
 .test(%0A    'shou
@@ -1802,18 +1802,16 @@
   )%0A%0A  t
-ap
 .test(%0A 

Fix lint error