import { error } from './'

describe('error', () => {
  it('Should handle axios response errors', () => {
    expect.assertions(1)
    const obj = { response: {} }
    expect(() => { error(obj) }).toThrow()
  })

  it('Should handle axios response errors with JSON:API errors', () => {
    expect.assertions(1)
    const obj = {
      response: {
        data: {
          errors: [
            {
              title: 'Filter is not allowed',
              detail: 'x is not allowed',
              code: '102',
              status: '400'
            }
          ]
        }
      }
    }
    expect(error(obj).errors).toEqual([
      {
        title: 'Filter is not allowed',
        detail: 'x is not allowed',
        code: '102',
        status: '400'
      }
    ])
  })

  it('Should handle top-level JSON:API errors', () => {
    expect.assertions(1)
    const obj = {
      errors: [ { code: 400 } ]
    }
    expect(error(obj)).toEqual({
      errors: [ { code: 400 } ]
    })
  })

  it('Should throw all other errors', () => {
    expect.assertions(2)
    expect(() => { error('Hello') }).toThrowError('Hello')
    expect(() => { error(new Error('Hello')) }).toThrowError('Hello')
  })
})

@@ -591,26 +591,71 @@
     
-expect(error(obj).
+try %7B%0A      error(obj)%0A    %7D catch (%7B errors %7D) %7B%0A      expect(
 erro
@@ -670,26 +670,30 @@
 ual(%5B%0A      
+ 
+ 
 %7B%0A
+  
         titl
@@ -712,32 +712,34 @@
 s not allowed',%0A
+  
         detail: 
@@ -758,32 +758,34 @@
 lowed',%0A        
+  
 code: '102',%0A   
@@ -773,32 +773,34 @@
    code: '102',%0A
+  
         status: 
@@ -815,17 +815,27 @@
     
+ 
+ 
 %7D%0A
+  
     %5D)%0A
+    %7D%0A
   %7D)
@@ -973,24 +973,73 @@
 %5D%0A    %7D%0A    
+try %7B%0A      error(obj)%0A    %7D catch (err) %7B%0A      
 expect(error
@@ -1036,23 +1036,16 @@
 pect(err
-or(obj)
 ).toEqua
@@ -1048,16 +1048,18 @@
 Equal(%7B%0A
+  
       er
@@ -1086,18 +1086,26 @@
 %7D %5D%0A    
+  %7D)%0A    
 %7D
-)
 %0A  %7D)%0A%0A 

update test cases