Skip to content
Snippets Groups Projects
Commit 479e84a3 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

fix: tests

parent 47fb5f4e
No related branches found
No related tags found
1 merge request!49Resolve "[2] [CONSENT_ID] Évolution du consent_id vers une id métier"
Pipeline #77794 passed
......@@ -45,7 +45,7 @@ describe('Backoffice routes', () => {
})
})
it('should handle unavailable BO', async () => {
axios.post.mockImplementationOnce(() => Promise.reject('fail'))
axios.post.mockRejectedValueOnce(new Error('request failed'))
try {
await createBoConsent(
'http://test.com',
......@@ -105,7 +105,7 @@ describe('Backoffice routes', () => {
})
})
it('should handle unavailable BO', async () => {
axios.put.mockImplementationOnce(() => Promise.reject('fail'))
axios.put.mockRejectedValueOnce(new Error('request failed'))
try {
await updateBoConsent(
'http://test.com',
......@@ -157,7 +157,7 @@ describe('Backoffice routes', () => {
})
})
it('should handle unavailable BO', async () => {
axios.put.mockImplementationOnce(() => Promise.reject('fail'))
axios.put.mockRejectedValueOnce(new Error('request failed'))
try {
await deleteBoConsent('http://test.com', 'token', 1)
expect(true).toBe(false)
......@@ -192,19 +192,28 @@ describe('Backoffice routes', () => {
})
it('should handle unavailable BO', async () => {
axios.get.mockImplementationOnce(() => Promise.reject(errors.MAINTENANCE))
axios.get.mockRejectedValueOnce(new Error('request failed'))
try {
await getBoConsent({
pointId: 11111111111111,
name: 'POUET',
adresse: '20 rue du lac',
postalCode: '69003',
inseeCode: '69383',
})
await getBoConsent('http://test.com', 'token', '1')
expect(true).toBe(false)
} catch (error) {
expect(error.message).toBe(errors.MAINTENANCE)
}
})
it('should handle not found consent', async () => {
axios.get.mockRejectedValueOnce({
response: {
status: 404,
data: { code: 404, description: 'Not Found' },
},
})
try {
await getBoConsent('http://test.com', 'token', 'n0tF0unD')
expect(true).toBe(false)
} catch (error) {
expect(error.message).toBe(errors.LOGIN_FAILED)
}
})
})
})
......@@ -134,10 +134,10 @@ async function getBoConsent(url, token, consentId) {
consentId: consentId,
},
})
if (err.response.status === 404) {
throw errors.LOGIN_FAILED
if (err.response?.status === 404) {
throw new Error(errors.LOGIN_FAILED)
}
throw errors.MAINTENANCE
throw new Error(errors.MAINTENANCE)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment