Skip to content
Snippets Groups Projects

Feat/rechercher point

Merged Bastien DUMONT requested to merge feat/rechercher-point into main
Files
12
+ 93
0
const { createBoConsent, getBoConsent } = require('../../src/requests/bo')
const { default: axios } = require('axios')
const { errors } = require('cozy-konnector-libs')
jest.mock('axios')
describe('Backoffice routes', () => {
describe('createBoConsent', () => {
it('should send consent to BO', async () => {
axios.post.mockResolvedValueOnce({ id: 1 })
const consent = await createBoConsent({
pdl: 11111111111111,
name: 'POUET',
adresse: '20 rue du lac',
postalCode: '69003',
inseeCode: '69383',
})
expect(consent).toBe({ id: 1 })
})
it('should handle unavailable BO', async () => {
axios.post.mockImplementationOnce(() =>
Promise.reject(errors.MAINTENANCE)
)
try {
await createBoConsent({
pdl: 11111111111111,
name: 'POUET',
adresse: '20 rue du lac',
postalCode: '69003',
inseeCode: '69383',
})
expect(true).toBe(false)
} catch (e) {
expect(e).toBe(errors.MAINTENANCE)
}
})
})
describe('getBoConsent', () => {
it('should get consent from BO', async () => {
axios.get.mockResolvedValueOnce({
id: 1,
pointId: 11111111111111,
name: 'POUET',
adresse: '20 rue du lac',
postalCode: '69003',
inseeCode: '69383',
})
const consent = await getBoConsent(1)
expect(consent).toBe({
pointId: 11111111111111,
name: 'POUET',
adresse: '20 rue du lac',
postalCode: '69003',
inseeCode: '69383',
})
})
it('should get consent from BO with service id', async () => {
axios.get.mockResolvedValueOnce({
id: 1,
pointId: 11111111111111,
name: 'POUET',
adresse: '20 rue du lac',
postalCode: '69003',
inseeCode: '69383',
serviceId: 'abcde',
})
const consent = await getBoConsent(1)
expect(consent.serviceId).toBeTruthy()
expect(consent).toBe({
pointId: 11111111111111,
name: 'POUET',
adresse: '20 rue du lac',
postalCode: '69003',
inseeCode: '69383',
serviceId: 'abcde',
})
})
it('should handle unavailable BO', async () => {
axios.get.mockImplementationOnce(() => Promise.reject(errors.MAINTENANCE))
try {
await createBoConsent({
pointId: 11111111111111,
name: 'POUET',
adresse: '20 rue du lac',
postalCode: '69003',
inseeCode: '69383',
})
expect(true).toBe(false)
} catch (e) {
expect(e).toBe(errors.MAINTENANCE)
}
})
})
})
Loading