Skip to content
Snippets Groups Projects
Commit aa58a3b3 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

fix: TU

parent c97ec9fc
No related branches found
No related tags found
1 merge request!21US878 feat(rechercherpoint): add two fallback in case of no rechercher point match
......@@ -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)
}
})
})
const { errors } = require('cozy-konnector-libs')
const { verifyUserIdentity } = require('../../src/core/verifyUserIdentity')
const { findUserPdl } = require('../../src/core/findUserPdl')
const { findUserAddress } = require('../../src/core/findUserAddress')
jest.mock('../../src/core/findUserPdl')
jest.mock('../../src/core/findUserAddress')
jest.mock('../../src/requests/insee', () => ({
getInseeCode: jest.fn().mockResolvedValue(69),
}))
jest.mock('../../src/core/findUserPdl', () => ({
findUserPdl: jest.fn().mockResolvedValue('12345'),
}))
jest.mock('../../src/index', () => ({
start: jest.fn(),
}))
describe('verifyUserIdentity', () => {
it('should throw LOGIN_FAILED when pdl given and recieved are NOT matching 🚫', async () => {
findUserPdl.mockResolvedValueOnce('12345')
try {
await verifyUserIdentity(
{
......@@ -32,7 +34,9 @@ describe('verifyUserIdentity', () => {
expect(error).toBe(errors.LOGIN_FAILED)
}
})
it('should throw TERMS_VERSION_MISMATCH when pdl give and recieved are NOT matching on alternate start 🚫', async () => {
findUserPdl.mockResolvedValueOnce('12345')
try {
await verifyUserIdentity(
{
......@@ -53,6 +57,7 @@ describe('verifyUserIdentity', () => {
})
it('should return void when pdl give and recieved are matching ✅', async () => {
findUserPdl.mockResolvedValueOnce('12345')
expect.assertions(1)
try {
await verifyUserIdentity(
......@@ -72,6 +77,7 @@ describe('verifyUserIdentity', () => {
}
})
it('should return void when pdl give and recieved are matching with stored inseecode ✅', async () => {
findUserPdl.mockResolvedValue('12345')
expect.assertions(1)
try {
await verifyUserIdentity(
......@@ -92,4 +98,62 @@ describe('verifyUserIdentity', () => {
expect(true).toBe(false)
}
})
it('should return void when pdl give and recieved are matching with SGE second chance onboarding ✅ ', async () => {
findUserPdl.mockResolvedValueOnce(null).mockResolvedValueOnce('12345')
findUserAddress.mockResolvedValueOnce({
escalierEtEtageEtAppartement: '12',
codePostal: '69003',
numeroEtNomVoie: '20 rue du lac',
commune: { $: { code: '69383' } },
})
try {
await verifyUserIdentity(
{
lastname: 'John',
firstname: 'DOE',
address: '1 street',
pointId: '12345',
postalCode: '69069',
},
'azertyuiop',
'apiKey',
'login@user.com'
)
expect(true).toBeTruthy()
} catch (error) {
expect(true).toBe(false)
}
})
it('should return void when pdl give and recieved are matching with SGE last chance onboarding✅ ', async () => {
findUserPdl
.mockResolvedValueOnce(null)
.mockResolvedValueOnce(null)
.mockResolvedValueOnce('12345')
findUserAddress.mockResolvedValueOnce({
escalierEtEtageEtAppartement: '12',
codePostal: '69003',
numeroEtNomVoie: '20 rue du lac',
commune: { $: { code: '69383' } },
})
try {
await verifyUserIdentity(
{
name: 'John',
address: '1 street',
pointId: '12345',
postalCode: '69069',
},
'azertyuiop',
'apiKey',
'login@user.com'
)
expect(true).toBeTruthy()
} catch (error) {
expect(true).toBe(false)
}
})
})
......@@ -4,6 +4,8 @@ const {
parseContracts,
parseServiceId,
parseSgeXmlData,
checkContractExists,
parseUserAddress,
formateDataForDoctype,
parseTags,
parseValue,
......@@ -132,6 +134,44 @@ describe('parsing', () => {
])
})
it('should format existing contract', async () => {
const result = {
Envelope: {
Body: {
rechercherServicesSouscritsMesuresResponse: {
servicesSouscritsMesures: {
v: 14361,
d: '2021-08-01T00:00:00.000+02:00',
},
},
},
},
}
const reply = checkContractExists(result)
expect(reply).toEqual({
v: 14361,
d: '2021-08-01T00:00:00.000+02:00',
})
})
it('should format user address', async () => {
const result = {
Envelope: {
Body: {
consulterDonneesTechniquesContractuellesResponse: {
point: {
donneesGenerales: { adresseInstallation: { numero: '12' } },
},
},
},
},
}
const reply = parseUserAddress(result)
expect(reply).toEqual({
numero: '12',
})
})
it('should parseTag with :', () => {
const reply = parseTags('test:tag')
expect(reply).toBe('tag')
......
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