From 23e99183e88ad5a7f1c5f883c5901e42a817913e Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 21 Apr 2024 22:00:27 +0100 Subject: [PATCH] test: field E --- src/ACTUD/ACTUDBody.ts | 14 +++++++++++--- tests/actud.test.ts | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/ACTUD/ACTUDBody.ts b/src/ACTUD/ACTUDBody.ts index de3fd61..d48b620 100644 --- a/src/ACTUD/ACTUDBody.ts +++ b/src/ACTUD/ACTUDBody.ts @@ -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"); + } + } } /** diff --git a/tests/actud.test.ts b/tests/actud.test.ts index d1cb211..da91aca 100644 --- a/tests/actud.test.ts +++ b/tests/actud.test.ts @@ -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")); + }); }); \ No newline at end of file