pricing - time restriction - cleanup
MODIFY
src/types/Pricing.ts
src/types/Pricing.ts
@@ -164,11 +164,7 @@ export class PricingTimeLimit {
return (this.hour > aTimeLimit.hour);
}
- isAfter(aTimeLimit: PricingTimeLimit): boolean {
- return this.isGreaterThan(aTimeLimit);
- }
-
- isSameOrBefore(aTimeLimit: PricingTimeLimit): boolean {
+ isSameOrLowerThan(aTimeLimit: PricingTimeLimit): boolean {
return !this.isGreaterThan(aTimeLimit);
}
@@ -182,11 +178,7 @@ export class PricingTimeLimit {
return (this.hour < aTimeLimit.hour);
}
- isBefore(aTimeLimit: PricingTimeLimit): boolean {
- return this.isLowerThan(aTimeLimit);
- }
-
- isSameOrAfter(aTimeLimit: PricingTimeLimit): boolean {
+ isSameOrGreaterThan(aTimeLimit: PricingTimeLimit): boolean {
return !this.isLowerThan(aTimeLimit);
}
@@ -195,9 +187,9 @@ export class PricingTimeLimit {
const spanTwoDays = timeTo.isLowerThan(timeFrom);
if (spanTwoDays) {
// Time range spanning two days - e.g.: - Time range from 20:00 to 08:00
- return !(this.isAfter(timeTo) || this.isSameOrBefore(timeFrom));
+ return !this.isBetween(timeTo, timeFrom); // Let's check the opposite
}
// Regular time range - e.g.: - Time range from 08:00 to 20:00
- return this.isSameOrAfter(timeFrom) && this.isBefore(timeTo);
+ return this.isSameOrGreaterThan(timeFrom) && this.isLowerThan(timeTo);
}
}

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -809,8 +809,8 @@ describe('Billing', function() {
it('should bill an invoice taking a reverted Time Range into account', async () => {
const atThatParticularMoment = moment();
- await billingTestHelper.initChargingStationContext2TestTimeRestrictions('REVERTED_TIME_RANGE', atThatParticularMoment);
- await billingTestHelper.initChargingStationContext2TestTimeRestrictions('NO_TIME_RESTRICTIONS', atThatParticularMoment);
+ await billingTestHelper.initChargingStationContext2TestTimeRestrictions('OTHER_HOURS', atThatParticularMoment);
+ await billingTestHelper.initChargingStationContext2TestTimeRestrictions('FROM_23:59', atThatParticularMoment);
// A tariff applied immediately
await billingTestHelper.userService.billingApi.forceSynchronizeUser({ id: billingTestHelper.userContext.id });
const userWithBillingData = await billingTestHelper.billingImpl.getUser(billingTestHelper.userContext);

MODIFY
test/api/BillingTestHelper.ts
test/api/BillingTestHelper.ts
@@ -326,19 +326,7 @@ export default class BillingTestHelper {
// Let's create a pricing definition
let dimensions: PricingDimensions;
let restrictions: PricingRestriction;
- if (testMode === 'REVERTED_TIME_RANGE') {
- dimensions = {
- energy: {
- price: 666,
- active: true
- }
- };
- restrictions = {
- daysOfWeek: [ atThatMoment.isoWeekday() ], // Sets today as the only day allowed for this pricing definition
- timeFrom: atThatMoment.add(30 + 60, 'minutes').format('HH:mm'), // Validity for half an hour
- timeTo: atThatMoment.format('HH:mm'), // From this hour
- };
- } else if (testMode === 'NO_TIME_RESTRICTIONS') {
+ if (testMode === 'FROM_23:59') {
dimensions = {
energy: {
price: 0.50,
@@ -347,6 +335,8 @@ export default class BillingTestHelper {
};
restrictions = {
daysOfWeek: [ atThatMoment.isoWeekday() ], // Sets today as the only day allowed for this pricing definition
+ timeFrom: '23:59', // Specific test to check the behavior when timeFrom is lower than timeTo
+ timeTo: atThatMoment.add(60 + 30, 'minutes').format('HH:mm'), // Validity for the whole session
};
} else if (testMode === 'FOR_HALF_AN_HOUR') {
dimensions = {

pricing - time restriction - cleanup