Update utils.test.js
This commit is contained in:
		
							parent
							
								
									18c3c8c223
								
							
						
					
					
						commit
						791cb0ff2f
					
				| 
						 | 
					@ -15,8 +15,6 @@ it('can load valid config.js', () => {
 | 
				
			||||||
    timeout: 5000,
 | 
					    timeout: 5000,
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      'Content-Type': 'application/json',
 | 
					      'Content-Type': 'application/json',
 | 
				
			||||||
      'User-Agent':
 | 
					 | 
				
			||||||
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71',
 | 
					 | 
				
			||||||
      Cookie: 'abc=123'
 | 
					      Cookie: 'abc=123'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
| 
						 | 
					@ -81,9 +79,23 @@ it('can escape url', () => {
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
it('can fetch data', () => {
 | 
					it('can fetch data', async () => {
 | 
				
			||||||
  const config = utils.loadConfig('./tests/input/example.com.config.js')
 | 
					  const request = {
 | 
				
			||||||
  utils.fetchData({}, config).then(jest.fn).catch(jest.fn)
 | 
					    data: { accountID: '123' },
 | 
				
			||||||
 | 
					    headers: {
 | 
				
			||||||
 | 
					      'Content-Type': 'application/json',
 | 
				
			||||||
 | 
					      Cookie: 'abc=123',
 | 
				
			||||||
 | 
					      'User-Agent':
 | 
				
			||||||
 | 
					        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71'
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    maxContentLength: 5242880,
 | 
				
			||||||
 | 
					    method: 'POST',
 | 
				
			||||||
 | 
					    responseType: 'arraybuffer',
 | 
				
			||||||
 | 
					    timeout: 5000,
 | 
				
			||||||
 | 
					    url: 'http://example.com/20210319/1tv.json',
 | 
				
			||||||
 | 
					    withCredentials: true
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  utils.fetchData(request).then(jest.fn).catch(jest.fn)
 | 
				
			||||||
  expect(mockAxios).toHaveBeenCalledWith(
 | 
					  expect(mockAxios).toHaveBeenCalledWith(
 | 
				
			||||||
    expect.objectContaining({
 | 
					    expect.objectContaining({
 | 
				
			||||||
      data: { accountID: '123' },
 | 
					      data: { accountID: '123' },
 | 
				
			||||||
| 
						 | 
					@ -101,3 +113,24 @@ it('can fetch data', () => {
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					it('can build request async', async () => {
 | 
				
			||||||
 | 
					  const config = utils.loadConfig('./tests/input/async.config.js')
 | 
				
			||||||
 | 
					  return utils.buildRequest({}, config).then(request => {
 | 
				
			||||||
 | 
					    expect(request).toMatchObject({
 | 
				
			||||||
 | 
					      data: { accountID: '123' },
 | 
				
			||||||
 | 
					      headers: {
 | 
				
			||||||
 | 
					        'Content-Type': 'application/json',
 | 
				
			||||||
 | 
					        Cookie: 'abc=123',
 | 
				
			||||||
 | 
					        'User-Agent':
 | 
				
			||||||
 | 
					          'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      maxContentLength: 5242880,
 | 
				
			||||||
 | 
					      method: 'POST',
 | 
				
			||||||
 | 
					      responseType: 'arraybuffer',
 | 
				
			||||||
 | 
					      timeout: 5000,
 | 
				
			||||||
 | 
					      url: 'http://example.com/20210319/1tv.json',
 | 
				
			||||||
 | 
					      withCredentials: true
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue