From 0f3303658ac74bce25e61b4f19436f67a4ac0cd7 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 6 Feb 2022 11:08:09 -0500 Subject: [PATCH] Init integration test --- .npmignore | 2 +- index.js | 4 +- .../geocoder/mapboxgeocoder.test.js | 58 +++++++++++++++++++ package.json | 7 ++- 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 integration_test/geocoder/mapboxgeocoder.test.js diff --git a/.npmignore b/.npmignore index acd7ab6..f5a5594 100644 --- a/.npmignore +++ b/.npmignore @@ -7,4 +7,4 @@ test.js package-lock.json playground.js .github - +integration_test diff --git a/index.js b/index.js index 7fa4113..2c9180a 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ 'use strict'; -var GeocoderFactory = require('./lib/geocoderfactory.js'); +const GeocoderFactory = require('./lib/geocoderfactory.js'); -var Exports = GeocoderFactory.getGeocoder.bind(GeocoderFactory); +const Exports = GeocoderFactory.getGeocoder.bind(GeocoderFactory); module.exports = Exports; diff --git a/integration_test/geocoder/mapboxgeocoder.test.js b/integration_test/geocoder/mapboxgeocoder.test.js new file mode 100644 index 0000000..bec68e4 --- /dev/null +++ b/integration_test/geocoder/mapboxgeocoder.test.js @@ -0,0 +1,58 @@ +const NodeGeocoder = require('../../index'); + +describe('Mapbox geocoder', () => { + let geocoder; + + beforeAll(() => { + const apiKey = process.env.MAPBOX_API_KEY; + const options = { + provider: 'mapbox', + apiKey + }; + + if (!apiKey || apiKey === '') { + throw new Error('MAPBOX_API_KEY not configured'); + } + + geocoder = NodeGeocoder(options); + }); + + describe('geocode', () => { + it('works', async () => { + const res = await geocoder.geocode('1231 Av. Lajoie, Montreal'); + + expect(res[0]).toBeDefined(); + expect(res[0]).toMatchObject({ + latitude: 45.521056, + longitude: -73.610734, + formattedAddress: + '1231 Avenue Lajoie, Montréal, Quebec H2V 1P2, Canada', + country: 'Canada', + countryCode: 'CA', + state: 'Quebec', + city: 'Montréal', + zipcode: 'H2V 1P2', + neighbourhood: 'Outremont' + }); + }); + }); + + describe('reverse', () => { + it('works', async () => { + const res = await geocoder.reverse({ lat: 45.521056, lon: -73.610734 }); + expect(res[0]).toBeDefined(); + expect(res[0]).toMatchObject({ + latitude: 45.52105585, + longitude: -73.61073425, + formattedAddress: + '1231 Avenue Lajoie, Montréal, Quebec H2V 1P2, Canada', + country: 'Canada', + countryCode: 'CA', + state: 'Quebec', + city: 'Montréal', + zipcode: 'H2V 1P2', + neighbourhood: 'Outremont' + }); + }); + }); +}); diff --git a/package.json b/package.json index 615bd35..d1b4909 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "description": "Node Geocoder, node geocoding library, supports google maps, mapquest, open street map, tom tom, promise", "main": "index.js", "scripts": { - "test": "jest --maxWorkers=2", + "test": "jest --maxWorkers=2 ./test", "lint": "eslint lib", - "ci": "npm run lint && npm run test" + "ci": "npm run lint && npm run test", + "test:integration": "jest --maxWorkers=2 ./integration_test" }, "repository": { "type": "git", @@ -37,7 +38,7 @@ "devDependencies": { "chai": "^3.5.0", "eslint": "^6.8.0", - "jest": "^25.1.0", + "jest": "^27.5.0", "sinon": "^1.17.3" }, "eslintConfig": {