@friggframework/api-module-hubspot 1.1.7 → 1.1.8-canary.88be3bc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/api.js +14 -3
  2. package/package.json +6 -5
  3. package/tests/api.test.js +22 -12
package/api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const {OAuth2Requester, get} = require('@friggframework/core');
2
+ const {Paginator} = require('avid-reader');
2
3
 
3
4
  class Api extends OAuth2Requester {
4
5
  constructor(params) {
@@ -71,7 +72,6 @@ class Api extends OAuth2Requester {
71
72
  listMembershipsAddRemove: (listId) => `/crm/v3/lists/${listId}/memberships/add-and-remove`,
72
73
  associations: (fromObject, toObject) => `/crm/v4/associations/${fromObject}/${toObject}`,
73
74
  associationLabels: (fromObject, toObject) => `/crm/v4/associations/${fromObject}/${toObject}/labels`,
74
-
75
75
  };
76
76
 
77
77
  this.authorizationUri = encodeURI(
@@ -81,6 +81,16 @@ class Api extends OAuth2Requester {
81
81
 
82
82
  this.access_token = get(params, 'access_token', null);
83
83
  this.refresh_token = get(params, 'refresh_token', null);
84
+ this.paginator = new Paginator(
85
+ this,
86
+ {
87
+ type: 'token',
88
+ tokenParam: 'after',
89
+ tokenPath: '/paging/next/after',
90
+ resultsKey: 'results',
91
+ args: { limit:100, after: 0 },
92
+ }
93
+ );
84
94
  }
85
95
 
86
96
  getAuthUri() {
@@ -217,11 +227,12 @@ class Api extends OAuth2Requester {
217
227
  url: this.baseUrl + this.URLs.contacts,
218
228
  query: {
219
229
  limit,
220
- after,
221
230
  properties,
222
231
  }
223
232
  };
224
-
233
+ if (after) {
234
+ options.query.after = after;
235
+ }
225
236
  return this._get(options);
226
237
  }
227
238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friggframework/api-module-hubspot",
3
- "version": "1.1.7",
3
+ "version": "1.1.8-canary.88be3bc.0",
4
4
  "prettier": "@friggframework/prettier-config",
5
5
  "description": "HubSpot API module that lets the Frigg Framework interact with HubSpot",
6
6
  "main": "index.js",
@@ -11,8 +11,8 @@
11
11
  "author": "",
12
12
  "license": "MIT",
13
13
  "devDependencies": {
14
- "@friggframework/devtools": "^1.1.2",
15
- "@friggframework/test": "^1.1.2",
14
+ "@friggframework/devtools": "^1.1.8",
15
+ "@friggframework/test": "^1.1.8",
16
16
  "dotenv": "^16.0.3",
17
17
  "eslint": "^8.22.0",
18
18
  "jest": "^28.1.3",
@@ -20,7 +20,8 @@
20
20
  "prettier": "^2.7.1"
21
21
  },
22
22
  "dependencies": {
23
- "@friggframework/core": "^1.1.2"
23
+ "@friggframework/core": "^1.1.8",
24
+ "avid-reader": "^0.1.1"
24
25
  },
25
- "gitHead": "cdfe2d135124d7dfe8ef49ae3c6e8e95d7990b40"
26
+ "gitHead": "88be3bc61aad168e615780d3dc6185cbe03aace3"
26
27
  }
package/tests/api.test.js CHANGED
@@ -67,24 +67,28 @@ describe(`${config.label} API tests`, () => {
67
67
  });
68
68
 
69
69
  // Skipping tests... inherited with bugs, needs refactor
70
- describe.skip('HS Deals', () => {
71
- it('should return a deal by id', async () => {
72
- const deal_id = '2022088696';
73
- const response = await api.getDealById(deal_id);
74
- expect(response.id).toBe(deal_id);
75
- expect(response.properties.amount).to.eq('100000');
76
- expect(response.properties.dealname).to.eq('Test');
77
- expect(response.properties.dealstage).to.eq('appointmentscheduled');
78
- });
79
-
80
- it('should return all deals of a company', async () => {
70
+ describe.only('HS Deals', () => {
71
+ let deal_id;
72
+ it('should return a page of deals', async () => {
81
73
  let response = await api.listDeals();
74
+ expect(response.results).toHaveProperty('length');
82
75
  expect(response.results[0]).toHaveProperty('id');
76
+ deal_id = response.results[0].id;
83
77
  expect(response.results[0]).toHaveProperty('properties');
84
78
  expect(response.results[0].properties).toHaveProperty('amount');
85
79
  expect(response.results[0].properties).toHaveProperty('dealname');
86
80
  expect(response.results[0].properties).toHaveProperty('dealstage');
87
81
  });
82
+ it('should return a deal by id', async () => {
83
+ const response = await api.getDealById(deal_id);
84
+ expect(response.id).toBe(deal_id);
85
+ });
86
+ it('should return all deals using paginator', async () => {
87
+ const results = await api.paginator.fetchAllPages(api.listDeals);
88
+ expect(results).toHaveProperty('length');
89
+ expect(results.length).toBeGreaterThan(100);
90
+ })
91
+
88
92
  });
89
93
 
90
94
  // Some tests skipped ... inherited with bugs, needs refactor
@@ -227,7 +231,7 @@ describe(`${config.label} API tests`, () => {
227
231
  });
228
232
 
229
233
  // Some tests skipped ... inherited with bugs, needs refactor
230
- describe('HS Contacts', () => {
234
+ describe.only('HS Contacts', () => {
231
235
  let createResponse;
232
236
 
233
237
  it('should create a Contact', async () => {
@@ -266,6 +270,12 @@ describe(`${config.label} API tests`, () => {
266
270
  let response = await api.archiveContact(createResponse.id);
267
271
  expect(response.status).toBe(204);
268
272
  });
273
+
274
+ it('should page all contacts using paginator', async () => {
275
+ const results = await api.paginator.fetchAllPages(api.listContacts);
276
+ expect(results).toHaveProperty('length');
277
+ expect(results.length).toBeGreaterThan(100);
278
+ });
269
279
  });
270
280
 
271
281
  // Skipping tests... inherited with bugs, needs refactor