Skip to content

Commit

Permalink
Merge pull request #67 from miles-grant-ibigroup/master
Browse files Browse the repository at this point in the history
Migrate to Typescript
  • Loading branch information
evansiroky authored Aug 23, 2021
2 parents b51378c + c503ac8 commit 8adf0ac
Show file tree
Hide file tree
Showing 9 changed files with 6,476 additions and 9,899 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Node.js CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Install npm packages using cache
uses: bahmutov/npm-install@v1
with:
# the IBI Group TSDX fork has some dependency issues
# that cause yarn install to fail on a ci runner. Disabling
# concurrency allows installation to complete successfully
install-command: yarn --frozen-lockfile --network-concurrency 1
- name: Lint Code
run: yarn lint
- name: Lint Docs
run: yarn lint-docs
- name: Test Code
run: yarn test-node
- name: Build Package
run: yarn build

# at this point, the build is successful
- name: Semantic Release
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn semantic-release
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ node_modules

# built files
build/*
dist/*

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# OS X
.DS_Store

# Handled by TSDX
.eslintrc.js
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
tmp
__tests__
coverage
.travis.yml
yarn.lock
.github
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

File renamed without changes.
37 changes: 28 additions & 9 deletions __tests__/index.js → __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const nock = require('nock')

const geocoder = require('../index.js')
const geocoder = require('../index')

const mockReverseResult = require('./mock-reverse-result.json')
const mockSearchResult = require('./mock-search-result.json')
const mockKey = 'test-key'
Expand All @@ -13,22 +14,25 @@ describe('autocomplete', () => {
.get(/v1\/autocomplete/)
.reply(200, mockSearchResult)

const result = await geocoder.autocomplete({apiKey: mockKey, text: '123 a'})
const result = await geocoder.autocomplete({
apiKey: mockKey,
text: '123 a'
})
expect(result.features[0].geometry.coordinates[0]).toEqual(-77.023104)
})

it('should successfully autocomplete with custom headers', async () => {
nock('https://search.mapzen.com/', {
// Check for custom headers passed in below autocomplete request.
reqheaders: {
'x-api-key': headerValue => headerValue.includes('123')
'x-api-key': (headerValue) => headerValue.includes('123')
}
})
.get(/v1\/autocomplete/)
.reply(200, mockSearchResult)

const result = await geocoder.autocomplete({
options: {headers: {'x-api-key': 'abc123'}},
options: { headers: { 'x-api-key': 'abc123' } },
text: '123+Main+St'
})
expect(result.features[0].geometry.coordinates[0]).toEqual(-77.023104)
Expand All @@ -39,7 +43,11 @@ describe('autocomplete', () => {
.get(/v1\/autocomplete/)
.reply(200, mockSearchResult)

const result = await geocoder.autocomplete({apiKey: mockKey, includeQueryInResponse: true, text: '123 a'})
const result = await geocoder.autocomplete({
apiKey: mockKey,
includeQueryInResponse: true,
text: '123 a'
})
expect(result).toMatchSnapshot()
})
})
Expand All @@ -52,7 +60,7 @@ describe('search', () => {
.get(/v1\/search/)
.reply(200, mockSearchResult)

const result = await geocoder.search({apiKey: mockKey, text: searchQuery})
const result = await geocoder.search({ apiKey: mockKey, text: searchQuery })
expect(result.features[0].geometry.coordinates[0]).toEqual(-77.023104)
})

Expand All @@ -74,7 +82,11 @@ describe('search', () => {
.get(/v1\/search/)
.reply(200, mockSearchResult)

const result = await geocoder.search({apiKey: mockKey, format: true, text: searchQuery})
const result = await geocoder.search({
apiKey: mockKey,
format: true,
text: searchQuery
})
expect(result).toMatchSnapshot()
expect(result[0].address).toEqual('Takoma, Takoma Park, MD, USA')
})
Expand All @@ -88,7 +100,10 @@ describe('reverse', () => {
.get(/v1\/reverse/)
.reply(200, mockReverseResult)

const result = await geocoder.reverse({apiKey: mockKey, point: reverseQuery})
const result = await geocoder.reverse({
apiKey: mockKey,
point: reverseQuery
})
expect(result.features[0].geometry.coordinates[0]).toEqual(-77.023104)
})

Expand All @@ -97,7 +112,11 @@ describe('reverse', () => {
.get(/v1\/reverse/)
.reply(200, mockReverseResult)

const result = await geocoder.reverse({apiKey: mockKey, format: true, point: reverseQuery})
const result = await geocoder.reverse({
apiKey: mockKey,
format: true,
point: reverseQuery
})
expect(result).toMatchSnapshot()
expect(result[0].address).toEqual('Takoma, Takoma Park, MD, USA')
})
Expand Down
Loading

0 comments on commit 8adf0ac

Please sign in to comment.