Skip to content

Commit a0df1fa

Browse files
committed
fix(world-country-state-util): fix match method
1 parent c874218 commit a0df1fa

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/util/world-country-state/world-country-state-util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export class WorldCountryStateUtil {
1212
*/
1313
private static match(state: WorldCountryState, filters: WorldCountryStateQuery): boolean {
1414
if (
15-
(filters.stateCode && state.stateCode.toLowerCase() === filters.stateCode.toLowerCase()) ||
16-
(filters.name && state.name.toLowerCase() === filters.name.toLowerCase())
15+
state.countryCode.toLowerCase() === filters.countryCode.toLowerCase() &&
16+
((filters.stateCode && state.stateCode.toLowerCase() === filters.stateCode.toLowerCase()) ||
17+
(filters.name && state.name.toLowerCase() === filters.name.toLowerCase()))
1718
) {
1819
return true;
1920
}

test/unit/util/world-country-state/world-country-stage-util.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@ import { WorldCountryState, WorldCountryStateUtil } from '../../../../src/util/w
33
describe('WorldCountryStateUtil (unit)', () => {
44
const worldCountryStateFixture: WorldCountryState = {
55
countryCode: 'US',
6-
stateCode: 'NY',
7-
name: 'New York',
6+
stateCode: 'MD',
7+
name: 'Maryland',
88
};
99

1010
describe('#find', () => {
1111
it('should find state by name', async () => {
1212
return WorldCountryStateUtil.find({
1313
countryCode: 'US',
14-
name: 'New York',
14+
name: 'Maryland',
1515
}).should.become(worldCountryStateFixture);
1616
});
1717

1818
it('should find state by countryCode', async () => {
1919
return WorldCountryStateUtil.find({
2020
countryCode: 'US',
21-
stateCode: 'NY',
21+
stateCode: 'MD',
2222
}).should.become(worldCountryStateFixture);
2323
});
2424

2525
it('should find state by valid countryCode and stateCode and wrong state name', async () => {
2626
return WorldCountryStateUtil.find({
2727
countryCode: 'US',
28-
stateCode: 'NY',
28+
stateCode: 'MD',
2929
name: 'Wrong state name',
3030
}).should.become(worldCountryStateFixture);
3131
});

0 commit comments

Comments
 (0)