This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef1bd0d
commit 962d96d
Showing
7 changed files
with
192 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _errorHandler = require('../helpers/errorHandler'); | ||
|
||
var _errorHandler2 = _interopRequireDefault(_errorHandler); | ||
|
||
var _responseHandler = require('../helpers/responseHandler'); | ||
|
||
var _responseHandler2 = _interopRequireDefault(_responseHandler); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
|
||
var Deals = function Deals() { | ||
var api = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
|
||
|
||
if (api === null) throw new Error('Request instance must be provided on constructor.'); | ||
|
||
return { | ||
createDeal: function createDeal(parameters) { | ||
var properties = parameters.properties, | ||
associations = parameters.associations; | ||
|
||
|
||
var mappedProperties = Object.keys(properties).map(function (property) { | ||
return { | ||
value: properties[property], | ||
name: property | ||
}; | ||
}); | ||
|
||
return api.post('deals/v1/deal', { properties: [].concat(_toConsumableArray(mappedProperties)), associations: associations }).then(function (response) { | ||
return (0, _responseHandler2.default)(response); | ||
}).catch(function (error) { | ||
return (0, _errorHandler2.default)(error); | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
exports.default = Deals; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import errorHandler from '../helpers/errorHandler' | ||
import responseHandler from '../helpers/responseHandler' | ||
|
||
const Deals = (api = null) => { | ||
|
||
if (api === null) throw new Error('Request instance must be provided on constructor.') | ||
|
||
return { | ||
createDeal(parameters) { | ||
|
||
let { properties, associations } = parameters | ||
|
||
let mappedProperties = Object.keys(properties).map(property => ({ | ||
value: properties[property], | ||
name: property, | ||
})) | ||
|
||
return api.post('deals/v1/deal', {properties: [ ...mappedProperties ], associations}) | ||
.then(response => responseHandler(response)) | ||
.catch(error => errorHandler(error)) | ||
}, | ||
} | ||
} | ||
|
||
export default Deals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import chai from 'chai' | ||
import api from './setup' | ||
|
||
let expect = chai.expect | ||
|
||
describe('Deals', () => { | ||
|
||
describe('Create a deal', () => { | ||
|
||
it('Should return the data for the newly created deal', done => { | ||
|
||
let dealInfo = { | ||
associations: { | ||
associatedCompanyIds: [], // Optional - companies association ID's | ||
associatedVids: [], // Optional - contacts association ID's | ||
}, | ||
properties: { | ||
dealname: 'This is a brand new deal. Awesome!', | ||
hubspot_owner_id: '70', // demo user ID, | ||
amount: '50000', | ||
dealtype: 'newbusiness', | ||
}, | ||
} | ||
|
||
api.deals.createDeal(dealInfo) | ||
.then(response => { | ||
expect(response.status).to.equal(200) | ||
expect(response.data).to.be.a('object') | ||
expect(response.data.properties.dealname.value).to.be.equal(dealInfo.properties.dealname) | ||
expect(response.data.properties.hubspot_owner_id.value).to.be.equal(dealInfo.properties.hubspot_owner_id) | ||
expect(response.data.properties.amount.value).to.be.equal(dealInfo.properties.amount) | ||
expect(response.data.properties.dealtype.value).to.be.equal(dealInfo.properties.dealtype) | ||
done() | ||
}) | ||
.catch(error => done(error)) | ||
}) | ||
}) | ||
}) |