Skip to content

Commit

Permalink
Merge pull request #77 from GIScience/refactor/remove-v2-requirement
Browse files Browse the repository at this point in the history
Refactor/remove v2 requirement
  • Loading branch information
TheGreatRefrigerator committed Sep 22, 2023
2 parents f520589 + caab49a commit 7b3a190
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 57 deletions.
13 changes: 4 additions & 9 deletions src/OrsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,12 @@ class OrsBase {

this.requestArgs = orsUtil.fillArgs(this.defaultArgs, this.requestArgs)

if (this.requestArgs[Constants.propNames.apiVersion] === Constants.defaultAPIVersion) {
this.argsCache = orsUtil.saveArgsToCache(this.requestArgs)
this.argsCache = orsUtil.saveArgsToCache(this.requestArgs)

this.httpArgs = orsUtil.prepareRequest(this.requestArgs)
const postBody = this.getBody(this.httpArgs)
this.httpArgs = orsUtil.prepareRequest(this.requestArgs)
const postBody = this.getBody(this.httpArgs)

return await this.createRequest(postBody)
} else {
// eslint-disable-next-line no-console
console.error(Constants.useAPIV2Msg)
}
return await this.createRequest(postBody)
}
}

Expand Down
13 changes: 0 additions & 13 deletions src/__tests__/OrsBase.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ describe('Test Base class', () => {
}
})

it('fails when API version not default API version', () => {
let base
try {
base = new OrsBase({
'api_key': 'test',
'apiVersion': 'v1'
})
} catch (err) {
expect(err.message).to.equal(constants.useAPIV2Msg)
expect(base.calculate()).to.throw(console.error)
}
})

it('passes Host correctly', () => {
const base = new OrsBase({
'api_key': 'test',
Expand Down
11 changes: 0 additions & 11 deletions src/__tests__/OrsDirections.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import OrsDirections from '../OrsDirections.js'
import Constants from '../constants.js'

const key = Cypress.env('api_key')
const orsDirections = new OrsDirections({ 'api_key': key })
Expand Down Expand Up @@ -93,16 +92,6 @@ describe('Test Directions', () => {
expect(req.headers).to.include({'Accept': 'application/json'})
})
})

it('fails when API version not default API version', () => {
orsDirections.calculate({
coordinates: [[8.690958, 49.404662], [8.687868, 49.390139]],
profile: 'driving-car',
api_version: 'v1'
}).catch((err) => {
expect(err.message).to.equal(Constants.useAPIV2Msg)
})
})
})
})
})
11 changes: 0 additions & 11 deletions src/__tests__/OrsIsochrones.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ describe('Isochrone Test', () => {
expect(orsIsochrones.defaultArgs.service).to.equal('isochrones')
expect(orsIsochrones.defaultArgs.api_version).to.equal('v2')
})

it('fails when API version not default API version', () => {
try {
new OrsIsochrones({
'api_key': 'test',
'apiVersion': 'v1'
})
} catch (err) {
expect(err.message).to.equal(Constants.useAPIV2Msg)
}
})
})

context('methods', () => {
Expand Down
12 changes: 0 additions & 12 deletions src/__tests__/OrsMatrix.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import OrsMatrix from '../OrsMatrix.js'
import Constants from '../constants.js'

const key = Cypress.env('api_key')
const orsMatrix = new OrsMatrix({ api_key: key })
Expand All @@ -11,17 +10,6 @@ describe('Matrix Test', () => {
expect(orsMatrix.defaultArgs.service).to.equal('matrix')
expect(orsMatrix.defaultArgs.api_version).to.equal('v2')
})

it('fails when API version not default API version', () => {
try {
new OrsMatrix({
'api_key': 'test',
'apiVersion': 'v1'
})
} catch (err) {
expect(err.message).to.equal(Constants.useAPIV2Msg)
}
})
})

context('methods', () => {
Expand Down
1 change: 0 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const constants = {
defaultAPIVersion: 'v2',
defaultHost: 'https://api.openrouteservice.org',
missingAPIKeyMsg: 'Please add your openrouteservice api_key..',
useAPIV2Msg: 'Please use ORS API v2',
baseUrlConstituents: ['host', 'service', 'api_version', 'mime_type'],
propNames: {
apiKey: 'api_key',
Expand Down

0 comments on commit 7b3a190

Please sign in to comment.