diff --git a/scripts/server.js b/scripts/server.js index f36c086ed29ae13b90654dfbd26074bde88a6dcc..376b0652329d4d8b1fe3245b18e043981b96b269 100644 --- a/scripts/server.js +++ b/scripts/server.js @@ -28,19 +28,19 @@ http const { rawHeaders, httpVersion, method, socket, url } = request const { remoteAddress, remoteFamily } = socket - // console.log( - // JSON.stringify({ - // timestamp: Date.now(), - // processingTime: Date.now() - requestStart, - // rawHeaders, - // errorMessage, - // httpVersion, - // method, - // remoteAddress, - // remoteFamily, - // url, - // }) - // ) + console.log( + JSON.stringify({ + timestamp: Date.now(), + processingTime: Date.now() - requestStart, + rawHeaders, + errorMessage, + httpVersion, + method, + remoteAddress, + remoteFamily, + url, + }) + ) console.log(JSON.parse(body)) }) diff --git a/src/components/Analysis/AnalysisConsumption.tsx b/src/components/Analysis/AnalysisConsumption.tsx index 58c291320d3d4aa67fedf6ec8a7de0189cb13489..d1cb39211d0f574e2e639fedf294999b79f9a52c 100644 --- a/src/components/Analysis/AnalysisConsumption.tsx +++ b/src/components/Analysis/AnalysisConsumption.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useState, Dispatch } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useSelector } from 'react-redux' import { AppStore } from 'store' @@ -11,7 +11,6 @@ import Button from '@material-ui/core/Button' import AnalysisConsumptionRow from 'components/Analysis/AnalysisConsumptionRow' import StyledCard from 'components/CommonKit/Card/StyledCard' import ProfileTypeService from 'services/profileType.service' -import ProfileService from 'services/profile.service' import { Client, useClient } from 'cozy-client' import { DateTime } from 'luxon' import ProfileTypeEntityService from 'services/profileTypeEntity.service' diff --git a/src/components/CommonKit/Spinner/StyledEcogestureSpinner.tsx b/src/components/CommonKit/Spinner/StyledEcogestureSpinner.tsx index 730b367faf5d7480df001d9697b219d8b156961a..6b3957417a8c50fc6d0c9543ee0cfa7ec2dd734e 100644 --- a/src/components/CommonKit/Spinner/StyledEcogestureSpinner.tsx +++ b/src/components/CommonKit/Spinner/StyledEcogestureSpinner.tsx @@ -12,10 +12,10 @@ const SpinnerBase = withStyles({ type StyledSpinnerProps = CircularProgressProps -const StyledSpinner: React.ComponentType<StyledSpinnerProps> = ({ +const StyledEcogestureSpinner: React.ComponentType<StyledSpinnerProps> = ({ ...props }: StyledSpinnerProps) => { return <SpinnerBase {...props} /> } -export default StyledSpinner +export default StyledEcogestureSpinner diff --git a/src/components/Connection/ConnectionFormLogin.tsx b/src/components/Connection/ConnectionFormLogin.tsx index 107bc5e83420a37348413fbbe73601ebc5cab2ee..1882f2481e18c51a029108e7363e12098263baac 100644 --- a/src/components/Connection/ConnectionFormLogin.tsx +++ b/src/components/Connection/ConnectionFormLogin.tsx @@ -3,7 +3,7 @@ import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useClient } from 'cozy-client' import { useDispatch } from 'react-redux' -import { Account, AccountAuthData, FluidStatus, FluidConnection } from 'models' +import { Account, FluidStatus, FluidConnection } from 'models' import AccountService from 'services/account.service' import ConnectionService from 'services/connection.service' @@ -156,7 +156,7 @@ const ConnectionFormLogin: React.FC<ConnectionFormLoginProps> = ({ useEffect(() => { if (account && account.auth) { const auth = account.auth - const authData = auth as AccountAuthData + const authData = auth if (authData.login) { setLogin(authData.login) } diff --git a/src/components/Duel/DuelResultModal.spec.tsx b/src/components/Duel/DuelResultModal.spec.tsx index ab5ba7898d22615ce97482dacdf115362ab60bcd..4970dbcfaab1dd9ba5f6daced1a016aa4a44fe6a 100644 --- a/src/components/Duel/DuelResultModal.spec.tsx +++ b/src/components/Duel/DuelResultModal.spec.tsx @@ -7,7 +7,6 @@ import { profileData } from '../../../tests/__mocks__/profile.mock' import configureStore from 'redux-mock-store' import { act } from 'react-dom/test-utils' -import UsageEventService from 'services/usageEvent.service' import DuelResultModal from './DuelResultModal' jest.mock('cozy-ui/transpiled/react/I18n', () => { diff --git a/src/migrations/migration.service.ts b/src/migrations/migration.service.ts index 1dfcc1f6135cdd7a2378fe8b4d2c3c093f2281ad..d23a0c16d9b5ef36a5237de0d36a9cbf1f01b949 100644 --- a/src/migrations/migration.service.ts +++ b/src/migrations/migration.service.ts @@ -15,10 +15,13 @@ export class MigrationService { log.info('[Migration] Running migrations...') for (const migration of migrations) { // First attempt - const result: MigrationResult = await migrate(migration, this._client) - log.info(migrationLog(migration, result)) + const migrationResult: MigrationResult = await migrate( + migration, + this._client + ) + log.info(migrationLog(migration, migrationResult)) - if (result.type === MIGRATION_RESULT_FAILED) { + if (migrationResult.type === MIGRATION_RESULT_FAILED) { // Retry in case of failure const result = await migrate(migration, this._client) diff --git a/src/services/action.service.ts b/src/services/action.service.ts index 2095ddfedfbf4c92bb582eab5f595378d6a57632..70643ede1a7ed7f100d945bba3e473a9dcf630bc 100644 --- a/src/services/action.service.ts +++ b/src/services/action.service.ts @@ -4,7 +4,7 @@ import { FluidType } from 'enum/fluid.enum' import { UserActionState } from 'enum/userAction.enum' import { UserChallengeUpdateFlag } from 'enum/userChallenge.enum' import { orderBy } from 'lodash' -import { DateTime, Interval } from 'luxon' +import { DateTime } from 'luxon' import { Ecogesture, UserAction, UserChallenge } from 'models' import { getSeason } from 'utils/utils' import ChallengeService from './challenge.service' diff --git a/src/services/profile.service.ts b/src/services/profile.service.ts index 5a8836af36c5c19f7a4c665e83753a28d146e24c..46a43c5c24a708e84dcabd51efebd9fef7616613 100644 --- a/src/services/profile.service.ts +++ b/src/services/profile.service.ts @@ -1,85 +1,69 @@ -import { - Client, - MongoSelector, - Q, - QueryDefinition, - QueryResult, -} from 'cozy-client' -import { Profile, ProfileEntity, ProfileType } from 'models' -import { PROFILETYPE_DOCTYPE, PROFILE_DOCTYPE } from 'doctypes' -import { DateTime } from 'luxon' -import { - ConstructionYear, - Floor, - HotWaterEquipment, - HousingType, - IndividualInsulationWork, - IndividualOrCollective, - OutsideFacingWalls, - ThreeChoicesAnswer, -} from 'enum/profileType.enum' - -export default class ProfileService { - private readonly _client: Client - - constructor(_client: Client) { - this._client = _client - } - /** - * Retrieve Profile from the ProfileEntity - * @param {ProfileEntity} profileEntity - * @returns {Profile} - */ - private parseProfileEntityToProfile(profileEntity: ProfileEntity): Profile { - const profile: Profile = { - ...profileEntity, - haveSeenOldFluidModal: - typeof profileEntity.haveSeenOldFluidModal === 'string' - ? DateTime.fromISO(profileEntity.haveSeenOldFluidModal, { - zone: 'utc', - }) - : profileEntity.haveSeenOldFluidModal, - monthlyAnalysisDate: - typeof profileEntity.monthlyAnalysisDate === 'string' - ? DateTime.fromISO(profileEntity.monthlyAnalysisDate, { - zone: 'utc', - }) - : profileEntity.monthlyAnalysisDate, - lastConnectionDate: DateTime.fromISO(profileEntity.lastConnectionDate, { - zone: 'utc', - }), - } - return profile - } - - public async getProfile(): Promise<Profile | null> { - const query: QueryDefinition = Q(PROFILE_DOCTYPE) - const { - data: [profile], - }: QueryResult<ProfileEntity[]> = await this._client.query(query.limitBy(1)) - const profileEntity: ProfileEntity | null = profile ? profile : null - if (profileEntity) { - return this.parseProfileEntityToProfile(profileEntity) - } - return null - } - - public async updateProfile( - attributes: Partial<Profile> - ): Promise<Profile | null> { - const query: QueryDefinition = Q(PROFILE_DOCTYPE) - const { - data: [doc], - }: QueryResult<ProfileEntity[]> = await this._client.query(query.limitBy(1)) - const { - data: profileEntity, - }: QueryResult<ProfileEntity | null> = await this._client.save({ - ...doc, - ...attributes, - }) - if (profileEntity) { - return this.parseProfileEntityToProfile(profileEntity) - } - return null - } -} +import { Client, Q, QueryDefinition, QueryResult } from 'cozy-client' +import { Profile, ProfileEntity } from 'models' +import { PROFILE_DOCTYPE } from 'doctypes' +import { DateTime } from 'luxon' + +export default class ProfileService { + private readonly _client: Client + + constructor(_client: Client) { + this._client = _client + } + /** + * Retrieve Profile from the ProfileEntity + * @param {ProfileEntity} profileEntity + * @returns {Profile} + */ + private parseProfileEntityToProfile(profileEntity: ProfileEntity): Profile { + const profile: Profile = { + ...profileEntity, + haveSeenOldFluidModal: + typeof profileEntity.haveSeenOldFluidModal === 'string' + ? DateTime.fromISO(profileEntity.haveSeenOldFluidModal, { + zone: 'utc', + }) + : profileEntity.haveSeenOldFluidModal, + monthlyAnalysisDate: + typeof profileEntity.monthlyAnalysisDate === 'string' + ? DateTime.fromISO(profileEntity.monthlyAnalysisDate, { + zone: 'utc', + }) + : profileEntity.monthlyAnalysisDate, + lastConnectionDate: DateTime.fromISO(profileEntity.lastConnectionDate, { + zone: 'utc', + }), + } + return profile + } + + public async getProfile(): Promise<Profile | null> { + const query: QueryDefinition = Q(PROFILE_DOCTYPE) + const { + data: [profile], + }: QueryResult<ProfileEntity[]> = await this._client.query(query.limitBy(1)) + const profileEntity: ProfileEntity | null = profile ? profile : null + if (profileEntity) { + return this.parseProfileEntityToProfile(profileEntity) + } + return null + } + + public async updateProfile( + attributes: Partial<Profile> + ): Promise<Profile | null> { + const query: QueryDefinition = Q(PROFILE_DOCTYPE) + const { + data: [doc], + }: QueryResult<ProfileEntity[]> = await this._client.query(query.limitBy(1)) + const { + data: profileEntity, + }: QueryResult<ProfileEntity | null> = await this._client.save({ + ...doc, + ...attributes, + }) + if (profileEntity) { + return this.parseProfileEntityToProfile(profileEntity) + } + return null + } +} diff --git a/src/services/profileType.service.spec.ts b/src/services/profileType.service.spec.ts index 14e969941c1454872a1f1283daa6d40f636fc726..f3cfb1b0c6b5b3ae3c35ef4940cf8f400d2344dc 100644 --- a/src/services/profileType.service.spec.ts +++ b/src/services/profileType.service.spec.ts @@ -1,455 +1,455 @@ -import { - Floor, - HotWaterEquipment, - HousingType, - IndividualInsulationWork, - IndividualOrCollective, - ProfileTypeStepForm, - ThreeChoicesAnswer, -} from 'enum/profileType.enum' -import { ProfileType } from 'models/profileType.model' -import { - mockCorrectedConsumption, - mockEstimatedConsumption, - mockMonthColdWaterConsumption, - mockMonthConsumption, - mockMonthConsumption1, - mockMonthConsumption2, - mockMonthCookingConsumption, - mockMonthElectricSpecificConsumption, - mockMonthEcsConsumption1Solar, - mockMonthEcsConsumptionOther, - mockMonthEcsConsumptionThermo, - mockProfileType, - mockProfileType1, - mockProfileType2, - mockTestProfile1, - mockTestProfile2, - mockTestProfile3, - mockwaterRawNeeds, - mockWaterSpreadNeeds, - mockMonthlyForecastJanuaryTestProfile1, - mockMonthlyForecastJanuaryTestProfile2, - mockMonthlyForecastJanuaryTestProfile3, - mockProfileTypeAnswers, - mockMonthlyForecastJanuaryTest1WithFullArrays, -} from '../../tests/__mocks__/profileType.mock' -import ProfileTypeService from './profileType.service' -import mockClient from '../../tests/__mocks__/client' -import { DateTime, Settings } from 'luxon' - -const wrongNumber = 99999 -describe('ProfileType service', () => { - const profileTypeService = new ProfileTypeService(mockProfileType, mockClient) - - describe('calculateWarmingEstimatedConsumption', () => { - it('shoud calculate the Warming Estimated Consumption', () => { - const estimatedConsumption = profileTypeService.calculateWarmingEstimatedConsumption() - expect(estimatedConsumption).toEqual(mockEstimatedConsumption) - }) - - it('shoud calculate the Warming Corrected Consumption', () => { - const correctedConsumption = profileTypeService.calculateWarmingCorrectedConsumption( - mockEstimatedConsumption - ) - expect(correctedConsumption).toEqual(mockCorrectedConsumption) - }) - it('shoud calculate the Warming Month Consumption', async () => { - const monthConsumption = await profileTypeService.calculateWarmingMonthConsumption( - mockCorrectedConsumption, - 3 - ) - expect(monthConsumption).toEqual(mockMonthConsumption) - }) - it('shoud get the heating consumption', async () => { - const monthConsumption = await profileTypeService.getMonthHeating(3) - expect(monthConsumption).toEqual(mockMonthConsumption) - }) - }) - describe('shoud get the heating consumption for a flat with collective heating', () => { - const _profileTypeService = new ProfileTypeService( - mockProfileType1, - mockClient - ) - it('shoud get the heating consumption', async () => { - const monthConsumption = await _profileTypeService.getMonthHeating(2) - expect(monthConsumption).toEqual(mockMonthConsumption1) - }) - }) - describe('shoud get the heating consumption for a house with individual heating, facilities, installation and individual work', () => { - const _profileTypeService = new ProfileTypeService( - mockProfileType2, - mockClient - ) - it('shoud get the heating consumption', async () => { - const monthConsumption = await _profileTypeService.getMonthHeating(1) - expect(monthConsumption).toEqual(mockMonthConsumption2) - }) - }) - describe('calculateMonthWaterRawNeeds', () => { - it('shoud calculate the water raw needs consumption by month', () => { - const waterRawNeeds = profileTypeService.calculateMonthWaterRawNeeds( - mockProfileType, - 1 - ) - expect(waterRawNeeds).toEqual(mockwaterRawNeeds) - }) - - it('shoud calculate the water spread needs Consumption', () => { - const waterSpreadNeeds = profileTypeService.calculateSpreadNeeds( - mockProfileType, - 1 - ) - expect(waterSpreadNeeds).toEqual(mockWaterSpreadNeeds) - }) - it('shoud calculate the total ecs consumption by month if profileType.hotWaterEquipment === "solar"', () => { - const monthEcsConsumption = profileTypeService.calculateTotalConsumption( - mockWaterSpreadNeeds, - mockProfileType1, - 1 - ) - expect(monthEcsConsumption).toEqual(mockMonthEcsConsumption1Solar) - }) - it('shoud calculate the total ecs consumption by month if profileType.hotWaterEquipment === "other"', () => { - const mockProfileTypeWithOther = { ...mockProfileType } - mockProfileTypeWithOther.hotWaterEquipment = HotWaterEquipment.OTHER - const monthEcsConsumption = profileTypeService.calculateTotalConsumption( - mockWaterSpreadNeeds, - mockProfileTypeWithOther, - 1 - ) - expect(monthEcsConsumption).toEqual(mockMonthEcsConsumptionOther) - }) - it('shoud get the ECS consumption if profileType.hotWaterEquipment === "thermodynamic"', () => { - const mockProfileTypeWithOther = { ...mockProfileType } - mockProfileTypeWithOther.hotWaterEquipment = - HotWaterEquipment.THERMODYNAMIC - const monthConsumption = profileTypeService.getMonthEcs(1) - expect(monthConsumption).toEqual(mockMonthEcsConsumptionThermo) - }) - - describe('shoud get the month cooking consumption', () => { - it('shoud get the month cooking consumption', () => { - const _profileTypeService = new ProfileTypeService( - mockProfileType, - mockClient - ) - - const monthCookingConsumption = _profileTypeService.getMonthCookingConsumption( - 1 - ) - expect(monthCookingConsumption).toEqual(mockMonthCookingConsumption) - }) - }) - describe('shoud get the month electric specific consumption', () => { - it('shoud get the electric specific consumption', () => { - const _profileTypeService = new ProfileTypeService( - mockProfileType, - mockClient - ) - - const monthElectricSpecificConsumption = _profileTypeService.getMonthElectricSpecificConsumption( - 1 - ) - expect(monthElectricSpecificConsumption).toEqual( - mockMonthElectricSpecificConsumption - ) - }) - }) - describe('shoud get the month cold water consumption', () => { - it('shoud get the cold water consumption', () => { - const _profileTypeService = new ProfileTypeService( - mockProfileType, - mockClient - ) - const monthColdWaterConsumption = _profileTypeService.getMonthColdWaterConsumption( - 1 - ) - expect(monthColdWaterConsumption).toEqual(mockMonthColdWaterConsumption) - }) - }) - }) - describe('shoud get the monthly Forecast', () => { - // For month of january - const profileTypeService1 = new ProfileTypeService( - mockTestProfile1, - mockClient - ) - it('shoud get the monthly forecast for test profile 1', async () => { - const monthlyForecast = await profileTypeService1.getMonthlyForecast(1) - expect(monthlyForecast).toEqual(mockMonthlyForecastJanuaryTestProfile1) - }) - const profileTypeService2 = new ProfileTypeService( - mockTestProfile2, - mockClient - ) - it('shoud get the monthly forecast for test profile 2', async () => { - const monthlyForecast = await profileTypeService2.getMonthlyForecast(1) - expect(monthlyForecast).toEqual(mockMonthlyForecastJanuaryTestProfile2) - }) - const profileTypeService3 = new ProfileTypeService( - mockTestProfile3, - mockClient - ) - it('shoud get the monthly forecast for test profile 3', async () => { - const monthlyForecast = await profileTypeService3.getMonthlyForecast(1) - expect(monthlyForecast).toEqual(mockMonthlyForecastJanuaryTestProfile3) - }) - it('shoud get the monthly forecast for test profile 1 with wall and roof and window insulation', async () => { - const mockProfileWithThreeInsulation: ProfileType = { - ...mockTestProfile1, - individualInsulationWork: [ - IndividualInsulationWork.ROOF_INSULATION, - IndividualInsulationWork.WALL_INSULATION, - IndividualInsulationWork.WINDOW_REPLACEMENT, - ], - hasInstalledVentilation: ThreeChoicesAnswer.YES, - hasReplacedHeater: ThreeChoicesAnswer.YES, - } - const _profileTypeService = new ProfileTypeService( - mockProfileWithThreeInsulation, - mockClient - ) - const monthlyForecast = await _profileTypeService.getMonthlyForecast(1) - expect(monthlyForecast).toEqual( - mockMonthlyForecastJanuaryTest1WithFullArrays - ) - }) - }) - describe('getNextFormStep', () => { - it('shoud get the next step in function of the current step', () => { - let nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.HOUSING_TYPE - ) - expect(nextStep).toEqual(ProfileTypeStepForm.AREA) - nextStep = profileTypeService.getNextFormStep(ProfileTypeStepForm.AREA) - expect(nextStep).toEqual(ProfileTypeStepForm.OCCUPANTS_NUMBER) - - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.OCCUPANTS_NUMBER - ) - expect(nextStep).toEqual(ProfileTypeStepForm.CONSTRUCTION_YEAR) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.CONSTRUCTION_YEAR - ) - expect(nextStep).toEqual(ProfileTypeStepForm.OUTSIDE_FACING_WALLS) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.OUTSIDE_FACING_WALLS - ) - expect(nextStep).toEqual(ProfileTypeStepForm.FLOOR) - nextStep = profileTypeService.getNextFormStep(ProfileTypeStepForm.FLOOR) - expect(nextStep).toEqual(ProfileTypeStepForm.HEATING) - nextStep = profileTypeService.getNextFormStep(ProfileTypeStepForm.HEATING) - expect(nextStep).toEqual(ProfileTypeStepForm.WARMING_FLUID) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.WARMING_FLUID - ) - expect(nextStep).toEqual(ProfileTypeStepForm.VENTILATION) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.VENTILATION - ) - expect(nextStep).toEqual(ProfileTypeStepForm.HEATER_REPLACEMENT) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.HEATER_REPLACEMENT - ) - expect(nextStep).toEqual(ProfileTypeStepForm.COLD_WATER) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.COLD_WATER - ) - expect(nextStep).toEqual(ProfileTypeStepForm.HOT_WATER) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.HOT_WATER - ) - expect(nextStep).toEqual(ProfileTypeStepForm.HOT_WATER_FLUID) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.HOT_WATER_FLUID - ) - expect(nextStep).toEqual(ProfileTypeStepForm.HOT_WATER_EQUIPMENT) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.HOT_WATER_EQUIPMENT - ) - expect(nextStep).toEqual(ProfileTypeStepForm.COOKING_FLUID) - nextStep = profileTypeService.getNextFormStep( - ProfileTypeStepForm.COOKING_FLUID - ) - expect(nextStep).toEqual(ProfileTypeStepForm.END) - nextStep = profileTypeService.getNextFormStep(wrongNumber) - expect(nextStep).toEqual(ProfileTypeStepForm.HOUSING_TYPE) - }) - }) - describe('getPreviousFormStep', () => { - it('shoud get the previus step in function of the current step', () => { - let previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.AREA - ) - expect(previousStep).toEqual(ProfileTypeStepForm.HOUSING_TYPE) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.OCCUPANTS_NUMBER - ) - expect(previousStep).toEqual(ProfileTypeStepForm.AREA) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.CONSTRUCTION_YEAR - ) - expect(previousStep).toEqual(ProfileTypeStepForm.OCCUPANTS_NUMBER) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.OUTSIDE_FACING_WALLS - ) - expect(previousStep).toEqual(ProfileTypeStepForm.CONSTRUCTION_YEAR) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.FLOOR - ) - expect(previousStep).toEqual(ProfileTypeStepForm.OUTSIDE_FACING_WALLS) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.HEATING - ) - expect(previousStep).toEqual(ProfileTypeStepForm.FLOOR) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.WARMING_FLUID - ) - expect(previousStep).toEqual(ProfileTypeStepForm.HEATING) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.INDIVIDUAL_INSULATION_WORK - ) - expect(previousStep).toEqual(ProfileTypeStepForm.WARMING_FLUID) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.VENTILATION - ) - expect(previousStep).toEqual(ProfileTypeStepForm.WARMING_FLUID) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.HEATER_REPLACEMENT - ) - expect(previousStep).toEqual(ProfileTypeStepForm.VENTILATION) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.HOT_WATER - ) - expect(previousStep).toEqual(ProfileTypeStepForm.COLD_WATER) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.HOT_WATER_FLUID - ) - expect(previousStep).toEqual(ProfileTypeStepForm.HOT_WATER) - - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.HOT_WATER_EQUIPMENT - ) - expect(previousStep).toEqual(ProfileTypeStepForm.HOT_WATER_FLUID) - previousStep = profileTypeService.getPreviousFormStep( - ProfileTypeStepForm.COOKING_FLUID - ) - expect(previousStep).toEqual(ProfileTypeStepForm.HOT_WATER_EQUIPMENT) - previousStep = profileTypeService.getPreviousFormStep(wrongNumber) - expect(previousStep).toEqual(ProfileTypeStepForm.HOUSING_TYPE) - }) - }) - describe('getAnswerForStep', () => { - it('shoud get the good answers in function of the current step', () => { - let answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.HOUSING_TYPE - ) - expect(answers).toEqual(mockProfileTypeAnswers[0]) - answers = ProfileTypeService.getAnswerForStep(ProfileTypeStepForm.AREA) - expect(answers).toEqual(mockProfileTypeAnswers[1]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.OCCUPANTS_NUMBER - ) - expect(answers).toEqual(mockProfileTypeAnswers[2]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.CONSTRUCTION_YEAR - ) - expect(answers).toEqual(mockProfileTypeAnswers[3]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.OUTSIDE_FACING_WALLS - ) - expect(answers).toEqual(mockProfileTypeAnswers[4]) - answers = ProfileTypeService.getAnswerForStep(ProfileTypeStepForm.FLOOR) - expect(answers).toEqual(mockProfileTypeAnswers[5]) - answers = ProfileTypeService.getAnswerForStep(ProfileTypeStepForm.HEATING) - expect(answers).toEqual(mockProfileTypeAnswers[6]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.WARMING_FLUID - ) - expect(answers).toEqual(mockProfileTypeAnswers[7]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.INDIVIDUAL_INSULATION_WORK - ) - expect(answers).toEqual(mockProfileTypeAnswers[8]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.VENTILATION - ) - expect(answers).toEqual(mockProfileTypeAnswers[9]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.HEATER_REPLACEMENT - ) - expect(answers).toEqual(mockProfileTypeAnswers[10]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.COLD_WATER - ) - expect(answers).toEqual(mockProfileTypeAnswers[11]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.HOT_WATER - ) - expect(answers).toEqual(mockProfileTypeAnswers[12]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.HOT_WATER_FLUID - ) - expect(answers).toEqual(mockProfileTypeAnswers[13]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.HOT_WATER_EQUIPMENT - ) - expect(answers).toEqual(mockProfileTypeAnswers[14]) - answers = ProfileTypeService.getAnswerForStep( - ProfileTypeStepForm.COOKING_FLUID - ) - expect(answers).toEqual(mockProfileTypeAnswers[15]) - answers = ProfileTypeService.getAnswerForStep(wrongNumber) - expect(answers).toEqual(mockProfileTypeAnswers[16]) - }) - }) - describe('checkConsistency', () => { - it('shoud return consistent profile for individual house', () => { - const mockProfile = { - ...mockProfileType1, - housingType: HousingType.INDIVIDUAL_HOUSE, - } - jest - .spyOn(DateTime, 'local') - .mockReturnValueOnce( - DateTime.fromISO('2021-01-01T00:00:00.000Z', { zone: 'utc' }) - ) - - const expectedResult = { - ...mockProfile, - floor: Floor.NOT_APPLICABLE, - heating: IndividualOrCollective.INDIVIDUAL, - coldWater: IndividualOrCollective.INDIVIDUAL, - hotWater: IndividualOrCollective.INDIVIDUAL, - } - const result = ProfileTypeService.checkConsistency(mockProfile) - expect(result).toEqual(expectedResult) - }) - it('shoud return consistent profile for appartment', () => { - const mockProfile = mockProfileType1 - jest - .spyOn(DateTime, 'local') - .mockReturnValueOnce( - DateTime.fromISO('2021-01-01T00:00:00.000Z', { zone: 'utc' }) - ) - - const expectedResult = { - ...mockProfile, - warmingFluid: null, - individualInsulationWork: [], - facilitiesInstallation: [], - hotWaterFluid: null, - hotWaterEquipment: HotWaterEquipment.OTHER, - } - const result = ProfileTypeService.checkConsistency(mockProfile) - expect(result).toEqual(expectedResult) - }) - }) - describe('getDjU', () => { - it('shoud return default dju', async () => { - const result = await profileTypeService.fetchDJU(2) - expect(result).toEqual(363) - }) - }) -}) +import { + Floor, + HotWaterEquipment, + HousingType, + IndividualInsulationWork, + IndividualOrCollective, + ProfileTypeStepForm, + ThreeChoicesAnswer, +} from 'enum/profileType.enum' +import { ProfileType } from 'models/profileType.model' +import { + mockCorrectedConsumption, + mockEstimatedConsumption, + mockMonthColdWaterConsumption, + mockMonthConsumption, + mockMonthConsumption1, + mockMonthConsumption2, + mockMonthCookingConsumption, + mockMonthElectricSpecificConsumption, + mockMonthEcsConsumption1Solar, + mockMonthEcsConsumptionOther, + mockMonthEcsConsumptionThermo, + mockProfileType, + mockProfileType1, + mockProfileType2, + mockTestProfile1, + mockTestProfile2, + mockTestProfile3, + mockwaterRawNeeds, + mockWaterSpreadNeeds, + mockMonthlyForecastJanuaryTestProfile1, + mockMonthlyForecastJanuaryTestProfile2, + mockMonthlyForecastJanuaryTestProfile3, + mockProfileTypeAnswers, + mockMonthlyForecastJanuaryTest1WithFullArrays, +} from '../../tests/__mocks__/profileType.mock' +import ProfileTypeService from './profileType.service' +import mockClient from '../../tests/__mocks__/client' +import { DateTime } from 'luxon' + +const wrongNumber = 99999 +describe('ProfileType service', () => { + const profileTypeService = new ProfileTypeService(mockProfileType, mockClient) + + describe('calculateWarmingEstimatedConsumption', () => { + it('shoud calculate the Warming Estimated Consumption', () => { + const estimatedConsumption = profileTypeService.calculateWarmingEstimatedConsumption() + expect(estimatedConsumption).toEqual(mockEstimatedConsumption) + }) + + it('shoud calculate the Warming Corrected Consumption', () => { + const correctedConsumption = profileTypeService.calculateWarmingCorrectedConsumption( + mockEstimatedConsumption + ) + expect(correctedConsumption).toEqual(mockCorrectedConsumption) + }) + it('shoud calculate the Warming Month Consumption', async () => { + const monthConsumption = await profileTypeService.calculateWarmingMonthConsumption( + mockCorrectedConsumption, + 3 + ) + expect(monthConsumption).toEqual(mockMonthConsumption) + }) + it('shoud get the heating consumption', async () => { + const monthConsumption = await profileTypeService.getMonthHeating(3) + expect(monthConsumption).toEqual(mockMonthConsumption) + }) + }) + describe('shoud get the heating consumption for a flat with collective heating', () => { + const _profileTypeService = new ProfileTypeService( + mockProfileType1, + mockClient + ) + it('shoud get the heating consumption', async () => { + const monthConsumption = await _profileTypeService.getMonthHeating(2) + expect(monthConsumption).toEqual(mockMonthConsumption1) + }) + }) + describe('shoud get the heating consumption for a house with individual heating, facilities, installation and individual work', () => { + const _profileTypeService = new ProfileTypeService( + mockProfileType2, + mockClient + ) + it('shoud get the heating consumption', async () => { + const monthConsumption = await _profileTypeService.getMonthHeating(1) + expect(monthConsumption).toEqual(mockMonthConsumption2) + }) + }) + describe('calculateMonthWaterRawNeeds', () => { + it('shoud calculate the water raw needs consumption by month', () => { + const waterRawNeeds = profileTypeService.calculateMonthWaterRawNeeds( + mockProfileType, + 1 + ) + expect(waterRawNeeds).toEqual(mockwaterRawNeeds) + }) + + it('shoud calculate the water spread needs Consumption', () => { + const waterSpreadNeeds = profileTypeService.calculateSpreadNeeds( + mockProfileType, + 1 + ) + expect(waterSpreadNeeds).toEqual(mockWaterSpreadNeeds) + }) + it('shoud calculate the total ecs consumption by month if profileType.hotWaterEquipment === "solar"', () => { + const monthEcsConsumption = profileTypeService.calculateTotalConsumption( + mockWaterSpreadNeeds, + mockProfileType1, + 1 + ) + expect(monthEcsConsumption).toEqual(mockMonthEcsConsumption1Solar) + }) + it('shoud calculate the total ecs consumption by month if profileType.hotWaterEquipment === "other"', () => { + const mockProfileTypeWithOther = { ...mockProfileType } + mockProfileTypeWithOther.hotWaterEquipment = HotWaterEquipment.OTHER + const monthEcsConsumption = profileTypeService.calculateTotalConsumption( + mockWaterSpreadNeeds, + mockProfileTypeWithOther, + 1 + ) + expect(monthEcsConsumption).toEqual(mockMonthEcsConsumptionOther) + }) + it('shoud get the ECS consumption if profileType.hotWaterEquipment === "thermodynamic"', () => { + const mockProfileTypeWithOther = { ...mockProfileType } + mockProfileTypeWithOther.hotWaterEquipment = + HotWaterEquipment.THERMODYNAMIC + const monthConsumption = profileTypeService.getMonthEcs(1) + expect(monthConsumption).toEqual(mockMonthEcsConsumptionThermo) + }) + + describe('shoud get the month cooking consumption', () => { + it('shoud get the month cooking consumption', () => { + const _profileTypeService = new ProfileTypeService( + mockProfileType, + mockClient + ) + + const monthCookingConsumption = _profileTypeService.getMonthCookingConsumption( + 1 + ) + expect(monthCookingConsumption).toEqual(mockMonthCookingConsumption) + }) + }) + describe('shoud get the month electric specific consumption', () => { + it('shoud get the electric specific consumption', () => { + const _profileTypeService = new ProfileTypeService( + mockProfileType, + mockClient + ) + + const monthElectricSpecificConsumption = _profileTypeService.getMonthElectricSpecificConsumption( + 1 + ) + expect(monthElectricSpecificConsumption).toEqual( + mockMonthElectricSpecificConsumption + ) + }) + }) + describe('shoud get the month cold water consumption', () => { + it('shoud get the cold water consumption', () => { + const _profileTypeService = new ProfileTypeService( + mockProfileType, + mockClient + ) + const monthColdWaterConsumption = _profileTypeService.getMonthColdWaterConsumption( + 1 + ) + expect(monthColdWaterConsumption).toEqual(mockMonthColdWaterConsumption) + }) + }) + }) + describe('shoud get the monthly Forecast', () => { + // For month of january + const profileTypeService1 = new ProfileTypeService( + mockTestProfile1, + mockClient + ) + it('shoud get the monthly forecast for test profile 1', async () => { + const monthlyForecast = await profileTypeService1.getMonthlyForecast(1) + expect(monthlyForecast).toEqual(mockMonthlyForecastJanuaryTestProfile1) + }) + const profileTypeService2 = new ProfileTypeService( + mockTestProfile2, + mockClient + ) + it('shoud get the monthly forecast for test profile 2', async () => { + const monthlyForecast = await profileTypeService2.getMonthlyForecast(1) + expect(monthlyForecast).toEqual(mockMonthlyForecastJanuaryTestProfile2) + }) + const profileTypeService3 = new ProfileTypeService( + mockTestProfile3, + mockClient + ) + it('shoud get the monthly forecast for test profile 3', async () => { + const monthlyForecast = await profileTypeService3.getMonthlyForecast(1) + expect(monthlyForecast).toEqual(mockMonthlyForecastJanuaryTestProfile3) + }) + it('shoud get the monthly forecast for test profile 1 with wall and roof and window insulation', async () => { + const mockProfileWithThreeInsulation: ProfileType = { + ...mockTestProfile1, + individualInsulationWork: [ + IndividualInsulationWork.ROOF_INSULATION, + IndividualInsulationWork.WALL_INSULATION, + IndividualInsulationWork.WINDOW_REPLACEMENT, + ], + hasInstalledVentilation: ThreeChoicesAnswer.YES, + hasReplacedHeater: ThreeChoicesAnswer.YES, + } + const _profileTypeService = new ProfileTypeService( + mockProfileWithThreeInsulation, + mockClient + ) + const monthlyForecast = await _profileTypeService.getMonthlyForecast(1) + expect(monthlyForecast).toEqual( + mockMonthlyForecastJanuaryTest1WithFullArrays + ) + }) + }) + describe('getNextFormStep', () => { + it('shoud get the next step in function of the current step', () => { + let nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.HOUSING_TYPE + ) + expect(nextStep).toEqual(ProfileTypeStepForm.AREA) + nextStep = profileTypeService.getNextFormStep(ProfileTypeStepForm.AREA) + expect(nextStep).toEqual(ProfileTypeStepForm.OCCUPANTS_NUMBER) + + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.OCCUPANTS_NUMBER + ) + expect(nextStep).toEqual(ProfileTypeStepForm.CONSTRUCTION_YEAR) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.CONSTRUCTION_YEAR + ) + expect(nextStep).toEqual(ProfileTypeStepForm.OUTSIDE_FACING_WALLS) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.OUTSIDE_FACING_WALLS + ) + expect(nextStep).toEqual(ProfileTypeStepForm.FLOOR) + nextStep = profileTypeService.getNextFormStep(ProfileTypeStepForm.FLOOR) + expect(nextStep).toEqual(ProfileTypeStepForm.HEATING) + nextStep = profileTypeService.getNextFormStep(ProfileTypeStepForm.HEATING) + expect(nextStep).toEqual(ProfileTypeStepForm.WARMING_FLUID) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.WARMING_FLUID + ) + expect(nextStep).toEqual(ProfileTypeStepForm.VENTILATION) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.VENTILATION + ) + expect(nextStep).toEqual(ProfileTypeStepForm.HEATER_REPLACEMENT) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.HEATER_REPLACEMENT + ) + expect(nextStep).toEqual(ProfileTypeStepForm.COLD_WATER) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.COLD_WATER + ) + expect(nextStep).toEqual(ProfileTypeStepForm.HOT_WATER) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.HOT_WATER + ) + expect(nextStep).toEqual(ProfileTypeStepForm.HOT_WATER_FLUID) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.HOT_WATER_FLUID + ) + expect(nextStep).toEqual(ProfileTypeStepForm.HOT_WATER_EQUIPMENT) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.HOT_WATER_EQUIPMENT + ) + expect(nextStep).toEqual(ProfileTypeStepForm.COOKING_FLUID) + nextStep = profileTypeService.getNextFormStep( + ProfileTypeStepForm.COOKING_FLUID + ) + expect(nextStep).toEqual(ProfileTypeStepForm.END) + nextStep = profileTypeService.getNextFormStep(wrongNumber) + expect(nextStep).toEqual(ProfileTypeStepForm.HOUSING_TYPE) + }) + }) + describe('getPreviousFormStep', () => { + it('shoud get the previus step in function of the current step', () => { + let previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.AREA + ) + expect(previousStep).toEqual(ProfileTypeStepForm.HOUSING_TYPE) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.OCCUPANTS_NUMBER + ) + expect(previousStep).toEqual(ProfileTypeStepForm.AREA) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.CONSTRUCTION_YEAR + ) + expect(previousStep).toEqual(ProfileTypeStepForm.OCCUPANTS_NUMBER) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.OUTSIDE_FACING_WALLS + ) + expect(previousStep).toEqual(ProfileTypeStepForm.CONSTRUCTION_YEAR) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.FLOOR + ) + expect(previousStep).toEqual(ProfileTypeStepForm.OUTSIDE_FACING_WALLS) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.HEATING + ) + expect(previousStep).toEqual(ProfileTypeStepForm.FLOOR) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.WARMING_FLUID + ) + expect(previousStep).toEqual(ProfileTypeStepForm.HEATING) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.INDIVIDUAL_INSULATION_WORK + ) + expect(previousStep).toEqual(ProfileTypeStepForm.WARMING_FLUID) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.VENTILATION + ) + expect(previousStep).toEqual(ProfileTypeStepForm.WARMING_FLUID) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.HEATER_REPLACEMENT + ) + expect(previousStep).toEqual(ProfileTypeStepForm.VENTILATION) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.HOT_WATER + ) + expect(previousStep).toEqual(ProfileTypeStepForm.COLD_WATER) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.HOT_WATER_FLUID + ) + expect(previousStep).toEqual(ProfileTypeStepForm.HOT_WATER) + + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.HOT_WATER_EQUIPMENT + ) + expect(previousStep).toEqual(ProfileTypeStepForm.HOT_WATER_FLUID) + previousStep = profileTypeService.getPreviousFormStep( + ProfileTypeStepForm.COOKING_FLUID + ) + expect(previousStep).toEqual(ProfileTypeStepForm.HOT_WATER_EQUIPMENT) + previousStep = profileTypeService.getPreviousFormStep(wrongNumber) + expect(previousStep).toEqual(ProfileTypeStepForm.HOUSING_TYPE) + }) + }) + describe('getAnswerForStep', () => { + it('shoud get the good answers in function of the current step', () => { + let answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.HOUSING_TYPE + ) + expect(answers).toEqual(mockProfileTypeAnswers[0]) + answers = ProfileTypeService.getAnswerForStep(ProfileTypeStepForm.AREA) + expect(answers).toEqual(mockProfileTypeAnswers[1]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.OCCUPANTS_NUMBER + ) + expect(answers).toEqual(mockProfileTypeAnswers[2]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.CONSTRUCTION_YEAR + ) + expect(answers).toEqual(mockProfileTypeAnswers[3]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.OUTSIDE_FACING_WALLS + ) + expect(answers).toEqual(mockProfileTypeAnswers[4]) + answers = ProfileTypeService.getAnswerForStep(ProfileTypeStepForm.FLOOR) + expect(answers).toEqual(mockProfileTypeAnswers[5]) + answers = ProfileTypeService.getAnswerForStep(ProfileTypeStepForm.HEATING) + expect(answers).toEqual(mockProfileTypeAnswers[6]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.WARMING_FLUID + ) + expect(answers).toEqual(mockProfileTypeAnswers[7]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.INDIVIDUAL_INSULATION_WORK + ) + expect(answers).toEqual(mockProfileTypeAnswers[8]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.VENTILATION + ) + expect(answers).toEqual(mockProfileTypeAnswers[9]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.HEATER_REPLACEMENT + ) + expect(answers).toEqual(mockProfileTypeAnswers[10]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.COLD_WATER + ) + expect(answers).toEqual(mockProfileTypeAnswers[11]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.HOT_WATER + ) + expect(answers).toEqual(mockProfileTypeAnswers[12]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.HOT_WATER_FLUID + ) + expect(answers).toEqual(mockProfileTypeAnswers[13]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.HOT_WATER_EQUIPMENT + ) + expect(answers).toEqual(mockProfileTypeAnswers[14]) + answers = ProfileTypeService.getAnswerForStep( + ProfileTypeStepForm.COOKING_FLUID + ) + expect(answers).toEqual(mockProfileTypeAnswers[15]) + answers = ProfileTypeService.getAnswerForStep(wrongNumber) + expect(answers).toEqual(mockProfileTypeAnswers[16]) + }) + }) + describe('checkConsistency', () => { + it('shoud return consistent profile for individual house', () => { + const mockProfile = { + ...mockProfileType1, + housingType: HousingType.INDIVIDUAL_HOUSE, + } + jest + .spyOn(DateTime, 'local') + .mockReturnValueOnce( + DateTime.fromISO('2021-01-01T00:00:00.000Z', { zone: 'utc' }) + ) + + const expectedResult = { + ...mockProfile, + floor: Floor.NOT_APPLICABLE, + heating: IndividualOrCollective.INDIVIDUAL, + coldWater: IndividualOrCollective.INDIVIDUAL, + hotWater: IndividualOrCollective.INDIVIDUAL, + } + const result = ProfileTypeService.checkConsistency(mockProfile) + expect(result).toEqual(expectedResult) + }) + it('shoud return consistent profile for appartment', () => { + const mockProfile = mockProfileType1 + jest + .spyOn(DateTime, 'local') + .mockReturnValueOnce( + DateTime.fromISO('2021-01-01T00:00:00.000Z', { zone: 'utc' }) + ) + + const expectedResult = { + ...mockProfile, + warmingFluid: null, + individualInsulationWork: [], + facilitiesInstallation: [], + hotWaterFluid: null, + hotWaterEquipment: HotWaterEquipment.OTHER, + } + const result = ProfileTypeService.checkConsistency(mockProfile) + expect(result).toEqual(expectedResult) + }) + }) + describe('getDjU', () => { + it('shoud return default dju', async () => { + const result = await profileTypeService.fetchDJU(2) + expect(result).toEqual(363) + }) + }) +}) diff --git a/src/services/profileType.service.ts b/src/services/profileType.service.ts index 4f821ec4a97b96ee1de79734f712caa10353595f..3752202924a9c202ffa7e5ec98ae16220c487d47 100644 --- a/src/services/profileType.service.ts +++ b/src/services/profileType.service.ts @@ -25,7 +25,7 @@ import { } from 'enum/profileType.enum' import { FluidType } from 'enum/fluid.enum' import ConverterService from './converter.service' -import { Client, Q, QueryDefinition, QueryResult } from 'cozy-client' +import { Client } from 'cozy-client' export default class ProfileTypeService { private readonly profileType: ProfileType diff --git a/src/services/profileTypeForm.ts b/src/services/profileTypeForm.ts index ab91f4799c34e4972c7de7980e8cd19924817f7a..52cce991f384c83988796aad287d7b0328f0e673 100644 --- a/src/services/profileTypeForm.ts +++ b/src/services/profileTypeForm.ts @@ -5,7 +5,6 @@ import { ProfileTypeStepForm, } from 'enum/profileType.enum' import { ProfileType } from 'models' -import { ProfileTypeActionTypes } from 'store/profileType/profileType.actions' export default class ProfileTypeFormService { private readonly profileType: ProfileType diff --git a/src/store/profileType/profileType.reducer.ts b/src/store/profileType/profileType.reducer.ts index f2655093811176a75f28de29d0c6d37fbd83148c..82e67620524ac41c4a24efd9854106b8d0c0e6d4 100644 --- a/src/store/profileType/profileType.reducer.ts +++ b/src/store/profileType/profileType.reducer.ts @@ -47,10 +47,6 @@ export const profileTypeReducer: Reducer<ProfileType> = ( ): ProfileType => { switch (action.type) { case UPDATE_PROFILETYPE: - return { - ...state, - ...action.payload, - } case CREATE_NEW_PROFILETYPE: return { ...state,