diff --git a/__tests__/helpers/env.spec.js b/__tests__/helpers/env.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..97161504b404dce04798658f2c5c8b26ce8b63e7 --- /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 ab0b4aa303cbe7bdd973508cc49b19b5a5b9be82..22109364ac9f00b37b87fdc026f3cc3381475aaa 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', () => ({