From 5f4321c986141083fad3e71b99495e7bcf236ec2 Mon Sep 17 00:00:00 2001 From: Christopher O'Donnell Date: Mon, 16 Sep 2019 16:28:16 -0400 Subject: [PATCH 1/3] add getPortalInfo method to OAuth --- lib/oauth.js | 7 +++++++ test/oauth.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/oauth.js b/lib/oauth.js index 04202ff..76e52ea 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -51,6 +51,13 @@ class OAuth { return results }) } + + getPortalInfo() { + return this.client._request({ + method: 'GET', + path: `/oauth/v1/access-tokens/${this.client.accessToken}` + }) + } } module.exports = OAuth diff --git a/test/oauth.js b/test/oauth.js index 395f317..fee3b0b 100644 --- a/test/oauth.js +++ b/test/oauth.js @@ -98,4 +98,40 @@ describe('oauth', function() { }) } }) + + + describe('getPortalInfo', function() { + beforeEach(() => { + hubspot = new Hubspot() + }) + + const accessToken = "fake_access_token" + const getPortalInfoEndpoint = { + path: `/oauth/v1/token/${accessToken}`, + response: { + "token": accessToken, + "user": "test@hubspot.com", + "hub_domain": "demo.hubapi.com", + "scopes": [ + "contacts", + "automation", + "oauth" + ], + "hub_id": 62515, + "app_id": 456, + "expires_in": 21588, + "user_id": 123, + "token_type": "access" + } + } + fakeHubspotApi.setupServer({ postEndpoints: [getPortalInfoEndpoint] }) + + it('should return the Portal metadata for a given portal', function() { + return hubspot.oauth.getPortalInfo(accessToken).then(response => { + console.log(response) + expect(response).to.be.a('object') + expect(response).to.contain('hub_id') + }) + }) + }) }) From 3c96522d19bbb64454173518b8a8e29458842837 Mon Sep 17 00:00:00 2001 From: Christopher O'Donnell Date: Mon, 16 Sep 2019 16:30:43 -0400 Subject: [PATCH 2/3] delete non-working test, need help with the test --- test/oauth.js | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/test/oauth.js b/test/oauth.js index fee3b0b..1a765a9 100644 --- a/test/oauth.js +++ b/test/oauth.js @@ -99,39 +99,4 @@ describe('oauth', function() { } }) - - describe('getPortalInfo', function() { - beforeEach(() => { - hubspot = new Hubspot() - }) - - const accessToken = "fake_access_token" - const getPortalInfoEndpoint = { - path: `/oauth/v1/token/${accessToken}`, - response: { - "token": accessToken, - "user": "test@hubspot.com", - "hub_domain": "demo.hubapi.com", - "scopes": [ - "contacts", - "automation", - "oauth" - ], - "hub_id": 62515, - "app_id": 456, - "expires_in": 21588, - "user_id": 123, - "token_type": "access" - } - } - fakeHubspotApi.setupServer({ postEndpoints: [getPortalInfoEndpoint] }) - - it('should return the Portal metadata for a given portal', function() { - return hubspot.oauth.getPortalInfo(accessToken).then(response => { - console.log(response) - expect(response).to.be.a('object') - expect(response).to.contain('hub_id') - }) - }) - }) }) From 97093fe8089891328d215409aeb5bd5fe9ee3d32 Mon Sep 17 00:00:00 2001 From: Christopher O'Donnell Date: Mon, 16 Sep 2019 16:31:13 -0400 Subject: [PATCH 3/3] Update oauth.js --- test/oauth.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/oauth.js b/test/oauth.js index 1a765a9..395f317 100644 --- a/test/oauth.js +++ b/test/oauth.js @@ -98,5 +98,4 @@ describe('oauth', function() { }) } }) - })