Skip to content

Commit

Permalink
Add ETH estimates (#34)
Browse files Browse the repository at this point in the history
* Add ETH estimates

* Remove mocha.opts

* Bump version

* Add tests
  • Loading branch information
pcothenet authored Jul 21, 2021
1 parent 36c9bb4 commit 225d781
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.8.0] - 2021-07-20

### Added

- Add support for Ethereum estimates

## [1.7.0] - 2021-07-14

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@patch-technology/patch",
"version": "1.7.0",
"version": "1.8.0",
"description": "JavaScript wrapper for the Patch API",
"license": "MIT",
"repository": {
Expand Down
48 changes: 48 additions & 0 deletions src/api/EstimatesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ApiClient from '../ApiClient';
import CreateBitcoinEstimateRequest from '../model/CreateBitcoinEstimateRequest';
import CreateEthereumEstimateRequest from '../model/CreateEthereumEstimateRequest';
import CreateFlightEstimateRequest from '../model/CreateFlightEstimateRequest';
import CreateMassEstimateRequest from '../model/CreateMassEstimateRequest';
import CreateShippingEstimateRequest from '../model/CreateShippingEstimateRequest';
Expand All @@ -21,6 +22,9 @@ export default class EstimatesApi {
this.createBitcoinEstimate = this.createBitcoinEstimate.bind(this);
this.createBitcoinEstimateWithHttpInfo =
this.createBitcoinEstimateWithHttpInfo.bind(this);
this.createEthereumEstimate = this.createEthereumEstimate.bind(this);
this.createEthereumEstimateWithHttpInfo =
this.createEthereumEstimateWithHttpInfo.bind(this);
this.createFlightEstimate = this.createFlightEstimate.bind(this);
this.createFlightEstimateWithHttpInfo =
this.createFlightEstimateWithHttpInfo.bind(this);
Expand Down Expand Up @@ -83,6 +87,50 @@ export default class EstimatesApi {
return this.createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest);
}

createEthereumEstimateWithHttpInfo(createEthereumEstimateRequest) {
let postBody = createEthereumEstimateRequest;

// verify the required parameter 'createEthereumEstimateRequest' is set
if (
createEthereumEstimateRequest === undefined ||
createEthereumEstimateRequest === null
) {
throw new Error(
"Missing the required parameter 'createEthereumEstimateRequest' when calling createEthereumEstimate"
);
}

let pathParams = {};
let queryParams = {};
let headerParams = {};
let formParams = {};

let authNames = ['bearer_auth'];
let contentTypes = ['application/json'];
let accepts = ['application/json'];
let returnType = EstimateResponse;

return this.apiClient.callApi(
'/v1/estimates/crypto/eth',
'POST',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
authNames,
contentTypes,
accepts,
returnType
);
}

createEthereumEstimate(createEthereumEstimateRequest) {
return this.createEthereumEstimateWithHttpInfo(
createEthereumEstimateRequest
);
}

createFlightEstimateWithHttpInfo(createFlightEstimateRequest) {
let postBody = createFlightEstimateRequest;

Expand Down
55 changes: 55 additions & 0 deletions src/model/CreateEthereumEstimateRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Patch API V1
* The core API used to integrate with Patch's service
*
* Contact: [email protected]
*/

import ApiClient from '../ApiClient';

class CreateEthereumEstimateRequest {
constructor() {
CreateEthereumEstimateRequest.initialize(this);
}

static initialize(obj) {}

static constructFromObject(data, obj) {
if (data) {
obj = obj || new CreateEthereumEstimateRequest();

if (data.hasOwnProperty('timestamp')) {
obj['timestamp'] = ApiClient.convertToType(data['timestamp'], 'String');
}

if (data.hasOwnProperty('gas_used')) {
obj['gas_used'] = ApiClient.convertToType(data['gas_used'], 'Number');
}

if (data.hasOwnProperty('project_id')) {
obj['project_id'] = ApiClient.convertToType(
data['project_id'],
'String'
);
}

if (data.hasOwnProperty('create_order')) {
obj['create_order'] = ApiClient.convertToType(
data['create_order'],
'Boolean'
);
}
}
return obj;
}
}

CreateEthereumEstimateRequest.prototype['timestamp'] = undefined;

CreateEthereumEstimateRequest.prototype['gas_used'] = undefined;

CreateEthereumEstimateRequest.prototype['project_id'] = undefined;

CreateEthereumEstimateRequest.prototype['create_order'] = undefined;

export default CreateEthereumEstimateRequest;
44 changes: 39 additions & 5 deletions test/integration/estimates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,50 @@ describe('Estimates Integration', function () {
expect(estimate.order).to.be.eq(null);
});

it('supports creating bitcoin estimates without an order', async function () {
const createEstimateResponse = await patch.estimates.createBitcoinEstimate({
create_order: false
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 estimate = createEstimateResponse.data;

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 () {
const { data: estimate1 } = await patch.estimates.createBitcoinEstimate({
timestamp: '2021-06-01T20:31:18.403Z'
});
const { data: estimate2 } = await patch.estimates.createBitcoinEstimate({
timestamp: '2021-07-01T20:31:18.403Z'
});

expect(estimate1.mass_g).to.be.above(estimate2.mass_g); // BTC emitted less in July than in June
});

it('supports creating bitcoin estimates with a transaction value', async function () {
const { data: estimate1 } = await patch.estimates.createBitcoinEstimate({
transaction_value_btc_sats: 2000
});
const { data: estimate2 } = await patch.estimates.createBitcoinEstimate({
transaction_value_btc_sats: 1000
});

expect(estimate1.mass_g).to.be.above(estimate2.mass_g);
});

it('supports creating ethereum estimates with a gas value', async function () {
const createEstimateResponse = await patch.estimates.createEthereumEstimate(
{
gas_used: 1000
}
);

const estimate = createEstimateResponse.data;

expect(estimate.type).to.be.eq('ethereum');
expect(estimate.mass_g).to.be.above(0);
expect(estimate.production).to.be.eq(false);
});
});

0 comments on commit 225d781

Please sign in to comment.