diff --git a/src/services/action.service.spec.ts b/src/services/action.service.spec.ts index 0b3d54e5f8e3523596bddbdbf3ab1fe37c42ad6d..01e769596b9fb367e39f479054f76e55b6ffa758 100644 --- a/src/services/action.service.spec.ts +++ b/src/services/action.service.spec.ts @@ -35,14 +35,14 @@ jest.mock('./ecogesture.service', () => { describe('Action Service', () => { const actionService = new ActionService(mockClient) - it('shoud return the default actions', async () => { + it('should return the default actions', async () => { mockgetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) mockgetEcogesturesByIds.mockResolvedValueOnce(defaultEcogestureData) const result: Ecogesture[] = await actionService.getDefaultActions() expect(result).toEqual(defaultEcogestureData) }) - it('shoud return the Available Action List', async () => { + it('should return the Available Action List', async () => { mockgetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) mockgetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) mockgetEcogesturesByIds.mockResolvedValueOnce([ @@ -58,7 +58,7 @@ describe('Action Service', () => { AllEcogestureData[4], ]) }) - it('shoud return winter ecogestures', () => { + it('should return winter ecogestures', () => { jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.WINTER) const result: Ecogesture[] = actionService.filterBySeason(AllEcogestureData) expect(result).toEqual([ @@ -67,13 +67,13 @@ describe('Action Service', () => { AllEcogestureData[5], ]) }) - it('shoud return no season ecogestures', () => { + it('should return no season ecogestures', () => { jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.NONE) const result: Ecogesture[] = actionService.filterBySeason(AllEcogestureData) expect(result).toEqual([AllEcogestureData[3], AllEcogestureData[4]]) }) - it('shoud return summer ecogestures', () => { + it('should return summer ecogestures', () => { jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.SUMMER) const result: Ecogesture[] = actionService.filterBySeason(AllEcogestureData) @@ -84,7 +84,7 @@ describe('Action Service', () => { ]) }) - it('shoud launch an action', () => { + it('should launch an action', () => { jest .spyOn(DateTime, 'local') .mockReturnValueOnce( @@ -119,7 +119,7 @@ describe('Action Service', () => { }) describe('getCustomActions function', () => { - it('shoud return filtered and sorted ecogestures and not complete the list', async () => { + it('should return filtered and sorted ecogestures and not complete the list', async () => { jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.WINTER) mockgetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) mockgetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) @@ -139,7 +139,7 @@ describe('Action Service', () => { AllEcogestureData[2], ]) }) - it('shoud return filtered and sorted ecogestures and complete the list with default ecogesture', async () => { + it('should return filtered and sorted ecogestures and complete the list with default ecogesture', async () => { jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.WINTER) mockgetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) mockgetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) diff --git a/src/services/connection.service.spec.ts b/src/services/connection.service.spec.ts index c2a73b9eb3460706591f67b62da3a683c8bb0012..8c44725272f38aa4d98c836e9a6a91ae78cdd410 100644 --- a/src/services/connection.service.spec.ts +++ b/src/services/connection.service.spec.ts @@ -35,7 +35,7 @@ describe('Connection service', () => { const connectionService = new ConnectionService(mockClient) describe('connectNewUser method', () => { - it('shoud return created Trigger', async () => { + it('should return created Trigger', async () => { mockGetKonnector.mockResolvedValueOnce(konnectorsData[0]) mockCreateAccount.mockResolvedValueOnce(accountsData[0]) mockCreateTrigger.mockResolvedValueOnce(triggersData[0]) @@ -48,7 +48,7 @@ describe('Connection service', () => { expect(result).toEqual(mockResult) }) - it('shoud throw error when konnector is not found', async () => { + it('should throw error when konnector is not found', async () => { let error try { await connectionService.connectNewUser( @@ -64,7 +64,7 @@ describe('Connection service', () => { ) }) - it('shoud throw error when account is not created', async () => { + it('should throw error when account is not created', async () => { mockGetKonnector.mockResolvedValueOnce(konnectorsData[0]) let error try { @@ -79,7 +79,7 @@ describe('Connection service', () => { expect(error).toEqual(new Error(`Error during account creation`)) }) - it('shoud throw error when trigger is not created', async () => { + it('should throw error when trigger is not created', async () => { mockGetKonnector.mockResolvedValueOnce(konnectorsData[0]) mockCreateAccount.mockResolvedValueOnce(accountsData[0]) let error diff --git a/src/services/consumption.service.spec.ts b/src/services/consumption.service.spec.ts index ed1c14666e930f3cfba592870cb988f8675ad93f..8d1fab9f92a92ad18ceac84b7e9fcd5feb4154cf 100644 --- a/src/services/consumption.service.spec.ts +++ b/src/services/consumption.service.spec.ts @@ -66,7 +66,7 @@ describe('Consumption service', () => { ) expect(result).toBeNull() }) - it('shoud return a mapped data for one fluid', async () => { + it('should return a mapped data for one fluid', async () => { mockFetchFluidData.mockResolvedValueOnce(mockFetchDataActual) mockFetchFluidData.mockResolvedValueOnce(mockFetchDataComparison) const mockResult = { @@ -241,7 +241,7 @@ describe('Consumption service', () => { }) }) describe('getMaxLoad method', () => { - it('shoud return the maxed value for a time period for the home', async () => { + it('should return the maxed value for a time period for the home', async () => { for (let i = 0; i < fluidTypes.length; i++) { mockFetchFluidData.mockResolvedValueOnce(mockFetchDataActual) mockFetchFluidData.mockResolvedValueOnce(mockFetchDataComparison) @@ -256,7 +256,7 @@ describe('Consumption service', () => { ) expect(result).toEqual(expectedResult) }) - it('shoud return the maxed value for a time period', async () => { + it('should return the maxed value for a time period', async () => { const mockFluidTypes = [1] const expectedResult = 63.1254 mockFetchFluidMaxData.mockResolvedValueOnce(expectedResult) @@ -271,7 +271,7 @@ describe('Consumption service', () => { }) }) describe('getPerformanceIndicators method', () => { - it('shoud return the performance indicator', async () => { + it('should return the performance indicator', async () => { mockFetchFluidData.mockResolvedValueOnce(mockFetchDataActual) mockFetchFluidData.mockResolvedValueOnce(mockFetchDataComparison) mockFetchFluidData.mockResolvedValueOnce(mockFetchDataActual) @@ -321,7 +321,7 @@ describe('Consumption service', () => { }) }) describe('fetchLastDateData method', () => { - it('shoud return the latest date data of one fluid', async () => { + it('should return the latest date data of one fluid', async () => { const mockFluidTypes = [0] const expectedResult = DateTime.fromISO('2020-09-03T23:59:59.999Z') mockGetLastDateData.mockResolvedValueOnce( @@ -332,7 +332,7 @@ describe('Consumption service', () => { ) expect(result).toEqual(expectedResult) }) - it('shoud return the latest date data of multiple fluid', async () => { + it('should return the latest date data of multiple fluid', async () => { const mockFluidTypes = [0, 2] mockGetLastDateData.mockResolvedValueOnce( DateTime.fromISO('2020-09-03T23:59:59.999Z') @@ -346,7 +346,7 @@ describe('Consumption service', () => { ) expect(result).toEqual(expectedResult) }) - it('shoud return the latest date data of all fluids', async () => { + it('should return the latest date data of all fluids', async () => { mockGetLastDateData.mockResolvedValueOnce( DateTime.fromISO('2020-09-02T23:59:59.999Z') ) @@ -365,7 +365,7 @@ describe('Consumption service', () => { }) }) describe('fetchAllLastDateData method', () => { - it('shoud return the latest date data of one fluid', async () => { + it('should return the latest date data of one fluid', async () => { const mockFluidTypes = [0] const expectedResult = [DateTime.fromISO('2020-09-03T23:59:59.999Z')] mockGetLastDateData.mockResolvedValueOnce( @@ -376,7 +376,7 @@ describe('Consumption service', () => { ) expect(result).toEqual(expectedResult) }) - it('shoud return the latest date data of All fluid', async () => { + it('should return the latest date data of All fluid', async () => { mockGetLastDateData.mockResolvedValueOnce( DateTime.fromISO('2020-09-02T23:59:59.999Z') ) @@ -398,7 +398,7 @@ describe('Consumption service', () => { }) }) describe('checkDoctypeEntries method', () => { - it('shoud return a boolean if doctype are correct', async () => { + it('should return a boolean if doctype are correct', async () => { let fluidType = 2 mockGetEntries.mockResolvedValueOnce({ data: [1] }) let result = await consumptionDataManager.checkDoctypeEntries( diff --git a/src/services/consumptionFormatter.service.spec.ts b/src/services/consumptionFormatter.service.spec.ts index efd1b69ef0effd0812fad23ceaff230b55696cb5..420129fa314891de5e828bc567d9ecf52bdcfb89 100644 --- a/src/services/consumptionFormatter.service.spec.ts +++ b/src/services/consumptionFormatter.service.spec.ts @@ -59,7 +59,7 @@ const unknowTimeStep = 999 describe('ConsumptionFormatter service', () => { const consumptionFormatterService = new ConsumptionFormatterService() describe('formatGraphData method', () => { - it('shoud return a formattedData for DAY', () => { + it('should return a formattedData for DAY', () => { const mockResult = [ { date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { @@ -90,7 +90,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toEqual(mockResult) }) - it('shoud return a formattedData for HALF_AN_HOUR', () => { + it('should return a formattedData for HALF_AN_HOUR', () => { mockTimePeriod = { startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', @@ -130,7 +130,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toEqual(mockResult) }) - it('shoud return a formattedData for MONTH', () => { + it('should return a formattedData for MONTH', () => { mockTimePeriod = { startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', @@ -170,7 +170,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toEqual(mockResult) }) - it('shoud return a formattedData for YEAR', () => { + it('should return a formattedData for YEAR', () => { mockTimePeriod = { startDate: DateTime.fromISO('2018-10-01T00:00:00.000Z', { zone: 'utc', @@ -210,7 +210,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toEqual(mockResult) }) - it('shoud return an error because of unknown TimeStep', () => { + it('should return an error because of unknown TimeStep', () => { try { consumptionFormatterService.formatGraphData( mockDataLoad, diff --git a/src/services/consumptionValidator.service.spec.ts b/src/services/consumptionValidator.service.spec.ts index 24845a1ab460c46d5a5372a803e8649f3e768c51..41aee67ea568051b34b999f90c11d3bc4aefb262 100644 --- a/src/services/consumptionValidator.service.spec.ts +++ b/src/services/consumptionValidator.service.spec.ts @@ -16,7 +16,7 @@ let fluidTypes: FluidType[] = [0, 1, 2] describe('ConsumptionFormatter service', () => { const consumptionValidatorService = new ConsumptionValidatorService() describe('formatGraphData method', () => { - it('shoud return true for DAY', () => { + it('should return true for DAY', () => { const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriod, TimeStep.DAY, @@ -24,7 +24,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeTruthy() }) - it('shoud return true with comparison Date', () => { + it('should return true with comparison Date', () => { const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriod, TimeStep.DAY, @@ -33,7 +33,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeTruthy() }) - it('shoud return false with comparison Date', () => { + it('should return false with comparison Date', () => { const wrongTimePeriodComparison: TimePeriod = { startDate: DateTime.fromISO('2020-09-05T00:00:00.000Z', { zone: 'utc', @@ -48,7 +48,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false with comparison Date', () => { + it('should return false with comparison Date', () => { const wrongTimePeriodComparison: TimePeriod = { startDate: DateTime.fromISO('2020-09-05T00:00:00.000Z', { zone: 'utc', @@ -63,7 +63,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false because of fluid', () => { + it('should return false because of fluid', () => { const wrongFluidType: FluidType[] = [] const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriod, @@ -72,7 +72,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false because of wrong TimePeriod', () => { + it('should return false because of wrong TimePeriod', () => { const wrongTimePeriod: TimePeriod = { startDate: DateTime.fromISO('2020-10-05T00:00:00.000Z', { zone: 'utc', @@ -86,7 +86,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false because of HALF_AN_HOUR and ELECTRICITY', () => { + it('should return false because of HALF_AN_HOUR and ELECTRICITY', () => { const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriod, TimeStep.HALF_AN_HOUR, @@ -94,7 +94,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false because of HALF_AN_HOUR and ValidateTimePeriodLength', () => { + it('should return false because of HALF_AN_HOUR and ValidateTimePeriodLength', () => { fluidTypes = [0] //Only fluid without TimeStep incompatibilty const mockTimePeriodTooLong: TimePeriod = { startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { @@ -109,7 +109,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false because of WEEK and ValidateTimePeriodLength', () => { + it('should return false because of WEEK and ValidateTimePeriodLength', () => { const mockTimePeriodTooLong: TimePeriod = { startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', @@ -123,7 +123,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false because of DAY and ValidateTimePeriodLength', () => { + it('should return false because of DAY and ValidateTimePeriodLength', () => { const mockTimePeriodTooLong: TimePeriod = { startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', @@ -137,7 +137,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false because of MONTH and ValidateTimePeriodLength', () => { + it('should return false because of MONTH and ValidateTimePeriodLength', () => { const mockTimePeriodTooLong: TimePeriod = { startDate: DateTime.fromISO('2018-10-01T00:00:00.000Z', { zone: 'utc', @@ -151,7 +151,7 @@ describe('ConsumptionFormatter service', () => { ) expect(result).toBeFalsy() }) - it('shoud return false because of YEAR and ValidateTimePeriodLength', () => { + it('should return false because of YEAR and ValidateTimePeriodLength', () => { const mockTimePeriodTooLong: TimePeriod = { startDate: DateTime.fromISO('2009-10-01T00:00:00.000Z', { zone: 'utc', diff --git a/src/services/converter.service.spec.ts b/src/services/converter.service.spec.ts index e9dde6f239a23698933417e039243e64cd13ef5e..8cb4471242601b01baace424cb0330ab680c1eb6 100644 --- a/src/services/converter.service.spec.ts +++ b/src/services/converter.service.spec.ts @@ -8,32 +8,32 @@ describe('Converter service', () => { describe('LoadToEuro method', () => { const fluidConfig = configService.getFluidConfig() - it('shoud return the load to euro for Electricity', () => { + it('should return the load to euro for Electricity', () => { const expectedConversion = 20 * fluidConfig[FluidType.ELECTRICITY].coefficient const result = converterService.LoadToEuro(20, FluidType.ELECTRICITY) expect(result).toEqual(expectedConversion) }) - it('shoud return the load to euro for Gas', () => { + it('should return the load to euro for Gas', () => { const expectedConversion = 20 * fluidConfig[FluidType.GAS].coefficient const result = converterService.LoadToEuro(20, FluidType.GAS) expect(result).toEqual(expectedConversion) }) - it('shoud return the load to euro for Water', () => { + it('should return the load to euro for Water', () => { const expectedConversion = 20 * fluidConfig[FluidType.WATER].coefficient const result = converterService.LoadToEuro(20, FluidType.WATER) expect(result).toEqual(expectedConversion) }) - it('shoud return the load to euro for Multifluid, no coeff apply', () => { + it('should return the load to euro for Multifluid, no coeff apply', () => { const expectedConversion = 20 const result = converterService.LoadToEuro(20, FluidType.MULTIFLUID) expect(result).toEqual(expectedConversion) }) - it('shoud return 0.01 if the load is below 0.01 euro', () => { + it('should return 0.01 if the load is below 0.01 euro', () => { const expectedConversion = 0.01 const result = converterService.LoadToEuro(0.002, FluidType.WATER) expect(result).toEqual(expectedConversion) diff --git a/src/services/ecogesture.service.spec.ts b/src/services/ecogesture.service.spec.ts index 5bf8a16774253fa6c9a77d6cde929287460f42ae..6f779445df328ea44ed96012452c932b4458acf9 100644 --- a/src/services/ecogesture.service.spec.ts +++ b/src/services/ecogesture.service.spec.ts @@ -20,7 +20,7 @@ describe('Ecogesture service', () => { const ecogestureService = new EcogestureService(mockClient) describe('getAllEcogestures', () => { - it('shoud return all ecogestures', async () => { + it('should return all ecogestures', async () => { const mockQueryResult: QueryResult<Ecogesture[]> = { data: ecogesturesData, bookmark: '', @@ -31,7 +31,7 @@ describe('Ecogesture service', () => { const result = await ecogestureService.getAllEcogestures() expect(result).toEqual(ecogesturesData) }) - it('shoud return empty array when no ecogestures stored', async () => { + it('should return empty array when no ecogestures stored', async () => { const mockQueryResult: QueryResult<Ecogesture[]> = { data: [], bookmark: '', @@ -45,7 +45,7 @@ describe('Ecogesture service', () => { }) describe('deleteAllEcogestures', () => { - it('shoud return true when 3 ecogestures stored', async () => { + it('should return true when 3 ecogestures stored', async () => { const mockQueryResult: QueryResult<Ecogesture[]> = { data: ecogesturesData, bookmark: '', @@ -57,7 +57,7 @@ describe('Ecogesture service', () => { expect(mockClient.destroy).toBeCalledTimes(3) expect(result).toBe(true) }) - it('shoud return true when no ecogestures stored', async () => { + it('should return true when no ecogestures stored', async () => { const mockQueryResult: QueryResult<Ecogesture[]> = { data: [], bookmark: '', @@ -68,7 +68,7 @@ describe('Ecogesture service', () => { const result = await ecogestureService.deleteAllEcogestures() expect(result).toBe(true) }) - it('shoud return false when error happened on deletion', async () => { + it('should return false when error happened on deletion', async () => { const mockQueryResult: QueryResult<Ecogesture[]> = { data: ecogesturesData, bookmark: '', @@ -84,7 +84,7 @@ describe('Ecogesture service', () => { describe('filteredEcogestureList', () => { describe('usage heating', () => { - it('shoud return ecogesture with electricity', async () => { + it('should return ecogesture with electricity', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesHeatingData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -97,7 +97,7 @@ describe('Ecogesture service', () => { ) expect(result).toEqual([mockEcogestureList[0], mockEcogestureList[2]]) }) - it('shoud return ecogesture with gas', async () => { + it('should return ecogesture with gas', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesHeatingData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -110,7 +110,7 @@ describe('Ecogesture service', () => { ) expect(result).toEqual([mockEcogestureList[1], mockEcogestureList[2]]) }) - it('shoud not return ecogesture when profile heating is collective', async () => { + it('should not return ecogesture when profile heating is collective', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesHeatingData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -126,7 +126,7 @@ describe('Ecogesture service', () => { }) describe('usage ECS', () => { - it('shoud return ecogesture with electricity', async () => { + it('should return ecogesture with electricity', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesECSData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -139,7 +139,7 @@ describe('Ecogesture service', () => { ) expect(result).toEqual([mockEcogestureList[0], mockEcogestureList[2]]) }) - it('shoud return ecogesture with gas', async () => { + it('should return ecogesture with gas', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesECSData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -152,7 +152,7 @@ describe('Ecogesture service', () => { ) expect(result).toEqual([mockEcogestureList[1], mockEcogestureList[2]]) }) - it('shoud not return ecogesture when profile warming is collective', async () => { + it('should not return ecogesture when profile warming is collective', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesECSData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -168,7 +168,7 @@ describe('Ecogesture service', () => { }) describe('usage COOKING', () => { - it('shoud return ecogesture with electricity', async () => { + it('should return ecogesture with electricity', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesCookingData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -180,7 +180,7 @@ describe('Ecogesture service', () => { ) expect(result).toEqual([mockEcogestureList[0], mockEcogestureList[2]]) }) - it('shoud return ecogesture with gas', async () => { + it('should return ecogesture with gas', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesCookingData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -195,7 +195,7 @@ describe('Ecogesture service', () => { }) describe('usage COLD_WATER', () => { - it('shoud return all water ecogestures', async () => { + it('should return all water ecogestures', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesColdWaterData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -207,7 +207,7 @@ describe('Ecogesture service', () => { ) expect(result).toEqual(mockEcogestureList) }) - it('shoud not return water ecogestures', async () => { + it('should not return water ecogestures', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesColdWaterData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -222,7 +222,7 @@ describe('Ecogesture service', () => { }) describe('usage ELECTRICITY_SPECIFIC', () => { - it('shoud return all ecogestures', async () => { + it('should return all ecogestures', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesElecSpecificData const mockProfileType: ProfileType = { ...profileData.profileType, @@ -236,7 +236,7 @@ describe('Ecogesture service', () => { }) describe('usage AIR_CONDITIONING', () => { - it('shoud not return ecogestures', async () => { + it('should not return ecogestures', async () => { const mockEcogestureList: Ecogesture[] = ecogesturesAirConditioningData const mockProfileType: ProfileType = { ...profileData.profileType, diff --git a/src/services/fluid.service.spec.ts b/src/services/fluid.service.spec.ts index b3084aa9976b3f20f0b13f53f35b6bf0203a9737..05995a31c7efa605f5a8f4504ad403b71ec8febe 100644 --- a/src/services/fluid.service.spec.ts +++ b/src/services/fluid.service.spec.ts @@ -57,7 +57,7 @@ describe('FLuid service', () => { }) describe('getFluidStatus method', () => { - it('shoud return fluid status for all fluids', async () => { + it('should return fluid status for all fluids', async () => { const mockLastDataDates: (DateTime | null)[] = [ DateTime.local().setZone('utc', { keepLocalTime: true, @@ -150,7 +150,7 @@ describe('FLuid service', () => { expect(result).toEqual(mockResult) }) - it('shoud return fluid status with NOT_CONNECTED status when no accounts', async () => { + it('should return fluid status with NOT_CONNECTED status when no accounts', async () => { const mockLastDataDates: (DateTime | null)[] = [ DateTime.local().setZone('utc', { keepLocalTime: true, @@ -243,7 +243,7 @@ describe('FLuid service', () => { expect(result).toEqual(mockResult) }) - it('shoud return fluid status with KONNECTOR_NOT_FOUND status when no konnector', async () => { + it('should return fluid status with KONNECTOR_NOT_FOUND status when no konnector', async () => { const mockLastDataDates: (DateTime | null)[] = [ DateTime.local().setZone('utc', { keepLocalTime: true, @@ -336,7 +336,7 @@ describe('FLuid service', () => { expect(result).toEqual(mockResult) }) - it('shoud return fluid status with NOT_CONNECTED status when no triggers', async () => { + it('should return fluid status with NOT_CONNECTED status when no triggers', async () => { const mockLastDataDates: (DateTime | null)[] = [ DateTime.local().setZone('utc', { keepLocalTime: true, @@ -429,7 +429,7 @@ describe('FLuid service', () => { expect(result).toEqual(mockResult) }) - it('shoud return fluid status with null laste date for water and gaz', async () => { + it('should return fluid status with null laste date for water and gaz', async () => { const mockLastDataDates: (DateTime | null)[] = [ DateTime.local(), null, @@ -521,7 +521,7 @@ describe('FLuid service', () => { }) describe('getOldFluidData method', () => { - it('shoud return Electricity as old fluid', async () => { + it('should return Electricity as old fluid', async () => { const mockFluidStatus: FluidStatus[] = [ { fluidType: FluidType.ELECTRICITY, @@ -552,7 +552,7 @@ describe('FLuid service', () => { expect(result).toEqual([FluidType.ELECTRICITY]) }) - it('shoud return empty array as lastdatadate < 5 days', async () => { + it('should return empty array as lastdatadate < 5 days', async () => { const mockFluidStatus: FluidStatus[] = [ { fluidType: FluidType.ELECTRICITY, @@ -585,7 +585,7 @@ describe('FLuid service', () => { expect(result).toEqual([]) }) - it('shoud return empty array as status is NOT_CONNECTED', async () => { + it('should return empty array as status is NOT_CONNECTED', async () => { const mockFluidStatus: FluidStatus[] = [ { fluidType: FluidType.ELECTRICITY, @@ -616,7 +616,7 @@ describe('FLuid service', () => { expect(result).toEqual([]) }) - it('shoud return empty array as status is KONNECTOR_NOT_FOUND', async () => { + it('should return empty array as status is KONNECTOR_NOT_FOUND', async () => { const mockFluidStatus: FluidStatus[] = [ { fluidType: FluidType.ELECTRICITY, @@ -647,7 +647,7 @@ describe('FLuid service', () => { expect(result).toEqual([]) }) - it('shoud return empty array', async () => { + it('should return empty array', async () => { const result: FluidType[] = await FluidService.getOldFluidData([]) expect(result).toEqual([]) }) diff --git a/src/services/fluidConfig.service.spec.ts b/src/services/fluidConfig.service.spec.ts index 931295dee1269eb3c64fdea6e1ccd45d430c797c..3714918d14345cca09ee437166f4a1bc2c4fc96d 100644 --- a/src/services/fluidConfig.service.spec.ts +++ b/src/services/fluidConfig.service.spec.ts @@ -3,13 +3,13 @@ import ConfigService from './fluidConfig.service' describe('ConfigService service', () => { const configService = new ConfigService() describe('getFluidConfig', () => { - it('shoud return an array with the fluid config', () => { + it('should return an array with the fluid config', () => { const result = configService.getFluidConfig() expect(result).toBeDefined() }) }) describe('getCronArgs', () => { - it('shoud return the args of a cron', () => { + it('should return the args of a cron', () => { const max = 5 const min = 5 const result = configService.getCronArgs(min, max) diff --git a/src/services/initialization.service.spec.ts b/src/services/initialization.service.spec.ts index 2b17d3c39b8bf042457aa7828996c3d825ab06b5..5ef38662aad2cd716766b194c81df791d0b8b5f6 100644 --- a/src/services/initialization.service.spec.ts +++ b/src/services/initialization.service.spec.ts @@ -154,7 +154,7 @@ describe('Initialization service', () => { mockCreateIndexKonnector.mockClear() mockCreateIndexAccount.mockClear() }) - it('shoud return true when all indexes created', async () => { + it('should return true when all indexes created', async () => { const mockQueryResult: QueryResult<boolean> = { data: true, bookmark: '', @@ -166,7 +166,7 @@ describe('Initialization service', () => { mockCreateIndexAccount.mockResolvedValueOnce(mockQueryResult) await expect(initializationService.initIndex()).resolves.toBe(true) }) - it('shoud throw error when an index is not created', async () => { + it('should throw error when an index is not created', async () => { const mockQueryResult: QueryResult<boolean> = { data: true, bookmark: '', @@ -187,14 +187,14 @@ describe('Initialization service', () => { mockGetProfile.mockClear() mockUpdateProfile.mockClear() }) - it('shoud return the profil when existing', async () => { + it('should return the profil when existing', async () => { mockGetProfile.mockResolvedValueOnce(profileData) mockUpdateProfile.mockResolvedValueOnce(profileData) await expect(initializationService.initProfile()).resolves.toEqual( profileData ) }) - it('shoud create and return the profil when no existing', async () => { + it('should create and return the profil when no existing', async () => { const mockQueryResult: QueryResult<boolean> = { data: true, bookmark: '', @@ -208,7 +208,7 @@ describe('Initialization service', () => { profileData ) }) - it('shoud throw error when the profile is not created', async () => { + it('should throw error when the profile is not created', async () => { const mockQueryResult: QueryResult<null> = { data: null, bookmark: '', @@ -221,11 +221,11 @@ describe('Initialization service', () => { new Error('initProfile: Profile not created') ) }) - it('shoud throw error when the profile could not be fetched', () => { + it('should throw error when the profile could not be fetched', () => { mockGetProfile.mockRejectedValueOnce(new Error()) expect(initializationService.initProfile()).rejects.toEqual(new Error()) }) - it('shoud throw error when the profile failed to be created', () => { + it('should throw error when the profile failed to be created', () => { mockGetProfile.mockResolvedValueOnce(null) mockClient.create.mockRejectedValueOnce(new Error()) expect(initializationService.initProfile()).rejects.toEqual(new Error()) @@ -237,14 +237,14 @@ describe('Initialization service', () => { mockGetAllEcogestures.mockClear() mockDeleteAllEcogestures.mockClear() }) - it('shoud return hash when ecogestures hash is already up to date', async () => { + it('should return hash when ecogestures hash is already up to date', async () => { mockGetAllEcogestures.mockResolvedValueOnce(ecogestureData) const hash = hashFile(ecogestureData) await expect(initializationService.initEcogesture(hash)).resolves.toEqual( hash ) }) - it('shoud return hash when ecogestures are created', async () => { + it('should return hash when ecogestures are created', async () => { mockGetAllEcogestures .mockResolvedValueOnce(null) .mockResolvedValueOnce(ecogestureData) @@ -260,7 +260,7 @@ describe('Initialization service', () => { hash ) }) - it('shoud throw an error when ecogestures should be created and created ecogestures number does not match', async () => { + it('should throw an error when ecogestures should be created and created ecogestures number does not match', async () => { mockGetAllEcogestures .mockResolvedValueOnce(null) .mockResolvedValueOnce(ecogesturesData) @@ -279,14 +279,14 @@ describe('Initialization service', () => { ) ) }) - it('shoud throw an error when ecogestures should be created and creation failed', async () => { + it('should throw an error when ecogestures should be created and creation failed', async () => { mockGetAllEcogestures.mockResolvedValueOnce(null) mockClient.create.mockRejectedValue(new Error()) await expect( initializationService.initEcogesture(hashFile(ecogestureData)) ).rejects.toThrow(new Error()) }) - it('shoud return hash when ecogestures are updated', async () => { + it('should return hash when ecogestures are updated', async () => { mockGetAllEcogestures .mockResolvedValueOnce(ecogestureData) .mockResolvedValueOnce(ecogestureData) @@ -302,7 +302,7 @@ describe('Initialization service', () => { hashFile(ecogestureData) ) }) - it('shoud throw an error when ecogestures should be updated and created ecogestures number does not match', async () => { + it('should throw an error when ecogestures should be updated and created ecogestures number does not match', async () => { mockGetAllEcogestures .mockResolvedValueOnce(ecogestureData) .mockResolvedValueOnce(ecogesturesData) @@ -320,7 +320,7 @@ describe('Initialization service', () => { ) ) }) - it('shoud throw an error when ecogestures should be updated and ecogestures creation failed', async () => { + it('should throw an error when ecogestures should be updated and ecogestures creation failed', async () => { mockGetAllEcogestures .mockResolvedValueOnce(ecogestureData) .mockResolvedValueOnce(ecogestureData) @@ -337,14 +337,14 @@ describe('Initialization service', () => { mockGetAllChallengeEntities.mockClear() mockDeleteAllChallengeEntities.mockClear() }) - it('shoud return hash when challenges hash is already up to date', async () => { + it('should return hash when challenges hash is already up to date', async () => { mockGetAllChallengeEntities.mockResolvedValueOnce(challengeEntityData) const hash = hashFile(challengeEntityData) await expect( initializationService.initChallengeEntity(hash) ).resolves.toEqual(hash) }) - it('shoud return hash when challenge entities are created', async () => { + it('should return hash when challenge entities are created', async () => { mockGetAllChallengeEntities .mockResolvedValueOnce(null) .mockResolvedValueOnce(challengeEntityData) @@ -360,7 +360,7 @@ describe('Initialization service', () => { initializationService.initChallengeEntity(hash) ).resolves.toEqual(hash) }) - it('shoud throw an error when challenge entities should be created and created challenge entities number does not match', async () => { + it('should throw an error when challenge entities should be created and created challenge entities number does not match', async () => { mockGetAllChallengeEntities .mockResolvedValueOnce(null) .mockResolvedValueOnce(allChallengeEntityData) @@ -379,14 +379,14 @@ describe('Initialization service', () => { ) ) }) - it('shoud throw an error when challenge entities should be created and creation failed', async () => { + it('should throw an error when challenge entities should be created and creation failed', async () => { mockGetAllChallengeEntities.mockResolvedValueOnce(null) mockClient.create.mockRejectedValue(new Error()) await expect( initializationService.initChallengeEntity(hashFile(challengeEntityData)) ).rejects.toThrow(new Error()) }) - it('shoud return hash when challenge entities are updated', async () => { + it('should return hash when challenge entities are updated', async () => { mockGetAllChallengeEntities .mockResolvedValueOnce(challengeEntityData) .mockResolvedValueOnce(challengeEntityData) @@ -402,7 +402,7 @@ describe('Initialization service', () => { initializationService.initChallengeEntity('') ).resolves.toEqual(hashFile(challengeEntityData)) }) - it('shoud throw an error when challenge entities should be updated and created challenge entities number does not match', async () => { + it('should throw an error when challenge entities should be updated and created challenge entities number does not match', async () => { mockGetAllChallengeEntities .mockResolvedValueOnce(challengeEntityData) .mockResolvedValueOnce(allChallengeEntityData) @@ -422,7 +422,7 @@ describe('Initialization service', () => { ) ) }) - it('shoud throw an error when challenge entities should be updated and challenge entities creation failed', async () => { + it('should throw an error when challenge entities should be updated and challenge entities creation failed', async () => { mockGetAllChallengeEntities .mockResolvedValueOnce(challengeEntityData) .mockResolvedValueOnce(challengeEntityData) @@ -439,14 +439,14 @@ describe('Initialization service', () => { mockGetAllDuelEntities.mockClear() mockDeleteAllDuelEntities.mockClear() }) - it('shoud return hash when duel hash is already up to date', async () => { + it('should return hash when duel hash is already up to date', async () => { mockGetAllDuelEntities.mockResolvedValueOnce(duelEntityData) const hash = hashFile(duelEntityData) await expect(initializationService.initDuelEntity(hash)).resolves.toEqual( hash ) }) - it('shoud return hash when duel entities are created', async () => { + it('should return hash when duel entities are created', async () => { mockGetAllDuelEntities .mockResolvedValueOnce(null) .mockResolvedValueOnce(duelEntityData) @@ -462,7 +462,7 @@ describe('Initialization service', () => { hash ) }) - it('shoud throw an error when duel entities should be created and created duel entities number does not match', async () => { + it('should throw an error when duel entities should be created and created duel entities number does not match', async () => { mockGetAllDuelEntities .mockResolvedValueOnce(null) .mockResolvedValueOnce(allDuelEntity) @@ -479,14 +479,14 @@ describe('Initialization service', () => { new Error('initDuelEntity: Created duel entities does not match') ) }) - it('shoud throw an error when duel entities should be created and creation failed', async () => { + it('should throw an error when duel entities should be created and creation failed', async () => { mockGetAllDuelEntities.mockResolvedValueOnce(null) mockClient.create.mockRejectedValue(new Error()) await expect( initializationService.initDuelEntity(hashFile(duelEntityData)) ).rejects.toThrow(new Error()) }) - it('shoud return hash when duel entities are updated', async () => { + it('should return hash when duel entities are updated', async () => { mockGetAllDuelEntities .mockResolvedValueOnce(duelEntityData) .mockResolvedValueOnce(duelEntityData) @@ -502,7 +502,7 @@ describe('Initialization service', () => { hashFile(duelEntityData) ) }) - it('shoud throw an error when duel entities should be updated and created duel entities number does not match', async () => { + it('should throw an error when duel entities should be updated and created duel entities number does not match', async () => { mockGetAllDuelEntities .mockResolvedValueOnce(duelEntityData) .mockResolvedValueOnce(allDuelEntity) @@ -518,7 +518,7 @@ describe('Initialization service', () => { new Error('initDuelEntity: Created duel entities does not match') ) }) - it('shoud throw an error when duel entities should be updated and duel entities creation failed', async () => { + it('should throw an error when duel entities should be updated and duel entities creation failed', async () => { mockGetAllDuelEntities .mockResolvedValueOnce(duelEntityData) .mockResolvedValueOnce(duelEntityData) @@ -535,14 +535,14 @@ describe('Initialization service', () => { mockGetAllQuizEntities.mockClear() mockDeleteAllQuizEntities.mockClear() }) - it('shoud return hash when quiz hash is already up to date', async () => { + it('should return hash when quiz hash is already up to date', async () => { mockGetAllQuizEntities.mockResolvedValueOnce(quizEntityData) const hash = hashFile(quizEntityData) await expect(initializationService.initQuizEntity(hash)).resolves.toEqual( hash ) }) - it('shoud return hash when quiz entities are created', async () => { + it('should return hash when quiz entities are created', async () => { mockGetAllQuizEntities .mockResolvedValueOnce(null) .mockResolvedValueOnce(quizEntityData) @@ -558,7 +558,7 @@ describe('Initialization service', () => { hash ) }) - it('shoud throw an error when quiz entities should be created and created quiz entities number does not match', async () => { + it('should throw an error when quiz entities should be created and created quiz entities number does not match', async () => { mockGetAllQuizEntities .mockResolvedValueOnce(null) .mockResolvedValueOnce(allQuizEntities) @@ -575,14 +575,14 @@ describe('Initialization service', () => { new Error('initQuizEntity: Created quiz entities does not match') ) }) - it('shoud throw an error when quiz entities should be created and creation failed', async () => { + it('should throw an error when quiz entities should be created and creation failed', async () => { mockGetAllQuizEntities.mockResolvedValueOnce(null) mockClient.create.mockRejectedValue(new Error()) await expect( initializationService.initQuizEntity(hashFile(quizEntityData)) ).rejects.toThrow(new Error()) }) - it('shoud return hash when quiz entities are updated', async () => { + it('should return hash when quiz entities are updated', async () => { mockGetAllQuizEntities .mockResolvedValueOnce(quizEntityData) .mockResolvedValueOnce(quizEntityData) @@ -598,7 +598,7 @@ describe('Initialization service', () => { hashFile(quizEntityData) ) }) - it('shoud throw an error when quiz entities should be updated and created quiz entities number does not match', async () => { + it('should throw an error when quiz entities should be updated and created quiz entities number does not match', async () => { mockGetAllQuizEntities .mockResolvedValueOnce(quizEntityData) .mockResolvedValueOnce(allQuizEntities) @@ -614,7 +614,7 @@ describe('Initialization service', () => { new Error('initQuizEntity: Created quiz entities does not match') ) }) - it('shoud throw an error when quiz entities should be updated and quiz entities creation failed', async () => { + it('should throw an error when quiz entities should be updated and quiz entities creation failed', async () => { mockGetAllQuizEntities .mockResolvedValueOnce(quizEntityData) .mockResolvedValueOnce(quizEntityData) @@ -631,14 +631,14 @@ describe('Initialization service', () => { mockGetAllExplorationEntities.mockClear() mockDeleteAllExplorationEntities.mockClear() }) - it('shoud return hash when explorations hash is already up to date', async () => { + it('should return hash when explorations hash is already up to date', async () => { mockGetAllExplorationEntities.mockResolvedValueOnce(explorationEntityData) const hash = hashFile(explorationEntityData) await expect( initializationService.initExplorationEntity(hash) ).resolves.toEqual(hash) }) - it('shoud return hash when exploration entities are created', async () => { + it('should return hash when exploration entities are created', async () => { mockGetAllExplorationEntities .mockResolvedValueOnce(null) .mockResolvedValueOnce(explorationEntityData) @@ -654,7 +654,7 @@ describe('Initialization service', () => { initializationService.initExplorationEntity(hash) ).resolves.toEqual(hash) }) - it('shoud throw an error when exploration entities should be created and created exploration entities number does not match', async () => { + it('should throw an error when exploration entities should be created and created exploration entities number does not match', async () => { mockGetAllExplorationEntities .mockResolvedValueOnce(null) .mockResolvedValueOnce(allExplorationEntities) @@ -675,7 +675,7 @@ describe('Initialization service', () => { ) ) }) - it('shoud throw an error when exploration entities should be created and creation failed', async () => { + it('should throw an error when exploration entities should be created and creation failed', async () => { mockGetAllExplorationEntities.mockResolvedValueOnce(null) mockClient.create.mockRejectedValue(new Error()) await expect( @@ -684,7 +684,7 @@ describe('Initialization service', () => { ) ).rejects.toThrow(new Error()) }) - it('shoud return hash when exploration entities are updated', async () => { + it('should return hash when exploration entities are updated', async () => { mockGetAllExplorationEntities .mockResolvedValueOnce(explorationEntityData) .mockResolvedValueOnce(explorationEntityData) @@ -700,7 +700,7 @@ describe('Initialization service', () => { initializationService.initExplorationEntity('') ).resolves.toEqual(hashFile(explorationEntityData)) }) - it('shoud throw an error when exploration entities should be updated and created exploration entities number does not match', async () => { + it('should throw an error when exploration entities should be updated and created exploration entities number does not match', async () => { mockGetAllExplorationEntities .mockResolvedValueOnce(explorationEntityData) .mockResolvedValueOnce(allExplorationEntities) @@ -720,7 +720,7 @@ describe('Initialization service', () => { ) ) }) - it('shoud throw an error when exploration entities should be updated and exploration entities creation failed', async () => { + it('should throw an error when exploration entities should be updated and exploration entities creation failed', async () => { mockGetAllExplorationEntities .mockResolvedValueOnce(explorationEntityData) .mockResolvedValueOnce(explorationEntityData) @@ -782,7 +782,7 @@ describe('Initialization service', () => { beforeEach(() => { mockGetKonnectorAccountStatus.mockClear() }) - it('shoud return all fluid types', async () => { + it('should return all fluid types', async () => { mockGetKonnectorAccountStatus.mockResolvedValueOnce([ FluidType.ELECTRICITY, FluidType.WATER, @@ -794,13 +794,13 @@ describe('Initialization service', () => { FluidType.GAS, ]) }) - it('shoud throw an error when null is retrieved as fluid types', async () => { + it('should throw an error when null is retrieved as fluid types', async () => { mockGetKonnectorAccountStatus.mockResolvedValueOnce(null) await expect(initializationService.initFluidTypes()).rejects.toThrow( new Error('initFluidTypes: FluidTypes not found') ) }) - it('shoud throw an error when it fails to retrieve the fluid types', async () => { + it('should throw an error when it fails to retrieve the fluid types', async () => { mockGetKonnectorAccountStatus.mockRejectedValueOnce(new Error()) await expect(initializationService.initFluidTypes()).rejects.toThrow( new Error() @@ -812,19 +812,19 @@ describe('Initialization service', () => { beforeEach(() => { mockGetFluidStatus.mockClear() }) - it('shoud return all fluids type', async () => { + it('should return all fluids type', async () => { mockGetFluidStatus.mockResolvedValueOnce(fluidStatusData) await expect(initializationService.initFluidStatus()).resolves.toEqual( fluidStatusData ) }) - it('shoud throw an error when null is retrieved as status', async () => { + it('should throw an error when null is retrieved as status', async () => { mockGetFluidStatus.mockResolvedValueOnce(null) await expect(initializationService.initFluidStatus()).rejects.toThrow( new Error('initFluidStatus: fluidStatus not found') ) }) - it('shoud throw an error when it fails to retrieve the status', async () => { + it('should throw an error when it fails to retrieve the status', async () => { mockGetFluidStatus.mockRejectedValueOnce(new Error()) await expect(initializationService.initFluidStatus()).rejects.toThrow( new Error() @@ -836,13 +836,13 @@ describe('Initialization service', () => { beforeEach(() => { mockBuildUserChallengeList.mockClear() }) - it('shoud return all userChallenges', async () => { + it('should return all userChallenges', async () => { mockBuildUserChallengeList.mockResolvedValueOnce(userChallengeData) await expect( initializationService.initUserChallenges([]) ).resolves.toEqual(userChallengeData) }) - it('shoud throw an error when null is retrieved as status', async () => { + it('should throw an error when null is retrieved as status', async () => { mockBuildUserChallengeList.mockResolvedValueOnce(null) await expect( initializationService.initUserChallenges([]) @@ -850,7 +850,7 @@ describe('Initialization service', () => { new Error('initUserChallenges: userChallengeList not found') ) }) - it('shoud throw an error when it fails to retrieve the status', async () => { + it('should throw an error when it fails to retrieve the status', async () => { mockBuildUserChallengeList.mockRejectedValueOnce(new Error()) await expect( initializationService.initUserChallenges([]) @@ -863,7 +863,7 @@ describe('Initialization service', () => { mockGetUserChallengeDataload.mockClear() mockUserChallengeUpdateFlag.mockClear() }) - it('shoud return updatedUserChallenge and dataload ', async () => { + it('should return updatedUserChallenge and dataload ', async () => { mockGetUserChallengeDataload.mockResolvedValueOnce(graphData.actualData) const expectedUpdatedUserChallenge: UserChallenge = { ...userChallengeData[0], @@ -883,7 +883,7 @@ describe('Initialization service', () => { initializationService.initDuelProgress(userChallengeData[0]) ).resolves.toEqual(expectedResult) }) - it('shoud throw an error when it fails to retrieve the status', async () => { + it('should throw an error when it fails to retrieve the status', async () => { mockGetUserChallengeDataload.mockRejectedValueOnce(new Error()) await expect( initializationService.initDuelProgress(userChallengeData[0]) @@ -891,17 +891,17 @@ describe('Initialization service', () => { }) }) describe('initTerms method', () => { - it('shoud not show consent page', async () => { + it('should not show consent page', async () => { mockIsConsentVersionUpToDate.mockResolvedValueOnce(true) mockIsLastTermValidated.mockResolvedValueOnce(true) await expect(initializationService.initConsent()).resolves.toEqual(true) }) - it('shoud show consent page', async () => { + it('should show consent page', async () => { mockIsConsentVersionUpToDate.mockResolvedValueOnce(false) mockIsLastTermValidated.mockResolvedValueOnce(false) await expect(initializationService.initConsent()).resolves.toEqual(false) }) - it('shoud throw an error when it fails to checks for consent', async () => { + it('should throw an error when it fails to checks for consent', async () => { mockIsConsentVersionUpToDate.mockRejectedValueOnce(new Error()) await expect(initializationService.initConsent()).rejects.toThrow( new Error() diff --git a/src/services/konnector.service.spec.ts b/src/services/konnector.service.spec.ts index 3067f86cc85bd5bf5e5cd735c2dc93e1cd3a7990..f5c683ac4c29066aa7441d0065f97c33a9e29797 100644 --- a/src/services/konnector.service.spec.ts +++ b/src/services/konnector.service.spec.ts @@ -22,7 +22,7 @@ describe('KonnectorService service', () => { const konnectorService = new KonnectorService(mockClient) describe('getKonnector method', () => { - it('shoud return konnector', async () => { + it('should return konnector', async () => { const mockQueryResult: QueryResult<Konnector[]> = { data: [konnectorsData[0]], bookmark: '', @@ -34,7 +34,7 @@ describe('KonnectorService service', () => { expect(result).toEqual(konnectorsData[0]) }) - it('shoud return null when konnector is not found', async () => { + it('should return null when konnector is not found', async () => { const mockQueryResult: QueryResult<Konnector[]> = { data: [], bookmark: '', @@ -48,7 +48,7 @@ describe('KonnectorService service', () => { }) describe('getKonnectorLastState method', () => { - it('shoud return the triggerState', async () => { + it('should return the triggerState', async () => { mockGetTrigger.mockResolvedValueOnce(triggersData[0]) mockFetchTriggerState.mockResolvedValueOnce(triggerStateData) const result = await konnectorService.getKonnectorLastState( @@ -58,7 +58,7 @@ describe('KonnectorService service', () => { expect(result).toEqual(triggerStateData) }) - it('shoud return null when trigger is not found', async () => { + it('should return null when trigger is not found', async () => { mockGetTrigger.mockResolvedValueOnce(null) mockFetchTriggerState.mockResolvedValueOnce(triggerStateData) const result = await konnectorService.getKonnectorLastState( @@ -70,7 +70,7 @@ describe('KonnectorService service', () => { }) describe('createIndexKonnector method', () => { - it('shoud return the query Result', async () => { + it('should return the query Result', async () => { const mockQueryResult: QueryResult<Konnector[]> = { data: [], bookmark: '', diff --git a/src/services/profile.service.spec.ts b/src/services/profile.service.spec.ts index 47e6af389fea3612953a00cdc0ad0c886e184136..55d223e9e4f97abfca45ebabe3930138e2a524ea 100644 --- a/src/services/profile.service.spec.ts +++ b/src/services/profile.service.spec.ts @@ -9,7 +9,7 @@ describe('UserProfile service', () => { const profileService = new ProfileService(mockClient) describe('getUserProfile', () => { - it('shoud return the user profile', async () => { + it('should return the user profile', async () => { const mockQueryResult: QueryResult<Profile[]> = { data: [profileData], bookmark: '', @@ -21,7 +21,7 @@ describe('UserProfile service', () => { expect(result).toEqual(profileData) }) - it('shoud return the user profile from string monthlyAnalysisDate', async () => { + it('should return the user profile from string monthlyAnalysisDate', async () => { const userProfile = { ...profileData, monthlyAnalysisDate: '2020-11-09T11:27:30.073Z', @@ -44,7 +44,7 @@ describe('UserProfile service', () => { expect(result).toEqual(resultUserProfile) }) - it('shoud return null if no user profile found', async () => { + it('should return null if no user profile found', async () => { const mockQueryResult: QueryResult<Profile[]> = { data: [], bookmark: '', @@ -58,7 +58,7 @@ describe('UserProfile service', () => { }) describe('updateUserProfile', () => { - it('shoud return an updated user profile', async () => { + it('should return an updated user profile', async () => { const userProfile = { ...profileData, monthlyAnalysisDate: '2020-11-03T00:00:00.000Z', @@ -97,7 +97,7 @@ describe('UserProfile service', () => { expect(result).toEqual(resultUserProfile) }) - it('shoud return null if no user profile found', async () => { + it('should return null if no user profile found', async () => { const mockQueryResult: QueryResult<Profile[]> = { data: [profileData], bookmark: '', diff --git a/src/services/profileType.service.spec.ts b/src/services/profileType.service.spec.ts index f3cfb1b0c6b5b3ae3c35ef4940cf8f400d2344dc..3061153a0fb3cebfac1811e45433a602c27bef7f 100644 --- a/src/services/profileType.service.spec.ts +++ b/src/services/profileType.service.spec.ts @@ -40,54 +40,60 @@ import { DateTime } from 'luxon' const wrongNumber = 99999 describe('ProfileType service', () => { - const profileTypeService = new ProfileTypeService(mockProfileType, mockClient) + const profileTypeService = new ProfileTypeService( + mockProfileType, + mockClient, + DateTime.now().year + ) describe('calculateWarmingEstimatedConsumption', () => { - it('shoud calculate the Warming Estimated Consumption', () => { + it('should calculate the Warming Estimated Consumption', () => { const estimatedConsumption = profileTypeService.calculateWarmingEstimatedConsumption() expect(estimatedConsumption).toEqual(mockEstimatedConsumption) }) - it('shoud calculate the Warming Corrected Consumption', () => { + it('should calculate the Warming Corrected Consumption', () => { const correctedConsumption = profileTypeService.calculateWarmingCorrectedConsumption( mockEstimatedConsumption ) expect(correctedConsumption).toEqual(mockCorrectedConsumption) }) - it('shoud calculate the Warming Month Consumption', async () => { + it('should calculate the Warming Month Consumption', async () => { const monthConsumption = await profileTypeService.calculateWarmingMonthConsumption( mockCorrectedConsumption, 3 ) expect(monthConsumption).toEqual(mockMonthConsumption) }) - it('shoud get the heating consumption', async () => { + it('should 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', () => { + describe('should get the heating consumption for a flat with collective heating', () => { const _profileTypeService = new ProfileTypeService( mockProfileType1, - mockClient + mockClient, + DateTime.now().year ) - it('shoud get the heating consumption', async () => { + it('should 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', () => { + describe('should get the heating consumption for a house with individual heating, facilities, installation and individual work', () => { const _profileTypeService = new ProfileTypeService( mockProfileType2, - mockClient + mockClient, + DateTime.now().year ) - it('shoud get the heating consumption', async () => { + it('should 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', () => { + it('should calculate the water raw needs consumption by month', () => { const waterRawNeeds = profileTypeService.calculateMonthWaterRawNeeds( mockProfileType, 1 @@ -95,14 +101,14 @@ describe('ProfileType service', () => { expect(waterRawNeeds).toEqual(mockwaterRawNeeds) }) - it('shoud calculate the water spread needs Consumption', () => { + it('should 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"', () => { + it('should calculate the total ecs consumption by month if profileType.hotWaterEquipment === "solar"', () => { const monthEcsConsumption = profileTypeService.calculateTotalConsumption( mockWaterSpreadNeeds, mockProfileType1, @@ -110,7 +116,7 @@ describe('ProfileType service', () => { ) expect(monthEcsConsumption).toEqual(mockMonthEcsConsumption1Solar) }) - it('shoud calculate the total ecs consumption by month if profileType.hotWaterEquipment === "other"', () => { + it('should calculate the total ecs consumption by month if profileType.hotWaterEquipment === "other"', () => { const mockProfileTypeWithOther = { ...mockProfileType } mockProfileTypeWithOther.hotWaterEquipment = HotWaterEquipment.OTHER const monthEcsConsumption = profileTypeService.calculateTotalConsumption( @@ -120,7 +126,7 @@ describe('ProfileType service', () => { ) expect(monthEcsConsumption).toEqual(mockMonthEcsConsumptionOther) }) - it('shoud get the ECS consumption if profileType.hotWaterEquipment === "thermodynamic"', () => { + it('should get the ECS consumption if profileType.hotWaterEquipment === "thermodynamic"', () => { const mockProfileTypeWithOther = { ...mockProfileType } mockProfileTypeWithOther.hotWaterEquipment = HotWaterEquipment.THERMODYNAMIC @@ -128,11 +134,12 @@ describe('ProfileType service', () => { expect(monthConsumption).toEqual(mockMonthEcsConsumptionThermo) }) - describe('shoud get the month cooking consumption', () => { - it('shoud get the month cooking consumption', () => { + describe('should get the month cooking consumption', () => { + it('should get the month cooking consumption', () => { const _profileTypeService = new ProfileTypeService( mockProfileType, - mockClient + mockClient, + DateTime.now().year ) const monthCookingConsumption = _profileTypeService.getMonthCookingConsumption( @@ -141,11 +148,12 @@ describe('ProfileType service', () => { expect(monthCookingConsumption).toEqual(mockMonthCookingConsumption) }) }) - describe('shoud get the month electric specific consumption', () => { - it('shoud get the electric specific consumption', () => { + describe('should get the month electric specific consumption', () => { + it('should get the electric specific consumption', () => { const _profileTypeService = new ProfileTypeService( mockProfileType, - mockClient + mockClient, + DateTime.now().year ) const monthElectricSpecificConsumption = _profileTypeService.getMonthElectricSpecificConsumption( @@ -156,11 +164,12 @@ describe('ProfileType service', () => { ) }) }) - describe('shoud get the month cold water consumption', () => { - it('shoud get the cold water consumption', () => { + describe('should get the month cold water consumption', () => { + it('should get the cold water consumption', () => { const _profileTypeService = new ProfileTypeService( mockProfileType, - mockClient + mockClient, + DateTime.now().year ) const monthColdWaterConsumption = _profileTypeService.getMonthColdWaterConsumption( 1 @@ -169,33 +178,36 @@ describe('ProfileType service', () => { }) }) }) - describe('shoud get the monthly Forecast', () => { + describe('should get the monthly Forecast', () => { // For month of january const profileTypeService1 = new ProfileTypeService( mockTestProfile1, - mockClient + mockClient, + DateTime.now().year ) - it('shoud get the monthly forecast for test profile 1', async () => { + it('should 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 + mockClient, + DateTime.now().year ) - it('shoud get the monthly forecast for test profile 2', async () => { + it('should 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 + mockClient, + DateTime.now().year ) - it('shoud get the monthly forecast for test profile 3', async () => { + it('should 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 () => { + it('should get the monthly forecast for test profile 1 with wall and roof and window insulation', async () => { const mockProfileWithThreeInsulation: ProfileType = { ...mockTestProfile1, individualInsulationWork: [ @@ -208,7 +220,8 @@ describe('ProfileType service', () => { } const _profileTypeService = new ProfileTypeService( mockProfileWithThreeInsulation, - mockClient + mockClient, + DateTime.now().year ) const monthlyForecast = await _profileTypeService.getMonthlyForecast(1) expect(monthlyForecast).toEqual( @@ -217,7 +230,7 @@ describe('ProfileType service', () => { }) }) describe('getNextFormStep', () => { - it('shoud get the next step in function of the current step', () => { + it('should get the next step in function of the current step', () => { let nextStep = profileTypeService.getNextFormStep( ProfileTypeStepForm.HOUSING_TYPE ) @@ -278,7 +291,7 @@ describe('ProfileType service', () => { }) }) describe('getPreviousFormStep', () => { - it('shoud get the previus step in function of the current step', () => { + it('should get the previus step in function of the current step', () => { let previousStep = profileTypeService.getPreviousFormStep( ProfileTypeStepForm.AREA ) @@ -341,7 +354,7 @@ describe('ProfileType service', () => { }) }) describe('getAnswerForStep', () => { - it('shoud get the good answers in function of the current step', () => { + it('should get the good answers in function of the current step', () => { let answers = ProfileTypeService.getAnswerForStep( ProfileTypeStepForm.HOUSING_TYPE ) @@ -405,7 +418,7 @@ describe('ProfileType service', () => { }) }) describe('checkConsistency', () => { - it('shoud return consistent profile for individual house', () => { + it('should return consistent profile for individual house', () => { const mockProfile = { ...mockProfileType1, housingType: HousingType.INDIVIDUAL_HOUSE, @@ -426,7 +439,7 @@ describe('ProfileType service', () => { const result = ProfileTypeService.checkConsistency(mockProfile) expect(result).toEqual(expectedResult) }) - it('shoud return consistent profile for appartment', () => { + it('should return consistent profile for appartment', () => { const mockProfile = mockProfileType1 jest .spyOn(DateTime, 'local') @@ -447,7 +460,7 @@ describe('ProfileType service', () => { }) }) describe('getDjU', () => { - it('shoud return default dju', async () => { + it('should 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 f07b7857f24314d07335356b3b9cd74c4ec99c49..5cbeae894da890c806ffda1bcb546b892ed9df61 100644 --- a/src/services/profileType.service.ts +++ b/src/services/profileType.service.ts @@ -35,7 +35,7 @@ export default class ProfileTypeService { constructor(profileType: ProfileType, _client: Client, year: number) { log.info( - '[ProfileType] Analysis loaded profileType relative to : ', + '[ProfileType] Analysis loaded profileType relative to: ', profileType.updateDate.toString() ) this.profileType = profileType diff --git a/src/services/profileTypeEntity.service.spec.ts b/src/services/profileTypeEntity.service.spec.ts index 4e6b121318b76437e448cd70e48e23e3f1bcb7c7..110127eaa48130bed884946382ed498ad7e9c892 100644 --- a/src/services/profileTypeEntity.service.spec.ts +++ b/src/services/profileTypeEntity.service.spec.ts @@ -8,7 +8,7 @@ describe('UserProfileTypeEntity service', () => { const pteService = new ProfileTypeEntityService(mockClient) describe('getUserProfileType', () => { - it('shoud return the last profileType in base', async () => { + it('should return the last profileType in base', async () => { const mockQueryResult: QueryResult<ProfileType[]> = { data: [profileTypeData], bookmark: '', @@ -20,9 +20,9 @@ describe('UserProfileTypeEntity service', () => { expect(result).toEqual(profileTypeData) }) - // it('shoud return the closest profileType according to passed argument updateDate', async () => {}) + // it('should return the closest profileType according to passed argument updateDate', async () => {}) - it('shoud return null if no user profile found', async () => { + it('should return null if no user profile found', async () => { const mockQueryResult: QueryResult<ProfileType[]> = { data: [], bookmark: '', diff --git a/src/services/profileTypeEntity.service.ts b/src/services/profileTypeEntity.service.ts index de3237a1b46c04679ea6c1f6bd6138f6665ed3d3..7e6947cc9b62eed69d133eaf7c0b17ee743f967f 100644 --- a/src/services/profileTypeEntity.service.ts +++ b/src/services/profileTypeEntity.service.ts @@ -3,6 +3,7 @@ import { ProfileType } from 'models' import { PROFILETYPE_DOCTYPE } from 'doctypes' import { DateTime } from 'luxon' import profileTypeData from 'db/profileTypeData.json' +import log from 'utils/logger' export default class ProfileTypeEntityService { private readonly _client: Client @@ -33,14 +34,28 @@ export default class ProfileTypeEntityService { if (result) { return this.parseProfileTypeEntityToProfileType(profileType) } else { - // If no entry is returned for a given date - // it means asked date is older than our last profile - // return default profiletype - const loadedProfileType: any = { - ...profileTypeData[0].profileType, - updateDate: date, + log.debug('No profileType found for: ', date.toString()) + log.debug( + 'Checking if user has already filled a profileType and uses it as default' + ) + const query: QueryDefinition = Q(PROFILETYPE_DOCTYPE) + const data: QueryResult<ProfileType[]> = await this._client.query(query) + if (data.data.length) { + const loadedProfileType: ProfileType = data.data[0] + log.debug( + 'found oldest profileType filled by user : ', + loadedProfileType + ) + return loadedProfileType + } else { + // return default profiletype + const loadedProfileType: any = { + ...profileTypeData[0].profileType, + updateDate: date, + } + log.debug('No profileType were found, loading default profileType') + return loadedProfileType } - return loadedProfileType } } else { const { diff --git a/src/services/triggers.service.spec.ts b/src/services/triggers.service.spec.ts index 0593ce67e66b291533dd0f2f36ebbb3b99d4ad07..ea078b3bc6a2bb45cd21756c67772a77783316e6 100644 --- a/src/services/triggers.service.spec.ts +++ b/src/services/triggers.service.spec.ts @@ -20,7 +20,7 @@ describe('TriggerService service', () => { const triggerService = new TriggerService(mockClient) describe('createTrigger method', () => { - it('shoud return created Trigger', async () => { + it('should return created Trigger', async () => { mockCreateTrigger.mockResolvedValueOnce(triggersData[0]) const result: Trigger = await triggerService.createTrigger( accountsData[0], @@ -31,7 +31,7 @@ describe('TriggerService service', () => { }) describe('getTrigger method', () => { - it('shoud return Trigger', async () => { + it('should return Trigger', async () => { const mockQueryResult: QueryResult<Trigger[]> = { data: [triggersData[0]], bookmark: '', @@ -46,7 +46,7 @@ describe('TriggerService service', () => { expect(result).toEqual(triggersData[0]) }) - it('shoud return null when no trigger found', async () => { + it('should return null when no trigger found', async () => { const mockQueryResult: QueryResult<Trigger[]> = { data: [], bookmark: '', @@ -63,7 +63,7 @@ describe('TriggerService service', () => { }) describe('fetchTriggerState method', () => { - it('shoud return Trigger state', async () => { + it('should return Trigger state', async () => { const mockResult = { data: { attributes: { @@ -79,7 +79,7 @@ describe('TriggerService service', () => { expect(result).toEqual(triggerStateData) }) - it('shoud return null when current_state is empty', async () => { + it('should return null when current_state is empty', async () => { const mockResult = { // eslint-disable-next-line @typescript-eslint/camelcase data: { attributes: { current_state: null } }, @@ -91,7 +91,7 @@ describe('TriggerService service', () => { expect(result).toBe(null) }) - it('shoud throw an error', async () => { + it('should throw an error', async () => { mockClient.getStackClient().fetchJSON.mockRejectedValueOnce(new Error()) try { await triggerService.fetchTriggerState(triggersData[0]) diff --git a/src/services/usageEvent.service.spec.ts b/src/services/usageEvent.service.spec.ts index dcb54647ac929200d429474f03084e791de1f665..a1fc7f891ec869144e1b871266da31f121537432 100644 --- a/src/services/usageEvent.service.spec.ts +++ b/src/services/usageEvent.service.spec.ts @@ -19,7 +19,7 @@ describe('UsageEvent service', () => { localSpy.mockClear() }) describe('addEvent method', () => { - it('shoud add event and return it', async () => { + it('should add event and return it', async () => { const { eventDate, ...addEventParams } = usageEventEntityData const params: AddEventParams = { ...addEventParams, @@ -45,7 +45,7 @@ describe('UsageEvent service', () => { }) }) describe('updateUsageEventsAggregated method', () => { - it('shoud return true Connection events', async () => { + it('should return true Connection events', async () => { const mockQueryResult: QueryResult<UsageEventEntity> = { data: usageEventEntityData, bookmark: '', @@ -61,7 +61,7 @@ describe('UsageEvent service', () => { }) }) describe('getEvents method', () => { - it('shoud return all Connection events', async () => { + it('should return all Connection events', async () => { const mockQueryResult: QueryResult<UsageEventEntity[]> = { data: connectionEventEntitiesData, bookmark: '', diff --git a/tests/__mocks__/profileType.mock.ts b/tests/__mocks__/profileType.mock.ts index d487d4524661b366ad8a433e1022dff72c58455a..851b7b4faea13424cdd4cd64300e7bb1a27ebd00 100644 --- a/tests/__mocks__/profileType.mock.ts +++ b/tests/__mocks__/profileType.mock.ts @@ -167,7 +167,7 @@ export const mockMonthlyForecastJanuaryTestProfile1: MonthlyForecast = { }, fluidType: 0, load: 4340, - value: 670.96, + value: 676.17, }, { detailsMonthlyForecast: { @@ -179,7 +179,7 @@ export const mockMonthlyForecastJanuaryTestProfile1: MonthlyForecast = { }, fluidType: 1, load: 14911, - value: 46.224, + value: 47.566, }, { detailsMonthlyForecast: { @@ -191,11 +191,11 @@ export const mockMonthlyForecastJanuaryTestProfile1: MonthlyForecast = { }, fluidType: 2, load: 375, - value: 29.737, + value: 42.038, }, ], month: 1, - totalValue: 746.921, + totalValue: 765.774, } export const mockTestProfile2: ProfileType = { @@ -232,7 +232,7 @@ export const mockMonthlyForecastJanuaryTestProfile2: MonthlyForecast = { }, fluidType: 0, load: 1670, - value: 258.18, + value: 260.19, }, { detailsMonthlyForecast: { @@ -244,7 +244,7 @@ export const mockMonthlyForecastJanuaryTestProfile2: MonthlyForecast = { }, fluidType: 1, load: 8494, - value: 26.331, + value: 27.096, }, { detailsMonthlyForecast: { @@ -260,7 +260,7 @@ export const mockMonthlyForecastJanuaryTestProfile2: MonthlyForecast = { }, ], month: 1, - totalValue: 284.511, + totalValue: 287.286, } export const mockTestProfile3: ProfileType = { @@ -297,7 +297,7 @@ export const mockMonthlyForecastJanuaryTestProfile3: MonthlyForecast = { }, fluidType: 0, load: 194, - value: 29.992, + value: 30.225, }, { detailsMonthlyForecast: { @@ -309,7 +309,7 @@ export const mockMonthlyForecastJanuaryTestProfile3: MonthlyForecast = { }, fluidType: 1, load: 8494, - value: 26.331, + value: 27.096, }, { detailsMonthlyForecast: { @@ -325,7 +325,7 @@ export const mockMonthlyForecastJanuaryTestProfile3: MonthlyForecast = { }, ], month: 1, - totalValue: 56.323, + totalValue: 57.321, } export const mockProfileTypeAnswers: ProfileTypeAnswer[] = [ @@ -428,7 +428,7 @@ export const mockMonthlyForecastJanuaryTest1WithFullArrays: MonthlyForecast = { }, fluidType: 0, load: 2745, - value: 424.38, + value: 427.67, }, { detailsMonthlyForecast: { @@ -440,7 +440,7 @@ export const mockMonthlyForecastJanuaryTest1WithFullArrays: MonthlyForecast = { }, fluidType: 1, load: 14911, - value: 46.224, + value: 47.566, }, { detailsMonthlyForecast: { @@ -452,9 +452,9 @@ export const mockMonthlyForecastJanuaryTest1WithFullArrays: MonthlyForecast = { }, fluidType: 2, load: 375, - value: 29.737, + value: 42.038, }, ], month: 1, - totalValue: 500.341, + totalValue: 517.274, }