From a2200c64432b0de6bc6cf209d8b6cc00b69c0652 Mon Sep 17 00:00:00 2001 From: marumoto Date: Fri, 26 Apr 2024 21:04:38 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feature:=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=AB=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=82=92=E7=94=A8=E6=84=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/searchAddressFromZipCode.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/searchAddressFromZipCode.test.ts b/src/test/searchAddressFromZipCode.test.ts index 50da083..01720fe 100644 --- a/src/test/searchAddressFromZipCode.test.ts +++ b/src/test/searchAddressFromZipCode.test.ts @@ -75,3 +75,16 @@ describe('オプションによってハイフンを付与', () => { ); }); }); + +test('', () => { + const expectedAddressData = { + zipcode: '7340001', + pref: '広島県', + city: '広島市南区', + town: '出汐', + }; + const expectedErrorMessage = + '指定の郵便番号に一致する住所は見つかりませんでした'; + const includedZipCode = '7340001'; + const notIncludedZipCodeFor = '7330001'; +}); From afa5861c9432ce84bffd914bf65ea542e46d140d Mon Sep 17 00:00:00 2001 From: marumoto Date: Fri, 26 Apr 2024 21:08:10 +0900 Subject: [PATCH 2/8] =?UTF-8?q?feature:=E6=9C=9F=E5=BE=85=E3=81=99?= =?UTF-8?q?=E3=82=8B=E7=B5=90=E6=9E=9C=E3=81=AB=E3=81=AA=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=83=86=E3=82=B9=E3=83=88=E3=82=B1=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/searchAddressFromZipCode.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/searchAddressFromZipCode.test.ts b/src/test/searchAddressFromZipCode.test.ts index 01720fe..33daef5 100644 --- a/src/test/searchAddressFromZipCode.test.ts +++ b/src/test/searchAddressFromZipCode.test.ts @@ -76,7 +76,7 @@ describe('オプションによってハイフンを付与', () => { }); }); -test('', () => { +test('郵便番号で検索して住所データを取得', () => { const expectedAddressData = { zipcode: '7340001', pref: '広島県', @@ -87,4 +87,7 @@ test('', () => { '指定の郵便番号に一致する住所は見つかりませんでした'; const includedZipCode = '7340001'; const notIncludedZipCodeFor = '7330001'; + + expect(includedZipCode).toBe(expectedAddressData); + expect(notIncludedZipCodeFor).toBe(expectedErrorMessage); }); From a835b34d82fef28e2c16baf2d9e8bb9208beb9e6 Mon Sep 17 00:00:00 2001 From: marumoto Date: Fri, 26 Apr 2024 21:13:31 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feature:=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E7=94=A8=E3=81=AE=E5=87=A6=E7=90=86=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/searchAddressFromZipCode.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/searchAddressFromZipCode.test.ts b/src/test/searchAddressFromZipCode.test.ts index 33daef5..7c8d2e8 100644 --- a/src/test/searchAddressFromZipCode.test.ts +++ b/src/test/searchAddressFromZipCode.test.ts @@ -88,6 +88,10 @@ test('郵便番号で検索して住所データを取得', () => { const includedZipCode = '7340001'; const notIncludedZipCodeFor = '7330001'; + const matchAddress = addresses.find( + (address) => address.zipcode === includedZipCode + ); + expect(includedZipCode).toBe(expectedAddressData); expect(notIncludedZipCodeFor).toBe(expectedErrorMessage); }); From 1ca7e534543f4f340c4afd505bf4967ab3e3e44b Mon Sep 17 00:00:00 2001 From: marumoto Date: Fri, 26 Apr 2024 21:18:09 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feature:=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E7=94=A8=E3=81=AB=E4=BD=9C=E6=88=90=E3=81=97=E3=81=A6=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E5=A4=96=E9=83=A8=E3=81=B8=E5=88=87=E3=82=8A?= =?UTF-8?q?=E5=87=BA=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/goqZiipCode.ts | 21 ++++++++++++++++++--- src/test/searchAddressFromZipCode.test.ts | 7 +------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/test/goqZiipCode.ts b/src/test/goqZiipCode.ts index 4987279..ee54bfc 100644 --- a/src/test/goqZiipCode.ts +++ b/src/test/goqZiipCode.ts @@ -2,11 +2,15 @@ import type { Address } from './type'; export const goqZipCode = { convertZipCode: function (testZipCode: string): string { - const halfWidthZipCode: string = testZipCode.replace(/[0-9]/g, (s: string) => - String.fromCharCode(s.charCodeAt(0) - 65248) + const halfWidthZipCode: string = testZipCode.replace( + /[0-9]/g, + (s: string) => String.fromCharCode(s.charCodeAt(0) - 65248) ); - const halfWidthZipCodeExcludingHyphen = halfWidthZipCode.replaceAll(/\D/g, ''); + const halfWidthZipCodeExcludingHyphen = halfWidthZipCode.replaceAll( + /\D/g, + '' + ); return halfWidthZipCodeExcludingHyphen; }, @@ -37,4 +41,15 @@ export const goqZipCode = { }; }); }, + + searchMachingZipCode: function ( + addresses: Address[], + zipCode: string + ): Address | string { + const matchAddress = addresses.find( + (address) => address.zipcode === zipCode + ); + + return matchAddress; + }, }; diff --git a/src/test/searchAddressFromZipCode.test.ts b/src/test/searchAddressFromZipCode.test.ts index 7c8d2e8..3d1998d 100644 --- a/src/test/searchAddressFromZipCode.test.ts +++ b/src/test/searchAddressFromZipCode.test.ts @@ -85,13 +85,8 @@ test('郵便番号で検索して住所データを取得', () => { }; const expectedErrorMessage = '指定の郵便番号に一致する住所は見つかりませんでした'; - const includedZipCode = '7340001'; const notIncludedZipCodeFor = '7330001'; - const matchAddress = addresses.find( - (address) => address.zipcode === includedZipCode - ); - - expect(includedZipCode).toBe(expectedAddressData); + expect(goqZipCode.searchMachingZipCode(addresses, '7340001')).toBe(expectedAddressData); expect(notIncludedZipCodeFor).toBe(expectedErrorMessage); }); From 4dcac97c324db04148c6b2ba293a5f08a2739bca Mon Sep 17 00:00:00 2001 From: marumoto Date: Fri, 26 Apr 2024 21:20:28 +0900 Subject: [PATCH 5/8] =?UTF-8?q?feature:=E9=83=B5=E4=BE=BF=E7=95=AA?= =?UTF-8?q?=E5=8F=B7=E3=81=A7=E6=A4=9C=E7=B4=A2=E3=81=97=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E3=81=97=E3=81=9F=E7=B5=90=E6=9E=9C=E3=81=8C=E5=BE=97=E3=82=89?= =?UTF-8?q?=E3=82=8C=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E6=99=82=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B1=E3=83=BC=E3=82=B9=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/goqZiipCode.ts | 4 ++++ src/test/searchAddressFromZipCode.test.ts | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/goqZiipCode.ts b/src/test/goqZiipCode.ts index ee54bfc..bf33a52 100644 --- a/src/test/goqZiipCode.ts +++ b/src/test/goqZiipCode.ts @@ -50,6 +50,10 @@ export const goqZipCode = { (address) => address.zipcode === zipCode ); + if (matchAddress === undefined) { + return '指定の住所に一致する郵便番号は見つかりませんでした'; + } + return matchAddress; }, }; diff --git a/src/test/searchAddressFromZipCode.test.ts b/src/test/searchAddressFromZipCode.test.ts index 3d1998d..3beb697 100644 --- a/src/test/searchAddressFromZipCode.test.ts +++ b/src/test/searchAddressFromZipCode.test.ts @@ -83,10 +83,7 @@ test('郵便番号で検索して住所データを取得', () => { city: '広島市南区', town: '出汐', }; - const expectedErrorMessage = - '指定の郵便番号に一致する住所は見つかりませんでした'; - const notIncludedZipCodeFor = '7330001'; expect(goqZipCode.searchMachingZipCode(addresses, '7340001')).toBe(expectedAddressData); - expect(notIncludedZipCodeFor).toBe(expectedErrorMessage); + expect(goqZipCode.searchMachingZipCode(addresses, '7330001')).toBe( '指定の郵便番号に一致する住所は見つかりませんでした'); }); From 8d5cf99079a76004bf12dfc3bf66f084777e8789 Mon Sep 17 00:00:00 2001 From: marumoto Date: Fri, 26 Apr 2024 21:26:08 +0900 Subject: [PATCH 6/8] =?UTF-8?q?feature:=E4=BD=9C=E6=88=90=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=83=86=E3=82=B9=E3=83=88=E3=82=B1=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=82=92=E3=83=86=E3=82=B9=E3=83=88=E3=82=B9=E3=82=A4=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=81=97=E3=81=A6=E3=81=BE=E3=81=A8=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/searchAddressFromZipCode.test.ts | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/test/searchAddressFromZipCode.test.ts b/src/test/searchAddressFromZipCode.test.ts index 3beb697..c16d8c3 100644 --- a/src/test/searchAddressFromZipCode.test.ts +++ b/src/test/searchAddressFromZipCode.test.ts @@ -76,14 +76,23 @@ describe('オプションによってハイフンを付与', () => { }); }); -test('郵便番号で検索して住所データを取得', () => { - const expectedAddressData = { - zipcode: '7340001', - pref: '広島県', - city: '広島市南区', - town: '出汐', - }; - - expect(goqZipCode.searchMachingZipCode(addresses, '7340001')).toBe(expectedAddressData); - expect(goqZipCode.searchMachingZipCode(addresses, '7330001')).toBe( '指定の郵便番号に一致する住所は見つかりませんでした'); +describe('郵便番号で住所データ検索', () => { + test('郵便番号で検索して住所データを取得', () => { + const expectedAddressData = { + zipcode: '7340001', + pref: '広島県', + city: '広島市南区', + town: '出汐', + }; + + expect(goqZipCode.searchMachingZipCode(addresses, '7340001')).toBe( + expectedAddressData + ); + }); + + test('郵便番号検索で一致するデータがない旨メッセージ表示', () => { + expect(goqZipCode.searchMachingZipCode(addresses, '7330001')).toBe( + '指定の郵便番号に一致する住所は見つかりませんでした' + ); + }); }); From a7b569f6f178e2df96f7f22d9a5b5da83583fa4b Mon Sep 17 00:00:00 2001 From: marumoto Date: Fri, 26 Apr 2024 21:26:57 +0900 Subject: [PATCH 7/8] =?UTF-8?q?refactor:lint=E5=AE=9F=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/constants/masterData/address.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/constants/masterData/address.ts b/src/test/constants/masterData/address.ts index 75b71c8..85eef04 100644 --- a/src/test/constants/masterData/address.ts +++ b/src/test/constants/masterData/address.ts @@ -1,4 +1,4 @@ -import { Address } from '../../type' +import { Address } from '../../type'; export const addresses: Address[] = [ { From 134f12c2d60f537b36b30dbdddbdc93aed9ff054 Mon Sep 17 00:00:00 2001 From: marumoto Date: Fri, 26 Apr 2024 21:41:42 +0900 Subject: [PATCH 8/8] =?UTF-8?q?feature:=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=B1=E3=83=BC=E3=82=B9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/searchAddressFromZipCode.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/searchAddressFromZipCode.test.ts b/src/test/searchAddressFromZipCode.test.ts index c16d8c3..fc0f585 100644 --- a/src/test/searchAddressFromZipCode.test.ts +++ b/src/test/searchAddressFromZipCode.test.ts @@ -85,14 +85,14 @@ describe('郵便番号で住所データ検索', () => { town: '出汐', }; - expect(goqZipCode.searchMachingZipCode(addresses, '7340001')).toBe( + expect(goqZipCode.searchMachingZipCode(addresses, '7340001')).toEqual( expectedAddressData ); }); test('郵便番号検索で一致するデータがない旨メッセージ表示', () => { expect(goqZipCode.searchMachingZipCode(addresses, '7330001')).toBe( - '指定の郵便番号に一致する住所は見つかりませんでした' + '指定の住所に一致する郵便番号は見つかりませんでした' ); }); });