From 14f045208922db63cdab7a40af0cf964094831b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 7 Jun 2023 16:47:39 +0200 Subject: [PATCH] Clean store old code --- site/source/sitePaths.ts | 16 --- site/source/store/actions/actions.ts | 2 - .../companyCreationChecklistActions.ts | 22 ---- .../reducers/choixStatutJuridiqueReducer.ts | 66 ----------- site/test/companyStatusSelectors.test.js | 103 ------------------ 5 files changed, 209 deletions(-) delete mode 100644 site/source/store/actions/companyCreationChecklistActions.ts delete mode 100644 site/test/companyStatusSelectors.test.js diff --git a/site/source/sitePaths.ts b/site/source/sitePaths.ts index 2d8e42045..b5fc788e1 100644 --- a/site/source/sitePaths.ts +++ b/site/source/sitePaths.ts @@ -2,22 +2,6 @@ import { useTranslation } from 'react-i18next' import { MetadataSrc } from '@/pages/simulateurs/metadata-src' -// export const LANDING_LEGAL_STATUS_LIST: Array = [ -// 'EI', -// 'EIRL', -// 'EURL', -// 'SAS', -// 'SARL', -// 'SASU', -// 'auto-entrepreneur', -// 'auto-entrepreneur-EIRL', -// 'SA', -// ] - -// const status = Object.fromEntries( -// LANDING_LEGAL_STATUS_LIST.map((statut) => [statut, statut]) -// ) as { [statut in LegalStatus]: statut } - const rawSitePathsFr = { index: '', assistants: { diff --git a/site/source/store/actions/actions.ts b/site/source/store/actions/actions.ts index 8f51598cd..16d96c477 100644 --- a/site/source/store/actions/actions.ts +++ b/site/source/store/actions/actions.ts @@ -6,7 +6,6 @@ import { ImmutableType } from '@/types/utils' import { buildSituationFromObject } from '@/utils' import { CompanyActions } from './companyActions' -import { CompanyCreationAction } from './companyCreationChecklistActions' import { HiringChecklistAction } from './hiringChecklistAction' export type Action = @@ -25,7 +24,6 @@ export type Action = | typeof batchUpdateSituation | typeof updateShouldFocusField > - | CompanyCreationAction | CompanyActions | HiringChecklistAction diff --git a/site/source/store/actions/companyCreationChecklistActions.ts b/site/source/store/actions/companyCreationChecklistActions.ts deleted file mode 100644 index 251511439..000000000 --- a/site/source/store/actions/companyCreationChecklistActions.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { LegalStatus } from '@/store/selectors/companyStatusSelectors' - -export type CompanyCreationAction = ReturnType< - typeof initializeCompanyCreationChecklist | typeof checkCompanyCreationItem -> - -export const initializeCompanyCreationChecklist = ( - statusName: LegalStatus, - checklistItems: Array -) => - ({ - type: 'INITIALIZE_COMPANY_CREATION_CHECKLIST', - checklistItems, - statusName, - } as const) - -export const checkCompanyCreationItem = (name: string, checked: boolean) => - ({ - type: 'CHECK_COMPANY_CREATION_ITEM', - name, - checked, - } as const) diff --git a/site/source/store/reducers/choixStatutJuridiqueReducer.ts b/site/source/store/reducers/choixStatutJuridiqueReducer.ts index bddcf0974..cbe259d51 100644 --- a/site/source/store/reducers/choixStatutJuridiqueReducer.ts +++ b/site/source/store/reducers/choixStatutJuridiqueReducer.ts @@ -1,34 +1,6 @@ import { combineReducers } from 'redux' import { Action } from '@/store/actions/actions' -import { LegalStatus } from '@/store/selectors/companyStatusSelectors' -import { LegalStatusRequirements } from '@/types/companyTypes' -import { omit } from '@/utils' - -function companyLegalStatus( - state: LegalStatusRequirements = {}, - action: Action -): LegalStatusRequirements { - switch (action.type) { - case 'COMPANY_IS_SOLE_PROPRIETORSHIP': - return { ...state, soleProprietorship: action.isSoleProprietorship } - - case 'DEFINE_DIRECTOR_STATUS': - return { ...state, directorStatus: action.status } - case 'COMPANY_HAS_MULTIPLE_ASSOCIATES': - return { ...state, multipleAssociates: action.multipleAssociates } - case 'COMPANY_IS_MICROENTERPRISE': - return { ...state, autoEntrepreneur: action.autoEntrepreneur } - case 'SPECIFY_DIRECTORS_SHARE': - return { ...state, minorityDirector: action.minorityDirector } - case 'RESET_COMPANY_STATUS_CHOICE': - return action.answersToReset - ? action.answersToReset.reduce(omit, state) - : {} - } - - return state -} function hiringChecklist( state: { [key: string]: boolean } = {}, @@ -52,45 +24,7 @@ function hiringChecklist( } } -function companyCreationChecklist( - state: { [key: string]: boolean } = {}, - action: Action -) { - switch (action.type) { - case 'CHECK_COMPANY_CREATION_ITEM': - return { - ...state, - [action.name]: action.checked, - } - case 'INITIALIZE_COMPANY_CREATION_CHECKLIST': - return Object.keys(state).length - ? state - : action.checklistItems.reduce( - (checklist, item) => ({ ...checklist, [item]: false }), - {} - ) - case 'RESET_COMPANY_STATUS_CHOICE': - return {} - default: - return state - } -} - -function companyStatusChoice(state: LegalStatus | null = null, action: Action) { - if (action.type === 'RESET_COMPANY_STATUS_CHOICE') { - return null - } - if (action.type !== 'INITIALIZE_COMPANY_CREATION_CHECKLIST') { - return state - } - - return action.statusName -} - const choixStatutJuridiqueReducer = combineReducers({ - companyLegalStatus, - companyStatusChoice, - companyCreationChecklist, hiringChecklist, }) diff --git a/site/test/companyStatusSelectors.test.js b/site/test/companyStatusSelectors.test.js deleted file mode 100644 index 76b2006a0..000000000 --- a/site/test/companyStatusSelectors.test.js +++ /dev/null @@ -1,103 +0,0 @@ -import { describe, expect, it } from 'vitest' - -import { nextQuestionSelector } from '@/store/selectors/companyStatusSelectors' - -const state = (companyLegalStatus) => ({ - choixStatutJuridique: { - companyLegalStatus, - existingCompany: null, - companyStatusChoice: null, - }, -}) -describe('company status selectors', function () { - describe('nextQuestionSelector', function () { - it('should return null there is only one status possible', () => { - const nextQuestion = nextQuestionSelector( - state({ - soleProprietorship: true, - directorStatus: 'SELF_EMPLOYED', - multipleAssociates: true, - }) - ) - expect(nextQuestion).to.be.equal(null) - }) - it('should not return null if no questions have been answered yet', () => { - const nextQuestion = nextQuestionSelector(state({})) - expect(nextQuestion).not.to.be.equal(null) - }) - it('should return null if all the questions have been answered', () => { - const nextQuestion = nextQuestionSelector( - state({ - soleProprietorship: null, - directorStatus: null, - autoEntrepreneur: null, - multipleAssociates: null, - minorityDirector: null, - }) - ) - expect(nextQuestion).to.be.equal(null) - }) - it('should always return a question that have not been answered yet', () => { - let nextQuestion = nextQuestionSelector( - state({ - directorStatus: null, - multipleAssociates: null, - }) - ) - expect(['directorStatus', 'multipleAssociates']).not.to.contain( - nextQuestion - ) - - nextQuestion = nextQuestionSelector( - state({ - directorStatus: 'SALARIED', - soleProprietorship: false, - }) - ) - expect(['directorStatus', 'soleProprietorship']).not.to.contain( - nextQuestion - ) - - nextQuestion = nextQuestionSelector( - state({ - multipleAssociates: true, - soleProprietorship: false, - }) - ) - expect(['multipleAssociates', 'soleProprietorship']).not.to.contain( - nextQuestion - ) - }) - it('should not return a question which can lead to no matching status', () => { - const nextQuestion = nextQuestionSelector( - state({ - multipleAssociates: true, - minorityDirector: true, - }) - ) - expect(nextQuestion).to.be.equal(null) - }) - it('should return a question if it can help to shrink down the possibilities', () => { - const nextQuestion = nextQuestionSelector( - state({ - soleProprietorship: false, - directorStatus: 'SALARIED', - }) - ) - expect(nextQuestion).not.to.be.equal(null) - }) - - it('should first return the question which convey the most information (which eliminates the most statuses ) ', () => { - const nextQuestion = nextQuestionSelector(state({})) - expect(nextQuestion).to.be.equal('soleProprietorship') - }) - it('should allow to skip question', () => { - const nextQuestion = nextQuestionSelector( - state({ - multipleAssociates: null, - }) - ) - expect(nextQuestion).not.to.be.equal(null) - }) - }) -})