-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c46638
commit 2fabb61
Showing
3 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Verify | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- master | ||
|
||
env: | ||
NODE_VERSION: 20 | ||
|
||
jobs: | ||
unit-test: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js ${{ env.NODE_VERSION }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-npm- | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run Unit tests | ||
run: npm run test:unit | ||
|
||
compile: | ||
name: Compile | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js ${{ env.NODE_VERSION }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-npm- | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Dry compilation | ||
run: npm run compile | ||
|
||
- name: Dry build | ||
run: npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { addGeography, Country, getGeography, Region } from '../../src'; | ||
|
||
describe('getGeography function', () => { | ||
it('should return an array of countries for given region', () => { | ||
const region = 'europe'; | ||
expect(Array.isArray(getGeography(region))).toBe(true); | ||
}); | ||
|
||
it('should return an array of countries for given country', () => { | ||
const country = 'uk'; | ||
expect(Array.isArray(getGeography(country))).toBe(true); | ||
}); | ||
|
||
it('should return an array of single item for country', () => { | ||
const country = 'uk'; | ||
expect(getGeography(country).length).toBe(1); | ||
}); | ||
|
||
it('should return an expected country', () => { | ||
const country = 'uk'; | ||
expect(getGeography(country)[0]!.name).toBe('United Kingdom'); | ||
}); | ||
|
||
it('should be able to add another country', () => { | ||
const country: Country = { | ||
type: 'country', | ||
name: 'Gondor', | ||
capital: 'Minas Tirith', | ||
abbr: 'gndr' | ||
}; | ||
|
||
addGeography(country); | ||
|
||
expect(() => getGeography('gndr')).not.toThrow(); | ||
expect(getGeography('gndr')[0]).not.toBeUndefined(); | ||
expect(getGeography('gndr')[0]!.name).toBe('Gondor'); | ||
}); | ||
|
||
it('should be able to add another region', () => { | ||
const countries: Country[] = [ | ||
{ type: 'country', name: 'Gondor', capital: 'Minas Tirith', abbr: 'gondor' }, | ||
{ type: 'country', name: 'Rohan', capital: 'Edoras', abbr: 'rohan' }, | ||
{ type: 'country', name: 'Rivendell', capital: 'Rivendell', abbr: 'rivendell' } | ||
]; | ||
|
||
const middleEarth: Region = { | ||
type: 'region', | ||
abbr: 'middle-earth-region', | ||
name: 'Middle Earth', | ||
subs: ['gondor', 'rohan', 'rivendell'] | ||
}; | ||
|
||
countries.forEach((c) => addGeography(c)); | ||
addGeography(middleEarth); | ||
|
||
expect(() => getGeography(middleEarth.abbr)).not.toThrow(); | ||
expect(getGeography(middleEarth.abbr).length).toBe(3); | ||
}); | ||
}); |