From 246d0ed3c2207afe467ae034a9e1612cf6214f21 Mon Sep 17 00:00:00 2001 From: Thomas <12561498+tn819@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:41:13 +0000 Subject: [PATCH] adjust for Korea, allow propagation of province to state --- lib/__tests__/postal-address.test.ts | 11 +++++++++++ lib/address-formats.ts | 6 +++--- lib/postal-address.ts | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/__tests__/postal-address.test.ts b/lib/__tests__/postal-address.test.ts index ef5b894..26e655f 100644 --- a/lib/__tests__/postal-address.test.ts +++ b/lib/__tests__/postal-address.test.ts @@ -342,4 +342,15 @@ describe('Propagation', () => { expect(myAddress.toObject().lastName).toBe('Doe') expect(myAddress.toObject().secondLastName).toBe('Smith') }) + + it('Propagation of changes to related properties overwrites with latest invoked even if both present', () => { + const myAddress = new PostalAddress() + + myAddress.setCity('City') + myAddress.setSi('Si') + expect(myAddress.toObject().si).toBe('Si') + expect(myAddress.toObject().city).toBe('Si') + + myAddress.setPropagation(false) + }) }) diff --git a/lib/address-formats.ts b/lib/address-formats.ts index a99a229..0983d0c 100644 --- a/lib/address-formats.ts +++ b/lib/address-formats.ts @@ -291,10 +291,10 @@ const addressFormats: AddressFormats = { KR: { default: { array: [ - ['country'], - ['do', 'si', 'dong', 'gu', 'addressNum'], - ['companyName'], ['lastName', 'firstName', 'honorific'], + ['companyName'], + ['do', 'si', 'dong', 'gu', 'addressNum'], + ['postalCode', 'country'], ], }, }, diff --git a/lib/postal-address.ts b/lib/postal-address.ts index 0da447b..c7fd691 100644 --- a/lib/postal-address.ts +++ b/lib/postal-address.ts @@ -282,6 +282,7 @@ class PostalAddress implements PostalAddressInterface { if (this.propagateToRelatedProperties) { this.setProperty('do', newValue) + this.setProperty('state', newValue) } return this } @@ -321,6 +322,10 @@ class PostalAddress implements PostalAddressInterface { public setState(newValue: string): this { this.setProperty('state', newValue) + + if (this.propagateToRelatedProperties) { + this.setProperty('province', newValue) + } return this }