Skip to content

Commit 704a03c

Browse files
authored
Merge pull request #16 from ConsumerDataStandardsAustralia/bau/v1.29.1
Bau/v1.29.1
2 parents a2eed0a + ddf6120 commit 704a03c

File tree

10 files changed

+249
-21
lines changed

10 files changed

+249
-21
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cds-au/testdata",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "Tools for the creation of manufactured test data for the Australian Consumer Data Right regime",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -27,7 +27,7 @@
2727
"typescript": "^4.5.5"
2828
},
2929
"dependencies": {
30-
"@types/consumer-data-standards": "7.1.0",
30+
"@types/consumer-data-standards": "^7.2.0",
3131
"better-ajv-errors": "^1.1.2",
3232
"big-json": "^3.2.0",
3333
"json-schema-to-typescript": "^10.1.5",

samples/options/create-combined.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
{
170170
"weighting": 50,
171171
"factory": {
172-
"id": "create-energy-transactions",
172+
"id": "create-energy-transactions-v3",
173173
"options": {
174174
"transactionUType": "usage"
175175
}
@@ -179,7 +179,7 @@
179179
{
180180
"weighting": 50,
181181
"factory": {
182-
"id": "create-energy-transactions",
182+
"id": "create-energy-transactions-v3",
183183
"options": {
184184
"transactionUType": "demand"
185185
}
@@ -188,7 +188,7 @@
188188
]
189189
},
190190
"balanceFactory" : {
191-
"id": "create-energy-transactions"
191+
"id": "create-energy-transactions-v3"
192192
},
193193
"concessionsFactory": {
194194
"id": "create-energy-concessions",

samples/options/create-energy-transactions.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{
3737
"weighting": 50,
3838
"factory": {
39-
"id": "create-energy-transactions",
39+
"id": "create-energy-transactions-v3",
4040
"options": {
4141
"transactionUType": "usage"
4242
}
@@ -46,7 +46,7 @@
4646
{
4747
"weighting": 50,
4848
"factory": {
49-
"id": "create-energy-transactions",
49+
"id": "create-energy-transactions-v3",
5050
"options": {
5151
"transactionUType": "demand"
5252
}
@@ -55,7 +55,7 @@
5555
]
5656
},
5757
"balanceFactory" : {
58-
"id": "create-energy-transactions"
58+
"id": "create-energy-transactions-v3"
5959
}
6060

6161
}

src/factories/energy/createEnergyAccountData.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ Key values randomly allocated:
4949
plans: [],
5050
accountId: uuidv4()
5151
};
52-
let displayName = Helper.randomBoolean(null) ? "Display name" : null;
52+
let displayName = Helper.randomBoolean(null) ? RandomEnergy.EnergyAccountName() : null;
5353
// 80% probability that an account number exists
54-
let accountNumber = Helper.randomBoolean(0.8) ? "23455-4567" : null;
54+
let accountNumber = Helper.randomBoolean(0.8) ? this.generateRandomEnergyAccountNumber() : null;
5555
// create a number of plan object, up to 10
5656
let planCount = Math.ceil(Math.random() * 3);
5757
let status = this.accountStatus;
@@ -127,6 +127,12 @@ Key values randomly allocated:
127127
return authorisedContacts;
128128
}
129129

130+
private generateRandomEnergyAccountNumber(): string {
131+
let val1 = Helper.generateRandomIntegerInRange(1000, 9999);
132+
let val2 = Helper.generateRandomIntegerInRange(1000, 9999);
133+
return `${val1}-${val2}`;
134+
}
135+
130136
public generateEnergyAccounts(customer: CustomerWrapper): EnergyAccountWrapper[] | undefined {
131137
let count = Helper.isPositiveInteger(this.options.options?.count) ? (this.options.options?.count as number) : 1;
132138

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
import { EnergyBillingDemandTransactionV3, EnergyBillingOnceOffTransaction, EnergyBillingOtherTransaction, EnergyBillingPaymentTransaction, EnergyBillingTransactionV2, EnergyBillingTransactionV3, EnergyBillingUsageTransactionV2} from "consumer-data-standards/energy";
2+
import { EnergyAccountWrapper, EnergyServicePointWrapper } from "../../logic/schema/cdr-test-data-schema";
3+
import { TransactionUType } from "../../random-generators";
4+
import { Factory, FactoryOptions, Helper } from "../../logic/factoryService";
5+
import { RandomEnergy } from '../../random-generators';
6+
7+
const factoryId: string = "create-energy-transactions-v3";
8+
9+
export class CreateEnergyTransactionV3 extends Factory {
10+
11+
constructor(options: FactoryOptions) {
12+
super(options, factoryId);
13+
this.transactionUType = options?.options?.transactionUType ? options?.options?.transactionUType: RandomEnergy.TransactionUType();
14+
}
15+
16+
public static id: string = factoryId;
17+
private transactionUType: TransactionUType;
18+
19+
private accountWrapper: EnergyAccountWrapper | undefined;
20+
private servicePointWrapper: EnergyServicePointWrapper[] | undefined;
21+
22+
public get briefDescription(): string {
23+
return "This factory will create some EnergyBillingTransactionsV3";
24+
}
25+
public get detailedDescription(): string {
26+
let st =`
27+
This factory will create some EnergyBillingTransactionsV3.
28+
29+
The factory will accept the following options:
30+
31+
count: The number of transactions to be issued for each account
32+
transactionUType: Should be 'usage', 'demand', 'onceOff', 'payment', or 'other'.
33+
The default is a random assignment
34+
35+
Key values randomly allocated:
36+
37+
The calculation factor for usage and demand transactions
38+
`
39+
return st;
40+
}
41+
42+
public canCreateEnergyTransaction(): boolean { return true; };
43+
public generateEnergyTransaction(account: EnergyAccountWrapper, servicePoints: EnergyServicePointWrapper[]): EnergyBillingTransactionV3 | undefined
44+
{
45+
this.accountWrapper = account;
46+
this.servicePointWrapper = servicePoints;
47+
48+
let id = this.accountWrapper.account.accountId;
49+
50+
let transaction : EnergyBillingTransactionV3 = {
51+
accountId: account.account.accountId,
52+
executionDateTime: Helper.randomDateTimeInThePast(),
53+
transactionUType: this.transactionUType
54+
}
55+
56+
if (this.transactionUType == TransactionUType.demand) transaction.demand = this.generateBillingDemand();
57+
if (this.transactionUType == TransactionUType.onceOff) transaction.onceOff = this.generateBillingOnceOff();
58+
if (this.transactionUType == TransactionUType.payment) transaction.payment = this.generateBillingPayment();
59+
if (this.transactionUType == TransactionUType.usage) transaction.usage = this.generateBillingUsage();
60+
if (this.transactionUType == TransactionUType.otherCharges) transaction.otherCharges = this.generateBillingOther();
61+
62+
return transaction;
63+
}
64+
65+
public canCreateEnergyTransactions(): boolean { return true; };
66+
public generateEnergyTransactions(account: EnergyAccountWrapper, servicePoints: EnergyServicePointWrapper[] ): any[] | undefined {
67+
let count = Helper.isPositiveInteger(this.options.options?.count) ? (this.options.options?.count as number) : 1;
68+
let ret: EnergyBillingTransactionV2[] = [];
69+
for (let i = 0; i < count; i++) {
70+
const el = this.generateEnergyTransaction(account, servicePoints);
71+
if (el) ret.push(el);
72+
}
73+
return ret;
74+
}
75+
76+
private generateBillingUsage(): EnergyBillingUsageTransactionV2 {
77+
let ret: EnergyBillingUsageTransactionV2 = {
78+
amount: Helper.generateRandomDecimalInRange(-100, 100, 2),
79+
endDate: Helper.randomDateTimeInTheFuture(),
80+
startDate: Helper.randomDateTimeInThePast(),
81+
timeOfUseType: RandomEnergy.TimeOfUseTypeUsage(),
82+
usage: Helper.generateRandomIntegerInRange(-100, 100),
83+
}
84+
let spID = this.getServicePointId();
85+
if (spID != null) ret.servicePointId = spID;
86+
let invoiceNumber = this.getInvoiceNumber();
87+
if (invoiceNumber != null) ret.invoiceNumber = invoiceNumber;
88+
if (Math.random() > 0.5) ret.description = "An optional description for billing usage transaction";
89+
if (Math.random() > 0.5) ret.isEstimate = Helper.randomBoolean(0.5);
90+
if (Math.random() > 0.1) ret.measureUnit = RandomEnergy.MeasureUnit();
91+
if (Math.random() > 0.1) {
92+
ret.calculationFactors = this.getCalcualtionFactors();
93+
}
94+
if (Math.random() > 0.1) {
95+
ret.adjustments = this.getAdjustments();
96+
}
97+
return ret;
98+
}
99+
100+
private generateBillingDemand(): EnergyBillingDemandTransactionV3 {
101+
let ret: EnergyBillingDemandTransactionV3 = {
102+
endDate: Helper.randomDateTimeInTheFuture(),
103+
startDate: Helper.randomDateTimeInThePast(),
104+
timeOfUseType: RandomEnergy.TimeOfUseTypeDemand(),
105+
rate: Helper.generateRandomIntegerInRange(-100, 100),
106+
amount: Helper.generateRandomDecimalInRange(-100, 100, 2),
107+
}
108+
let spID = this.getServicePointId();
109+
if (spID != null) ret.servicePointId = spID;
110+
let invoiceNumber = this.getInvoiceNumber();
111+
if (invoiceNumber != null) ret.invoiceNumber = invoiceNumber;
112+
if (Math.random() > 0.5) ret.description = "An optional description for billing demand transaction";
113+
if (Math.random() > 0.5) ret.isEstimate = Helper.randomBoolean(0.5);
114+
115+
if (Math.random() > 0.1) {
116+
ret.calculationFactors = this.getCalcualtionFactors();
117+
}
118+
if (Math.random() > 0.1) {
119+
ret.adjustments = this.getAdjustments();
120+
}
121+
return ret;
122+
}
123+
124+
private generateBillingOnceOff(): EnergyBillingOnceOffTransaction {
125+
let ret: EnergyBillingOnceOffTransaction = {
126+
amount: Helper.generateRandomDecimalInRange(-100, 100, 2),
127+
description: "Mandatory description for a once off billing charge"
128+
}
129+
let spID = this.getServicePointId();
130+
if (spID != null) ret.servicePointId = spID;
131+
let invoiceNumber = this.getInvoiceNumber();
132+
if (invoiceNumber != null) ret.invoiceNumber = invoiceNumber;
133+
return ret;
134+
}
135+
136+
137+
private generateBillingOther(): EnergyBillingOtherTransaction {
138+
let ret: EnergyBillingOtherTransaction = {
139+
amount: Helper.generateRandomDecimalInRange(-100, 100, 2),
140+
description: "Mandatory description for other billing charge"
141+
}
142+
if (Math.random() > 0.5) ret.type = RandomEnergy.OtherUsageChargesType();
143+
ret.endDate = Helper.randomDateTimeInTheFuture();
144+
ret.startDate = Helper.randomDateTimeInThePast();
145+
let spID = this.getServicePointId();
146+
if (spID != null) ret.servicePointId = spID;
147+
let invoiceNumber = this.getInvoiceNumber();
148+
if (invoiceNumber != null) ret.invoiceNumber = invoiceNumber;
149+
150+
if (Math.random() > 0.1) {
151+
ret.calculationFactors = this.getCalcualtionFactors();
152+
}
153+
if (Math.random() > 0.1) {
154+
ret.adjustments = this.getAdjustments();
155+
}
156+
return ret;
157+
}
158+
159+
private generateBillingPayment(): EnergyBillingPaymentTransaction {
160+
let ret: EnergyBillingPaymentTransaction = {
161+
amount: Helper.generateRandomDecimalInRange(-100, 100, 2),
162+
method: RandomEnergy.EnergyBillPaymentMethod()
163+
}
164+
return ret;
165+
}
166+
167+
168+
private getServicePointId(): string | null {
169+
let cnt = this.servicePointWrapper ? this.servicePointWrapper.length : 0;
170+
if (cnt > 0) {
171+
let randomIdx = Helper.generateRandomIntegerInRange(0, cnt-1);
172+
if (this.servicePointWrapper)
173+
return this.servicePointWrapper[randomIdx]?.servicePoint?.servicePointId;
174+
}
175+
return null;
176+
}
177+
178+
private getInvoiceNumber(): string | null {
179+
let cnt = this.accountWrapper ? this.accountWrapper?.invoices?.length as number : 0;
180+
if (cnt > 0) {
181+
let randomIdx = Helper.generateRandomIntegerInRange(0, cnt-1);
182+
if (this.accountWrapper?.invoices)
183+
return this.accountWrapper?.invoices[randomIdx]?.invoiceNumber
184+
}
185+
return null;
186+
}
187+
188+
private getCalcualtionFactors(): any {
189+
let calculationFactors: any[] = [];
190+
let calcFactor: any = {};
191+
calcFactor.value = Helper.generateRandomIntegerInRange(1,100);
192+
calcFactor.type = RandomEnergy.CalculationFactorType();
193+
calculationFactors.push(calcFactor)
194+
return calculationFactors;
195+
}
196+
197+
private getAdjustments(): any {
198+
let adjustments: any[] = [];
199+
let adj: any = {};
200+
adj.amount = Helper.generateRandomDecimalInRange(10,50);
201+
adj.description = "Mandatory description for billing usage transaction adjustments";
202+
adjustments.push(adj)
203+
return adjustments;
204+
}
205+
206+
207+
}

src/factories/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ factories[CreateEnergyTransaction.id] = (options: any): Factory => { return new
5252
import { CreateEnergyTransactionV2 } from './energy/createEnergyTransactionsV2';
5353
factories[CreateEnergyTransactionV2.id] = (options: any): Factory => { return new CreateEnergyTransactionV2(options)}
5454

55+
import { CreateEnergyTransactionV3 } from './energy/createEnergyTransactionsV3';
56+
factories[CreateEnergyTransactionV3.id] = (options: any): Factory => { return new CreateEnergyTransactionV3(options)}
57+
5558
import { CreateEnergyConcessions } from './energy/createConcessions';
5659
factories[CreateEnergyConcessions.id] = (options: any): Factory => { return new CreateEnergyConcessions(options)}
5760

src/logic/schema/cdr-test-data-schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BankingAccount, BankingBalance, BankingDirectDebit, BankingPayeeDetailV2, BankingProductV4, BankingScheduledPayment, BankingTransaction } from "consumer-data-standards/banking";
1+
import { BankingAccountV2, BankingBalance, BankingDirectDebit, BankingPayeeDetailV2, BankingProductV4, BankingScheduledPayment, BankingTransaction } from "consumer-data-standards/banking";
22
import { CommonOrganisationDetailV2, CommonPersonDetailV2 } from "consumer-data-standards/common";
3-
import { EnergyAccount, EnergyAccountDetailV2, EnergyAccountDetailV3, EnergyBillingTransaction, EnergyConcession, EnergyDerRecord, EnergyInvoice, EnergyPaymentSchedule, EnergyPlan, EnergyPlanDetail, EnergyServicePoint, EnergyServicePointDetail, EnergyUsageRead } from "consumer-data-standards/energy";
3+
import { EnergyAccountV2, EnergyAccountDetailV2, EnergyAccountDetailV3, EnergyBillingTransaction, EnergyConcession, EnergyDerRecord, EnergyInvoice, EnergyPaymentSchedule, EnergyPlan, EnergyPlanDetail, EnergyServicePoint, EnergyServicePointDetail, EnergyUsageRead } from "consumer-data-standards/energy";
44
import { RegisterDataRecipient } from "consumer-data-standards/register";
55

66
/* A JSON schema for defining test data files that can be used to seed a mock, or test, implementation of a Data Holder for the Consumer Data Right
@@ -85,7 +85,7 @@ export interface HolderWrapper {
8585
* A wrapper for a single bank account to contain all of the data related to the account
8686
*/
8787
export interface BankAccountWrapper {
88-
account: BankingAccount;
88+
account: BankingAccountV2;
8989
balance?: BankingBalance;
9090
/**
9191
* An array of transactions for the account

src/random-generators/random-energy.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,14 @@ export enum PlanTermType {
365365
, OTHER = "OTHER"
366366
}
367367

368+
export enum EnergyAccountName {
369+
VALUE_SAVER = "Value Saver",
370+
SOLAR_SAVER = "Solar Saver",
371+
STANDARD_ACCOUNT = "Standard Account",
372+
PENSIONER_ACCOUNT = "Pensioner Account",
373+
COMBINATION_ACCOUNT = "Combination Account",
374+
}
375+
368376
export class RandomEnergy {
369377

370378
public static GetRandomValue(enumeration: any) {
@@ -636,4 +644,8 @@ export class RandomEnergy {
636644
public static PlanTermType(): any {
637645
return this.GetRandomValue(PlanTermType);
638646
}
647+
648+
public static EnergyAccountName(): any {
649+
return this.GetRandomValue(EnergyAccountName);
650+
}
639651
}

0 commit comments

Comments
 (0)