diff --git a/.eslintrc.js b/.eslintrc.js index adcc93e..2831dba 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,8 +1,8 @@ module.exports = { - 'extends': 'standard', - 'env': { - 'es6': true, - 'node': true, - 'mocha': true + extends: ['standard', 'plugin:prettier/recommended'], + env: { + es6: true, + node: true, + mocha: true } } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..467b73f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "semi": false, + "printWidth": 80, + "trailingComma": "all", +} diff --git a/lib/broadcast.js b/lib/broadcast.js index 6327fb2..35a433d 100644 --- a/lib/broadcast.js +++ b/lib/broadcast.js @@ -1,19 +1,22 @@ class Broadcast { - constructor (client) { + constructor(client) { this.client = client } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/broadcast/v1/broadcasts', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/broadcast/v1/broadcasts', + qs: options, + }, + cb, + ) } } diff --git a/lib/campaign.js b/lib/campaign.js index c3a1e0e..c73028d 100644 --- a/lib/campaign.js +++ b/lib/campaign.js @@ -1,35 +1,41 @@ class Campaign { - constructor (client) { + constructor(client) { this.client = client } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/email/public/v1/campaigns', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/email/public/v1/campaigns', + qs: options, + }, + cb, + ) } - getById (options, cb) { + getById(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/email/public/v1/campaigns/by-id', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/email/public/v1/campaigns/by-id', + qs: options, + }, + cb, + ) } - getOne (id, appId, cb) { + getOne(id, appId, cb) { if (!id || typeof id === 'function') { return cb(new Error('id parameter must be provided.')) } @@ -41,29 +47,32 @@ class Campaign { var call = { method: 'GET', - path: '/email/public/v1/campaigns/' + id + path: '/email/public/v1/campaigns/' + id, } if (appId) { call.qs = { - appId: appId + appId: appId, } } return this.client._request(call, cb) } - events (options, cb) { + events(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/email/public/v1/events', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/email/public/v1/events', + qs: options, + }, + cb, + ) } } diff --git a/lib/client.js b/lib/client.js index a41b1cb..994dbf2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -18,7 +18,7 @@ const EventEmitter = require('events').EventEmitter const Bottleneck = require('bottleneck') const limiter = new Bottleneck({ maxConcurrent: 9, - minTime: 1000 + minTime: 1000, }) const debug = require('debug')('hubspot:client') @@ -28,13 +28,16 @@ const API_TIMEOUT = 15000 const MAX_USE_PERCENT_DEFAULT = 90 class Client extends EventEmitter { - constructor (options = {}) { + constructor(options = {}) { super() this.qs = {} this.auth = undefined this.setAuth(options) this.setOAuth(options) - this.maxUsePercent = typeof options.maxUsePercent !== 'undefined' ? options.maxUsePercent : MAX_USE_PERCENT_DEFAULT + this.maxUsePercent = + typeof options.maxUsePercent !== 'undefined' + ? options.maxUsePercent + : MAX_USE_PERCENT_DEFAULT this.baseUrl = options.baseUrl || 'http://api.hubapi.com' this.apiTimeout = options.timeout || API_TIMEOUT this.apiCalls = 0 @@ -59,44 +62,47 @@ class Client extends EventEmitter { this.workflows = new Workflow(this) } - requestStats () { + requestStats() { return { running: limiter.running(), - queued: limiter.queued() + queued: limiter.queued(), } } - setAccessToken (accessToken) { + setAccessToken(accessToken) { this.accessToken = accessToken - this.auth = { 'bearer': accessToken } + this.auth = { bearer: accessToken } } - refreshAccessToken () { + refreshAccessToken() { return this.oauth.refreshAccessToken() } - setOAuth (options = {}) { + setOAuth(options = {}) { this.clientId = options.clientId this.clientSecret = options.clientSecret this.redirectUri = options.redirectUri this.refreshToken = options.refreshToken } - setAuth (options = {}) { + setAuth(options = {}) { if (options.apiKey) { this.qs.hapikey = options.apiKey } else if (options.accessToken) { if (options.useOAuth1) { this.qs.access_token = options.accessToken - } else { // defaults to OAuth2 + } else { + // defaults to OAuth2 this.setAccessToken(options.accessToken) } } } - _request (opts, cb = () => {}) { + _request(opts, cb = () => {}) { const params = _.cloneDeep(opts) - if (this.auth) { params.auth = this.auth } + if (this.auth) { + params.auth = this.auth + } params.json = true params.url = this.baseUrl + params.path @@ -104,40 +110,44 @@ class Client extends EventEmitter { params.qs = Object.assign({}, this.qs, params.qs) params.qsStringifyOptions = { - arrayFormat: 'repeat' + arrayFormat: 'repeat', } params.timeout = this.apiTimeout - return this.checkApiLimit(params) - .then(() => { - this.emit('apiCall', params) - return limiter.schedule(() => request(params)) // limit the number of concurrent requests - .then(body => { - cb(null, body) - return body - }).catch(err => { - cb(err) - throw err - }) - }) + return this.checkApiLimit(params).then(() => { + this.emit('apiCall', params) + return limiter + .schedule(() => request(params)) // limit the number of concurrent requests + .then(body => { + cb(null, body) + return body + }) + .catch(err => { + cb(err) + throw err + }) + }) } - checkApiLimit (params) { - if (this.auth) { // don't check the api limit for the api call + checkApiLimit(params) { + if (this.auth) { + // don't check the api limit for the api call return Promise.resolve() } - if ((/integrations\/v1\/limit|oauth/).test(params.url)) { // don't check the api limit for the api call + if (/integrations\/v1\/limit|oauth/.test(params.url)) { + // don't check the api limit for the api call return Promise.resolve() } - if (this.maxUsePercent === 0) { // if maxUsePercent set to 0, do not check for the API limit (use at your own risk) + if (this.maxUsePercent === 0) { + // if maxUsePercent set to 0, do not check for the API limit (use at your own risk) return Promise.resolve() } return this.getApiLimit().then(results => { const { usageLimit = 40000, currentUsage = 0 } = results - const usagePercent = 100.0 * currentUsage / usageLimit + const usagePercent = (100.0 * currentUsage) / usageLimit debug('usagePercent', usagePercent, 'apiCalls', this.apiCalls) - if (usagePercent > (this.maxUsePercent)) { + if (usagePercent > this.maxUsePercent) { const err = new Error('Too close to the API limit') err.usageLimit = usageLimit err.currentUsage = currentUsage @@ -147,7 +157,7 @@ class Client extends EventEmitter { }) } - getApiLimit () { + getApiLimit() { this.limit = this.limit || {} const collectedAt = this.limit.collectedAt || 0 const recencyMinutes = (Date.now() - collectedAt) / (60 * 1000) @@ -157,9 +167,9 @@ class Client extends EventEmitter { } return this._request({ method: 'GET', - path: '/integrations/v1/limit/daily' + path: '/integrations/v1/limit/daily', }).then(results => { - this.limit = results.filter((r) => r.name === 'api-calls-daily')[0] + this.limit = results.filter(r => r.name === 'api-calls-daily')[0] return this.limit }) } diff --git a/lib/company.js b/lib/company.js index 8a8d4ec..5e7cbb0 100644 --- a/lib/company.js +++ b/lib/company.js @@ -1,137 +1,177 @@ const Property = require('./company_property') class Company { - constructor (client) { + constructor(client) { this.client = client this.properties = new Property(this.client) } - getById (id, cb) { - return this.client._request({ - method: 'GET', - path: '/companies/v2/companies/' + id - }, cb) + getById(id, cb) { + return this.client._request( + { + method: 'GET', + path: '/companies/v2/companies/' + id, + }, + cb, + ) } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/companies/v2/companies/paged', - qs: options, - qsStringifyOptions: { - arrayFormat: 'repeat' - } - }, cb) + return this.client._request( + { + method: 'GET', + path: '/companies/v2/companies/paged', + qs: options, + qsStringifyOptions: { + arrayFormat: 'repeat', + }, + }, + cb, + ) } - getAll (options, cb) { + getAll(options, cb) { return this.get(options, cb) } - getRecentlyCreated (options, cb) { + getRecentlyCreated(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/companies/v2/companies/recent/created', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/companies/v2/companies/recent/created', + qs: options, + }, + cb, + ) } - getRecentlyModified (options, cb) { + getRecentlyModified(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/companies/v2/companies/recent/modified', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/companies/v2/companies/recent/modified', + qs: options, + }, + cb, + ) } - getByDomain (domain, cb) { - return this.client._request({ - method: 'GET', - path: '/companies/v2/companies/domain/' + domain - }, cb) + getByDomain(domain, cb) { + return this.client._request( + { + method: 'GET', + path: '/companies/v2/companies/domain/' + domain, + }, + cb, + ) } - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/companies/v2/companies/', - body: data - }, cb) + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/companies/v2/companies/', + body: data, + }, + cb, + ) } - delete (id, cb) { - return this.client._request({ - method: 'DELETE', - path: '/companies/v2/companies/' + id - }, cb) + delete(id, cb) { + return this.client._request( + { + method: 'DELETE', + path: '/companies/v2/companies/' + id, + }, + cb, + ) } - update (id, data, cb) { - return this.client._request({ - method: 'PUT', - path: '/companies/v2/companies/' + id, - body: data - }, cb) + update(id, data, cb) { + return this.client._request( + { + method: 'PUT', + path: '/companies/v2/companies/' + id, + body: data, + }, + cb, + ) } - updateBatch (data, cb) { - return this.client._request({ - method: 'POST', - path: '/companies/v1/batch-async/update', - body: data - }, cb) + updateBatch(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/companies/v1/batch-async/update', + body: data, + }, + cb, + ) } - addContactToCompany (data, cb) { + addContactToCompany(data, cb) { if (!data || !data.companyId || !data.contactVid) { return cb(new Error('companyId and contactVid params must be provided')) } - return this.client._request({ - method: 'PUT', - path: '/companies/v2/companies/' + data.companyId + '/contacts/' + data.contactVid - }, cb) + return this.client._request( + { + method: 'PUT', + path: + '/companies/v2/companies/' + + data.companyId + + '/contacts/' + + data.contactVid, + }, + cb, + ) } - getContactIds (id, options, cb) { + getContactIds(id, options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/companies/v2/companies/' + id + '/vids', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/companies/v2/companies/' + id + '/vids', + qs: options, + }, + cb, + ) } - getContacts (id, options, cb) { + getContacts(id, options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/companies/v2/companies/' + id + '/contacts', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/companies/v2/companies/' + id + '/contacts', + qs: options, + }, + cb, + ) } } diff --git a/lib/company_property.js b/lib/company_property.js index dc95cc8..829743e 100644 --- a/lib/company_property.js +++ b/lib/company_property.js @@ -1,60 +1,72 @@ const Group = require('./company_property_group') class Properties { - constructor (client) { + constructor(client) { this.client = client this.groups = new Group(this.client) } - getAll (options, cb) { + getAll(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/properties/v1/companies/properties', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/properties/v1/companies/properties', + qs: options, + }, + cb, + ) } - get (options, cb) { + get(options, cb) { return this.getAll(options, cb) } - getByName (name, cb) { - return this.client._request({ - method: 'GET', - path: '/properties/v1/companies/properties/named/' + name - }, cb) + getByName(name, cb) { + return this.client._request( + { + method: 'GET', + path: '/properties/v1/companies/properties/named/' + name, + }, + cb, + ) } - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/properties/v1/companies/properties', - body: data - }, cb) + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/properties/v1/companies/properties', + body: data, + }, + cb, + ) } - update (name, data, cb) { - return this.client._request({ - method: 'PUT', - path: '/properties/v1/companies/properties/named/' + name, - body: data - }, cb) + update(name, data, cb) { + return this.client._request( + { + method: 'PUT', + path: '/properties/v1/companies/properties/named/' + name, + body: data, + }, + cb, + ) } - upsert (data) { - return this.create(data) - .catch(err => { - if (err.statusCode === 409) { // if 409, the property already exists, update it - return this.update(data.name, data) - } else { - throw err - } - }) + upsert(data) { + return this.create(data).catch(err => { + if (err.statusCode === 409) { + // if 409, the property already exists, update it + return this.update(data.name, data) + } else { + throw err + } + }) } } diff --git a/lib/company_property_group.js b/lib/company_property_group.js index e533427..da88705 100644 --- a/lib/company_property_group.js +++ b/lib/company_property_group.js @@ -1,50 +1,59 @@ class Groups { - constructor (client) { + constructor(client) { this.client = client } - getAll (options, cb) { + getAll(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/properties/v1/companies/groups', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/properties/v1/companies/groups', + qs: options, + }, + cb, + ) } - get (options, cb) { + get(options, cb) { return this.getAll(options, cb) } - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/properties/v1/companies/groups', - body: data - }, cb) + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/properties/v1/companies/groups', + body: data, + }, + cb, + ) } - update (name, data, cb) { - return this.client._request({ - method: 'PUT', - path: '/properties/v1/companies/groups/named/' + name, - body: data - }, cb) + update(name, data, cb) { + return this.client._request( + { + method: 'PUT', + path: '/properties/v1/companies/groups/named/' + name, + body: data, + }, + cb, + ) } - upsert (data) { - return this.create(data) - .catch(err => { - if (err.statusCode === 409) { // if 409, the property group already exists, update it - return this.update(data.name, data) - } else { - throw err - } - }) + upsert(data) { + return this.create(data).catch(err => { + if (err.statusCode === 409) { + // if 409, the property group already exists, update it + return this.update(data.name, data) + } else { + throw err + } + }) } } diff --git a/lib/contact.js b/lib/contact.js index 207d71a..94b5329 100644 --- a/lib/contact.js +++ b/lib/contact.js @@ -1,143 +1,185 @@ const Property = require('./contact_property') class Contact { - constructor (client) { + constructor(client) { this.client = client this.properties = new Property(this.client) } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/contacts/v1/lists/all/contacts/all', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/lists/all/contacts/all', + qs: options, + }, + cb, + ) } - getAll (options, cb) { + getAll(options, cb) { return this.get(options, cb) } - getRecentlyModified (options, cb) { + getRecentlyModified(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/contacts/v1/lists/recently_updated/contacts/recent', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/lists/recently_updated/contacts/recent', + qs: options, + }, + cb, + ) } - getRecentlyCreated (options, cb) { + getRecentlyCreated(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/contacts/v1/lists/all/contacts/recent', - qs: options - }, cb) - } - - getByEmail (email, cb) { - return this.client._request({ - method: 'GET', - path: '/contacts/v1/contact/email/' + email + '/profile' - }, cb) - } - - getByEmailBatch (emails, cb) { - return this.client._request({ - method: 'GET', - path: '/contacts/v1/contact/emails/batch', - qs: { email: emails }, - qsStringifyOptions: { indices: false } - }, cb) - } - - getById (id, cb) { - return this.client._request({ - method: 'GET', - path: '/contacts/v1/contact/vid/' + id + '/profile' - }, cb) - } - - getByIdBatch (ids, cb) { - return this.client._request({ - method: 'GET', - path: '/contacts/v1/contact/vids/batch', - qs: { vid: ids }, - qsStringifyOptions: { indices: false } - }, cb) - } - - getByToken (token, cb) { - return this.client._request({ - method: 'GET', - path: '/contacts/v1/contact/utk/' + token + '/profile' - }, cb) - } - - delete (id, cb) { - return this.client._request({ - method: 'DELETE', - path: '/contacts/v1/contact/vid/' + id - }, cb) - } - - update (id, data, cb) { - return this.client._request({ - method: 'POST', - path: '/contacts/v1/contact/vid/' + id + '/profile', - body: data - }, cb) - } - - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/contacts/v1/contact', - body: data - }, cb) - } - - createOrUpdate (email, data, cb) { - return this.client._request({ - method: 'POST', - path: '/contacts/v1/contact/createOrUpdate/email/' + email, - body: data - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/lists/all/contacts/recent', + qs: options, + }, + cb, + ) + } + + getByEmail(email, cb) { + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/contact/email/' + email + '/profile', + }, + cb, + ) + } + + getByEmailBatch(emails, cb) { + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/contact/emails/batch', + qs: { email: emails }, + qsStringifyOptions: { indices: false }, + }, + cb, + ) + } + + getById(id, cb) { + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/contact/vid/' + id + '/profile', + }, + cb, + ) + } + + getByIdBatch(ids, cb) { + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/contact/vids/batch', + qs: { vid: ids }, + qsStringifyOptions: { indices: false }, + }, + cb, + ) + } + + getByToken(token, cb) { + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/contact/utk/' + token + '/profile', + }, + cb, + ) + } + + delete(id, cb) { + return this.client._request( + { + method: 'DELETE', + path: '/contacts/v1/contact/vid/' + id, + }, + cb, + ) + } + + update(id, data, cb) { + return this.client._request( + { + method: 'POST', + path: '/contacts/v1/contact/vid/' + id + '/profile', + body: data, + }, + cb, + ) + } + + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/contacts/v1/contact', + body: data, + }, + cb, + ) + } + + createOrUpdate(email, data, cb) { + return this.client._request( + { + method: 'POST', + path: '/contacts/v1/contact/createOrUpdate/email/' + email, + body: data, + }, + cb, + ) } // note: response to successful batch update is undefined by design : http://developers.hubspot.com/docs/methods/contacts/batch_create_or_update - createOrUpdateBatch (data, cb) { - return this.client._request({ - method: 'POST', - path: '/contacts/v1/contact/batch', - body: data - }, cb) - } - - search (query, options, cb) { + createOrUpdateBatch(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/contacts/v1/contact/batch', + body: data, + }, + cb, + ) + } + + search(query, options, cb) { if (typeof options === 'function') { cb = options options = {} } if (!options) options = {} options.q = query - return this.client._request({ - method: 'GET', - path: '/contacts/v1/search/query', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/search/query', + qs: options, + }, + cb, + ) } } diff --git a/lib/contact_property.js b/lib/contact_property.js index 0ab6490..cc59bec 100644 --- a/lib/contact_property.js +++ b/lib/contact_property.js @@ -1,94 +1,121 @@ class Properties { - constructor (client) { + constructor(client) { this.client = client } - getAll (options, cb) { + getAll(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/contacts/v2/properties', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v2/properties', + qs: options, + }, + cb, + ) } - get (options, cb) { + get(options, cb) { return this.getAll(options, cb) } - getByName (name, cb) { - return this.client._request({ - method: 'GET', - path: '/properties/v1/contacts/properties/named/' + name - }, cb) + getByName(name, cb) { + return this.client._request( + { + method: 'GET', + path: '/properties/v1/contacts/properties/named/' + name, + }, + cb, + ) } - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/properties/v1/contacts/properties', - body: data - }, cb) + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/properties/v1/contacts/properties', + body: data, + }, + cb, + ) } - update (name, data, cb) { - return this.client._request({ - method: 'PUT', - path: '/properties/v1/contacts/properties/named/' + name, - body: data - }, cb) + update(name, data, cb) { + return this.client._request( + { + method: 'PUT', + path: '/properties/v1/contacts/properties/named/' + name, + body: data, + }, + cb, + ) } - delete (name, cb) { - return this.client._request({ - method: 'DELETE', - path: '/properties/v1/contacts/properties/named/' + name - }, cb) + delete(name, cb) { + return this.client._request( + { + method: 'DELETE', + path: '/properties/v1/contacts/properties/named/' + name, + }, + cb, + ) } - upsert (data) { - return this.create(data) - .catch(err => { - if (err.statusCode === 409) { // if 409, the property already exists, update it - return this.update(data.name, data) - } else { - throw err - } - }) + upsert(data) { + return this.create(data).catch(err => { + if (err.statusCode === 409) { + // if 409, the property already exists, update it + return this.update(data.name, data) + } else { + throw err + } + }) } - getGroups (cb) { - return this.client._request({ - method: 'GET', - path: '/properties/v1/contacts/groups' - }, cb) + getGroups(cb) { + return this.client._request( + { + method: 'GET', + path: '/properties/v1/contacts/groups', + }, + cb, + ) } - createGroup (data, cb) { - return this.client._request({ - method: 'POST', - path: '/properties/v1/contacts/groups', - body: data - }, cb) + createGroup(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/properties/v1/contacts/groups', + body: data, + }, + cb, + ) } - updateGroup (name, data, cb) { - return this.client._request({ - method: 'PUT', - path: '/properties/v1/contacts/groups/named/' + name, - body: data - }, cb) + updateGroup(name, data, cb) { + return this.client._request( + { + method: 'PUT', + path: '/properties/v1/contacts/groups/named/' + name, + body: data, + }, + cb, + ) } - deleteGroup (name, cb) { - return this.client._request({ - method: 'DELETE', - path: '/properties/v1/contacts/groups/named/' + name - }, cb) + deleteGroup(name, cb) { + return this.client._request( + { + method: 'DELETE', + path: '/properties/v1/contacts/groups/named/' + name, + }, + cb, + ) } } diff --git a/lib/deal.js b/lib/deal.js index 1bb39a8..6c3100e 100644 --- a/lib/deal.js +++ b/lib/deal.js @@ -1,102 +1,145 @@ const Property = require('./deal_property') class Deal { - constructor (client) { + constructor(client) { this.client = client this.properties = new Property(client) } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/deals/v1/deal/paged', - qs: options, - useQuerystring: true - }, cb) + return this.client._request( + { + method: 'GET', + path: '/deals/v1/deal/paged', + qs: options, + useQuerystring: true, + }, + cb, + ) } - getRecentlyModified (options, cb) { + getRecentlyModified(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/deals/v1/deal/recent/modified', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/deals/v1/deal/recent/modified', + qs: options, + }, + cb, + ) } - getRecentlyCreated (options, cb) { + getRecentlyCreated(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/deals/v1/deal/recent/created', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/deals/v1/deal/recent/created', + qs: options, + }, + cb, + ) } - getById (id, cb) { - return this.client._request({ - method: 'GET', - path: '/deals/v1/deal/' + id - }, cb) + getById(id, cb) { + return this.client._request( + { + method: 'GET', + path: '/deals/v1/deal/' + id, + }, + cb, + ) } - getAssociated (objectType, objectId, options, cb) { + getAssociated(objectType, objectId, options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/deals/v1/deal/associated/' + objectType + '/' + objectId + '/paged', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: + '/deals/v1/deal/associated/' + objectType + '/' + objectId + '/paged', + qs: options, + }, + cb, + ) } - deleteById (id, cb) { - return this.client._request({ - method: 'DELETE', - path: '/deals/v1/deal/' + id - }, cb) + deleteById(id, cb) { + return this.client._request( + { + method: 'DELETE', + path: '/deals/v1/deal/' + id, + }, + cb, + ) } - updateById (id, data, cb) { - return this.client._request({ - method: 'PUT', - path: '/deals/v1/deal/' + id, - body: data - }, cb) + updateById(id, data, cb) { + return this.client._request( + { + method: 'PUT', + path: '/deals/v1/deal/' + id, + body: data, + }, + cb, + ) } - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/deals/v1/deal/', - body: data - }, cb) + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/deals/v1/deal/', + body: data, + }, + cb, + ) } - associate (id, objectType, associatedObjectId, cb) { - return this.client._request({ - method: 'PUT', - path: '/deals/v1/deal/' + id + '/associations/' + objectType + '?id=' + associatedObjectId - }, cb) + associate(id, objectType, associatedObjectId, cb) { + return this.client._request( + { + method: 'PUT', + path: + '/deals/v1/deal/' + + id + + '/associations/' + + objectType + + '?id=' + + associatedObjectId, + }, + cb, + ) } - removeAssociation (id, objectType, associatedObjectId, cb) { - return this.client._request({ - method: 'DELETE', - path: '/deals/v1/deal/' + id + '/associations/' + objectType + '?id=' + associatedObjectId - }, cb) + removeAssociation(id, objectType, associatedObjectId, cb) { + return this.client._request( + { + method: 'DELETE', + path: + '/deals/v1/deal/' + + id + + '/associations/' + + objectType + + '?id=' + + associatedObjectId, + }, + cb, + ) } } diff --git a/lib/deal_property.js b/lib/deal_property.js index 029f526..ddce307 100644 --- a/lib/deal_property.js +++ b/lib/deal_property.js @@ -1,67 +1,82 @@ const Group = require('./deal_property_group') class Properties { - constructor (client) { + constructor(client) { this.client = client this.groups = new Group(this.client) } - getAll (options, cb) { + getAll(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/properties/v1/deals/properties', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/properties/v1/deals/properties', + qs: options, + }, + cb, + ) } - get (options, cb) { + get(options, cb) { return this.getAll(options, cb) } - getByName (name, cb) { - return this.client._request({ - method: 'GET', - path: '/properties/v1/deals/properties/named/' + name - }, cb) + getByName(name, cb) { + return this.client._request( + { + method: 'GET', + path: '/properties/v1/deals/properties/named/' + name, + }, + cb, + ) } - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/properties/v1/deals/properties', - body: data - }, cb) + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/properties/v1/deals/properties', + body: data, + }, + cb, + ) } - update (name, data, cb) { - return this.client._request({ - method: 'PUT', - path: '/properties/v1/deals/properties/named/' + name, - body: data - }, cb) + update(name, data, cb) { + return this.client._request( + { + method: 'PUT', + path: '/properties/v1/deals/properties/named/' + name, + body: data, + }, + cb, + ) } - delete (name, cb) { - return this.client._request({ - method: 'DELETE', - path: '/properties/v1/deals/properties/named/' + name - }, cb) + delete(name, cb) { + return this.client._request( + { + method: 'DELETE', + path: '/properties/v1/deals/properties/named/' + name, + }, + cb, + ) } - upsert (data) { - return this.create(data) - .catch(err => { - if (err.statusCode === 409) { // if 409, the property already exists, update it - return this.update(data.name, data) - } else { - throw err - } - }) + upsert(data) { + return this.create(data).catch(err => { + if (err.statusCode === 409) { + // if 409, the property already exists, update it + return this.update(data.name, data) + } else { + throw err + } + }) } } diff --git a/lib/deal_property_group.js b/lib/deal_property_group.js index 1e8a0ed..3f5bf3d 100644 --- a/lib/deal_property_group.js +++ b/lib/deal_property_group.js @@ -1,50 +1,59 @@ class DealGroups { - constructor (client) { + constructor(client) { this.client = client } - getAll (options, cb) { + getAll(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/properties/v1/deals/groups', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/properties/v1/deals/groups', + qs: options, + }, + cb, + ) } - get (options, cb) { + get(options, cb) { return this.getAll(options, cb) } - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/properties/v1/deals/groups', - body: data - }, cb) + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/properties/v1/deals/groups', + body: data, + }, + cb, + ) } - update (name, data, cb) { - return this.client._request({ - method: 'PUT', - path: '/properties/v1/deals/groups/named/' + name, - body: data - }, cb) + update(name, data, cb) { + return this.client._request( + { + method: 'PUT', + path: '/properties/v1/deals/groups/named/' + name, + body: data, + }, + cb, + ) } - upsert (data) { - return this.create(data) - .catch(err => { - if (err.statusCode === 409) { // if 409, the property group already exists, update it - return this.update(data.name, data) - } else { - throw err - } - }) + upsert(data) { + return this.create(data).catch(err => { + if (err.statusCode === 409) { + // if 409, the property group already exists, update it + return this.update(data.name, data) + } else { + throw err + } + }) } } diff --git a/lib/engagement.js b/lib/engagement.js index e342724..52d190b 100644 --- a/lib/engagement.js +++ b/lib/engagement.js @@ -1,53 +1,70 @@ class Engagement { - constructor (client) { + constructor(client) { this.client = client } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/engagements/v1/engagements/paged', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/engagements/v1/engagements/paged', + qs: options, + }, + cb, + ) } - getRecentlyModified (options, cb) { + getRecentlyModified(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/engagements/v1/engagements/recent/modified', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/engagements/v1/engagements/recent/modified', + qs: options, + }, + cb, + ) } - getAssociated (objectType, objectId, options, cb) { + getAssociated(objectType, objectId, options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/engagements/v1/engagements/associated/' + objectType + '/' + objectId + '/paged', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: + '/engagements/v1/engagements/associated/' + + objectType + + '/' + + objectId + + '/paged', + qs: options, + }, + cb, + ) } - create (data, cb) { - return this.client._request({ - method: 'POST', - path: '/engagements/v1/engagements', - body: data - }, cb) + create(data, cb) { + return this.client._request( + { + method: 'POST', + path: '/engagements/v1/engagements', + body: data, + }, + cb, + ) } } diff --git a/lib/file.js b/lib/file.js index 6986b8a..82e62da 100644 --- a/lib/file.js +++ b/lib/file.js @@ -1,24 +1,30 @@ class File { - constructor (client) { + constructor(client) { this.client = client } - get (cb) { - return this.client._request({ - method: 'GET', - path: '/filemanager/api/v2/files' - }, cb) + get(cb) { + return this.client._request( + { + method: 'GET', + path: '/filemanager/api/v2/files', + }, + cb, + ) } - getOne (id, cb) { - if (!id || typeof (id) === 'function') { + getOne(id, cb) { + if (!id || typeof id === 'function') { return cb(new Error('id parameter must be provided.')) } - return this.client._request({ - method: 'GET', - path: '/filemanager/api/v2/files/' + id - }, cb) + return this.client._request( + { + method: 'GET', + path: '/filemanager/api/v2/files/' + id, + }, + cb, + ) } } diff --git a/lib/list.js b/lib/list.js index 7193d59..5a93637 100644 --- a/lib/list.js +++ b/lib/list.js @@ -1,82 +1,97 @@ class List { - constructor (client) { + constructor(client) { this.client = client } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/contacts/v1/lists', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/lists', + qs: options, + }, + cb, + ) } - getOne (id, cb) { - if (!id || typeof (id) === 'function') { + getOne(id, cb) { + if (!id || typeof id === 'function') { return cb(new Error('id parameter must be provided.')) } - return this.client._request({ - method: 'GET', - path: '/contacts/v1/lists/' + id - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/lists/' + id, + }, + cb, + ) } - getContacts (id, options, cb) { - if (!id || typeof (id) === 'function') { + getContacts(id, options, cb) { + if (!id || typeof id === 'function') { return cb(new Error('id parameter must be provided.')) } - if (typeof (options) === 'function') { + if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/contacts/v1/lists/' + id + '/contacts/all', - qs: options, - qsStringifyOptions: { indices: false } - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/lists/' + id + '/contacts/all', + qs: options, + qsStringifyOptions: { indices: false }, + }, + cb, + ) } - getRecentContacts (id, options, cb) { - if (!id || typeof (id) === 'function') { + getRecentContacts(id, options, cb) { + if (!id || typeof id === 'function') { return cb(new Error('id parameter must be provided.')) } - if (typeof (options) === 'function') { + if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/contacts/v1/lists/' + id + '/contacts/recent', - qs: options, - qsStringifyOptions: { indices: false } - }, cb) + return this.client._request( + { + method: 'GET', + path: '/contacts/v1/lists/' + id + '/contacts/recent', + qs: options, + qsStringifyOptions: { indices: false }, + }, + cb, + ) } - addContacts (id, contactBody, cb) { - if (!id || typeof (id) === 'function') { + addContacts(id, contactBody, cb) { + if (!id || typeof id === 'function') { return cb(new Error('id parameter must be provided.')) } - if (!contactBody || typeof (contactBody) === 'function') { + if (!contactBody || typeof contactBody === 'function') { return cb(new Error('contactBody parameter must be provided.')) } var body = contactBody - return this.client._request({ - method: 'POST', - path: '/contacts/v1/lists/' + id + '/add', - body: body - }, cb) + return this.client._request( + { + method: 'POST', + path: '/contacts/v1/lists/' + id + '/add', + body: body, + }, + cb, + ) } } diff --git a/lib/oauth.js b/lib/oauth.js index 8d653ec..10c5b15 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -2,52 +2,57 @@ const _ = require('lodash') const qs = require('querystring') class OAuth { - constructor (client) { + constructor(client) { this.client = client } - getAuthorizationUrl (data) { + getAuthorizationUrl(data) { const params = { client_id: this.client.clientId, - redirect_uri: this.client.redirectUri + redirect_uri: this.client.redirectUri, } _.extend(params, data) return 'https://app.hubspot.com/oauth/authorize?' + qs.stringify(params) } - getAccessToken (data, cb) { + getAccessToken(data, cb) { const form = { grant_type: 'authorization_code', client_id: this.client.clientId, client_secret: this.client.clientSecret, - redirect_uri: this.client.redirectUri + redirect_uri: this.client.redirectUri, } _.extend(form, data) - return this.client._request({ - method: 'POST', - path: '/oauth/v1/token', - form - }, cb) + return this.client._request( + { + method: 'POST', + path: '/oauth/v1/token', + form, + }, + cb, + ) } - refreshAccessToken (data, cb) { + refreshAccessToken(data, cb) { const form = { grant_type: 'refresh_token', client_id: this.client.clientId, client_secret: this.client.clientSecret, redirect_uri: this.client.redirectUri, - refresh_token: this.client.refreshToken + refresh_token: this.client.refreshToken, } _.extend(form, data) - return this.client._request({ - method: 'POST', - path: '/oauth/v1/token', - form - }).then(results => { - this.client.setAccessToken(results.access_token) // refresh the new access_token on the client - // cb(null, results) - return results - }) + return this.client + ._request({ + method: 'POST', + path: '/oauth/v1/token', + form, + }) + .then(results => { + this.client.setAccessToken(results.access_token) // refresh the new access_token on the client + // cb(null, results) + return results + }) // callback not implemented/test // .catch(err => { // cb(err) diff --git a/lib/owner.js b/lib/owner.js index 617a6e7..1a6e875 100644 --- a/lib/owner.js +++ b/lib/owner.js @@ -1,13 +1,16 @@ class Owner { - constructor (client) { + constructor(client) { this.client = client } - get (cb) { - return this.client._request({ - method: 'GET', - path: '/owners/v2/owners' - }, cb) + get(cb) { + return this.client._request( + { + method: 'GET', + path: '/owners/v2/owners', + }, + cb, + ) } } diff --git a/lib/page.js b/lib/page.js index 78fce96..303db17 100644 --- a/lib/page.js +++ b/lib/page.js @@ -1,19 +1,22 @@ class Page { - constructor (client) { + constructor(client) { this.client = client } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/content/api/v2/pages', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/content/api/v2/pages', + qs: options, + }, + cb, + ) } } diff --git a/lib/pipeline.js b/lib/pipeline.js index 07b59d3..1004e8d 100644 --- a/lib/pipeline.js +++ b/lib/pipeline.js @@ -1,19 +1,22 @@ class Pipeline { - constructor (client) { + constructor(client) { this.client = client } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/deals/v1/pipelines', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/deals/v1/pipelines', + qs: options, + }, + cb, + ) } } diff --git a/lib/subscription.js b/lib/subscription.js index 7a32640..6b4d518 100644 --- a/lib/subscription.js +++ b/lib/subscription.js @@ -1,19 +1,22 @@ class Subscription { - constructor (client) { + constructor(client) { this.client = client } - get (options, cb) { + get(options, cb) { if (typeof options === 'function') { cb = options options = {} } - return this.client._request({ - method: 'GET', - path: '/email/public/v1/subscriptions/timeline', - qs: options - }, cb) + return this.client._request( + { + method: 'GET', + path: '/email/public/v1/subscriptions/timeline', + qs: options, + }, + cb, + ) } } diff --git a/lib/workflow.js b/lib/workflow.js index cc4427f..5e282b1 100644 --- a/lib/workflow.js +++ b/lib/workflow.js @@ -1,41 +1,56 @@ class Workflow { - constructor (client) { + constructor(client) { this.client = client } - get (workflowId, cb) { - return this.client._request({ - method: 'GET', - path: `/automation/v3/workflows/${workflowId}` - }, cb) + get(workflowId, cb) { + return this.client._request( + { + method: 'GET', + path: `/automation/v3/workflows/${workflowId}`, + }, + cb, + ) } - getAll (cb) { - return this.client._request({ - method: 'GET', - path: '/automation/v3/workflows' - }, cb) + getAll(cb) { + return this.client._request( + { + method: 'GET', + path: '/automation/v3/workflows', + }, + cb, + ) } - enroll (workflowId, email, cb) { - return this.client._request({ - method: 'POST', - path: `/automation/v2/workflows/${workflowId}/enrollments/contacts/${email}` - }, cb) + enroll(workflowId, email, cb) { + return this.client._request( + { + method: 'POST', + path: `/automation/v2/workflows/${workflowId}/enrollments/contacts/${email}`, + }, + cb, + ) } - unenroll (workflowId, email, cb) { - return this.client._request({ - method: 'DELETE', - path: `/automation/v2/workflows/${workflowId}/enrollments/contacts/${email}` - }, cb) + unenroll(workflowId, email, cb) { + return this.client._request( + { + method: 'DELETE', + path: `/automation/v2/workflows/${workflowId}/enrollments/contacts/${email}`, + }, + cb, + ) } - current (contactId, cb) { - return this.client._request({ - method: 'GET', - path: `/automation/v2/workflows/enrollments/contacts/${contactId}` - }, cb) + current(contactId, cb) { + return this.client._request( + { + method: 'GET', + path: `/automation/v2/workflows/enrollments/contacts/${contactId}`, + }, + cb, + ) } } diff --git a/package-lock.json b/package-lock.json index ea78ca3..b9c5aaf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -554,6 +554,15 @@ } } }, + "eslint-config-prettier": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-3.3.0.tgz", + "integrity": "sha512-Bc3bh5bAcKNvs3HOpSi6EfGA2IIp7EzWcg2tS4vP7stnXu/J1opihHDM7jI9JCIckyIDTgZLSWn7J3HY0j2JfA==", + "dev": true, + "requires": { + "get-stdin": "^6.0.0" + } + }, "eslint-config-standard": { "version": "12.0.0", "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-12.0.0.tgz", @@ -676,6 +685,15 @@ } } }, + "eslint-plugin-prettier": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.0.tgz", + "integrity": "sha512-4g11opzhqq/8+AMmo5Vc2Gn7z9alZ4JqrbZ+D4i8KlSyxeQhZHlmIrY8U9Akf514MoEhogPa87Jgkq87aZ2Ohw==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-plugin-promise": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-4.0.1.tgz", @@ -783,6 +801,12 @@ "resolved": false, "integrity": "sha1-liVqO8l1WV6zbYLpkp0GDYk0Of8=" }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", @@ -874,6 +898,12 @@ "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", "dev": true }, + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -1529,6 +1559,21 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, + "prettier": { + "version": "1.15.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.15.3.tgz", + "integrity": "sha512-gAU9AGAPMaKb3NNSUUuhhFAS7SCO4ALTN4nRIn6PJ075Qd28Yn2Ig2ahEJWdJwJmlEBTUfC7mMUSFy8MwsOCfg==", + "dev": true + }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "progress": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.1.tgz", diff --git a/package.json b/package.json index f6e2cf3..ef4c850 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,12 @@ "main": "index.js", "scripts": { "test": "npm run lint && npm run mocha && npm run tsc", + "lint": "npm run prettier && npm run eslint", "tsc": "tsc", "ts-node": "ts-node test/typescript/hubspot.ts", "mocha": "./node_modules/mocha/bin/mocha --recursive test/ --timeout 15000", - "lint": "./node_modules/eslint/bin/eslint.js . --fix", + "eslint": "./node_modules/eslint/bin/eslint.js . --fix", + "prettier": "./node_modules/prettier/bin-prettier.js --write '{lib,test}/**/*.js'", "watch-test": "./node_modules/mocha/bin/mocha --recursive test/ --timeout 15000 --watch" }, "repository": { @@ -36,12 +38,15 @@ "@types/request-promise": "^4.1.41", "chai": "^4.1.2", "eslint": "^5.7.0", + "eslint-config-prettier": "^3.3.0", "eslint-config-standard": "12.0.0", "eslint-plugin-import": "^2.9.0", "eslint-plugin-node": "^7.0.1", + "eslint-plugin-prettier": "^3.0.0", "eslint-plugin-promise": "^4.0.1", "eslint-plugin-standard": "4.0.0", "mocha": "^5.0.1", + "prettier": "^1.15.3", "ts-node": "^7.0.1", "typescript": "^3.1.3" } diff --git a/test/broadcasts.js b/test/broadcasts.js index a68fc67..b953b4f 100644 --- a/test/broadcasts.js +++ b/test/broadcasts.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('broadcasts', function () { - describe('get', function () { - it('Should return details on a set of broadcast messages', function () { +describe('broadcasts', function() { + describe('get', function() { + it('Should return details on a set of broadcast messages', function() { return hubspot.broadcasts.get().then(data => { expect(data).to.be.a('array') }) diff --git a/test/campaigns.js b/test/campaigns.js index 5714b77..e999bb1 100644 --- a/test/campaigns.js +++ b/test/campaigns.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('campaigns', function () { - describe('get', function () { - it('Should return campaign IDs with recent activity associated with the portal', function () { +describe('campaigns', function() { + describe('get', function() { + it('Should return campaign IDs with recent activity associated with the portal', function() { return hubspot.campaigns.get().then(data => { expect(data.campaigns).to.be.an('array') expect(data.hasMore).to.equal(true) @@ -14,8 +14,8 @@ describe('campaigns', function () { }) }) - describe('getOne', function () { - it('Should return campaign IDs with recent activity associated with the portal.', function () { + describe('getOne', function() { + it('Should return campaign IDs with recent activity associated with the portal.', function() { return hubspot.campaigns.getOne('by-id').then(data => { expect(data.campaigns).to.be.an('array') expect(data.hasMore).to.equal(true) @@ -23,8 +23,8 @@ describe('campaigns', function () { }) }) - describe('events', function () { - it('Should return campaign IDs with recent activity associated with the portal', function () { + describe('events', function() { + it('Should return campaign IDs with recent activity associated with the portal', function() { return hubspot.campaigns.events().then(data => { expect(data.events).to.be.an('array') expect(data.hasMore).to.equal(true) @@ -32,7 +32,7 @@ describe('campaigns', function () { }) }) - describe('getById', function () { + describe('getById', function() { // it('Should return campaign IDs with recent activity associated with the portal', function () { // return hubspot.campaigns.getById().then(data => { // expect(data.campaigns).to.be.an('array') diff --git a/test/client.js b/test/client.js index 1f68ff7..f83f1a4 100644 --- a/test/client.js +++ b/test/client.js @@ -3,16 +3,16 @@ const expect = chai.expect const Hubspot = require('..') -describe('client', function () { +describe('client', function() { this.timeout(10000) let hubspot - describe('apiKey', function () { + describe('apiKey', function() { before(() => { hubspot = new Hubspot({ apiKey: 'demo' }) }) - it('should instantiate all methods', function () { + it('should instantiate all methods', function() { expect(hubspot.campaigns).to.be.an('object') expect(hubspot.subscriptions).to.be.an('object') expect(hubspot.contacts).to.be.an('object') @@ -26,8 +26,8 @@ describe('client', function () { expect(hubspot.workflows).to.be.an('object') }) - describe('getApiLimit', function () { - it('should return the api limit', function () { + describe('getApiLimit', function() { + it('should return the api limit', function() { return hubspot.getApiLimit().then(data => { expect(data).to.be.an('object') expect(data.usageLimit).to.be.a('number') @@ -35,9 +35,9 @@ describe('client', function () { }) }) - it('should return from cache the second time', function () { + it('should return from cache the second time', function() { return hubspot.getApiLimit().then(data => { - // console.log(data) + // console.log(data) expect(data).to.be.an('object') expect(data.usageLimit).to.be.a('number') expect(data.currentUsage).to.be.a('number') @@ -46,7 +46,7 @@ describe('client', function () { }) }) - describe('bad apiKey', function () { + describe('bad apiKey', function() { it('should instantiate all methods', async () => { const hubspot = new Hubspot({ apiKey: 'bad' }) try { @@ -59,34 +59,45 @@ describe('client', function () { }) }) - describe('accessToken', function () { - it('should fail if no auth at all', function (done) { + describe('accessToken', function() { + it('should fail if no auth at all', function(done) { const hubspot = new Hubspot() - hubspot.contacts.get().then(data => { // access_key needs contacts scope - throw new Error('this call should have failed') - }).catch(() => done()) + hubspot.contacts + .get() + .then(data => { + // access_key needs contacts scope + throw new Error('this call should have failed') + }) + .catch(() => done()) }) - it('should work with an accessToken', function () { - if (!process.env.accessToken) { return } // hard to reproduce on CI. local testing only for now + it('should work with an accessToken', function() { + if (!process.env.accessToken) { + return + } // hard to reproduce on CI. local testing only for now const hubspot = new Hubspot({ accessToken: process.env.accessToken }) - return hubspot.contacts.get().then(data => { // access_key used for test needs `contacts` scope + return hubspot.contacts.get().then(data => { + // access_key used for test needs `contacts` scope expect(data.contacts).to.be.an('array') }) }) - it('should work if we have a refreshToken and refresh the access_token', function () { - if (!process.env.refreshToken) { return } // hard to reproduce on CI. local testing only for now + it('should work if we have a refreshToken and refresh the access_token', function() { + if (!process.env.refreshToken) { + return + } // hard to reproduce on CI. local testing only for now const params = { clientId: process.env.clientId, clientSecret: process.env.clientSecret, redirectUri: process.env.redirectUri, - refreshToken: process.env.refreshToken + refreshToken: process.env.refreshToken, } const hubspot = new Hubspot(params) - return hubspot.refreshAccessToken() + return hubspot + .refreshAccessToken() .then(() => hubspot.contacts.get()) - .then(data => { // access_key needs contacts scope + .then(data => { + // access_key needs contacts scope expect(data.contacts).to.be.an('array') }) }) diff --git a/test/companies.js b/test/companies.js index fc1676b..be5bdac 100644 --- a/test/companies.js +++ b/test/companies.js @@ -5,16 +5,16 @@ const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) const _ = require('lodash') -describe('companies', function () { - describe('get', function () { - it('should return all companies', function () { +describe('companies', function() { + describe('get', function() { + it('should return all companies', function() { return hubspot.companies.get().then(data => { expect(data).to.be.an('object') expect(data.companies).to.be.a('array') }) }) - it('should return a limited number of companies', function () { + it('should return a limited number of companies', function() { return hubspot.companies.get({ limit: 5 }).then(data => { expect(data).to.be.an('object') expect(data.companies).to.be.a('array') @@ -23,32 +23,34 @@ describe('companies', function () { }) }) - it('should return the requested properties', function () { - return hubspot.companies.get({ limit: 5, properties: ['name', 'country', 'city'] }).then(data => { - expect(data.companies).to.be.a('array') - expect(data.companies[0].properties.name.value).to.be.a('string') - }) + it('should return the requested properties', function() { + return hubspot.companies + .get({ limit: 5, properties: ['name', 'country', 'city'] }) + .then(data => { + expect(data.companies).to.be.a('array') + expect(data.companies[0].properties.name.value).to.be.a('string') + }) }) }) - describe('getById', function () { + describe('getById', function() { let companyId - before(function () { + before(function() { return hubspot.companies.get().then(data => { companyId = data.companies[0].companyId }) }) - it('should return a company', function () { + it('should return a company', function() { return hubspot.companies.getById(companyId).then(data => { expect(data).to.be.an('object') }) }) }) - describe('getRecentlyCreated', function () { - it('should return recently created companies', function () { + describe('getRecentlyCreated', function() { + it('should return recently created companies', function() { return hubspot.companies.getRecentlyCreated().then(data => { expect(data).to.be.an('object') expect(data.results).to.be.a('array') @@ -56,8 +58,8 @@ describe('companies', function () { }) }) - describe('getRecentlyModified', function () { - it('should return recently modified companies', function () { + describe('getRecentlyModified', function() { + it('should return recently modified companies', function() { return hubspot.companies.getRecentlyModified().then(data => { expect(data).to.be.an('object') expect(data.results).to.be.a('array') @@ -65,8 +67,8 @@ describe('companies', function () { }) }) - describe('getByDomain', function () { - it('should returns a list of all companies that have a matching domain to the specified domain in the request URL', function () { + describe('getByDomain', function() { + it('should returns a list of all companies that have a matching domain to the specified domain in the request URL', function() { this.timeout(10000) return hubspot.companies.getByDomain('example.com').then(data => { // console.log(data) @@ -76,9 +78,14 @@ describe('companies', function () { }) }) - describe('create', function () { - it('should create a company in a given portal', function () { - const payload = { 'properties': [{'name': 'name', 'value': 'A company name'}, {'name': 'description', 'value': 'A company description'}] } + describe('create', function() { + it('should create a company in a given portal', function() { + const payload = { + properties: [ + { name: 'name', value: 'A company name' }, + { name: 'description', value: 'A company description' }, + ], + } return hubspot.companies.create(payload).then(data => { expect(data).to.be.an('object') // console.log(data) @@ -87,25 +94,30 @@ describe('companies', function () { }) }) - describe('delete', function () { - it('can delete', function () { - const payload = { 'properties': [{'name': 'name', 'value': 'A company name'}, {'name': 'description', 'value': 'A company description'}] } + describe('delete', function() { + it('can delete', function() { + const payload = { + properties: [ + { name: 'name', value: 'A company name' }, + { name: 'description', value: 'A company description' }, + ], + } return hubspot.companies.create(payload).then(data => { return hubspot.companies.delete(data.companyId) }) }) }) - describe('getContactIds', function () { + describe('getContactIds', function() { let companyId - before(function () { + before(function() { return hubspot.companies.get().then(data => { companyId = data.companies[0].companyId }) }) - it('should return a list of contact vids', function () { + it('should return a list of contact vids', function() { const payload = { count: 10 } return hubspot.companies.getContactIds(companyId, payload).then(data => { expect(data).to.be.an('object') @@ -117,16 +129,16 @@ describe('companies', function () { }) }) - describe('getContacts', function () { + describe('getContacts', function() { let companyId - before(function () { + before(function() { return hubspot.companies.get().then(data => { companyId = data.companies[0].companyId }) }) - it('should return a list of contact objects', function () { + it('should return a list of contact objects', function() { const payload = { count: 10 } return hubspot.companies.getContacts(companyId, payload).then(data => { expect(data).to.be.an('object') @@ -138,18 +150,21 @@ describe('companies', function () { }) }) - describe('updateBatch', function () { + describe('updateBatch', function() { let companies - before(function () { + before(function() { return hubspot.companies.get().then(data => { companies = data.companies }) }) - it('should update a batch of company', function () { + it('should update a batch of company', function() { const batch = _.map(companies, company => { - const update = { objectId: company.companyId, properties: [ { name: 'about_us', value: 'Thumbs up!' } ] } + const update = { + objectId: company.companyId, + properties: [{ name: 'about_us', value: 'Thumbs up!' }], + } return update }) return hubspot.companies.updateBatch(batch).then(data => { diff --git a/test/company_properties.js b/test/company_properties.js index b06d31b..ff9fa35 100644 --- a/test/company_properties.js +++ b/test/company_properties.js @@ -13,12 +13,12 @@ const property = { fieldType: 'text', formField: false, displayOrder: -1, - options: [] + options: [], } -describe('companies.properties', function () { - describe('get', function () { - it('should return the list of properties for companies', function () { +describe('companies.properties', function() { + describe('get', function() { + it('should return the list of properties for companies', function() { return hubspot.companies.properties.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -28,8 +28,8 @@ describe('companies.properties', function () { }) }) - describe('getAll', function () { - it('should return the same thing as get', function () { + describe('getAll', function() { + it('should return the same thing as get', function() { return hubspot.companies.properties.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -39,28 +39,29 @@ describe('companies.properties', function () { }) }) - describe('getByName', function () { + describe('getByName', function() { let propertyName before(() => { - return hubspot.companies.properties.get() + return hubspot.companies.properties.get().then(results => { + // console.log(results) + propertyName = results[0].name + }) + }) + + it('should get a property by name', function() { + return hubspot.companies.properties + .getByName(propertyName) .then(results => { // console.log(results) - propertyName = results[0].name + expect(results).to.be.an('object') + expect(results).to.have.a.property('name') }) }) - - it('should get a property by name', function () { - return hubspot.companies.properties.getByName(propertyName).then(results => { - // console.log(results) - expect(results).to.be.an('object') - expect(results).to.have.a.property('name') - }) - }) }) - describe('upsert (create)', function () { - it('should create or update the property', function () { + describe('upsert (create)', function() { + it('should create or update the property', function() { return hubspot.companies.properties.upsert(property).then(data => { expect(data).to.be.an('object') expect(data).to.have.a.property('name') @@ -68,15 +69,17 @@ describe('companies.properties', function () { }) }) - describe('update', function () { + describe('update', function() { property.label = 'MadKudo Company Fit' - it('should update the property', function () { - return hubspot.companies.properties.update(property.name, property).then(data => { - expect(data).to.be.an('object') - expect(data).to.have.a.property('name') - expect(data.label).to.equal(property.label) - }) + it('should update the property', function() { + return hubspot.companies.properties + .update(property.name, property) + .then(data => { + expect(data).to.be.an('object') + expect(data).to.have.a.property('name') + expect(data.label).to.equal(property.label) + }) }) }) }) diff --git a/test/company_properties_groups.js b/test/company_properties_groups.js index 13ee475..82606dc 100644 --- a/test/company_properties_groups.js +++ b/test/company_properties_groups.js @@ -6,12 +6,12 @@ const hubspot = new Hubspot({ apiKey: 'demo' }) const group = { displayName: 'GROUP DIPLAY NAME', - name: 'mk_group_fit_segment' + name: 'mk_group_fit_segment', } -describe('companies.properties.groups', function () { - describe('get', function () { - it('should return the list of properties groups for companies', function () { +describe('companies.properties.groups', function() { + describe('get', function() { + it('should return the list of properties groups for companies', function() { return hubspot.companies.properties.groups.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -21,8 +21,8 @@ describe('companies.properties.groups', function () { }) }) - describe('getAll', function () { - it('should return the same thing as get', function () { + describe('getAll', function() { + it('should return the same thing as get', function() { return hubspot.companies.properties.groups.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -32,8 +32,8 @@ describe('companies.properties.groups', function () { }) }) - describe('upsert (create)', function () { - it('should create or update the properties group', function () { + describe('upsert (create)', function() { + it('should create or update the properties group', function() { return hubspot.companies.properties.groups.upsert(group).then(data => { expect(data).to.be.an('object') expect(data).to.have.a.property('name') @@ -41,15 +41,17 @@ describe('companies.properties.groups', function () { }) }) - describe('update', function () { + describe('update', function() { group.displayName = 'MadKudo Company Fit' - it('should update the property', function () { - return hubspot.companies.properties.groups.update(group.name, group).then(data => { - expect(data).to.be.an('object') - expect(data).to.have.a.property('name') - expect(data.displayName).to.equal(group.displayName) - }) + it('should update the property', function() { + return hubspot.companies.properties.groups + .update(group.name, group) + .then(data => { + expect(data).to.be.an('object') + expect(data).to.have.a.property('name') + expect(data.displayName).to.equal(group.displayName) + }) }) }) }) diff --git a/test/contact_properties.js b/test/contact_properties.js index d440dc9..ae05f57 100644 --- a/test/contact_properties.js +++ b/test/contact_properties.js @@ -13,12 +13,12 @@ const property = { fieldType: 'text', formField: false, displayOrder: -1, - options: [] + options: [], } -describe('contacts.properties', function () { - describe('get', function () { - it('should return the list of properties for contacts', function () { +describe('contacts.properties', function() { + describe('get', function() { + it('should return the list of properties for contacts', function() { return hubspot.contacts.properties.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -28,8 +28,8 @@ describe('contacts.properties', function () { }) }) - describe('getAll', function () { - it('should return the same thing as get', function () { + describe('getAll', function() { + it('should return the same thing as get', function() { return hubspot.contacts.properties.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -41,7 +41,7 @@ describe('contacts.properties', function () { describe('groups', () => { describe('getGroups', () => { - it('should return groups', function () { + it('should return groups', function() { return hubspot.contacts.properties.getGroups().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -56,17 +56,21 @@ describe('contacts.properties', function () { beforeEach(() => { name = 'test_group_' + Date.now() - return hubspot.contacts.properties.createGroup({ - name, - displayName: 'Test Group' - }).then(data => { - createdGroup = data - }) + return hubspot.contacts.properties + .createGroup({ + name, + displayName: 'Test Group', + }) + .then(data => { + createdGroup = data + }) }) afterEach(done => { // ignore error in the case where group was deleted - hubspot.contacts.properties.deleteGroup(name).then(() => done(), () => done()) + hubspot.contacts.properties + .deleteGroup(name) + .then(() => done(), () => done()) }) it('resolves with the created group', () => { @@ -76,11 +80,13 @@ describe('contacts.properties', function () { }) it('can update the group with updateGroup', () => { - return hubspot.contacts.properties.updateGroup(name, { displayName: 'Updated display name' }).then(data => { - expect(data).to.be.an('object') - expect(data).to.have.a.property('name') - expect(data).to.have.a.property('displayName') - }) + return hubspot.contacts.properties + .updateGroup(name, { displayName: 'Updated display name' }) + .then(data => { + expect(data).to.be.an('object') + expect(data).to.have.a.property('name') + expect(data).to.have.a.property('displayName') + }) }) it('can delete the group with deleteGroup', () => { @@ -89,28 +95,29 @@ describe('contacts.properties', function () { }) }) - describe('getByName', function () { + describe('getByName', function() { let propertyName before(() => { - return hubspot.contacts.properties.get() + return hubspot.contacts.properties.get().then(results => { + // console.log(results) + propertyName = results[0].name + }) + }) + + it('should get a property by name', function() { + return hubspot.contacts.properties + .getByName(propertyName) .then(results => { // console.log(results) - propertyName = results[0].name + expect(results).to.be.an('object') + expect(results).to.have.a.property('name') }) }) - - it('should get a property by name', function () { - return hubspot.contacts.properties.getByName(propertyName).then(results => { - // console.log(results) - expect(results).to.be.an('object') - expect(results).to.have.a.property('name') - }) - }) }) - describe('upsert', function () { - it('should create or update the property', function () { + describe('upsert', function() { + it('should create or update the property', function() { return hubspot.contacts.properties.upsert(property).then(data => { expect(data).to.be.an('object') expect(data).to.have.a.property('name') @@ -118,7 +125,7 @@ describe('contacts.properties', function () { }) }) - describe('delete', function () { + describe('delete', function() { const testDeleteProperty = { name: 'delete_test_property_' + Date.now(), label: 'node-hubspot test property', @@ -128,26 +135,30 @@ describe('contacts.properties', function () { fieldType: 'text', formField: false, displayOrder: -1, - options: [] + options: [], } - it('can delete', function () { - return hubspot.contacts.properties.upsert(testDeleteProperty).then(data => { - expect(data).to.be.an('object') - expect(data).to.have.a.property('name') - return hubspot.contacts.properties.delete(testDeleteProperty.name) - }) + it('can delete', function() { + return hubspot.contacts.properties + .upsert(testDeleteProperty) + .then(data => { + expect(data).to.be.an('object') + expect(data).to.have.a.property('name') + return hubspot.contacts.properties.delete(testDeleteProperty.name) + }) }) }) - describe('update', function () { + describe('update', function() { property.label = 'MadKudo Customer Fit' - it('should update the property', function () { - return hubspot.contacts.properties.update(property.name, property).then(data => { - expect(data).to.be.an('object') - expect(data).to.have.a.property('name') - expect(data.label).to.equal(property.label) - }) + it('should update the property', function() { + return hubspot.contacts.properties + .update(property.name, property) + .then(data => { + expect(data).to.be.an('object') + expect(data).to.have.a.property('name') + expect(data.label).to.equal(property.label) + }) }) }) }) diff --git a/test/contacts.js b/test/contacts.js index 0fbc674..8ae3e45 100644 --- a/test/contacts.js +++ b/test/contacts.js @@ -5,11 +5,11 @@ const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) const _ = require('lodash') -describe('contacts', function () { +describe('contacts', function() { this.timeout(10000) - describe('get', function () { - it('should return a batch of contacts', function () { + describe('get', function() { + it('should return a batch of contacts', function() { return hubspot.contacts.get().then(data => { expect(data).to.be.a('object') expect(data.contacts).to.be.a('array') @@ -17,7 +17,7 @@ describe('contacts', function () { }) }) - it('should return the number of contacts requested', function () { + it('should return the number of contacts requested', function() { const count = 10 return hubspot.contacts.get({ count: 10 }).then(data => { expect(data).to.be.a('object') @@ -27,32 +27,32 @@ describe('contacts', function () { }) }) - describe('getRecentlyModified', function () { - it('should return last 100 updated contacts', function () { + describe('getRecentlyModified', function() { + it('should return last 100 updated contacts', function() { return hubspot.contacts.getRecentlyModified().then(data => { expect(data.contacts).to.be.an('array') }) }) }) - describe('getRecentlyCreated', function () { - it('should return last 100 updated contacts', function () { + describe('getRecentlyCreated', function() { + it('should return last 100 updated contacts', function() { return hubspot.contacts.getRecentlyCreated().then(data => { expect(data.contacts).to.be.an('array') }) }) }) - describe('getById', function () { + describe('getById', function() { let contactId - before(function () { + before(function() { return hubspot.contacts.get().then(data => { contactId = data.contacts[0].vid }) }) - it('should return a contact based on its id', function () { + it('should return a contact based on its id', function() { return hubspot.contacts.getById(contactId).then(data => { expect(data.vid).to.equal(contactId) expect(data.properties.company).to.be.an('object') @@ -60,16 +60,16 @@ describe('contacts', function () { }) }) - describe('getByIdBatch', function () { + describe('getByIdBatch', function() { let contactIds - before(function () { + before(function() { return hubspot.contacts.get({ count: 10 }).then(data => { contactIds = _.map(data.contacts, 'vid') }) }) - it('should return a contact record based on a array of ids', function () { + it('should return a contact record based on a array of ids', function() { return hubspot.contacts.getByIdBatch(contactIds).then(data => { expect(data).to.be.an('object') expect(data).to.have.a.property(contactIds[0]) @@ -77,213 +77,233 @@ describe('contacts', function () { }) }) - describe('getByEmail', function () { - it('should return a contact record based on the email', function () { - return hubspot.contacts.getByEmail('testingapis@hubspot.com').then(data => { - expect(data).to.be.a('object') - expect(data.properties).to.be.a('object') - }) + describe('getByEmail', function() { + it('should return a contact record based on the email', function() { + return hubspot.contacts + .getByEmail('testingapis@hubspot.com') + .then(data => { + expect(data).to.be.a('object') + expect(data.properties).to.be.a('object') + }) }) }) - describe('getByEmailBatch', function () { - it('should return a contact record based on a array of emails', function () { - return hubspot.contacts.getByEmailBatch(['testingapis@hubspot.com', 'testingapisawesomeandstuff@hubspot.com']).then(data => { - expect(data).to.be.an('object') - }) + describe('getByEmailBatch', function() { + it('should return a contact record based on a array of emails', function() { + return hubspot.contacts + .getByEmailBatch([ + 'testingapis@hubspot.com', + 'testingapisawesomeandstuff@hubspot.com', + ]) + .then(data => { + expect(data).to.be.an('object') + }) }) }) - describe('update', function () { + describe('update', function() { let contactId - before(function () { + before(function() { return hubspot.contacts.get().then(data => { contactId = data.contacts[0].vid }) }) - it('should update an existing contact', function () { - return hubspot.contacts.update(contactId, { - 'properties': [ - { - 'property': 'email', - 'value': `new-email${Date.now()}@hubspot.com` - }, - { - 'property': 'firstname', - 'value': 'Updated', - 'timestamp': Date.now() - }, - { - 'property': 'lastname', - 'value': 'Lead', - 'timestamp': Date.now() - }, - { - 'property': 'website', - 'value': 'http://hubspot-updated-lead.com' - }, - { - 'property': 'lifecyclestage', - 'value': 'customer' - } - ] - }).then(data => { - expect(data).to.be.an('undefined') - }) + it('should update an existing contact', function() { + return hubspot.contacts + .update(contactId, { + properties: [ + { + property: 'email', + value: `new-email${Date.now()}@hubspot.com`, + }, + { + property: 'firstname', + value: 'Updated', + timestamp: Date.now(), + }, + { + property: 'lastname', + value: 'Lead', + timestamp: Date.now(), + }, + { + property: 'website', + value: 'http://hubspot-updated-lead.com', + }, + { + property: 'lifecyclestage', + value: 'customer', + }, + ], + }) + .then(data => { + expect(data).to.be.an('undefined') + }) }) }) - describe('createOrUpdate', function () { - it('should Create or Update a contact', function () { - return hubspot.contacts.createOrUpdate('test@hubspot.com', - { - 'properties': [ + describe('createOrUpdate', function() { + it('should Create or Update a contact', function() { + return hubspot.contacts + .createOrUpdate('test@hubspot.com', { + properties: [ { - 'property': 'email', - 'value': 'test@hubspot.com' + property: 'email', + value: 'test@hubspot.com', }, { - 'property': 'firstname', - 'value': 'Matt' + property: 'firstname', + value: 'Matt', }, { - 'property': 'lastname', - 'value': 'Schnitt' + property: 'lastname', + value: 'Schnitt', }, { - 'property': 'website', - 'value': 'http://hubspot.com' + property: 'website', + value: 'http://hubspot.com', }, { - 'property': 'company', - 'value': 'HubSpot' + property: 'company', + value: 'HubSpot', }, { - 'property': 'phone', - 'value': '555-122-2323' + property: 'phone', + value: '555-122-2323', }, { - 'property': 'address', - 'value': '25 First Street' + property: 'address', + value: '25 First Street', }, { - 'property': 'city', - 'value': 'Cambridge' + property: 'city', + value: 'Cambridge', }, { - 'property': 'state', - 'value': 'MA' + property: 'state', + value: 'MA', }, { - 'property': 'zip', - 'value': '02139' - } - ] - }).then(data => { - expect(data).to.be.an('object') - }) + property: 'zip', + value: '02139', + }, + ], + }) + .then(data => { + expect(data).to.be.an('object') + }) }) }) - describe('create', function () { - it('should create a new contact', function () { - return hubspot.contacts.create({ - 'properties': [ - { - 'property': 'email', - 'value': 'node-hubspot' + Date.now() + '@madkudu.com' - }, - { - 'property': 'firstname', - 'value': 'Try' - }, - { - 'property': 'lastname', - 'value': 'MadKudu' - }, - { - 'property': 'website', - 'value': 'http://www.madkudu.com' - }, - { - 'property': 'company', - 'value': 'MadKudu' - } - ] - }).then(data => { - expect(data).to.be.an('object') - expect(data.properties.company.value).to.equal('MadKudu') - }) + describe('create', function() { + it('should create a new contact', function() { + return hubspot.contacts + .create({ + properties: [ + { + property: 'email', + value: 'node-hubspot' + Date.now() + '@madkudu.com', + }, + { + property: 'firstname', + value: 'Try', + }, + { + property: 'lastname', + value: 'MadKudu', + }, + { + property: 'website', + value: 'http://www.madkudu.com', + }, + { + property: 'company', + value: 'MadKudu', + }, + ], + }) + .then(data => { + expect(data).to.be.an('object') + expect(data.properties.company.value).to.equal('MadKudu') + }) }) - it('should fail if the contact already exists', function () { - return hubspot.contacts.create({ - 'properties': [ - { - 'property': 'email', - 'value': 'node-hubspot@hubspot.com' - }, - { - 'property': 'firstname', - 'value': 'Test' - } - ] - }).then(data => { - throw new Error('This should have failed') - }).catch(err => { - expect(err instanceof Error).to.equal(true) - expect(err.error.message).to.equal('Contact already exists') - }) + it('should fail if the contact already exists', function() { + return hubspot.contacts + .create({ + properties: [ + { + property: 'email', + value: 'node-hubspot@hubspot.com', + }, + { + property: 'firstname', + value: 'Test', + }, + ], + }) + .then(data => { + throw new Error('This should have failed') + }) + .catch(err => { + expect(err instanceof Error).to.equal(true) + expect(err.error.message).to.equal('Contact already exists') + }) }) }) - describe('delete', function () { - it('can delete', function () { - return hubspot.contacts.create({ - 'properties': [ - { - 'property': 'email', - 'value': 'node-hubspot' + Date.now() + '@madkudu.com' - }, - { - 'property': 'firstname', - 'value': 'Try' - }, - { - 'property': 'lastname', - 'value': 'MadKudu' - }, - { - 'property': 'website', - 'value': 'http://www.madkudu.com' - }, - { - 'property': 'company', - 'value': 'MadKudu' - } - ] - }).then(data => { - return hubspot.contacts.delete(data.vid) - }) + describe('delete', function() { + it('can delete', function() { + return hubspot.contacts + .create({ + properties: [ + { + property: 'email', + value: 'node-hubspot' + Date.now() + '@madkudu.com', + }, + { + property: 'firstname', + value: 'Try', + }, + { + property: 'lastname', + value: 'MadKudu', + }, + { + property: 'website', + value: 'http://www.madkudu.com', + }, + { + property: 'company', + value: 'MadKudu', + }, + ], + }) + .then(data => { + return hubspot.contacts.delete(data.vid) + }) }) }) - describe('createOrUpdateBatch', function () { + describe('createOrUpdateBatch', function() { // this.timeout(10000) let contacts - before(function () { + before(function() { return hubspot.contacts.get().then(data => { contacts = data.contacts }) }) - it('should update a batch of company', function () { + it('should update a batch of company', function() { const batch = _.map(contacts, contact => { - const update = { vid: contact.vid, properties: [ { property: 'company', value: 'MadKudu ' } ] } + const update = { + vid: contact.vid, + properties: [{ property: 'company', value: 'MadKudu ' }], + } return update }) return hubspot.contacts.createOrUpdateBatch(batch).then(data => { @@ -292,8 +312,8 @@ describe('contacts', function () { }) }) - describe('search', function () { - it('should return contacts and some data associated with those contacts by the contact\'s email address or name.', function () { + describe('search', function() { + it("should return contacts and some data associated with those contacts by the contact's email address or name.", function() { return hubspot.contacts.search('example').then(data => { expect(data.contacts).to.be.a('array') expect(data.query).to.equal('example') diff --git a/test/deal_properties.js b/test/deal_properties.js index 5b6333e..0ebf875 100644 --- a/test/deal_properties.js +++ b/test/deal_properties.js @@ -13,12 +13,12 @@ const property = { fieldType: 'text', formField: false, displayOrder: -1, - options: [] + options: [], } -describe('deals.properties', function () { - describe('get', function () { - it('should return the list of properties for deals', function () { +describe('deals.properties', function() { + describe('get', function() { + it('should return the list of properties for deals', function() { return hubspot.deals.properties.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -28,8 +28,8 @@ describe('deals.properties', function () { }) }) - describe('getAll', function () { - it('should return the same thing as get', function () { + describe('getAll', function() { + it('should return the same thing as get', function() { return hubspot.deals.properties.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -39,18 +39,17 @@ describe('deals.properties', function () { }) }) - describe('getByName', function () { + describe('getByName', function() { let propertyName before(() => { - return hubspot.deals.properties.get() - .then(results => { - // console.log(results) - propertyName = results[0].name - }) + return hubspot.deals.properties.get().then(results => { + // console.log(results) + propertyName = results[0].name + }) }) - it('should get a property by name', function () { + it('should get a property by name', function() { return hubspot.deals.properties.getByName(propertyName).then(results => { // console.log(results) expect(results).to.be.an('object') @@ -59,8 +58,8 @@ describe('deals.properties', function () { }) }) - describe('upsert (create)', function () { - it('should create or update the property', function () { + describe('upsert (create)', function() { + it('should create or update the property', function() { return hubspot.deals.properties.upsert(property).then(data => { expect(data).to.be.an('object') expect(data).to.have.a.property('name') @@ -68,7 +67,7 @@ describe('deals.properties', function () { }) }) - describe('delete', function () { + describe('delete', function() { const testDeleteProperty = { name: 'delete_test_property_' + Date.now(), label: 'node-hubspot test property', @@ -78,10 +77,10 @@ describe('deals.properties', function () { fieldType: 'text', formField: false, displayOrder: -1, - options: [] + options: [], } - it('should delete a property', function () { + it('should delete a property', function() { return hubspot.deals.properties.upsert(testDeleteProperty).then(data => { expect(data).to.be.an('object') expect(data).to.have.a.property('name') @@ -90,15 +89,17 @@ describe('deals.properties', function () { }) }) - describe('update', function () { + describe('update', function() { property.label = 'MadKudo Company Fit' - it('should update the property', function () { - return hubspot.deals.properties.update(property.name, property).then(data => { - expect(data).to.be.an('object') - expect(data).to.have.a.property('name') - expect(data.label).to.equal(property.label) - }) + it('should update the property', function() { + return hubspot.deals.properties + .update(property.name, property) + .then(data => { + expect(data).to.be.an('object') + expect(data).to.have.a.property('name') + expect(data.label).to.equal(property.label) + }) }) }) }) diff --git a/test/deal_properties_group.js b/test/deal_properties_group.js index 127330a..89bc33b 100644 --- a/test/deal_properties_group.js +++ b/test/deal_properties_group.js @@ -6,12 +6,12 @@ const hubspot = new Hubspot({ apiKey: 'demo' }) const group = { displayName: 'GROUP DIPLAY NAME', - name: 'mk_group_fit_segment' + name: 'mk_group_fit_segment', } -describe('deals.properties.groups', function () { - describe('get', function () { - it('should return the list of properties groups for deals', function () { +describe('deals.properties.groups', function() { + describe('get', function() { + it('should return the list of properties groups for deals', function() { return hubspot.deals.properties.groups.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -21,8 +21,8 @@ describe('deals.properties.groups', function () { }) }) - describe('getAll', function () { - it('should return the same thing as get', function () { + describe('getAll', function() { + it('should return the same thing as get', function() { return hubspot.deals.properties.groups.get().then(data => { // console.log(data) expect(data).to.be.an('array') @@ -32,8 +32,8 @@ describe('deals.properties.groups', function () { }) }) - describe('upsert (create)', function () { - it('should create or update the properties group', function () { + describe('upsert (create)', function() { + it('should create or update the properties group', function() { return hubspot.deals.properties.groups.upsert(group).then(data => { expect(data).to.be.an('object') expect(data).to.have.a.property('name') @@ -41,15 +41,17 @@ describe('deals.properties.groups', function () { }) }) - describe('update', function () { + describe('update', function() { group.displayName = 'MadKudo Company Fit' - it('should update the property', function () { - return hubspot.deals.properties.groups.update(group.name, group).then(data => { - expect(data).to.be.an('object') - expect(data).to.have.a.property('name') - expect(data.displayName).to.equal(group.displayName) - }) + it('should update the property', function() { + return hubspot.deals.properties.groups + .update(group.name, group) + .then(data => { + expect(data).to.be.an('object') + expect(data).to.have.a.property('name') + expect(data.displayName).to.equal(group.displayName) + }) }) }) }) diff --git a/test/deals.js b/test/deals.js index fd522ae..2e4dce9 100644 --- a/test/deals.js +++ b/test/deals.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('Deals', function () { - describe('get', function () { - it('Should return deal properties', function () { +describe('Deals', function() { + describe('get', function() { + it('Should return deal properties', function() { return hubspot.deals.get().then(data => { expect(data).to.be.a('object') expect(data.deals).to.be.an('array') @@ -14,8 +14,8 @@ describe('Deals', function () { }) }) - describe('getRecentlyCreated', function () { - it('Returns Recently Created Deals', function () { + describe('getRecentlyCreated', function() { + it('Returns Recently Created Deals', function() { return hubspot.deals.getRecentlyCreated().then(data => { // console.log(data) expect(data.results).to.be.an('array') @@ -24,8 +24,8 @@ describe('Deals', function () { }) }) - describe('getRecentlyModified', function () { - it('Returns Recently Modified Deals', function () { + describe('getRecentlyModified', function() { + it('Returns Recently Modified Deals', function() { return hubspot.deals.getRecentlyModified().then(data => { expect(data.results).to.be.an('array') expect(data.hasMore).to.equal(true) @@ -33,23 +33,23 @@ describe('Deals', function () { }) }) - describe('getById', function () { + describe('getById', function() { let dealId - before(function () { + before(function() { return hubspot.deals.get().then(data => { dealId = data.deals[0].dealId }) }) - it('Returns the entire deal, including all of it\'s properties', function () { + it("Returns the entire deal, including all of it's properties", function() { return hubspot.deals.getById(dealId).then(data => { expect(data).to.be.an('object') }) }) }) - describe('getAssociated', function () { - it('Returns the deals associated to the object', function () { + describe('getAssociated', function() { + it('Returns the deals associated to the object', function() { return hubspot.deals.getAssociated('CONTACT', 394455).then(data => { expect(data).to.be.an('object') expect(data.hasMore).to.equal(false) @@ -59,85 +59,89 @@ describe('Deals', function () { }) }) - describe('deleteById', function () { + describe('deleteById', function() { let dealId - before(function () { + before(function() { return hubspot.deals.get().then(data => { dealId = data.deals[0].dealId }) }) - it('should delete a deal by Id', function () { + it('should delete a deal by Id', function() { return hubspot.deals.deleteById(dealId).then(data => { expect(data).to.be.an('undefined') }) }) }) - describe('updateById', function () { + describe('updateById', function() { let dealId - before(function () { + before(function() { return hubspot.deals.get().then(data => { dealId = data.deals[0].dealId }) }) - it('Returns the entire deal profile', function () { - return hubspot.deals.updateById(dealId, { - 'properties': [{'name': 'dealname', 'value': 'MadKudu'}] - }).then(data => { - expect(data).to.be.an('object') - }) + it('Returns the entire deal profile', function() { + return hubspot.deals + .updateById(dealId, { + properties: [{ name: 'dealname', value: 'MadKudu' }], + }) + .then(data => { + expect(data).to.be.an('object') + }) }) }) - describe('create', function () { - it('Returns a 200 with the newly created Deal', function () { - return hubspot.deals.create({ - // 'associations': { - // 'associatedCompanyIds': [ - // 8954037 - // ], - // 'associatedVids': [ - // 27136 - // ] - // }, - 'portalId': 62515, - 'properties': [ - { - 'value': 'MadKudu', - 'name': 'dealname' - }, - { - 'value': 'appointmentscheduled', - 'name': 'dealstage' - }, - { - 'value': 'default', - 'name': 'pipeline' - }, - // { - // 'value': '24', - // 'name': 'hubspot_owner_id' + describe('create', function() { + it('Returns a 200 with the newly created Deal', function() { + return hubspot.deals + .create({ + // 'associations': { + // 'associatedCompanyIds': [ + // 8954037 + // ], + // 'associatedVids': [ + // 27136 + // ] // }, - { - 'value': Date.now(), - 'name': 'closedate' - }, - { - 'value': '60000', - 'name': 'amount' - }, - { - 'value': 'newbusiness', - 'name': 'dealtype' - } - ] - }).then(data => { - expect(data).to.be.a('object') - }) + portalId: 62515, + properties: [ + { + value: 'MadKudu', + name: 'dealname', + }, + { + value: 'appointmentscheduled', + name: 'dealstage', + }, + { + value: 'default', + name: 'pipeline', + }, + // { + // 'value': '24', + // 'name': 'hubspot_owner_id' + // }, + { + value: Date.now(), + name: 'closedate', + }, + { + value: '60000', + name: 'amount', + }, + { + value: 'newbusiness', + name: 'dealtype', + }, + ], + }) + .then(data => { + expect(data).to.be.a('object') + }) }) }) diff --git a/test/engagements.js b/test/engagements.js index 488b0d0..7ed5f9f 100644 --- a/test/engagements.js +++ b/test/engagements.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('Engagements', function () { - describe('Get All Engagements', function () { - it('Should return engagement properties', function () { +describe('Engagements', function() { + describe('Get All Engagements', function() { + it('Should return engagement properties', function() { return hubspot.engagements.get().then(data => { expect(data).to.be.an('object') expect(data.results).to.be.a('array') @@ -15,8 +15,8 @@ describe('Engagements', function () { }) }) - describe('Get Recent Engagements', function () { - it('Should return engagement properties', function () { + describe('Get Recent Engagements', function() { + it('Should return engagement properties', function() { return hubspot.engagements.getRecentlyModified().then(data => { expect(data).to.be.an('object') expect(data.results).to.be.a('array') diff --git a/test/files.js b/test/files.js index 0a6cb06..df16b8a 100644 --- a/test/files.js +++ b/test/files.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('files', function () { - describe('get', function () { - it('Should return all files', function () { +describe('files', function() { + describe('get', function() { + it('Should return all files', function() { return hubspot.files.get().then(data => { // console.log(data) expect(data).to.be.a('object') @@ -15,16 +15,16 @@ describe('files', function () { }) }) - describe('getOne', function () { + describe('getOne', function() { let fileId - before(function () { + before(function() { return hubspot.files.get().then(data => { fileId = data.objects[0].id }) }) - it('Should return one file', function () { + it('Should return one file', function() { return hubspot.files.getOne(fileId).then(data => { // console.log(data) expect(data).to.be.an('object') diff --git a/test/lists.js b/test/lists.js index 13f0b44..8404c31 100644 --- a/test/lists.js +++ b/test/lists.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('Lists', function () { - describe('Get Lists', function () { - it('Should return contact lists', function () { +describe('Lists', function() { + describe('Get Lists', function() { + it('Should return contact lists', function() { return hubspot.lists.get().then(data => { expect(data).to.be.a('object') expect(data.lists).to.be.a('array') @@ -14,8 +14,8 @@ describe('Lists', function () { }) }) - describe('Get List by Id', function () { - it('Should return one contact in a list', function () { + describe('Get List by Id', function() { + it('Should return one contact in a list', function() { return hubspot.lists.getOne(1).then(data => { expect(data).to.be.a('object') expect(data).to.have.a.property('name') @@ -23,17 +23,17 @@ describe('Lists', function () { }) }) - describe('Get Contacts In A List', function () { + describe('Get Contacts In A List', function() { let listId // obtain a valid listID - before(function () { + before(function() { return hubspot.lists.get().then(data => { listId = data.lists[0].listId }) }) - it('Should return all contacts in a list', function () { + it('Should return all contacts in a list', function() { return hubspot.lists.getContacts(listId).then(data => { expect(data).to.be.a('object') expect(data.contacts).to.be.a('array') @@ -41,17 +41,17 @@ describe('Lists', function () { }) }) - describe('Get recently updated and created contacts', function () { + describe('Get recently updated and created contacts', function() { let listId // obtain a valid listID - before(function () { + before(function() { return hubspot.lists.get().then(data => { listId = data.lists[0].listId }) }) - it('Should a list of recently_updated contacts', function () { + it('Should a list of recently_updated contacts', function() { return hubspot.lists.getRecentContacts(listId).then(data => { expect(data).to.be.a('object') expect(data.contacts).to.be.a('array') @@ -59,14 +59,14 @@ describe('Lists', function () { }) }) - describe('Add existing contacts to a list', function () { - // it('Should add contact to a list of contacts', function () { - // return hubspot.lists.addContacts(5, { - // 'vids': [61571], 'emails': ['testingapis@hubspot.com'] - // }).then(data => { - // expect(data).to.be.a('object') - // expect(data.updated).to.be.a('array') - // }) - // }) + describe('Add existing contacts to a list', function() { + // it('Should add contact to a list of contacts', function () { + // return hubspot.lists.addContacts(5, { + // 'vids': [61571], 'emails': ['testingapis@hubspot.com'] + // }).then(data => { + // expect(data).to.be.a('object') + // expect(data.updated).to.be.a('array') + // }) + // }) }) }) diff --git a/test/oauth.js b/test/oauth.js index eb4cc2b..24e8fc3 100644 --- a/test/oauth.js +++ b/test/oauth.js @@ -3,19 +3,19 @@ const expect = chai.expect const Hubspot = require('..') -describe('oauth', function () { +describe('oauth', function() { let hubspot - describe('getAuthorizationUrl', function () { + describe('getAuthorizationUrl', function() { beforeEach(() => { hubspot = new Hubspot() }) - it('should return the correct authorizationUrl for a given app', function () { + it('should return the correct authorizationUrl for a given app', function() { const params = { client_id: 'fake_client_id', scopes: 'some scopes', - redirect_uri: 'take_me_to_the_ballpark' + redirect_uri: 'take_me_to_the_ballpark', } const uri = hubspot.oauth.getAuthorizationUrl(params) expect(uri).to.be.a('string') @@ -23,16 +23,18 @@ describe('oauth', function () { }) }) - describe('refreshAccessToken', function () { - it('should return (and refresh) an accessToken, given a refreshToken - constructor', function () { + describe('refreshAccessToken', function() { + it('should return (and refresh) an accessToken, given a refreshToken - constructor', function() { const params = { clientId: process.env.clientId, clientSecret: process.env.clientSecret, redirectUri: process.env.redirectUri, - refreshToken: process.env.refreshToken + refreshToken: process.env.refreshToken, } const hubspot = new Hubspot(params) - if (!process.env.refreshToken) { return } // hard to reproduce on CI. local testing only for now + if (!process.env.refreshToken) { + return + } // hard to reproduce on CI. local testing only for now return hubspot.oauth.refreshAccessToken().then(res => { expect(res.refresh_token).to.equal(params.refreshToken) expect(res).to.have.a.property('access_token') @@ -40,14 +42,16 @@ describe('oauth', function () { }) }) - it('should return (and refresh) an accessToken, given a refreshToken - params', function () { + it('should return (and refresh) an accessToken, given a refreshToken - params', function() { const hubspot = new Hubspot({ accessToken: process.env.accessToken }) - if (!process.env.refreshToken) { return } // hard to reproduce on CI. local testing only for now + if (!process.env.refreshToken) { + return + } // hard to reproduce on CI. local testing only for now const params = { client_id: process.env.clientId, client_secret: process.env.clientSecret, redirect_uri: process.env.redirectUri, - refresh_token: process.env.refreshToken + refresh_token: process.env.refreshToken, } return hubspot.oauth.refreshAccessToken(params).then(res => { expect(res.refresh_token).to.equal(params.refresh_token) diff --git a/test/owners.js b/test/owners.js index 09913ba..0090abe 100644 --- a/test/owners.js +++ b/test/owners.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('Owners', function () { - describe('get', function () { - it('Should return all owners', function () { +describe('Owners', function() { + describe('get', function() { + it('Should return all owners', function() { return hubspot.owners.get().then(data => { expect(data).to.be.a('array') }) diff --git a/test/page.js b/test/page.js index 830edf4..a947c04 100644 --- a/test/page.js +++ b/test/page.js @@ -4,17 +4,17 @@ var expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('pages', function () { - describe('get', function () { - it('should return all pages', function () { +describe('pages', function() { + describe('get', function() { + it('should return all pages', function() { return hubspot.pages.get().then(data => { expect(data).to.be.an('object') expect(data.objects).to.be.a('array') }) }) - it('should return only published pages', function () { - return hubspot.pages.get({is_draft: false}).then(data => { + it('should return only published pages', function() { + return hubspot.pages.get({ is_draft: false }).then(data => { expect(data).to.be.an('object') expect(data.objects).to.be.a('array') }) diff --git a/test/pipelines.js b/test/pipelines.js index 9e02d34..5cc4d96 100644 --- a/test/pipelines.js +++ b/test/pipelines.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('Pipelines', function () { - describe('get', function () { - it('Should return all deal pipelines for a given portal', function () { +describe('Pipelines', function() { + describe('get', function() { + it('Should return all deal pipelines for a given portal', function() { return hubspot.pipelines.get().then(data => { expect(data).to.be.a('array') expect(data[0]).to.have.a.property('pipelineId') diff --git a/test/subscriptions.js b/test/subscriptions.js index 63fc882..c2086af 100644 --- a/test/subscriptions.js +++ b/test/subscriptions.js @@ -4,9 +4,9 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('subscriptions', function () { - describe('get', function () { - it('Should return a list of subscriptions', function () { +describe('subscriptions', function() { + describe('get', function() { + it('Should return a list of subscriptions', function() { return hubspot.subscriptions.get().then(data => { expect(data.timeline).to.be.a('array') expect(data.hasMore).to.equal(true) diff --git a/test/workflows.js b/test/workflows.js index df0c8d4..a0e67f4 100644 --- a/test/workflows.js +++ b/test/workflows.js @@ -4,57 +4,55 @@ const expect = chai.expect const Hubspot = require('..') const hubspot = new Hubspot({ apiKey: 'demo' }) -describe('workflows', function () { +describe('workflows', function() { let workflowId = 2641273 let contactId let contactEmail - before(function () { + before(function() { return hubspot.contacts.get().then(data => { const firstContact = data.contacts[0] contactId = firstContact.vid - contactEmail = firstContact['identity-profiles'][0].identities.find(obj => obj.type === 'EMAIL').value + contactEmail = firstContact['identity-profiles'][0].identities.find( + obj => obj.type === 'EMAIL', + ).value }) }) - describe('get', function () { - it('Should get all workflows', function () { + describe('get', function() { + it('Should get all workflows', function() { return hubspot.workflows.getAll().then(data => { expect(data.workflows).to.be.a('array') }) }) - it('Should get a specific workflow', function () { + it('Should get a specific workflow', function() { return hubspot.workflows.get(workflowId).then(data => { expect(data).to.be.a('object') }) }) }) - describe.skip('create', function () { + describe.skip('create', function() {}) - }) - - describe.skip('delete', function () { - - }) + describe.skip('delete', function() {}) - describe('enroll', function () { - it('Enrolls a contact into a workflow', function () { + describe('enroll', function() { + it('Enrolls a contact into a workflow', function() { return hubspot.workflows.enroll(workflowId, contactEmail).then(data => { expect(true).to.equal(true) }) }) - it('Unenrolls a contact into a workflow', function () { + it('Unenrolls a contact into a workflow', function() { return hubspot.workflows.unenroll(workflowId, contactEmail).then(data => { expect(true).to.equal(true) }) }) }) - describe('current', function () { - it('Gets the workflows of a contact', function () { + describe('current', function() { + it('Gets the workflows of a contact', function() { return hubspot.workflows.current(contactId).then(data => { expect(data).to.be.an('array') })