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

Implement owners.betById #183

Merged
merged 3 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
)
})
})
})
})