Skip to content

Commit

Permalink
test: field E
Browse files Browse the repository at this point in the history
  • Loading branch information
Dannyps committed Apr 21, 2024
1 parent 9d18696 commit 23e9918
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/ACTUD/ACTUDBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,20 @@ export class ACTUDBody {
*
* code: ***E***
*/
private _InvoiceStatus: InvoiceStatus;
private _InvoiceStatus: InvoiceStatus | null;
public get InvoiceStatus(): string {
return GetNameFromInvoiceStatus(this._InvoiceStatus);
return GetNameFromInvoiceStatus(this._InvoiceStatus!);
}
public set InvoiceStatus(value: string) {
this._InvoiceStatus = InvoiceStatus[this.CheckValue("InvoiceStatus", value, 1, 1) as keyof typeof InvoiceStatus];
if(this.CheckValue("InvoiceStatus", value, 1, 1) && Object.values(InvoiceStatus).includes(value)) {
this._InvoiceStatus = InvoiceStatus[value as keyof typeof InvoiceStatus];
} else {
if (this._options?.ignoreErrors) {
this._InvoiceStatus = null;
} else {
throw new InvalidArgumentCheckError("InvoiceStatus");
}
}
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/actud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,20 @@ describe('Invalid D field', () => {
test('invalid field leads to a special thrown exception', () => {
expect(t("ZZ")).toThrow(new InvalidArgumentCheckError("InvoiceType"));
});
});

describe('Invalid E field', () => {
const t = (eValue: string) => () => new ACTUD(`A:999999990*B:100000061*C:PT*D:FT*E:${eValue}*F:20201123*G:FAC 1/19*H:0*I1:PT*I7:17.90*I8:4.12*N:4.12*O:22.02*Q:LJT/*R:2648`);

test('field too long leads to a thrown exception', () => {
expect(t("Normal")).toThrow(new InvalidArgumentLengthError("InvoiceStatus", 1, 1));
});

test('field too short leads to a thrown exception', () => {
expect(t("")).toThrow(new InvalidArgumentLengthError("InvoiceStatus", 1, 1));
});

test('invalid field leads to a special thrown exception', () => {
expect(t("X")).toThrow(new InvalidArgumentCheckError("InvoiceStatus"));
});
});

0 comments on commit 23e9918

Please sign in to comment.