@unito/integration-cli 0.55.1

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 (150) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +32 -0
  3. package/bin/run +11 -0
  4. package/bin/run.cmd +3 -0
  5. package/dist/.eslintrc.d.ts +10 -0
  6. package/dist/.eslintrc.js +20 -0
  7. package/dist/integrationGenerator/errors.d.ts +2 -0
  8. package/dist/integrationGenerator/errors.js +6 -0
  9. package/dist/integrationGenerator/index.d.ts +2 -0
  10. package/dist/integrationGenerator/index.js +5 -0
  11. package/dist/integrationGenerator/integrationBoilerplate/.dockerignore +3 -0
  12. package/dist/integrationGenerator/integrationBoilerplate/.eslintrc.js +74 -0
  13. package/dist/integrationGenerator/integrationBoilerplate/.nvmrc +1 -0
  14. package/dist/integrationGenerator/integrationBoilerplate/.prettierignore +1 -0
  15. package/dist/integrationGenerator/integrationBoilerplate/.prettierrc +7 -0
  16. package/dist/integrationGenerator/integrationBoilerplate/.unito.json +1 -0
  17. package/dist/integrationGenerator/integrationBoilerplate/Dockerfile +38 -0
  18. package/dist/integrationGenerator/integrationBoilerplate/README.md +21 -0
  19. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.dockerignore +3 -0
  20. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.eslintrc.js +74 -0
  21. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.nvmrc +1 -0
  22. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierignore +1 -0
  23. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierrc +7 -0
  24. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.unito.json +1 -0
  25. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/Dockerfile +38 -0
  26. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/README.md +21 -0
  27. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/package.json +43 -0
  28. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/index.ts +94 -0
  29. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/logger.ts +55 -0
  30. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/middlewares/additionalLoggingContext.ts +22 -0
  31. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/middlewares/correlationId.ts +13 -0
  32. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/middlewares/credentials.ts +38 -0
  33. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/request.ts +59 -0
  34. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/routes/index.ts +11 -0
  35. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/routes/me.ts +15 -0
  36. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/routes/root.ts +12 -0
  37. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/tsconfig.json +37 -0
  38. package/dist/integrationGenerator/integrationBoilerplate/package.json +43 -0
  39. package/dist/integrationGenerator/integrationBoilerplate/src/index.ts +90 -0
  40. package/dist/integrationGenerator/integrationBoilerplate/src/logger.ts +37 -0
  41. package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/correlationId.ts +18 -0
  42. package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/credentials.ts +38 -0
  43. package/dist/integrationGenerator/integrationBoilerplate/src/request.ts +59 -0
  44. package/dist/integrationGenerator/integrationBoilerplate/src/routes/index.ts +11 -0
  45. package/dist/integrationGenerator/integrationBoilerplate/src/routes/me.ts +15 -0
  46. package/dist/integrationGenerator/integrationBoilerplate/src/routes/root.ts +12 -0
  47. package/dist/integrationGenerator/integrationBoilerplate/tsconfig.json +37 -0
  48. package/dist/integrationGenerator/src/index.d.ts +1 -0
  49. package/dist/integrationGenerator/src/index.js +5 -0
  50. package/dist/integrationGenerator/src/resources/index.d.ts +1 -0
  51. package/dist/integrationGenerator/src/resources/index.js +5 -0
  52. package/dist/integrationGenerator/src/resources/integration.d.ts +9 -0
  53. package/dist/integrationGenerator/src/resources/integration.js +60 -0
  54. package/dist/integrationGenerator/test/resources/integration.test.d.ts +1 -0
  55. package/dist/integrationGenerator/test/resources/integration.test.js +51 -0
  56. package/dist/schemas/authorization.json +204 -0
  57. package/dist/schemas/automation.json +81 -0
  58. package/dist/schemas/configuration.json +89 -0
  59. package/dist/scripts/generateTypes.d.ts +8 -0
  60. package/dist/scripts/generateTypes.js +44 -0
  61. package/dist/src/baseCommand.d.ts +14 -0
  62. package/dist/src/baseCommand.js +39 -0
  63. package/dist/src/commands/activity.d.ts +12 -0
  64. package/dist/src/commands/activity.js +75 -0
  65. package/dist/src/commands/dev.d.ts +15 -0
  66. package/dist/src/commands/dev.js +123 -0
  67. package/dist/src/commands/encrypt.d.ts +11 -0
  68. package/dist/src/commands/encrypt.js +50 -0
  69. package/dist/src/commands/init.d.ts +10 -0
  70. package/dist/src/commands/init.js +51 -0
  71. package/dist/src/commands/invite.d.ts +11 -0
  72. package/dist/src/commands/invite.js +71 -0
  73. package/dist/src/commands/login.d.ts +11 -0
  74. package/dist/src/commands/login.js +76 -0
  75. package/dist/src/commands/oauth2.d.ts +10 -0
  76. package/dist/src/commands/oauth2.js +99 -0
  77. package/dist/src/commands/publish.d.ts +28 -0
  78. package/dist/src/commands/publish.js +302 -0
  79. package/dist/src/commands/test.d.ts +9 -0
  80. package/dist/src/commands/test.js +165 -0
  81. package/dist/src/commands/upgrade.d.ts +7 -0
  82. package/dist/src/commands/upgrade.js +88 -0
  83. package/dist/src/configurationTypes.d.ts +209 -0
  84. package/dist/src/configurationTypes.js +49 -0
  85. package/dist/src/errors.d.ts +38 -0
  86. package/dist/src/errors.js +159 -0
  87. package/dist/src/hooks/init/displayLogo.d.ts +3 -0
  88. package/dist/src/hooks/init/displayLogo.js +37 -0
  89. package/dist/src/index.d.ts +1 -0
  90. package/dist/src/index.js +5 -0
  91. package/dist/src/oauth2Helper/oauth2Helper.d.ts +63 -0
  92. package/dist/src/oauth2Helper/oauth2Helper.js +235 -0
  93. package/dist/src/oauth2Helper/types.d.ts +22 -0
  94. package/dist/src/oauth2Helper/types.js +2 -0
  95. package/dist/src/resources/configuration.d.ts +30 -0
  96. package/dist/src/resources/configuration.js +191 -0
  97. package/dist/src/resources/decryption.d.ts +5 -0
  98. package/dist/src/resources/decryption.js +62 -0
  99. package/dist/src/resources/fileSystem.d.ts +2 -0
  100. package/dist/src/resources/fileSystem.js +22 -0
  101. package/dist/src/resources/globalConfiguration.d.ts +13 -0
  102. package/dist/src/resources/globalConfiguration.js +44 -0
  103. package/dist/src/resources/integrations.d.ts +2 -0
  104. package/dist/src/resources/integrations.js +17 -0
  105. package/dist/src/resources/integrationsPlatform.d.ts +2 -0
  106. package/dist/src/resources/integrationsPlatform.js +33 -0
  107. package/dist/src/services/integrationsPlatform.d.ts +36 -0
  108. package/dist/src/services/integrationsPlatform.js +162 -0
  109. package/dist/src/services/oauth2Helper.d.ts +3 -0
  110. package/dist/src/services/oauth2Helper.js +34 -0
  111. package/dist/test/commands/activity.test.d.ts +1 -0
  112. package/dist/test/commands/activity.test.js +62 -0
  113. package/dist/test/commands/dev.test.d.ts +1 -0
  114. package/dist/test/commands/dev.test.js +139 -0
  115. package/dist/test/commands/encrypt.test.d.ts +1 -0
  116. package/dist/test/commands/encrypt.test.js +73 -0
  117. package/dist/test/commands/init.test.d.ts +1 -0
  118. package/dist/test/commands/init.test.js +45 -0
  119. package/dist/test/commands/invite.test.d.ts +1 -0
  120. package/dist/test/commands/invite.test.js +56 -0
  121. package/dist/test/commands/login.test.d.ts +1 -0
  122. package/dist/test/commands/login.test.js +90 -0
  123. package/dist/test/commands/oauth2.test.d.ts +1 -0
  124. package/dist/test/commands/oauth2.test.js +104 -0
  125. package/dist/test/commands/publish.test.d.ts +1 -0
  126. package/dist/test/commands/publish.test.js +429 -0
  127. package/dist/test/commands/test.test.d.ts +1 -0
  128. package/dist/test/commands/test.test.js +171 -0
  129. package/dist/test/commands/upgrade.test.d.ts +1 -0
  130. package/dist/test/commands/upgrade.test.js +47 -0
  131. package/dist/test/errors.test.d.ts +1 -0
  132. package/dist/test/errors.test.js +96 -0
  133. package/dist/test/helpers/init.d.ts +1 -0
  134. package/dist/test/helpers/init.js +6 -0
  135. package/dist/test/mocha.hooks.d.ts +2 -0
  136. package/dist/test/mocha.hooks.js +37 -0
  137. package/dist/test/oauth2Helper/oauth2Helper.test.d.ts +1 -0
  138. package/dist/test/oauth2Helper/oauth2Helper.test.js +150 -0
  139. package/dist/test/resources/configuration.test.d.ts +1 -0
  140. package/dist/test/resources/configuration.test.js +586 -0
  141. package/dist/test/resources/decryption.test.d.ts +1 -0
  142. package/dist/test/resources/decryption.test.js +68 -0
  143. package/dist/test/resources/globalConfiguration.test.d.ts +1 -0
  144. package/dist/test/resources/globalConfiguration.test.js +32 -0
  145. package/dist/test/services/integrationsPlatform.test.d.ts +1 -0
  146. package/dist/test/services/integrationsPlatform.test.js +168 -0
  147. package/dist/test/services/oauth2Helper.test.d.ts +1 -0
  148. package/dist/test/services/oauth2Helper.test.js +85 -0
  149. package/oclif.manifest.json +423 -0
  150. package/package.json +98 -0
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const chai_1 = require("chai");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const sinon = tslib_1.__importStar(require("sinon"));
7
+ const GlobalConfiguration = tslib_1.__importStar(require("../../src/resources/globalConfiguration"));
8
+ describe('globalConfiguration', () => {
9
+ afterEach(() => {
10
+ sinon.restore();
11
+ });
12
+ it('reads', async function () {
13
+ const configuration = await GlobalConfiguration.getDefault();
14
+ configuration.apiKey = 'foo';
15
+ sinon.stub(fs_1.default.promises, 'mkdir').resolves('');
16
+ sinon.stub(fs_1.default.promises, 'readFile').resolves(JSON.stringify(configuration));
17
+ (0, chai_1.expect)(await GlobalConfiguration.read('bar')).to.deep.equal(configuration);
18
+ });
19
+ it('reads - error', async function () {
20
+ sinon.stub(fs_1.default.promises, 'mkdir').resolves('');
21
+ sinon.stub(fs_1.default.promises, 'readFile').throws();
22
+ (0, chai_1.expect)(await GlobalConfiguration.read('bar')).to.deep.equal(await GlobalConfiguration.getDefault());
23
+ });
24
+ it('writes', async function () {
25
+ const configuration = GlobalConfiguration.getDefault();
26
+ configuration.apiKey = 'foo';
27
+ sinon.stub(fs_1.default.promises, 'mkdir').resolves('');
28
+ const stubbedWrite = sinon.stub(fs_1.default.promises, 'writeFile');
29
+ await GlobalConfiguration.write('bar', configuration);
30
+ sinon.assert.calledWith(stubbedWrite, sinon.match.string, JSON.stringify(configuration, null, 2), sinon.match.any);
31
+ });
32
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const chai_1 = require("chai");
5
+ const sinon = tslib_1.__importStar(require("sinon"));
6
+ const integrations_platform_client_1 = tslib_1.__importDefault(require("@unito/integrations-platform-client"));
7
+ const IntegrationsPlatform = tslib_1.__importStar(require("../../src/services/integrationsPlatform"));
8
+ const globalConfiguration_1 = require("../../src/resources/globalConfiguration");
9
+ const configurationTypes_1 = require("../../src/configurationTypes");
10
+ describe('integrations platform', function () {
11
+ const user = {
12
+ id: 1,
13
+ apiKey: 'foo',
14
+ email: 'foo@bar.com',
15
+ role: 'unitoAdministrator',
16
+ createdAt: '',
17
+ updatedAt: '',
18
+ archivedAt: '',
19
+ termsAcceptedAt: null,
20
+ defaultUnitoOrganizationId: '',
21
+ };
22
+ const integrationSummary = {
23
+ id: 1,
24
+ name: '',
25
+ baseUrl: '',
26
+ graphRelativeUrl: '',
27
+ credentialAccountRelativeUrl: '',
28
+ visibility: 'private',
29
+ unitoOrganizationIds: [],
30
+ ui: {
31
+ displayName: '',
32
+ logo: '',
33
+ },
34
+ createdAt: '',
35
+ updatedAt: '',
36
+ archivedAt: '',
37
+ };
38
+ const integration = {
39
+ ...integrationSummary,
40
+ authorizations: [],
41
+ userIds: [],
42
+ };
43
+ afterEach(function () {
44
+ sinon.restore();
45
+ });
46
+ it('environment', function () {
47
+ (0, chai_1.expect)(integrations_platform_client_1.default.defaults.baseUrl).to.equal(integrations_platform_client_1.default.servers.local);
48
+ IntegrationsPlatform.setEnvironment(globalConfiguration_1.Environment.Production);
49
+ (0, chai_1.expect)(integrations_platform_client_1.default.defaults.baseUrl).to.equal(integrations_platform_client_1.default.servers.production);
50
+ });
51
+ it('apiKey', function () {
52
+ IntegrationsPlatform.setApiKey('foo');
53
+ (0, chai_1.expect)(IntegrationsPlatform.getApiKey()).to.equal('foo');
54
+ (0, chai_1.expect)(integrations_platform_client_1.default.defaults.headers).to.deep.equal({
55
+ Authorization: 'Bearer foo',
56
+ });
57
+ IntegrationsPlatform.setApiKey(undefined);
58
+ (0, chai_1.expect)(IntegrationsPlatform.getApiKey()).to.equal(undefined);
59
+ (0, chai_1.expect)(integrations_platform_client_1.default.defaults.headers).to.be.undefined;
60
+ });
61
+ it('getProfile', async function () {
62
+ sinon.stub(integrations_platform_client_1.default, 'getProfile').resolves(user);
63
+ (0, chai_1.expect)(await IntegrationsPlatform.getProfile()).to.deep.equal(user);
64
+ });
65
+ it('getIntegration', async function () {
66
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrationById').resolves(integration);
67
+ (0, chai_1.expect)(await IntegrationsPlatform.getIntegration(1)).to.deep.equal(integration);
68
+ });
69
+ it('getIntegrationByName', async function () {
70
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrationByName').resolves(integration);
71
+ (0, chai_1.expect)(await IntegrationsPlatform.getIntegrationByName('foo')).to.deep.equal(integration);
72
+ });
73
+ it('getIntegrationByName - error', async function () {
74
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrationByName').throws();
75
+ (0, chai_1.expect)(await IntegrationsPlatform.getIntegrationByName('foo')).to.deep.equal(null);
76
+ });
77
+ it('getIntegrations', async function () {
78
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrations').resolves({ total: 1, data: [integrationSummary] });
79
+ (0, chai_1.expect)(await IntegrationsPlatform.getIntegrations()).to.deep.equal([integrationSummary]);
80
+ });
81
+ it('createIntegration', async function () {
82
+ sinon.stub(integrations_platform_client_1.default, 'createIntegration').resolves(integration);
83
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrationById').resolves(integration);
84
+ sinon.stub(integrations_platform_client_1.default, 'updateIntegration').resolves(integration);
85
+ (0, chai_1.expect)(await IntegrationsPlatform.createIntegration({ name: 'foo' })).to.deep.equal(integration);
86
+ });
87
+ it('updateIntegration', async function () {
88
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrationById').resolves(integration);
89
+ sinon.stub(integrations_platform_client_1.default, 'updateIntegration').resolves(integration);
90
+ (0, chai_1.expect)(await IntegrationsPlatform.updateIntegration(1, { name: 'foo' })).to.deep.equal(integration);
91
+ });
92
+ it('updateIntegration - create / archive authorization', async function () {
93
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrationById').resolves({
94
+ ...integration,
95
+ authorizations: [
96
+ {
97
+ id: 1,
98
+ name: 'spam',
99
+ method: configurationTypes_1.Method.CUSTOM,
100
+ createdAt: '',
101
+ updatedAt: '',
102
+ archivedAt: null,
103
+ integrationId: 1,
104
+ oauth2: null,
105
+ variables: {},
106
+ },
107
+ ],
108
+ });
109
+ sinon.stub(integrations_platform_client_1.default, 'updateIntegration').resolves(integration);
110
+ (0, chai_1.expect)(await IntegrationsPlatform.updateIntegration(1, {
111
+ name: 'foo',
112
+ authorizations: [{ name: 'bar', method: configurationTypes_1.Method.CUSTOM }],
113
+ })).to.deep.equal(integration);
114
+ });
115
+ it('updateIntegration - update authorization', async function () {
116
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrationById').resolves({
117
+ ...integration,
118
+ authorizations: [
119
+ {
120
+ id: 1,
121
+ name: 'bar',
122
+ method: configurationTypes_1.Method.CUSTOM,
123
+ createdAt: '',
124
+ updatedAt: '',
125
+ archivedAt: null,
126
+ integrationId: 1,
127
+ oauth2: null,
128
+ variables: {},
129
+ },
130
+ ],
131
+ });
132
+ sinon.stub(integrations_platform_client_1.default, 'updateIntegration').resolves(integration);
133
+ (0, chai_1.expect)(await IntegrationsPlatform.updateIntegration(1, { name: 'foo' })).to.deep.equal(integration);
134
+ (0, chai_1.expect)(await IntegrationsPlatform.updateIntegration(1, {
135
+ name: 'foo',
136
+ authorizations: [{ name: 'bar', method: configurationTypes_1.Method.CUSTOM }],
137
+ })).to.deep.equal(integration);
138
+ });
139
+ it('updateIntegration - update secrets', async function () {
140
+ sinon.stub(integrations_platform_client_1.default, 'getIntegrationById').resolves({ ...integration });
141
+ const mockUpdateIntegration = sinon.stub(integrations_platform_client_1.default, 'updateIntegration');
142
+ const integrationId = 1;
143
+ const configuration = {
144
+ name: 'foo',
145
+ secrets: {
146
+ foo: 'bar',
147
+ },
148
+ };
149
+ await IntegrationsPlatform.updateIntegration(integrationId, configuration);
150
+ (0, chai_1.expect)(mockUpdateIntegration.getCall(0).args.at(1)).to.deep.equal({
151
+ ui: undefined,
152
+ authorizations: [],
153
+ baseUrl: undefined,
154
+ credentialAccountRelativeUrl: '/me',
155
+ graphRelativeUrl: '/',
156
+ secrets: configuration.secrets,
157
+ webhookAcknowledgeRelativeUrl: undefined,
158
+ webhookParsingRelativeUrl: undefined,
159
+ webhookSubscriptionsRelativeUrl: undefined,
160
+ });
161
+ });
162
+ it('encryptData', async function () {
163
+ sinon.stub(integrations_platform_client_1.default, 'encryptData').resolves({ encryptedData: 'encryptedFoo' });
164
+ (0, chai_1.expect)(await IntegrationsPlatform.encryptData('mySuperIntegration', 'foo')).to.deep.equal({
165
+ encryptedData: 'encryptedFoo',
166
+ });
167
+ });
168
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const chai_1 = require("chai");
5
+ const sinon_1 = tslib_1.__importDefault(require("sinon"));
6
+ const oauth2Helper_1 = tslib_1.__importDefault(require("../../src/oauth2Helper/oauth2Helper"));
7
+ const configurationTypes_1 = require("../../src/configurationTypes");
8
+ const oauth2HelperService = tslib_1.__importStar(require("../../src/services/oauth2Helper"));
9
+ const errors_1 = require("../../src/errors");
10
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
11
+ describe('OAuth2Helper', () => {
12
+ let fetchStub;
13
+ const authorizationInfo = {
14
+ clientId: 'your-client-id',
15
+ clientSecret: 'your-client-secret',
16
+ authorizationUrl: 'https://provider.com/oauth/authorize',
17
+ scopes: [{ name: 'scope1' }, { name: 'scope2' }],
18
+ tokenUrl: 'https://provider.com/oauth/token',
19
+ grantType: configurationTypes_1.GrantType.AUTHORIZATION_CODE,
20
+ requestContentType: configurationTypes_1.RequestContentType.URL_ENCODED,
21
+ responseContentType: configurationTypes_1.RequestContentType.JSON,
22
+ };
23
+ beforeEach(() => {
24
+ sinon_1.default.stub(oauth2Helper_1.default.prototype, 'startServer').returns('http://localhost:5050');
25
+ sinon_1.default.stub(oauth2Helper_1.default.prototype, 'stopServer');
26
+ sinon_1.default.stub(oauth2Helper_1.default.prototype, 'callbackIsDone');
27
+ sinon_1.default.stub(inquirer_1.default, 'prompt');
28
+ });
29
+ afterEach(() => {
30
+ sinon_1.default.restore();
31
+ });
32
+ describe('performOAuth2Flow', () => {
33
+ it('should perform the oauth flow', async () => {
34
+ fetchStub = sinon_1.default
35
+ .stub()
36
+ .onFirstCall()
37
+ .resolves({ status: 200 })
38
+ .onSecondCall()
39
+ .resolves({ status: 200 })
40
+ .onThirdCall()
41
+ .resolves({
42
+ status: 200,
43
+ json: () => {
44
+ return { accessToken: 'token', refresToken: 'refreshToken' };
45
+ },
46
+ });
47
+ sinon_1.default.replace(global, 'fetch', fetchStub);
48
+ await oauth2HelperService.performOAuth2Flow(authorizationInfo);
49
+ (0, chai_1.expect)(fetchStub.getCall(0).args.at(0)).to.eq('http://localhost:5050/health');
50
+ (0, chai_1.expect)(fetchStub.getCall(1).args.at(0)).to.eq('http://localhost:5050/credentials/new/oauth2/authorize');
51
+ (0, chai_1.expect)(fetchStub.getCall(2).args.at(0)).to.eq('http://localhost:5050/credentials/new/oauth2/token');
52
+ });
53
+ it('raises a FailedToRetrieveAccessTokenError', async () => {
54
+ fetchStub = sinon_1.default
55
+ .stub()
56
+ .onFirstCall()
57
+ .resolves({ status: 200 })
58
+ .onSecondCall()
59
+ .resolves({ status: 200 })
60
+ .onThirdCall()
61
+ .resolves({ status: 500, text: () => 'error' });
62
+ sinon_1.default.replace(global, 'fetch', fetchStub);
63
+ const response = oauth2HelperService.performOAuth2Flow(authorizationInfo);
64
+ await (0, chai_1.expect)(response).to.be.rejectedWith(errors_1.FailedToRetrieveAccessTokenError);
65
+ });
66
+ it('raises a FailedToRetrieveAccessTokenError when the accessToken is not returned', async () => {
67
+ fetchStub = sinon_1.default
68
+ .stub()
69
+ .onFirstCall()
70
+ .resolves({ status: 200 })
71
+ .onSecondCall()
72
+ .resolves({ status: 200 })
73
+ .onThirdCall()
74
+ .resolves({
75
+ status: 200,
76
+ json: () => {
77
+ return {};
78
+ },
79
+ });
80
+ sinon_1.default.replace(global, 'fetch', fetchStub);
81
+ const response = oauth2HelperService.performOAuth2Flow(authorizationInfo);
82
+ await (0, chai_1.expect)(response).to.be.rejectedWith(errors_1.FailedToRetrieveAccessTokenError);
83
+ });
84
+ });
85
+ });