Skip to content

Commit

Permalink
wip: v2
Browse files Browse the repository at this point in the history
  • Loading branch information
joostdebruijn committed Dec 29, 2023
1 parent 573ddd8 commit f927460
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 27 deletions.
23 changes: 0 additions & 23 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,6 @@ exports.validatePostcodeP4 = (postcode) => {
return /[1-9][0-9]{3}$/g.test(postcode)
}

/**
* Helper to handle responses from the API that are not specifically defined
* @name handleOtherResponses
* @method
* @static
* @private
* @param {Object} response - The response object from the request-module
* @param {Object} body - The body object from the request-module
* @param {Function} callback - The callback as defined by the end-user
* @returns {Function} - callback
* @since 1.0.0
*/
exports.handleOtherResponses = (response, body, callback) => {
// The API will respond with an error-key in the body in some cases, so we pass it to the end user
if (body && body.error) {
return callback(new Error(body.error), null)
} else {
// If there is no error in the body, the error is unknown, so we inform the end user about that
return callback(new Error('An unknown error has occuring while calling the external API. HTTP status code: ' +
response.statusCode), null)
}
}

/**
* Helper that is able to merge two results in the _embedded-object from the API together in one single response. It is used within followNext(), however it may be useful in other circumstanses.
* @method
Expand Down
1 change: 0 additions & 1 deletion lib/requestApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

'use strict'
const helpers = require('./helpers.js')

/**
* To perform requests to the API, handle errors, based on given paramters and return the result to the end-user
Expand Down
1 change: 1 addition & 0 deletions test/global.getAddresses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef, no-unused-expressions */
'use strict'
const postcodeApi = require('../index.js')
const sinon = require('sinon')
Expand Down
1 change: 1 addition & 0 deletions test/global.getAddressesByPostcodeAndNumber.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef, no-unused-expressions */
'use strict'
const postcodeApi = require('../index.js')
const sinon = require('sinon')
Expand Down
1 change: 1 addition & 0 deletions test/global.getPostcodes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef, no-unused-expressions */
'use strict'
const postcodeApi = require('../index.js')
const sinon = require('sinon')
Expand Down
1 change: 1 addition & 0 deletions test/global.getSingleAddress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef, no-unused-expressions */
'use strict'
const postcodeApi = require('../index.js')
const sinon = require('sinon')
Expand Down
1 change: 1 addition & 0 deletions test/global.getSinglePostcode.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef, no-unused-expressions */
'use strict'
const postcodeApi = require('../index.js')
const sinon = require('sinon')
Expand Down
7 changes: 4 additions & 3 deletions test/global.requestApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
'use strict'
const sinon = require('sinon')
const chai = require('chai')
Expand All @@ -11,12 +12,11 @@ function fakeResponse (status = 200) {
headers: {
'Content-type': 'application/json'
}
});
})

return Promise.resolve(mockResponse);
return Promise.resolve(mockResponse)
}


before(() => {
chai.use(sinonChai)
})
Expand Down Expand Up @@ -76,6 +76,7 @@ describe('global/requestApi()', () => {
requestStub.onCall(0).returns(fakeResponse())

return requestApi.get(options, (error, body, rateLimit) => {
expect(error).to.eql(null)
expect(rateLimit).to.eql(rateLimitReturn)
})
})
Expand Down
1 change: 1 addition & 0 deletions test/helpers.followNext.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef, no-unused-expressions */
'use strict'
const postcodeApi = require('../index.js')
const sinon = require('sinon')
Expand Down
1 change: 1 addition & 0 deletions test/helpers.handleOtherResponses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
'use strict'
const postcodeApi = require('../index.js')
const chai = require('chai')
Expand Down
1 change: 1 addition & 0 deletions test/helpers.mergeResults.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
'use strict'
const postcodeApi = require('../index.js')
const chai = require('chai')
Expand Down
1 change: 1 addition & 0 deletions test/helpers.validatePostcodeP4.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
'use strict'
const postcodeApi = require('../index.js')
const checkP4 = postcodeApi.helpers.validatePostcodeP4
Expand Down
1 change: 1 addition & 0 deletions test/helpers.validatePostcodeP6.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
'use strict'
const postcodeApi = require('../index.js')
const checkP6 = postcodeApi.helpers.validatePostcodeP6
Expand Down
1 change: 1 addition & 0 deletions test/promises.combined.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef, no-unused-expressions */
'use strict'
const postcodeApi = require('../index.js')
const interalApi = require('../lib/promisesRequires.js')
Expand Down

0 comments on commit f927460

Please sign in to comment.