@friggframework/api-module-pipedrive 1.0.1-v1-alpha.5 → 2.1.0-canary.56.2dc58f9.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.
- package/LICENSE.md +10 -3
- package/README.md +3 -2
- package/defaultConfig.json +9 -7
- package/dist/api.d.ts +59 -0
- package/dist/api.js +160 -0
- package/dist/definition.d.ts +4 -0
- package/dist/definition.js +79 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +9 -0
- package/package.json +31 -21
- package/.eslintrc.json +0 -3
- package/CHANGELOG.md +0 -171
- package/api.js +0 -117
- package/index.js +0 -13
- package/jest-setup.js +0 -2
- package/jest-teardown.js +0 -2
- package/jest.config.js +0 -20
- package/manager.js +0 -193
- package/manager.test.js +0 -26
- package/mocks/activities/createActivity.js +0 -172
- package/mocks/activities/deleteActivity.js +0 -3
- package/mocks/activities/listActivities.js +0 -1538
- package/mocks/activities/updateActivity.js +0 -172
- package/mocks/apiMock.js +0 -28
- package/mocks/deals/listDeals.js +0 -236
- package/models/credential.js +0 -21
- package/models/entity.js +0 -9
- package/test/Api.test.js +0 -157
- package/test/Manager.test.js +0 -138
package/test/Manager.test.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
const chai = require('chai');
|
|
2
|
-
const { expect } = chai;
|
|
3
|
-
const PipedriveManager = require('../manager');
|
|
4
|
-
const Authenticator = require('../../../../test/utils/Authenticator');
|
|
5
|
-
const TestUtils = require('../../../../test/utils/TestUtils');
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line no-only-tests/no-only-tests
|
|
8
|
-
describe('Pipedrive Manager', async () => {
|
|
9
|
-
let manager;
|
|
10
|
-
before(async () => {
|
|
11
|
-
this.userManager = await TestUtils.getLoggedInTestUserManagerInstance();
|
|
12
|
-
|
|
13
|
-
manager = await PipedriveManager.getInstance({
|
|
14
|
-
userId: this.userManager.getUserId(),
|
|
15
|
-
});
|
|
16
|
-
const res = await manager.getAuthorizationRequirements();
|
|
17
|
-
|
|
18
|
-
chai.assert.hasAnyKeys(res, ['url', 'type']);
|
|
19
|
-
const { url } = res;
|
|
20
|
-
const response = await Authenticator.oauth2(url);
|
|
21
|
-
const baseArr = response.base.split('/');
|
|
22
|
-
response.entityType = baseArr[baseArr.length - 1];
|
|
23
|
-
delete response.base;
|
|
24
|
-
|
|
25
|
-
const ids = await manager.processAuthorizationCallback({
|
|
26
|
-
userId: this.userManager.getUserId(),
|
|
27
|
-
data: response.data,
|
|
28
|
-
});
|
|
29
|
-
chai.assert.hasAllKeys(ids, ['credential_id', 'entity_id', 'type']);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('getInstance tests', async () => {
|
|
33
|
-
it('should return a manager instance without credential or entity data', async () => {
|
|
34
|
-
const userId = this.userManager.getUserId();
|
|
35
|
-
const freshManager = await PipedriveManager.getInstance({
|
|
36
|
-
userId,
|
|
37
|
-
});
|
|
38
|
-
expect(freshManager).to.haveOwnProperty('api');
|
|
39
|
-
expect(freshManager).to.haveOwnProperty('userId');
|
|
40
|
-
expect(freshManager.userId).to.equal(userId);
|
|
41
|
-
expect(freshManager.entity).to.be.undefined;
|
|
42
|
-
expect(freshManager.credential).to.be.undefined;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should return a manager instance with a credential ID', async () => {
|
|
46
|
-
const userId = this.userManager.getUserId();
|
|
47
|
-
const freshManager = await PipedriveManager.getInstance({
|
|
48
|
-
userId,
|
|
49
|
-
credentialId: manager.credential.id,
|
|
50
|
-
});
|
|
51
|
-
expect(freshManager).to.haveOwnProperty('api');
|
|
52
|
-
expect(freshManager).to.haveOwnProperty('userId');
|
|
53
|
-
expect(freshManager.userId).to.equal(userId);
|
|
54
|
-
expect(freshManager.entity).to.be.undefined;
|
|
55
|
-
expect(freshManager.credential).to.exist;
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should return a fresh manager instance with an entity ID', async () => {
|
|
59
|
-
const userId = this.userManager.getUserId();
|
|
60
|
-
const freshManager = await PipedriveManager.getInstance({
|
|
61
|
-
userId,
|
|
62
|
-
entityId: manager.entity.id,
|
|
63
|
-
});
|
|
64
|
-
expect(freshManager).to.haveOwnProperty('api');
|
|
65
|
-
expect(freshManager).to.haveOwnProperty('userId');
|
|
66
|
-
expect(freshManager.userId).to.equal(userId);
|
|
67
|
-
expect(freshManager.entity).to.exist;
|
|
68
|
-
expect(freshManager.credential).to.exist;
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('getAuthorizationRequirements tests', async () => {
|
|
73
|
-
it('should return authorization requirements of username and password', async () => {
|
|
74
|
-
// Check authorization requirements
|
|
75
|
-
const res = await manager.getAuthorizationRequirements();
|
|
76
|
-
expect(res.type).to.equal('oauth2');
|
|
77
|
-
chai.assert.hasAllKeys(res, ['url', 'type']);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('processAuthorizationCallback tests', async () => {
|
|
82
|
-
it('asserts that the original manager has a working credential', async () => {
|
|
83
|
-
const res = await manager.testAuth();
|
|
84
|
-
expect(res).to.be.true;
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('getEntityOptions tests', async () => {
|
|
89
|
-
// NA
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('findOrCreateEntity tests', async () => {
|
|
93
|
-
it('should create a new entity for the selected profile and attach to manager', async () => {
|
|
94
|
-
const userDetails = await manager.api.getUser();
|
|
95
|
-
const entityRes = await manager.findOrCreateEntity({
|
|
96
|
-
companyId: userDetails.data.company_id,
|
|
97
|
-
companyName: userDetails.data.company_name,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
expect(entityRes.entity_id).to.exist;
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('testAuth tests', async () => {
|
|
104
|
-
it('Should refresh token and update the credential with new token', async () => {
|
|
105
|
-
const badAccessToken = 'smith';
|
|
106
|
-
manager.api.access_token = badAccessToken;
|
|
107
|
-
await manager.testAuth();
|
|
108
|
-
|
|
109
|
-
const posttoken = manager.api.access_token;
|
|
110
|
-
expect('smith').to.not.equal(posttoken);
|
|
111
|
-
const credential = await manager.credentialMO.get(
|
|
112
|
-
manager.entity.credential
|
|
113
|
-
);
|
|
114
|
-
expect(credential.accessToken).to.equal(posttoken);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('receiveNotification tests', async () => {
|
|
119
|
-
it('should fail to refresh token and mark auth as invalid', async () => {
|
|
120
|
-
// Need to use a valid but old refresh token,
|
|
121
|
-
// so we need to refresh first
|
|
122
|
-
const oldRefresh = manager.api.refresh_token;
|
|
123
|
-
const badAccessToken =
|
|
124
|
-
'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzZWFuLm1hdHRoZXdzQGxlZnRob29rLmNvbSIsImlhdCI6MTYzNTUzMDk3OCwiZXhwIjoxNjM1NTM4MTc4LCJiZW50byI6ImFwcDFlIiwiYWN0Ijp7InN1YiI6IlZob0NzMFNRZ25Fa2RDanRkaFZLemV5bXBjNW9valZoRXB2am03Rjh1UVEiLCJuYW1lIjoiTGVmdCBIb29rIiwiaXNzIjoiZmxhZ3NoaXAiLCJ0eXBlIjoiYXBwIn0sIm9yZ191c2VyX2lkIjoxLCJhdWQiOiJMZWZ0IEhvb2siLCJzY29wZXMiOiJBSkFBOEFIUUFCQUJRQT09Iiwib3JnX2d1aWQiOiJmNzY3MDEzZC1mNTBiLTRlY2QtYjM1My0zNWU0MWQ5Y2RjNGIiLCJvcmdfc2hvcnRuYW1lIjoibGVmdGhvb2tzYW5kYm94In0.XFmIai0GpAePsYeA4MjRntZS3iW6effmKmIhT7SBzTQ';
|
|
125
|
-
manager.api.access_token = badAccessToken;
|
|
126
|
-
await manager.testAuth();
|
|
127
|
-
expect(manager.api.access_token).to.not.equal(badAccessToken);
|
|
128
|
-
manager.api.access_token = badAccessToken;
|
|
129
|
-
manager.api.refresh_token = undefined;
|
|
130
|
-
|
|
131
|
-
const authTest = await manager.testAuth();
|
|
132
|
-
const credential = await manager.credentialMO.get(
|
|
133
|
-
manager.entity.credential
|
|
134
|
-
);
|
|
135
|
-
credential.auth_is_valid.should.equal(false);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|