From 085bba38f9b0ec68c94159bf5a7f1fc9df40cfe7 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Sun, 5 Sep 2021 14:47:50 -0700 Subject: [PATCH 1/5] Update for flights --- .github/workflows/health_check.yml | 2 +- .github/workflows/publish.yml | 12 +++--- package-lock.json | 4 +- package.json | 2 +- src/ApiClient.js | 2 +- src/model/CreateFlightEstimateRequest.js | 53 +++++++++++++++++++++--- test/integration/estimates.test.js | 18 ++++++-- 7 files changed, 74 insertions(+), 19 deletions(-) diff --git a/.github/workflows/health_check.yml b/.github/workflows/health_check.yml index 21cf3e7..1c0060f 100644 --- a/.github/workflows/health_check.yml +++ b/.github/workflows/health_check.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: ['10','12','14','16'] + node: ['10', '12', '14', '16'] max-parallel: 1 name: Node ${{ matrix.node }} Test steps: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6f05263..d3eeb43 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ jobs: name: Create GitHub deployment id: deployment with: - token: "${{ github.token }}" + token: '${{ github.token }}' target_url: ${{ env.TARGET_URL }} environment: production @@ -45,16 +45,16 @@ jobs: if: success() uses: chrnorm/deployment-status@releases/v1 with: - token: "${{ github.token }}" + token: '${{ github.token }}' target_url: ${{ env.TARGET_URL }} - state: "success" + state: 'success' deployment_id: ${{ steps.deployment.outputs.deployment_id }} - name: Update deployment status (failure) if: failure() uses: chrnorm/deployment-status@releases/v1 with: - token: "${{ github.token }}" + token: '${{ github.token }}' target_url: ${{ env.TARGET_URL }} - state: "failure" - deployment_id: ${{ steps.deployment.outputs.deployment_id }} \ No newline at end of file + state: 'failure' + deployment_id: ${{ steps.deployment.outputs.deployment_id }} diff --git a/package-lock.json b/package-lock.json index 89c08ba..70030db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "1.10.2", + "version": "1.11.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "1.10.2", + "version": "1.11.0", "license": "MIT", "dependencies": { "query-string": "^7.0.1", diff --git a/package.json b/package.json index 7425edb..c83692f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.10.2", + "version": "1.11.0", "description": "Node.js wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index ae45994..bf7ae12 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -16,7 +16,7 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/1.10.2' + 'User-Agent': 'patch-node/1.11.0' }; /** diff --git a/src/model/CreateFlightEstimateRequest.js b/src/model/CreateFlightEstimateRequest.js index af10332..a2f3701 100644 --- a/src/model/CreateFlightEstimateRequest.js +++ b/src/model/CreateFlightEstimateRequest.js @@ -8,13 +8,11 @@ import ApiClient from '../ApiClient'; class CreateFlightEstimateRequest { - constructor(distanceM) { - CreateFlightEstimateRequest.initialize(this, distanceM); + constructor() { + CreateFlightEstimateRequest.initialize(this); } - static initialize(obj, distanceM) { - obj['distance_m'] = distanceM; - } + static initialize(obj) {} static constructFromObject(data, obj) { if (data) { @@ -27,6 +25,41 @@ class CreateFlightEstimateRequest { ); } + if (data.hasOwnProperty('origin_airport')) { + obj['origin_airport'] = ApiClient.convertToType( + data['origin_airport'], + 'String' + ); + } + + if (data.hasOwnProperty('destination_airport')) { + obj['destination_airport'] = ApiClient.convertToType( + data['destination_airport'], + 'String' + ); + } + + if (data.hasOwnProperty('aircraft_code')) { + obj['aircraft_code'] = ApiClient.convertToType( + data['aircraft_code'], + 'String' + ); + } + + if (data.hasOwnProperty('cabin_class')) { + obj['cabin_class'] = ApiClient.convertToType( + data['cabin_class'], + 'String' + ); + } + + if (data.hasOwnProperty('passenger_count')) { + obj['passenger_count'] = ApiClient.convertToType( + data['passenger_count'], + 'Number' + ); + } + if (data.hasOwnProperty('project_id')) { obj['project_id'] = ApiClient.convertToType( data['project_id'], @@ -47,6 +80,16 @@ class CreateFlightEstimateRequest { CreateFlightEstimateRequest.prototype['distance_m'] = undefined; +CreateFlightEstimateRequest.prototype['origin_airport'] = undefined; + +CreateFlightEstimateRequest.prototype['destination_airport'] = undefined; + +CreateFlightEstimateRequest.prototype['aircraft_code'] = undefined; + +CreateFlightEstimateRequest.prototype['cabin_class'] = undefined; + +CreateFlightEstimateRequest.prototype['passenger_count'] = undefined; + CreateFlightEstimateRequest.prototype['project_id'] = undefined; CreateFlightEstimateRequest.prototype['create_order'] = undefined; diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index c2e4e57..ed64b6f 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -21,10 +21,9 @@ describe('Estimates Integration', function () { expect(retrieveEstimatesResponse.data.length).to.be.above(0); }); - it('supports creating flight estimates with an order', async function () { + it('supports creating flight estimates with distance', async function () { const createEstimateResponse = await patch.estimates.createFlightEstimate({ - distance_m: 1000, - create_order: true + distance_m: 1000 }); const estimate = createEstimateResponse.data; @@ -34,6 +33,19 @@ describe('Estimates Integration', function () { expect(estimate.order.state).to.be.eq('draft'); }); + it('supports creating flight estimates with airports', async function () { + const { data: estimate1 } = await patch.estimates.createFlightEstimate({ + origin_airport: 'SFO', + destination_airport: 'LAX' + }); + const { data: estimate2 } = await patch.estimates.createFlightEstimate({ + origin_airport: 'SFO', + destination_airport: 'JFK' + }); + + expect(estimate2.mass_g).to.be.greaterThan(estimate1.mass_g); + }); + it('supports creating shipping estimates without an order', async function () { const createEstimateResponse = await patch.estimates.createShippingEstimate( { From 0ccdc6809ce1a35a64103b2a15a0b1af7d901189 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Mon, 6 Sep 2021 17:16:55 -0700 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da94fad..8616585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.11.0] - 2021-09-07 + +### Added + +- Adds support for airports, aircracts, cabin class and passenger count in flight estimates + ## [1.10.0] - 2021-08-27 ### Added From 234177bf71372b94904f7e223cecf293df5b0ff3 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Mon, 6 Sep 2021 18:13:18 -0700 Subject: [PATCH 3/5] Validate parameters with corresponding class --- CHANGELOG.md | 6 +++ package-lock.json | 4 +- package.json | 2 +- src/ApiClient.js | 2 +- src/api/EstimatesApi.js | 66 ++++++++++++++++++++++-------- src/api/OrdersApi.js | 8 +++- src/api/PreferencesApi.js | 11 +++-- test/integration/estimates.test.js | 8 ++-- 8 files changed, 76 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8616585..a88f22e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.11.1] - 2021-09-07 + +### Changed + +- Body parameters are validated before being sent to the API. This gives developers faster feedback as they develop their applications. + ## [1.11.0] - 2021-09-07 ### Added diff --git a/package-lock.json b/package-lock.json index 70030db..50bab42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "1.11.0", + "version": "1.11.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "1.11.0", + "version": "1.11.1", "license": "MIT", "dependencies": { "query-string": "^7.0.1", diff --git a/package.json b/package.json index c83692f..d481691 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.11.0", + "version": "1.11.1", "description": "Node.js wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index bf7ae12..bb8184c 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -16,7 +16,7 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/1.11.0' + 'User-Agent': 'patch-node/1.11.1' }; /** diff --git a/src/api/EstimatesApi.js b/src/api/EstimatesApi.js index 11df401..7254fc3 100644 --- a/src/api/EstimatesApi.js +++ b/src/api/EstimatesApi.js @@ -22,12 +22,17 @@ export default class EstimatesApi { } createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest) { - let postBody = createBitcoinEstimateRequest; + const _createBitcoinEstimateRequest = + CreateBitcoinEstimateRequest.constructFromObject( + createBitcoinEstimateRequest, + new CreateBitcoinEstimateRequest() + ); + let postBody = _createBitcoinEstimateRequest; // verify the required parameter 'createBitcoinEstimateRequest' is set if ( - createBitcoinEstimateRequest === undefined || - createBitcoinEstimateRequest === null + _createBitcoinEstimateRequest === undefined || + _createBitcoinEstimateRequest === null ) { throw new Error( "Missing the required parameter 'createBitcoinEstimateRequest' when calling createBitcoinEstimate" @@ -64,12 +69,17 @@ export default class EstimatesApi { } createEthereumEstimateWithHttpInfo(createEthereumEstimateRequest) { - let postBody = createEthereumEstimateRequest; + const _createEthereumEstimateRequest = + CreateEthereumEstimateRequest.constructFromObject( + createEthereumEstimateRequest, + new CreateEthereumEstimateRequest() + ); + let postBody = _createEthereumEstimateRequest; // verify the required parameter 'createEthereumEstimateRequest' is set if ( - createEthereumEstimateRequest === undefined || - createEthereumEstimateRequest === null + _createEthereumEstimateRequest === undefined || + _createEthereumEstimateRequest === null ) { throw new Error( "Missing the required parameter 'createEthereumEstimateRequest' when calling createEthereumEstimate" @@ -108,12 +118,17 @@ export default class EstimatesApi { } createFlightEstimateWithHttpInfo(createFlightEstimateRequest) { - let postBody = createFlightEstimateRequest; + const _createFlightEstimateRequest = + CreateFlightEstimateRequest.constructFromObject( + createFlightEstimateRequest, + new CreateFlightEstimateRequest() + ); + let postBody = _createFlightEstimateRequest; // verify the required parameter 'createFlightEstimateRequest' is set if ( - createFlightEstimateRequest === undefined || - createFlightEstimateRequest === null + _createFlightEstimateRequest === undefined || + _createFlightEstimateRequest === null ) { throw new Error( "Missing the required parameter 'createFlightEstimateRequest' when calling createFlightEstimate" @@ -150,12 +165,17 @@ export default class EstimatesApi { } createMassEstimateWithHttpInfo(createMassEstimateRequest) { - let postBody = createMassEstimateRequest; + const _createMassEstimateRequest = + CreateMassEstimateRequest.constructFromObject( + createMassEstimateRequest, + new CreateMassEstimateRequest() + ); + let postBody = _createMassEstimateRequest; // verify the required parameter 'createMassEstimateRequest' is set if ( - createMassEstimateRequest === undefined || - createMassEstimateRequest === null + _createMassEstimateRequest === undefined || + _createMassEstimateRequest === null ) { throw new Error( "Missing the required parameter 'createMassEstimateRequest' when calling createMassEstimate" @@ -192,12 +212,17 @@ export default class EstimatesApi { } createShippingEstimateWithHttpInfo(createShippingEstimateRequest) { - let postBody = createShippingEstimateRequest; + const _createShippingEstimateRequest = + CreateShippingEstimateRequest.constructFromObject( + createShippingEstimateRequest, + new CreateShippingEstimateRequest() + ); + let postBody = _createShippingEstimateRequest; // verify the required parameter 'createShippingEstimateRequest' is set if ( - createShippingEstimateRequest === undefined || - createShippingEstimateRequest === null + _createShippingEstimateRequest === undefined || + _createShippingEstimateRequest === null ) { throw new Error( "Missing the required parameter 'createShippingEstimateRequest' when calling createShippingEstimate" @@ -236,12 +261,17 @@ export default class EstimatesApi { } createVehicleEstimateWithHttpInfo(createVehicleEstimateRequest) { - let postBody = createVehicleEstimateRequest; + const _createVehicleEstimateRequest = + CreateVehicleEstimateRequest.constructFromObject( + createVehicleEstimateRequest, + new CreateVehicleEstimateRequest() + ); + let postBody = _createVehicleEstimateRequest; // verify the required parameter 'createVehicleEstimateRequest' is set if ( - createVehicleEstimateRequest === undefined || - createVehicleEstimateRequest === null + _createVehicleEstimateRequest === undefined || + _createVehicleEstimateRequest === null ) { throw new Error( "Missing the required parameter 'createVehicleEstimateRequest' when calling createVehicleEstimate" diff --git a/src/api/OrdersApi.js b/src/api/OrdersApi.js index cb13a1a..036f521 100644 --- a/src/api/OrdersApi.js +++ b/src/api/OrdersApi.js @@ -58,10 +58,14 @@ export default class OrdersApi { } createOrderWithHttpInfo(createOrderRequest) { - let postBody = createOrderRequest; + const _createOrderRequest = CreateOrderRequest.constructFromObject( + createOrderRequest, + new CreateOrderRequest() + ); + let postBody = _createOrderRequest; // verify the required parameter 'createOrderRequest' is set - if (createOrderRequest === undefined || createOrderRequest === null) { + if (_createOrderRequest === undefined || _createOrderRequest === null) { throw new Error( "Missing the required parameter 'createOrderRequest' when calling createOrder" ); diff --git a/src/api/PreferencesApi.js b/src/api/PreferencesApi.js index e43a9be..c43ff70 100644 --- a/src/api/PreferencesApi.js +++ b/src/api/PreferencesApi.js @@ -17,12 +17,17 @@ export default class PreferencesApi { } createPreferenceWithHttpInfo(createPreferenceRequest) { - let postBody = createPreferenceRequest; + const _createPreferenceRequest = + CreatePreferenceRequest.constructFromObject( + createPreferenceRequest, + new CreatePreferenceRequest() + ); + let postBody = _createPreferenceRequest; // verify the required parameter 'createPreferenceRequest' is set if ( - createPreferenceRequest === undefined || - createPreferenceRequest === null + _createPreferenceRequest === undefined || + _createPreferenceRequest === null ) { throw new Error( "Missing the required parameter 'createPreferenceRequest' when calling createPreference" diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index ed64b6f..efc5bb7 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -80,14 +80,14 @@ describe('Estimates Integration', function () { }); it('supports creating bitcoin estimates without parameters', async function () { - const { data: estimate } = await patch.estimates.createBitcoinEstimate({ - create_order: false // TODO: this should work without this - }); + // const { data: estimate } = await patch.estimates.createBitcoinEstimate({ + // create_order: false // TODO: this should work without this + // }); + const { data: estimate } = await patch.estimates.createBitcoinEstimate(); expect(estimate.type).to.be.eq('bitcoin'); expect(estimate.mass_g).to.be.above(0); expect(estimate.production).to.be.eq(false); - expect(estimate.order).to.be.eq(null); }); it('supports creating bitcoin estimates with a timestamp', async function () { From 7e24b5253e8c286fee9bd9d873eafd9ff36e5c95 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Mon, 6 Sep 2021 18:18:23 -0700 Subject: [PATCH 4/5] Cleanup test --- test/integration/estimates.test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index efc5bb7..b9eff7c 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -80,9 +80,6 @@ describe('Estimates Integration', function () { }); it('supports creating bitcoin estimates without parameters', async function () { - // const { data: estimate } = await patch.estimates.createBitcoinEstimate({ - // create_order: false // TODO: this should work without this - // }); const { data: estimate } = await patch.estimates.createBitcoinEstimate(); expect(estimate.type).to.be.eq('bitcoin'); From 6780281faeaf2ece1a89be02a55e85e114348da8 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Tue, 7 Sep 2021 16:42:08 -0700 Subject: [PATCH 5/5] Simplify the test --- test/integration/preferences.test.js | 59 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/test/integration/preferences.test.js b/test/integration/preferences.test.js index b20134d..21f8560 100644 --- a/test/integration/preferences.test.js +++ b/test/integration/preferences.test.js @@ -2,45 +2,44 @@ import { expect } from 'chai'; import Patch from '../../dist/index'; const patch = Patch(process.env.SANDBOX_API_KEY); +async function getProjectId() { + const retrieveProjectResponse = await patch.projects.retrieveProjects(); + return retrieveProjectResponse.data[0].id; +} + describe('Preferences Integration', async function () { it('supports creating, deleting, and listing preferences', async function () { - const preferencesList = await patch.preferences.retrievePreferences(); - - // If there is an existing preference, delete it and create a new one with the same - // project id. If there is not any existing preferences, create and delete one with - // any project id. - if (preferencesList.data.length > 0) { - const preference = preferencesList.data[0]; - const projectId = preference.project.id; - - await patch.preferences.deletePreference(preference.id); - const createdPreference = await patch.preferences.createPreference({ - project_id: projectId - }); - - expect(createdPreference.data.project.id).to.eq(projectId); + const projectId = await getProjectId(); - const preferencesList2 = await patch.preferences.retrievePreferences(); - expect(preferencesList2.data.length).to.be.above(0); - } else { - const projectResponse = await patch.projects.retrieveProjects(); - expect(projectResponse.data.length).to.be.above(0); - const projectId = projectResponse.data[0].id; + let preferenceId; + try { const createdPreference = await patch.preferences.createPreference({ project_id: projectId }); + preferenceId = createdPreference.data.id; + } catch (err) { + if ( + !/Your organization already has a preferred project/.test( + err.error.message + ) + ) { + throw err; + } + const preferencesList = await patch.preferences.retrievePreferences(); + preferenceId = preferencesList.data[0].id; + } - expect(createdPreference.data.projectId).to.eq(projectId); - - const preferencesList2 = await patch.preferences.retrievePreferences(); - const preferencesCount = preferencesList2.data.length; - expect(preferencesList2.data.length).to.be.above(0); + const preferencesList = await patch.preferences.retrievePreferences(); + expect(preferencesList.data.length).to.be.above(0); - await patch.preferences.deletePreference(preference.id); + const preferencesResponse = await patch.preferences.retrievePreference( + preferenceId + ); + expect(preferencesResponse.data.id).to.eq(preferenceId); - const preferencesList3 = await patch.preferences.retrievePreferences(); - expect(preferencesList3.data.length).to.eq(preferencesCount - 1); - } + const deletePreferenceResponse = + await patch.preferences.retrievePreferences(preferenceId); + expect(deletePreferenceResponse.data[0].id).to.eq(preferenceId); }); });