Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

郵便番号で住所データを検索する処理のテスト作成 #35

Draft
wants to merge 11 commits into
base: feature/unit-testing
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/test/searchMachingZipCode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from '@jest/globals';
import { goqZipCode } from './utils/goqZipCode';
import { addresses } from './constants';

describe('郵便番号で住所データ検索', () => {
test('郵便番号で検索して住所データを取得', () => {
const expectedAddressData = {
zipcode: '7340001',
pref: '広島県',
city: '広島市南区',
town: '出汐',
};

expect(goqZipCode.searchMachingZipCode(addresses, '7340001')).toEqual(
expectedAddressData
);
});

test('郵便番号検索で一致するデータがない旨メッセージ表示', () => {
expect(goqZipCode.searchMachingZipCode(addresses, '7330001')).toBe(
'指定の住所に一致する郵便番号は見つかりませんでした'
);
});
});
15 changes: 15 additions & 0 deletions src/test/utils/goqZipCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ export const goqZipCode = {
};
});
},

searchMachingZipCode: function (
addresses: Address[],
zipCode: string
): Address | string {
const matchAddress = addresses.find(
(address) => address.zipcode === zipCode
);

if (matchAddress === undefined) {
return '指定の住所に一致する郵便番号は見つかりませんでした';
}

return matchAddress;
},
};
Loading