Skip to content

Commit

Permalink
fix failed test:
Browse files Browse the repository at this point in the history
validator atlas
  • Loading branch information
hendurhance committed Apr 14, 2024
1 parent cffc489 commit 826e4ac
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ The `isValidStateCode()` method is used to validate the given `stateCode` proper
```typescript
import { ValidatorAtlas } from '@amplifiedhq/countries-atlas'

const isValid = ValidatorAtlas.isValidStateCode('AD', '07')
const isValid = await ValidatorAtlas.isValidStateCode('AD', '07')
// true
const isValid = ValidatorAtlas.isValidStateCode('AD', 'ABC')
const isValid = await ValidatorAtlas.isValidStateCode('AD', 'ABC')
// false
```

Expand Down
141 changes: 126 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@
},
"files": [
"dist/**/*"
]
],
"dependencies": {
"@rollup/plugin-commonjs": "^25.0.7"
}
}
8 changes: 4 additions & 4 deletions src/__tests__/ValidatorAtlas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ describe('ValidatorAtlas', () => {
// expect(isValid).toBe(false);
// });

it('should return true if the state code is valid', () => {
expect(ValidatorAtlas.isValidStateCode('US', 'AZ')).toBe(true);
it('should return true if the state code is valid', async () => {
expect(await ValidatorAtlas.isValidStateCode('US', 'AZ')).toBe(true);
});

it('should return false if the state code is invalid', () => {
expect(ValidatorAtlas.isValidStateCode('US', 'XX')).toBe(false);
it('should return false if the state code is invalid', async () => {
expect(await ValidatorAtlas.isValidStateCode('US', 'XX')).toBe(false);
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/helpers/ValidatorAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class ValidatorAtlas {
*
* @param {string} iso2 - ISO2 code of the country.
* @param {string} stateCode - State code.
* @returns {boolean} - True if valid, false otherwise.
* @returns {Promise<boolean>} - True if valid, false otherwise.
*/
static isValidStateCode(iso2: string, stateCode: string): boolean {
return !!CountriesAtlas.state(iso2, stateCode);
static async isValidStateCode(iso2: string, stateCode: string): Promise<boolean> {
return !!(await CountriesAtlas.state(iso2, stateCode));
}
}

Expand Down

0 comments on commit 826e4ac

Please sign in to comment.