Skip to content

Commit

Permalink
Init integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Feb 6, 2022
1 parent 5de7be0 commit 0f33036
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ test.js
package-lock.json
playground.js
.github

integration_test
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
58 changes: 58 additions & 0 deletions integration_test/geocoder/mapboxgeocoder.test.js
Original file line number Diff line number Diff line change
@@ -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'
});
});
});
});
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 0f33036

Please sign in to comment.