Skip to content

Commit

Permalink
Merge branch 'feature/unit-testing' into feature/unit-testing-search-…
Browse files Browse the repository at this point in the history
…address-from-partial-zipcode
  • Loading branch information
marumoto-goq committed May 1, 2024
2 parents d2aa7c8 + 9b42acd commit 024c41d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/test/constants/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address } from '../type/type';
import { Address, UnHyphenatedZipCode } from '../type/type';

export const addresses: Address[] = [
export const addresses: Address<UnHyphenatedZipCode>[] = [
{
zipcode: '7340001',
pref: '広島県',
Expand Down
4 changes: 3 additions & 1 deletion src/test/constants/addressIncludingHyphenDataList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const addressIncludingHyphenDataList = [
import type { Address, HyphenatedZipCode } from '../type/type';

export const addressIncludingHyphenDataList: Address<HyphenatedZipCode>[] = [
{
zipcode: '734-0001',
pref: '広島県',
Expand Down
3 changes: 1 addition & 2 deletions src/test/convertHyphenatedZipCode.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from '@jest/globals';
import { goqZipCode } from './utils/goqZipCode';
import { addresses } from './constants/address';
import { addressIncludingHyphenDataList } from './constants';
import { addresses, addressIncludingHyphenDataList } from './constants';

describe('オプションによってハイフンを付与', () => {
test('オプションでハイフンありを指定している場合、郵便番号にハイフンを追加する', () => {
Expand Down
1 change: 1 addition & 0 deletions src/test/convertZipCode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { goqZipCode } from './utils/goqZipCode';

describe('convertZipCodeの動作をテスト', () => {
const expectedZipCodeExcludingHyphen = '7320021';

test('全角の郵便番号を半角に変換', () => {
expect(goqZipCode.convertZipCode('7320021')).toBe(
expectedZipCodeExcludingHyphen
Expand Down
7 changes: 5 additions & 2 deletions src/test/type/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export type Address = {
zipcode: string;
export type Address<ZipCode extends string> = {
zipcode: ZipCode;
pref: string;
city: string;
town: string;
};

export type UnHyphenatedZipCode = `${string}`;
export type HyphenatedZipCode = `${string}-${string}`;
10 changes: 7 additions & 3 deletions src/test/utils/goqZipCode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { Address } from '../type/type';
import type {
Address,
HyphenatedZipCode,
UnHyphenatedZipCode,
} from '../type/type';

export const goqZipCode = {
convertZipCode: function (testZipCode: string): string {
Expand Down Expand Up @@ -29,8 +33,8 @@ export const goqZipCode = {

convertHyphenatedZipCode: function (
hasOptionHyphen: boolean,
addresses: Address[]
): Address[] {
addresses: Address<string>[]
): Address<UnHyphenatedZipCode | HyphenatedZipCode>[] {
if (hasOptionHyphen === false) {
return addresses;
}
Expand Down

0 comments on commit 024c41d

Please sign in to comment.