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 diff --git a/lib/owner.js b/lib/owner.js index bb5cb94..e75dc14 100644 --- a/lib/owner.js +++ b/lib/owner.js @@ -1,22 +1,23 @@ -class Owner { - constructor(client) { - this.client = client - } - - get(options) { - return this.client._request({ - method: 'GET', - path: '/owners/v2/owners', - qs: options, - }) - } - - getById(id) { - return this.client._request({ - method: 'GET', - path: '/owners/v2/owners/' + id - }) - } -} - -module.exports = Owner +class Owner { + constructor(client) { + this.client = client + } + + get(options) { + return this.client._request({ + method: 'GET', + path: '/owners/v2/owners', + 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 1425289..bbc222c 100644 --- a/lib/typescript/owner.ts +++ b/lib/typescript/owner.ts @@ -1,9 +1,38 @@ -import { RequestPromise } from 'request-promise' - -declare class Owner { - get(opts?: {}): RequestPromise - - getById(number: string): RequestPromise -} - -export { Owner } +import { RequestPromise } from 'request-promise' + +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 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' + ) + }) + }) + }) })