Genability / genability-js

Node.js and Browser Javascript SDK for Genability APIs.
MIT License
0 stars 2 forks source link

New `TariffRateFactory` #108

Closed jasonriley closed 3 years ago

jasonriley commented 3 years ago

This issue is to create a new class that implements the factory pattern for creating new TariffRate objects in common, useful ways.

  1. Create a new class, TariffRateFactory in a new folder src/util. Create a test class for it too.

  2. First factory method is createTaxRate which takes as inputs ...

rateAmount : number
isFixedAmount : boolean = false
rateName : string = 'Taxes'

This returns an object that implements the existing TariffRate with the following fields set :

  rateGroupName = 'Taxes';
  rateName = the rateName passed in;
  chargeType = ChargeType.TAX;
  chargeClass = ChargeClass.TAX;
  chargePeriod = ChargePeriod.MONTHLY;
  transactionType = TransactionType.BUY;

Also add 1 TariffRateBand object on the rateBands property with the following set on it

  rateAmount: the rateAmount passed in ;
  rateUnit: RateUnit.PERCENTAGE, or if isFixedAmount is true, use RateUnit.COST_PER_UNIT;
  1. Create unit tests to cover the method above, including test for error when not passing in a rateAmount, test for true and false for isFixedAmount and whether the rateName defaults or not. Asset that all the fields expected to be set are set correctly. Assert that the tariffId field is null.
faizahmadf commented 3 years ago

Please clarify the below points:

createTaxRate method can't be called without rateAmount having Number value. Typescript will not allow that. Hence this case will not be able to be tested.

Isn't tariffId field is mandatory in TariffRate?