From 356c7362cb998e0b8adb52084e21e9097ddc1817 Mon Sep 17 00:00:00 2001
From: Bastien DUMONT <bdumont@grandlyon.com>
Date: Tue, 2 Aug 2022 17:39:07 +0200
Subject: [PATCH] pwet

---
 __tests__/findUserPdl.spec.js        |  4 +++-
 __tests__/recherchePoint.spec.js     | 12 ------------
 __tests__/verifyUserIdentity.spec.js | 29 ++++++++++++++++++++++++++++
 importedData.json                    |  7 ++++++-
 src/index.js                         | 11 ++++++++---
 5 files changed, 46 insertions(+), 17 deletions(-)
 delete mode 100644 __tests__/recherchePoint.spec.js
 create mode 100644 __tests__/verifyUserIdentity.spec.js

diff --git a/__tests__/findUserPdl.spec.js b/__tests__/findUserPdl.spec.js
index a4c9063..6907f93 100644
--- a/__tests__/findUserPdl.spec.js
+++ b/__tests__/findUserPdl.spec.js
@@ -2,10 +2,12 @@ const { errors } = require('cozy-konnector-libs')
 const { findUserPdl } = require('../src')
 
 describe('recherchePoint', () => {
+  // mock soap request with result
+  // mock soap request to throw error
   it('should throw LOGIN_FAILED for too many responses', () => {
     expect(
       findUserPdl()
-      // How to get params ?
+      //
       // .env
     ).toBe(errors.LOGIN_FAILED)
   })
diff --git a/__tests__/recherchePoint.spec.js b/__tests__/recherchePoint.spec.js
deleted file mode 100644
index 1ed6f04..0000000
--- a/__tests__/recherchePoint.spec.js
+++ /dev/null
@@ -1,12 +0,0 @@
-const { errors } = require('cozy-konnector-libs')
-const { verifyUserIdentity } = require('../src/index')
-
-describe('recherchePoint', () => {
-  it('should throw LOGIN_FAILED when pdl give and recieved are not mathing', () => {
-    expect(
-      verifyUserIdentity()
-      // params ?
-      // fields.pdl value
-    ).toBe(errors.LOGIN_FAILED)
-  })
-})
diff --git a/__tests__/verifyUserIdentity.spec.js b/__tests__/verifyUserIdentity.spec.js
new file mode 100644
index 0000000..cf8aee4
--- /dev/null
+++ b/__tests__/verifyUserIdentity.spec.js
@@ -0,0 +1,29 @@
+const { errors } = require('cozy-konnector-libs')
+const { verifyUserIdentity } = require('../src/index')
+const insee = require('./requests/insee')
+
+describe('verifyUserIdentity', () => {
+  // mock insee code
+  // mock find User Pdl
+  // const mockGetInseeCode = jest.fn()
+  // const mockFindUserPdl = jest.fn()
+
+  it('should throw LOGIN_FAILED when pdl give and recieved are not matching', async () => {
+    jest.spyOn(insee, 'getInseeCode').mockResolvedValueOnce(696969)
+    // jest.spyOn(verifyUserIdentity, 'findUserPdl').mockResolvedValueOnce(696969)
+
+    expect(
+      verifyUserIdentity(
+        {
+          name: 'John',
+          address: '1 street',
+          pointId: 987654321,
+          postalCode: '69069',
+        },
+        'baseUrl',
+        'apiKey',
+        'login@user.com'
+      )
+    ).toBe(errors.LOGIN_FAILED)
+  })
+})
diff --git a/importedData.json b/importedData.json
index 9e26dfe..5b3d3e9 100644
--- a/importedData.json
+++ b/importedData.json
@@ -1 +1,6 @@
-{}
\ No newline at end of file
+{
+  "io.cozy.files": [],
+  "com.grandlyon.enedis.year": [],
+  "com.grandlyon.enedis.month": [],
+  "com.grandlyon.enedis.minute": []
+}
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index b9ab672..d3fb8fb 100644
--- a/src/index.js
+++ b/src/index.js
@@ -117,7 +117,7 @@ async function start(fields, cozyParameters) {
  * @param {string} apiAuthKey
  * @param {string} loginUtilisateur
  */
-export async function verifyUserIdentity(
+async function verifyUserIdentity(
   fields,
   baseUrl,
   apiAuthKey,
@@ -130,7 +130,7 @@ export async function verifyUserIdentity(
     apiAuthKey,
     loginUtilisateur,
     fields.name,
-    fields.addresse,
+    fields.address,
     fields.postalCode,
     inseeCode
   )
@@ -480,7 +480,7 @@ function isFirstStart() {
 /**
  * @return {Promise<string>} User Pdl
  */
-export async function findUserPdl(
+async function findUserPdl(
   url,
   apiAuthKey,
   appLogin,
@@ -513,3 +513,8 @@ export async function findUserPdl(
   //TODO: handle errors
   return parseUserPdl(parsedReply)
 }
+
+module.exports = {
+  verifyUserIdentity,
+  findUserPdl,
+}
-- 
GitLab