From 110cfce0ccebc2514829ff84c1f19390b80bd1a2 Mon Sep 17 00:00:00 2001 From: antoine-pous Date: Wed, 31 Jul 2019 11:35:14 +0200 Subject: [PATCH 1/2] Ignore IntelliJ IDEA config --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c8ff9d3..448a462 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ npm-debug.log yarn.lock coverage .nyc_output +.idea From d118931f896b093c1de1865394a71b804bf62434 Mon Sep 17 00:00:00 2001 From: antoine-pous Date: Wed, 31 Jul 2019 11:35:55 +0200 Subject: [PATCH 2/2] Implement owners getById, types, and test from HS demo API for consistency" --- lib/owner.js | 8 ++++++++ lib/typescript/owner.ts | 36 ++++++++++++++++++++++++++++++++++-- test/owners.js | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/lib/owner.js b/lib/owner.js index a5873be..0d019da 100644 --- a/lib/owner.js +++ b/lib/owner.js @@ -10,6 +10,14 @@ class Owner { qs: options, }) } + + getById(id, options) { + return this.client._request({ + method: 'GET', + path: '/owners/v2/owners/' + id, + qs: options, + }) + } } module.exports = Owner diff --git a/lib/typescript/owner.ts b/lib/typescript/owner.ts index e858624..e1f26b0 100644 --- a/lib/typescript/owner.ts +++ b/lib/typescript/owner.ts @@ -1,7 +1,39 @@ import { RequestPromise } from 'request-promise' -declare class Owner { +export declare class Owner { get(opts?: {}): RequestPromise + + getById(ownerId: number | string, opts?: {}): RequestPromise +} + +export enum OwnerType { + person = 'PERSON', +} + +export enum RemoteType { + hubspot = 'HUBSPOT', +} + +export interface OwnerRemote { + portalId: number + ownerId: number + remoteId: string + remoteType: RemoteType + active: boolean } -export { Owner } +export interface OwnerInterface { + portalId: number + ownerId: number + type: OwnerType + firstName: string + lastName: string + email: string + createdAt: number + updatedAt: number + remoteList: OwnerRemote[] + hasContactsAccess: boolean + activeUserId: number + userIdIncludingInactive: number + isActive: boolean +} diff --git a/test/owners.js b/test/owners.js index e5733e0..fcb0e40 100644 --- a/test/owners.js +++ b/test/owners.js @@ -1,11 +1,7 @@ const { expect } = require('chai') -const fakeHubspotApi = require('./helpers/fake_hubspot_api') const Hubspot = require('..') describe('Owners', function() { - const ownersGetEndpoint = { path: '/owners/v2/owners', response: [] } - fakeHubspotApi.setupServer({ demo: true, getEndpoints: [ownersGetEndpoint] }) - describe('get', function() { it('Should return all owners', function() { const hubspot = new Hubspot({ apiKey: 'demo' }) @@ -15,4 +11,37 @@ describe('Owners', function() { }) }) }) + + describe('getById', function() { + it('should return one owner', function() { + const hubspot = new Hubspot({ apiKey: 'demo' }) + + return hubspot.owners.getById(66).then(data => { + expect(data).to.be.a('object') + expect(data).to.have.all.keys( + 'portalId', + 'ownerId', + 'type', + 'firstName', + 'lastName', + 'email', + 'createdAt', + 'updatedAt', + 'remoteList', + 'hasContactsAccess', + 'activeUserId', + 'userIdIncludingInactive', + 'isActive' + ) + expect(data.remoteList[0]).to.have.all.keys( + 'id', + 'portalId', + 'ownerId', + 'remoteId', + 'remoteType', + 'active' + ) + }) + }) + }) })