Newer
Older
const { errors } = require('cozy-konnector-libs')
const { findUserPdl } = require('../src/findUserPdl')
jest.mock('../src/parsing', () => ({
parseUserPdl: mockParsePdl = jest.fn(),
}))
// Dependencies
jest.mock('easy-soap-request', () =>
jest.fn().mockResolvedValue({
response: {
body: 'test',
},
})
)
jest.mock('../src/requests/sge', () => ({
rechercherPoint: jest.fn().mockResolvedValue('response'),
}))
//OK
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValue('response')
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
describe('recherchePoint', () => {
it('should throw LOGIN_FAILED for too many responses', async () => {
mockParsePdl.mockImplementationOnce(() => {
throw new Error('fail')
})
try {
const result = await findUserPdl(
'azertyuiop',
'apiKey',
'login@user.com',
'John',
'1 street',
'69069',
'69069'
)
console.log('result: ' + result)
expect(true).toBe(false)
} catch (error) {
console.log('error in test file ' + error)
expect(error).toBe(errors.LOGIN_FAILED)
}
})
it('should return a correct pdl number', async () => {
mockParsePdl.mockResolvedValue('12345')
expect(
await findUserPdl(
'azertyuiop',
'apiKey',
'login@user.com',
'John',
'1 street',
'69069',
'69069'
)
).toBe('12345')
})
})