diff --git a/src/services/consumption.service.spec.ts b/src/services/consumption.service.spec.ts index 3220ebd0943ac24b8c0f328e01daa958bedb8fee..6d57b2bc94d606bf9db975131d354ea09210d3e0 100644 --- a/src/services/consumption.service.spec.ts +++ b/src/services/consumption.service.spec.ts @@ -3,7 +3,7 @@ import mockClient from './__mocks__/client' import { TimeStep } from 'enum/timeStep.enum' import { DateTime } from 'luxon' import { FluidType } from 'enum/fluid.enum' -import { Dataload } from 'models' +import { Dataload, TimePeriod } from 'models' const mockFetchFluidData = jest.fn() const mockFetchFluidMaxData = jest.fn() @@ -23,15 +23,15 @@ jest.mock('./queryRunner.service', () => { describe('Consuption service', () => { const consumptionDataManager = new ConsumptionDataManager(mockClient) let fluidTypes: FluidType[] = [0] - const mockTimePeriod = { + const mockTimePeriod: TimePeriod = { startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), endDate: DateTime.fromISO('2020-10-03T23:59:59.999'), } - const mockTimePeriodComparison = { + const mockTimePeriodComparison: TimePeriod = { startDate: DateTime.fromISO('2020-09-01T00:00:00.000'), endDate: DateTime.fromISO('2020-09-03T23:59:59.999'), } - const mockFetchDataActual = [ + const mockFetchDataActual: Dataload[] = [ { date: DateTime.fromMillis(1601503200000), value: 291.9, @@ -41,7 +41,7 @@ describe('Consuption service', () => { value: 260.15, }, ] - const mockFetchDataComparison = [ + const mockFetchDataComparison: Dataload[] = [ { date: DateTime.fromMillis(1598911200000), value: 228.23, @@ -100,6 +100,7 @@ describe('Consuption service', () => { ) expect(result).toEqual(mockResult) }) + it('should return a mapped data for multiple fluid', async () => { fluidTypes = [0, 1, 2] for (let i = 0; i < fluidTypes.length; i++) { @@ -160,7 +161,37 @@ describe('Consuption service', () => { ) expect(result).toEqual(mockResult) }) - + it('should return a mapped data for one fluid without comparison date', async () => { + const mockResult = { + actualData: [ + { + date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + value: 45.127739999999996, + valueDetail: [45.127739999999996], + }, + { + date: DateTime.fromISO('2020-10-02T00:00:00.000+02:00'), + value: 40.21918999999999, + valueDetail: [40.21918999999999], + }, + { + date: DateTime.fromISO('2020-10-03T00:00:00.000+02:00'), + value: 0, + valueDetail: [-1], + }, + ], + comparisonData: [], + } + for (let i = 0; i < fluidTypes.length; i++) { + mockFetchFluidData.mockResolvedValueOnce(mockFetchDataActual) + } + const result = await consumptionDataManager.getGraphData( + mockTimePeriod, + TimeStep.DAY, + fluidTypes + ) + expect(result).toEqual(mockResult) + }) it('should return null because of wrong parameters', async () => { const mockFluidTypes = [1] const result = await consumptionDataManager.getGraphData( diff --git a/src/services/consumption.service.ts b/src/services/consumption.service.ts index 3df43ab97181977e4188ddc218d08f3e71246041..22f3c7337969e23a78c668ef6bead16ece083a90 100644 --- a/src/services/consumption.service.ts +++ b/src/services/consumption.service.ts @@ -92,7 +92,6 @@ export default class ConsumptionDataManager { chartFluid: fluidType, }) } - const aggregatedData = this.aggregateGraphData(toBeAgreggatedData) // mapping result to contract @@ -100,8 +99,6 @@ export default class ConsumptionDataManager { return mappedData } else return null - - return mappedData } public async getMaxLoad( @@ -152,6 +149,7 @@ export default class ConsumptionDataManager { [fluideType], compareTimePeriod ) + if (graphData) { const performanceIndicator: PerformanceIndicator = { value: null, @@ -368,7 +366,7 @@ export default class ConsumptionDataManager { singleFluidCharts[0].chartData.comparisonData.length, singleFluidCharts[0].chartData.actualData.length ) - } else zlength = singleFluidCharts[0].chartData.actualData.length + } else length = singleFluidCharts[0].chartData.actualData.length for (let i = 0; i < length; i++) { //const agreggatedDate= singleFluidCharts[0].chartData.actualData[i].; diff --git a/src/services/consumptionFormatter.service.spec.ts b/src/services/consumptionFormatter.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..ff053cef2c3e7e8d56d781a9c66bd6afeb128e72 --- /dev/null +++ b/src/services/consumptionFormatter.service.spec.ts @@ -0,0 +1,167 @@ +import ConsumptionFormatterService from './consumptionFormatter.service' +import { TimeStep } from 'enum/timeStep.enum' +import { DateTime } from 'luxon' +import { Dataload, TimePeriod } from 'models' + +const mockDataLoad: Dataload[] = [ + { + date: DateTime.fromISO('2020-10-01T00:00:00.000'), + value: 291.9, + }, + { + date: DateTime.fromISO('2020-10-01T00:30:00.000'), + value: 235.5, + }, + { + date: DateTime.fromISO('2020-10-03T18:59:59.999'), + value: 260.15, + }, + { + date: DateTime.fromISO('2020-10-03T20:59:59.999'), + value: 293.33, + }, + { + date: DateTime.fromISO('2020-11-03T20:59:59.999'), + value: 268.55, + }, + { + date: DateTime.fromISO('2018-11-03T20:59:59.999'), + value: 272.33, + }, +] +let mockTimePeriod: TimePeriod = { + startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-10-03T23:59:59.999'), +} +const unknowTimeStep = 999 +describe('ConsumptionFormatter service', () => { + const consumptionFormatterService = new ConsumptionFormatterService() + describe('formatGraphData method', () => { + it('shoud return a formattedData for DAY', async () => { + const mockResult = [ + { + date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + value: 291.9, + valueDetail: null, + }, + { + date: DateTime.fromISO('2020-10-02T00:00:00.000+02:00'), + value: -1, + valueDetail: null, + }, + { + date: DateTime.fromISO('2020-10-03T18:59:59.999+02:00'), + value: 260.15, + valueDetail: null, + }, + ] + const result = await consumptionFormatterService.formatGraphData( + mockDataLoad, + mockTimePeriod, + TimeStep.DAY + ) + expect(result).toEqual(mockResult) + }) + it('shoud return a formattedData for HALF_AN_HOUR', async () => { + mockTimePeriod = { + startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-10-01T01:00:00.000'), + } + + const mockResult = [ + { + date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + value: 291.9, + valueDetail: null, + }, + { + date: DateTime.fromISO('2020-10-01T00:30:00.000+02:00'), + value: 235.5, + valueDetail: null, + }, + { + date: DateTime.fromISO('2020-10-01T01:00:00.000+02:00'), + value: -1, + valueDetail: null, + }, + ] + const result = await consumptionFormatterService.formatGraphData( + mockDataLoad, + mockTimePeriod, + TimeStep.HALF_AN_HOUR + ) + expect(result).toEqual(mockResult) + }) + it('shoud return a formattedData for MONTH', async () => { + mockTimePeriod = { + startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-12-01T00:00:00.000'), + } + + const mockResult = [ + { + date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + value: 291.9, + valueDetail: null, + }, + { + date: DateTime.fromISO('2020-11-03T20:59:59.999+01:00'), + value: 268.55, + valueDetail: null, + }, + { + date: DateTime.fromISO('2020-12-01T01:00:00.000+02:00'), + value: -1, + valueDetail: null, + }, + ] + const result = await consumptionFormatterService.formatGraphData( + mockDataLoad, + mockTimePeriod, + TimeStep.MONTH + ) + expect(result).toEqual(mockResult) + }) + it('shoud return a formattedData for YEAR', async () => { + mockTimePeriod = { + startDate: DateTime.fromISO('2018-10-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-12-01T00:00:00.000'), + } + + const mockResult = [ + { + date: DateTime.fromISO('2018-11-03T20:59:59.999+01:00'), + value: 272.33, + valueDetail: null, + }, + { + date: DateTime.fromISO('2019-10-01T00:00:00.000+02:00'), + value: -1, + valueDetail: null, + }, + { + date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + value: 291.9, + valueDetail: null, + }, + ] + const result = await consumptionFormatterService.formatGraphData( + mockDataLoad, + mockTimePeriod, + TimeStep.YEAR + ) + expect(result).toEqual(mockResult) + }) + it('shoud return an error because of unknown TimeStep', async () => { + try { + await consumptionFormatterService.formatGraphData( + mockDataLoad, + mockTimePeriod, + unknowTimeStep + ) + } catch (error) { + expect(error).toEqual(new Error('TimeStep unknown')) + } + }) + }) +}) diff --git a/src/services/consumptionFormatter.service.ts b/src/services/consumptionFormatter.service.ts index f810dee905ea8598107db154f0abcf62d0b7d0a9..41e8faf6aff47b3b9130bd9c17e949fac572e93d 100644 --- a/src/services/consumptionFormatter.service.ts +++ b/src/services/consumptionFormatter.service.ts @@ -33,7 +33,6 @@ export default class ConsumptionFormatterService { const filtereddata = data.filter(dt => dateChartService.compareStepDate(timeStep, dt.date, parsingDate) ) - const newElement = filtereddata[0] ? filtereddata[0] : { @@ -61,8 +60,8 @@ export default class ConsumptionFormatterService { case TimeStep.YEAR: return { years: 1 } - default: - return { minutes: 30 } + // default: + // return { minutes: 30 } } } } diff --git a/src/services/consumptionValidator.service.spec.ts b/src/services/consumptionValidator.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..40b8216a1215d6298f73491c99c8af616a1fa836 --- /dev/null +++ b/src/services/consumptionValidator.service.spec.ts @@ -0,0 +1,150 @@ +import ConsumptionValidatorService from './consumptionValidator.service' +import mockClient from './__mocks__/client' +import { TimeStep } from 'enum/timeStep.enum' +import { DateTime } from 'luxon' +import { FluidType } from 'enum/fluid.enum' +import { Dataload, TimePeriod } from 'models' + +const mockTimePeriod: TimePeriod = { + startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-10-03T23:59:59.999'), +} +const mockTimePeriodComparison: TimePeriod = { + startDate: DateTime.fromISO('2020-09-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-09-03T23:59:59.999'), +} +let fluidTypes: FluidType[] = [0, 1, 2] +describe('ConsumptionFormatter service', () => { + const consumptionValidatorService = new ConsumptionValidatorService() + describe('formatGraphData method', () => { + it('shoud return true for DAY', () => { + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriod, + TimeStep.DAY, + fluidTypes + ) + expect(result).toBeTruthy() + }) + it('shoud return true with comparison Date', () => { + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriod, + TimeStep.DAY, + fluidTypes, + mockTimePeriodComparison + ) + expect(result).toBeTruthy() + }) + it('shoud return false with comparison Date', () => { + const wrongTimePeriodComparison: TimePeriod = { + startDate: DateTime.fromISO('2020-09-05T00:00:00.000'), + endDate: DateTime.fromISO('2020-09-03T23:59:59.999'), + } + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriod, + TimeStep.DAY, + fluidTypes, + wrongTimePeriodComparison + ) + expect(result).toBeFalsy() + }) + it('shoud return false with comparison Date', () => { + const wrongTimePeriodComparison: TimePeriod = { + startDate: DateTime.fromISO('2020-09-05T00:00:00.000'), + endDate: DateTime.fromISO('2020-09-07T23:59:59.999'), + } + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriod, + TimeStep.HALF_AN_HOUR, + [0], + wrongTimePeriodComparison + ) + expect(result).toBeFalsy() + }) + it('shoud return false because of fluid', () => { + const wrongFluidType: FluidType[] = [] + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriod, + TimeStep.DAY, + wrongFluidType + ) + expect(result).toBeFalsy() + }) + it('shoud return false because of wrong TimePeriod', () => { + const wrongTimePeriod: TimePeriod = { + startDate: DateTime.fromISO('2020-10-05T00:00:00.000'), + endDate: DateTime.fromISO('2020-10-03T23:59:59.999'), + } + const result = consumptionValidatorService.ValidateGetGraphData( + wrongTimePeriod, + TimeStep.DAY, + fluidTypes + ) + expect(result).toBeFalsy() + }) + it('shoud return false because of HALF_AN_HOUR and ELECTRICITY', () => { + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriod, + TimeStep.HALF_AN_HOUR, + fluidTypes + ) + expect(result).toBeFalsy() + }) + it('shoud return false because of HOUR and GAS', () => { + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriod, + TimeStep.HOUR, + fluidTypes + ) + expect(result).toBeFalsy() + }) + it('shoud 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.000'), + endDate: DateTime.fromISO('2020-10-02T22:59:59.999'), + } + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriodTooLong, + TimeStep.HALF_AN_HOUR, + fluidTypes + ) + expect(result).toBeFalsy() + }) + it('shoud return false because of DAY and ValidateTimePeriodLength', () => { + const mockTimePeriodTooLong: TimePeriod = { + startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-12-01T22:59:59.999'), + } + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriodTooLong, + TimeStep.DAY, + fluidTypes + ) + expect(result).toBeFalsy() + }) + it('shoud return false because of MONTH and ValidateTimePeriodLength', () => { + const mockTimePeriodTooLong: TimePeriod = { + startDate: DateTime.fromISO('2018-10-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-12-01T22:59:59.999'), + } + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriodTooLong, + TimeStep.MONTH, + fluidTypes + ) + expect(result).toBeFalsy() + }) + it('shoud return false because of YEAR and ValidateTimePeriodLength', () => { + const mockTimePeriodTooLong: TimePeriod = { + startDate: DateTime.fromISO('2009-10-01T00:00:00.000'), + endDate: DateTime.fromISO('2020-12-01T22:59:59.999'), + } + const result = consumptionValidatorService.ValidateGetGraphData( + mockTimePeriodTooLong, + TimeStep.YEAR, + fluidTypes + ) + expect(result).toBeFalsy() + }) + }) +}) diff --git a/src/services/timePeriod.service.spec.ts b/src/services/timePeriod.service.spec.ts index 0e3bd9d1094815c68daebe2fa0270731a46b74f7..60b75294b78a41baebc644a1109ced23918b0c91 100644 --- a/src/services/timePeriod.service.spec.ts +++ b/src/services/timePeriod.service.spec.ts @@ -11,22 +11,17 @@ describe('timePeriod service', () => { describe('getTimePeriods method', () => { const lastDatePeriod = DateTime.fromISO('2020-10-31T08:00:00.000') const fluidTypes: FluidType[] = [0, 1, 2] - - it('should return the current timePeriod and the comparison timePeriod for all timeStep', () => { - const comparisonTimePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-08-01T00:00:00.000').setLocale( - 'fr-FR' - ), - endDate: DateTime.fromISO('2020-08-31T00:00:00.000').setLocale('fr-FR'), - } - - const timePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-09-01T00:00:00.000').setLocale( - 'fr-FR' - ), - endDate: DateTime.fromISO('2020-09-30T23:59:59.999').setLocale('fr-FR'), - } - let result = timePeriodService.getTimePeriods( + const comparisonTimePeriod: TimePeriod = { + startDate: DateTime.fromISO('2020-08-01T00:00:00.000').setLocale('fr-FR'), + endDate: DateTime.fromISO('2020-08-31T00:00:00.000').setLocale('fr-FR'), + } + const timePeriod: TimePeriod = { + startDate: DateTime.fromISO('2020-09-01T00:00:00.000').setLocale('fr-FR'), + endDate: DateTime.fromISO('2020-09-30T23:59:59.999').setLocale('fr-FR'), + } + let result = null + it('should return the current timePeriod and the comparison timePeriod for DAY', () => { + result = timePeriodService.getTimePeriods( lastDatePeriod, fluidTypes, TimeStep.DAY @@ -35,7 +30,8 @@ describe('timePeriod service', () => { timePeriod, comparisonTimePeriod, }) - + }) + it('should return the current timePeriod and the comparison timePeriod for MONTH', () => { comparisonTimePeriod.endDate = DateTime.fromISO( '2020-08-31T23:59:59.999' ).setLocale('') @@ -58,7 +54,8 @@ describe('timePeriod service', () => { timePeriod, comparisonTimePeriod, }) - + }) + it('should return the current timePeriod and the comparison timePeriod for YEAR', () => { comparisonTimePeriod.endDate = DateTime.fromISO('2018-12-31T23:59:59.999') comparisonTimePeriod.startDate = DateTime.fromISO( '2018-01-01T00:00:00.000' @@ -112,18 +109,19 @@ describe('timePeriod service', () => { startDate: DateTime.fromISO('2020-10-07T08:00:00.000+02:00'), endDate: DateTime.fromISO('2020-10-14T08:00:00.000+02:00'), } - it('should return the comparison TimePeriod', () => { - let expectedComparisonDateTime: TimePeriod = { - startDate: DateTime.fromISO('2020-10-06T08:00:00.000+02:00'), - endDate: DateTime.fromISO('2020-10-13T08:00:00.000+02:00'), - } - - let result = timePeriodService.getComparisonTimePeriod( + let expectedComparisonDateTime: TimePeriod = { + startDate: DateTime.fromISO('2020-10-06T08:00:00.000+02:00'), + endDate: DateTime.fromISO('2020-10-13T08:00:00.000+02:00'), + } + let result = null + it('should return the comparison TimePeriod for HOUR', () => { + result = timePeriodService.getComparisonTimePeriod( timePeriod, TimeStep.HOUR ) expect(result).toEqual(expectedComparisonDateTime) - + }) + it('should return the comparison TimePeriod for DAY', () => { expectedComparisonDateTime = { startDate: DateTime.fromISO('2020-10-01T00:00:00.000+02:00').setLocale( 'fr-FR' @@ -135,7 +133,8 @@ describe('timePeriod service', () => { TimeStep.DAY ) expect(result).toEqual(expectedComparisonDateTime) - + }) + it('should return the comparison TimePeriod for MONTH', () => { expectedComparisonDateTime = { startDate: DateTime.fromISO('2020-09-07T00:00:00.000+02:00'), endDate: DateTime.fromISO('2020-09-30T23:59:59.999+02:00'), @@ -145,7 +144,8 @@ describe('timePeriod service', () => { TimeStep.MONTH ) expect(result).toEqual(expectedComparisonDateTime) - + }) + it('should return the comparison TimePeriod for YEAR', () => { expectedComparisonDateTime = { startDate: DateTime.fromISO('2019-10-07T00:00:00.000+02:00'), endDate: DateTime.fromISO('2019-12-31T23:59:59.999+01:00'), @@ -155,7 +155,8 @@ describe('timePeriod service', () => { TimeStep.YEAR ) expect(result).toEqual(expectedComparisonDateTime) - + }) + it('should return an error because of unknown TimeStep', () => { try { result = timePeriodService.getComparisonTimePeriod( timePeriod, @@ -168,14 +169,16 @@ describe('timePeriod service', () => { }) describe('getLastDayOfCompletePeriod method', () => { - it('should return the date of the last day of a completed period', () => { - let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000+02:00') - let result = timePeriodService.getLastDayOfCompletePeriod( + let result = null + let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000+02:00') + it('should return the date of the last day of a completed period for HOUR', () => { + result = timePeriodService.getLastDayOfCompletePeriod( randomDate, TimeStep.HOUR ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of a completed period for DAY', () => { expectedDate = DateTime.fromISO( '2020-09-30T00:00:00.000+02:00' ).setLocale('fr-FR') @@ -184,21 +187,24 @@ describe('timePeriod service', () => { TimeStep.DAY ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of a completed period for MONTH', () => { expectedDate = DateTime.fromISO('2020-09-30T00:00:00.000+02:00') result = timePeriodService.getLastDayOfCompletePeriod( randomDate, TimeStep.MONTH ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of a completed period for YEAR', () => { expectedDate = DateTime.fromISO('2019-12-31T00:00:00.000+01:00') result = timePeriodService.getLastDayOfCompletePeriod( randomDate, TimeStep.YEAR ) expect(result).toEqual(expectedDate) - + }) + it('should return an error because of unknown TimeStep', () => { try { result = timePeriodService.getLastDayOfCompletePeriod( randomDate, @@ -211,14 +217,16 @@ describe('timePeriod service', () => { }) describe('getLastDayOfTimePeriod method', () => { + let result = null + let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000+02:00') it('should return the date of the last day of current period', () => { - let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000+02:00') - let result = timePeriodService.getLastDayOfTimePeriod( + result = timePeriodService.getLastDayOfTimePeriod( randomDate, TimeStep.HOUR ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of current period', () => { expectedDate = DateTime.fromISO( '2020-10-31T23:59:59.999+01:00' ).setLocale('fr-FR') @@ -227,21 +235,24 @@ describe('timePeriod service', () => { TimeStep.DAY ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of current period', () => { expectedDate = DateTime.fromISO('2020-10-31T00:00:00.000+01:00') result = timePeriodService.getLastDayOfTimePeriod( randomDate, TimeStep.MONTH ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of current period', () => { expectedDate = DateTime.fromISO('2020-12-31T00:00:00.000+01:00') result = timePeriodService.getLastDayOfTimePeriod( randomDate, TimeStep.YEAR ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of current period', () => { try { result = timePeriodService.getLastDayOfTimePeriod( randomDate, @@ -254,14 +265,16 @@ describe('timePeriod service', () => { }) describe('getStartDateFromEndDateByTimeStep method', () => { + let result = null + let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000+02:00') it('should return the date of the first day of a period', () => { - let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000+02:00') - let result = timePeriodService.getStartDateFromEndDateByTimeStep( + result = timePeriodService.getStartDateFromEndDateByTimeStep( randomDate, TimeStep.HOUR ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of current period', () => { expectedDate = DateTime.fromISO( '2020-10-01T00:00:00.000+02:00' ).setLocale('fr-FR') @@ -270,21 +283,24 @@ describe('timePeriod service', () => { TimeStep.DAY ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of current period', () => { expectedDate = DateTime.fromISO('2020-10-01T00:00:00.000+02:00') result = timePeriodService.getStartDateFromEndDateByTimeStep( randomDate, TimeStep.MONTH ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of current period', () => { expectedDate = DateTime.fromISO('2020-01-01T00:00:00.000+01:00') result = timePeriodService.getStartDateFromEndDateByTimeStep( randomDate, TimeStep.YEAR ) expect(result).toEqual(expectedDate) - + }) + it('should return the date of the last day of current period', () => { try { result = timePeriodService.getStartDateFromEndDateByTimeStep( randomDate,