Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #183 from antoine-pous/owners-get-by-id
Browse files Browse the repository at this point in the history
Implement owners.betById
  • Loading branch information
pcothenet authored Aug 20, 2019
2 parents 3360789 + c5e0ca9 commit d01f744
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
yarn.lock
coverage
.nyc_output
.idea
45 changes: 23 additions & 22 deletions lib/owner.js
Original file line number Diff line number Diff line change
@@ -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
47 changes: 38 additions & 9 deletions lib/typescript/owner.ts
Original file line number Diff line number Diff line change
@@ -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
}
37 changes: 33 additions & 4 deletions test/owners.js
Original file line number Diff line number Diff line change
@@ -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' })
Expand All @@ -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'
)
})
})
})
})

0 comments on commit d01f744

Please sign in to comment.