From eb69b49183ce34435e88cdfbd123bd4040e08aeb Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Fri, 23 Sep 2022 12:17:22 +0200
Subject: [PATCH] feat: add TU

---
 __tests__/helpers/env.spec.js   | 32 +++++++++++++++++++++++++++
 __tests__/requests/cozy.spec.js | 39 ++++++++++++++++++++++++++++++++-
 2 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 __tests__/helpers/env.spec.js

diff --git a/__tests__/helpers/env.spec.js b/__tests__/helpers/env.spec.js
new file mode 100644
index 0000000..9716150
--- /dev/null
+++ b/__tests__/helpers/env.spec.js
@@ -0,0 +1,32 @@
+const { isAlpha } = require('../../src/helpers/env')
+describe('isAlpha', () => {
+  const OLD_ENV = process.env
+
+  beforeEach(() => {
+    jest.resetModules() // Most important - it clears the cache
+    process.env = { ...OLD_ENV } // Make a copy
+  })
+
+  afterAll(() => {
+    process.env = OLD_ENV // Restore old environment
+  })
+
+  it('should return false for local', () => {
+    // Set the variables
+    process.env.COZY_URL = 'http://cozy.tools:8080'
+    const reply = isAlpha()
+    expect(reply).toBe(false)
+  })
+  it('should return false for prod URL', () => {
+    // Set the variables
+    process.env.COZY_URL = 'https://pouet-ecolyo.cozygrandlyon.cloud/'
+    const reply = isAlpha()
+    expect(reply).toBe(false)
+  })
+  it('should return true for alpha', () => {
+    // Set the variables
+    process.env.COZY_URL = 'https://pouet.cozy.self-data.alpha.grandlyon.com/'
+    const reply = isAlpha()
+    expect(reply).toBe(true)
+  })
+})
diff --git a/__tests__/requests/cozy.spec.js b/__tests__/requests/cozy.spec.js
index ab0b4aa..2210936 100644
--- a/__tests__/requests/cozy.spec.js
+++ b/__tests__/requests/cozy.spec.js
@@ -1,5 +1,9 @@
 const { cozyClient } = require('cozy-konnector-libs')
-const { getAccount, saveAccountData } = require('../../src/requests/cozy')
+const {
+  getAccount,
+  saveAccountData,
+  getAccountForDelete,
+} = require('../../src/requests/cozy')
 
 const mockUpdateOrCreate = jest.fn()
 
@@ -36,6 +40,39 @@ describe('getAccount', () => {
     })
   })
 })
+describe('getAccountForDelete', () => {
+  it('should find account with provided ID', async () => {
+    const spy = jest.spyOn(cozyClient, 'fetchJSON')
+    spy.mockResolvedValueOnce(
+      {
+        _id: '123456',
+        account_type: '123456',
+        auth: {
+          address: '12 rue du pouet',
+          city: 'Lyon',
+          firstname: 'Jean',
+          lastname: 'POUET',
+          pointId: '1234567891234567',
+          postalCode: '69007',
+        },
+      },
+      { _id: '1111111', account_type: '1111111' }
+    )
+    const account = await getAccountForDelete('123456', '789456')
+    expect(account).toEqual({
+      _id: '123456',
+      account_type: '123456',
+      auth: {
+        address: '12 rue du pouet',
+        city: 'Lyon',
+        firstname: 'Jean',
+        lastname: 'POUET',
+        pointId: '1234567891234567',
+        postalCode: '69007',
+      },
+    })
+  })
+})
 
 describe('saveAccountData', () => {
   jest.mock('cozy-konnector-libs', () => ({
-- 
GitLab