Skip to content
Snippets Groups Projects

US878 feat(rechercherpoint): add two fallback in case of no rechercher point match

Merged Hugo SUBTIL requested to merge feat/868-sge-fallback into main
3 files
+ 134
35
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -12,37 +12,10 @@ const responseMock = {
}
describe('recherchePoint', () => {
afterEach(() => {
beforeEach(() => {
jest.clearAllMocks()
})
it('should throw LOGIN_FAIL if soapRequest fails', async () => {
const mockParseUserPdl = jest.fn()
jest.mock('../../src/helpers/parsing', () => ({
parseUserPdl: () => mockParseUserPdl(),
}))
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValueOnce({
Envelope: {
Body: {
Fault: { detail: { erreur: { resultat: { $: { code: 401 } } } } },
faultstring: 'Mock error',
},
},
})
mockSoapRequest.mockRejectedValueOnce('reject')
try {
await findUserPdl()
expect(true).toBe(false)
} catch (error) {
expect(error).toBe(errors.LOGIN_FAILED)
}
})
it('should return a correct pdl number', async () => {
const mockParseUserPdl = jest.fn()
jest.mock('../../src/helpers/parsing', () => ({
parseUserPdl: () => mockParseUserPdl(),
}))
it('should return a correct pdl number ✅', async () => {
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValueOnce({
Envelope: {
Body: {
@@ -57,7 +30,7 @@ describe('recherchePoint', () => {
expect(await findUserPdl()).toBe('191919119')
})
it('should handle issue on parsing', async () => {
it('should handle issue on parsing', async () => {
const cozyKonnectorsLib = require('cozy-konnector-libs')
const spyer = jest.spyOn(cozyKonnectorsLib, 'log')
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValueOnce({
@@ -81,6 +54,28 @@ describe('recherchePoint', () => {
await findUserPdl()
// Only verifing that we are going through logs
expect(spyer).toBeCalledTimes(3)
expect(spyer).toBeCalledTimes(5)
})
it('should throw LOGIN_FAIL if soapRequest fails 🚫', async () => {
const mockParseUserPdl = jest.fn()
jest.mock('../../src/helpers/parsing', () => ({
parseUserPdl: () => mockParseUserPdl(),
}))
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValueOnce({
Envelope: {
Body: {
Fault: { detail: { erreur: { resultat: { $: { code: 401 } } } } },
faultstring: 'Mock error',
},
},
})
mockSoapRequest.mockRejectedValueOnce('reject')
try {
await findUserPdl()
expect(true).toBe(false)
} catch (error) {
expect(error).toBe(errors.LOGIN_FAILED)
}
})
})
Loading