@unito/integration-cli 0.57.0 → 0.57.2

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 (48) hide show
  1. package/dist/integrationGenerator/test/resources/integration.test.js +7 -8
  2. package/dist/src/commands/activity.d.ts +2 -2
  3. package/dist/src/commands/activity.js +2 -2
  4. package/dist/src/commands/dev.d.ts +4 -4
  5. package/dist/src/commands/dev.js +3 -2
  6. package/dist/src/commands/encrypt.d.ts +1 -1
  7. package/dist/src/commands/encrypt.js +1 -1
  8. package/dist/src/commands/init.d.ts +1 -1
  9. package/dist/src/commands/init.js +1 -1
  10. package/dist/src/commands/invite.d.ts +1 -1
  11. package/dist/src/commands/invite.js +2 -2
  12. package/dist/src/commands/login.d.ts +1 -1
  13. package/dist/src/commands/login.js +1 -1
  14. package/dist/src/commands/oauth2.d.ts +3 -3
  15. package/dist/src/commands/oauth2.js +4 -4
  16. package/dist/src/commands/publish.d.ts +2 -2
  17. package/dist/src/commands/publish.js +12 -12
  18. package/dist/src/commands/test.js +5 -3
  19. package/dist/src/commands/upgrade.js +3 -3
  20. package/dist/src/oauth2Helper/oauth2Helper.d.ts +4 -2
  21. package/dist/src/oauth2Helper/oauth2Helper.js +31 -11
  22. package/dist/src/services/oauth2Helper.d.ts +2 -1
  23. package/dist/src/services/oauth2Helper.js +4 -3
  24. package/dist/test/commands/activity.test.js +12 -9
  25. package/dist/test/commands/dev.test.js +38 -10
  26. package/dist/test/commands/encrypt.test.js +6 -7
  27. package/dist/test/commands/init.test.js +6 -8
  28. package/dist/test/commands/invite.test.js +11 -11
  29. package/dist/test/commands/login.test.js +19 -23
  30. package/dist/test/commands/oauth2.test.js +4 -1
  31. package/dist/test/commands/publish.test.js +151 -218
  32. package/dist/test/commands/test.test.js +43 -13
  33. package/dist/test/commands/upgrade.test.js +3 -6
  34. package/dist/test/errors.test.js +36 -36
  35. package/dist/test/helpers/integrations.d.ts +26 -0
  36. package/dist/test/helpers/integrations.js +25 -0
  37. package/dist/test/helpers/styles.d.ts +1 -0
  38. package/dist/test/helpers/styles.js +8 -0
  39. package/dist/test/oauth2Helper/oauth2Helper.test.js +20 -20
  40. package/dist/test/resources/configuration.test.js +24 -24
  41. package/dist/test/resources/decryption.test.js +9 -9
  42. package/dist/test/resources/globalConfiguration.test.js +4 -4
  43. package/dist/test/services/integrationsPlatform.test.js +20 -20
  44. package/dist/test/services/oauth2Helper.test.js +7 -7
  45. package/oclif.manifest.json +1 -1
  46. package/package.json +3 -7
  47. package/dist/test/mocha.hooks.d.ts +0 -2
  48. package/dist/test/mocha.hooks.js +0 -37
@@ -12,21 +12,16 @@ const IntegrationResource = tslib_1.__importStar(require("../../src/resources/in
12
12
  const IntegrationConfiguration = tslib_1.__importStar(require("../../src/resources/configuration"));
13
13
  const errors_1 = require("../../src/errors");
14
14
  const FileSystem = tslib_1.__importStar(require("../../src/resources/fileSystem"));
15
+ const integrations_1 = require("../helpers/integrations");
16
+ const styles_1 = require("../helpers/styles");
15
17
  describe('Publish', () => {
16
- let createIntegrationStub;
17
- let updateIntegrationStub;
18
+ const integration = (0, integrations_1.generateIntegration)();
18
19
  beforeEach(() => {
19
20
  sinon_1.default.stub(IntegrationResource, 'validateIsIntegrationDirectory');
20
21
  sinon_1.default.stub(IntegrationsPlatform, 'setEnvironment');
21
22
  sinon_1.default.stub(IntegrationsPlatform, 'setApiKey');
22
23
  sinon_1.default.stub(IntegrationsPlatform, 'publishIntegration');
23
24
  sinon_1.default.stub(IntegrationsPlatform, 'reencryptData').resolves({ encryptedData: 'newEncryptedSecret' });
24
- createIntegrationStub = sinon_1.default
25
- .stub(IntegrationsPlatform, 'createIntegration')
26
- .resolves({});
27
- updateIntegrationStub = sinon_1.default
28
- .stub(IntegrationsPlatform, 'updateIntegration')
29
- .resolves({});
30
25
  sinon_1.default.stub(ngrok_1.default, 'connect');
31
26
  sinon_1.default.stub(child_process_1.default, 'spawn');
32
27
  sinon_1.default.stub(IntegrationsPlatform, 'getProfile').resolves({
@@ -46,266 +41,216 @@ describe('Publish', () => {
46
41
  });
47
42
  test_1.test
48
43
  .stdout()
49
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
50
- .stub(IntegrationConfiguration, 'getConfiguration',
51
- // eslint-disable-next-line
52
- // @ts-ignore typing doesn't work here, for some reason.
53
- (environment, customPath) => {
54
- (0, test_1.expect)(environment).to.equal(GlobalConfiguration.Environment.Production);
55
- (0, test_1.expect)(customPath).to.be.undefined;
56
- return { name: 'a' };
57
- })
58
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
59
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
44
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
45
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'a' }))
46
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
47
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
60
48
  .command(['publish'])
61
49
  .it('publish the integration - default', ctx => {
62
50
  (0, test_1.expect)(ctx.stdout).to.contain('published');
63
51
  });
64
52
  test_1.test
65
53
  .stdout()
66
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
67
- .stub(IntegrationConfiguration, 'getConfiguration',
68
- // eslint-disable-next-line
69
- // @ts-ignore typing doesn't work here, for some reason.
70
- (environment, customPath) => {
71
- (0, test_1.expect)(environment).to.equal(GlobalConfiguration.Environment.Production);
72
- (0, test_1.expect)(customPath).to.equal('/custom-config.json');
73
- return { name: 'a' };
74
- })
75
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
76
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
54
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
55
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'a' }))
56
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
57
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
77
58
  .command(['publish', '--config-path', '/custom-config.json'])
78
59
  .it('publish the integration with custom config - default', ctx => {
79
60
  (0, test_1.expect)(ctx.stdout).to.contain('published');
80
61
  });
81
62
  test_1.test
82
63
  .stdout()
83
- .stub(GlobalConfiguration, 'read', () => ({ apiKeyLocal: 'foo' }))
84
- .stub(IntegrationConfiguration, 'getConfiguration',
85
- // eslint-disable-next-line
86
- // @ts-ignore typing doesn't work here, for some reason.
87
- (environment, customPath) => {
88
- (0, test_1.expect)(environment).to.equal(GlobalConfiguration.Environment.Local);
89
- (0, test_1.expect)(customPath).to.be.undefined;
90
- return { name: 'a' };
91
- })
92
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
93
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
64
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKeyLocal: 'foo' }))
65
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'a' }))
66
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
67
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
94
68
  .command(['publish', '--environment', 'local'])
95
69
  .it('publish the integration - local', ctx => {
96
70
  (0, test_1.expect)(ctx.stdout).to.contain('published');
97
71
  });
98
72
  test_1.test
99
73
  .stdout()
100
- .stub(GlobalConfiguration, 'read', () => ({ apiKeyLocal: 'foo' }))
101
- .stub(IntegrationConfiguration, 'getConfigurationPath', () => '/.unito.local.json')
102
- .stub(IntegrationConfiguration, 'getConfiguration',
103
- // eslint-disable-next-line
104
- // @ts-ignore typing doesn't work here, for some reason.
105
- (environment, customPath) => {
106
- (0, test_1.expect)(environment).to.equal(GlobalConfiguration.Environment.Local);
107
- (0, test_1.expect)(customPath).to.be.undefined;
108
- return { name: 'a' };
109
- })
110
- .stub(IntegrationConfiguration, 'writeConfiguration', () => Promise)
111
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
112
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
74
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKeyLocal: 'foo' }))
75
+ .stub(IntegrationConfiguration, 'getConfigurationPath', stub => stub.returns('/.unito.local.json'))
76
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'a' }))
77
+ .stub(IntegrationConfiguration, 'writeConfiguration', stub => stub.resolves())
78
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
79
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
113
80
  .command(['publish', '--environment', 'local'])
114
81
  .it('publish the integration using .unito.local.json - local', ctx => {
115
82
  (0, test_1.expect)(ctx.stdout).to.contain('published');
116
83
  });
117
84
  test_1.test
118
85
  .stdout()
119
- .stub(GlobalConfiguration, 'read', () => ({ apiKeyStaging: 'foo' }))
120
- .stub(IntegrationConfiguration, 'getConfigurationPath', () => '/.unito.json')
121
- .stub(IntegrationConfiguration, 'getConfiguration',
122
- // eslint-disable-next-line
123
- // @ts-ignore typing doesn't work here, for some reason.
124
- (environment, customPath) => {
125
- (0, test_1.expect)(environment).to.equal(GlobalConfiguration.Environment.Staging);
126
- (0, test_1.expect)(customPath).to.be.undefined;
127
- return { name: 'a' };
128
- })
129
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
130
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
86
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKeyStaging: 'foo' }))
87
+ .stub(IntegrationConfiguration, 'getConfigurationPath', stub => stub.returns('/.unito.json'))
88
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'a' }))
89
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
90
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
131
91
  .command(['publish', '--environment', 'staging'])
132
92
  .it('publish the integration - staging', ctx => {
133
93
  (0, test_1.expect)(ctx.stdout).to.contain('published');
134
94
  });
135
95
  test_1.test
136
96
  .stdout()
137
- .stub(GlobalConfiguration, 'read', () => ({ apiKeyStaging: 'foo' }))
138
- .stub(IntegrationConfiguration, 'getConfigurationPath', () => '/.unito.staging.json')
139
- .stub(IntegrationConfiguration, 'getConfiguration',
140
- // eslint-disable-next-line
141
- // @ts-ignore typing doesn't work here, for some reason.
142
- (environment, customPath) => {
143
- (0, test_1.expect)(environment).to.equal(GlobalConfiguration.Environment.Staging);
144
- (0, test_1.expect)(customPath).to.be.undefined;
145
- return {};
146
- })
147
- .stub(IntegrationConfiguration, 'writeConfiguration', () => Promise)
148
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
149
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
97
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKeyStaging: 'foo' }))
98
+ .stub(IntegrationConfiguration, 'getConfigurationPath', stub => stub.returns('/.unito.staging.json'))
99
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({}))
100
+ .stub(IntegrationConfiguration, 'writeConfiguration', stub => stub.resolves())
101
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
102
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
150
103
  .command(['publish', '--environment', 'staging'])
151
104
  .it('publish the integration using .unito.staging.json - staging', ctx => {
152
105
  (0, test_1.expect)(ctx.stdout).to.contain('published');
153
106
  });
154
107
  test_1.test
155
108
  .stdout()
156
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
157
- .stub(IntegrationConfiguration, 'getConfigurationPath', () => '/.unito.json')
158
- .stub(IntegrationConfiguration, 'getConfiguration',
159
- // eslint-disable-next-line
160
- // @ts-ignore typing doesn't work here, for some reason.
161
- (environment, customPath) => {
162
- (0, test_1.expect)(environment).to.equal(GlobalConfiguration.Environment.Production);
163
- (0, test_1.expect)(customPath).to.equal('/my-awesome-config.json');
164
- return { name: 'a' };
165
- })
166
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
167
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
109
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
110
+ .stub(IntegrationConfiguration, 'getConfigurationPath', stub => stub.returns('/.unito.json'))
111
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'a' }))
112
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
113
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
168
114
  .command(['publish', '--config-path', '/my-awesome-config.json'])
169
115
  .it('publish the integration using custom configuration', ctx => {
170
116
  (0, test_1.expect)(ctx.stdout).to.contain('published');
171
117
  });
172
118
  test_1.test
173
119
  .stdout()
174
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
175
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
176
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
177
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
178
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: false }))
120
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
121
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({}))
122
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
123
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
124
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: false }))
179
125
  .command(['publish', '--registry-only'])
180
126
  .it('aborts on user negative input', ctx => {
181
- (0, test_1.expect)(createIntegrationStub.called).to.be.false;
182
- (0, test_1.expect)(updateIntegrationStub.called).to.be.false;
183
127
  (0, test_1.expect)(ctx.stdout).to.contain('🙊 Abort! You are safe now 🍸 relax');
184
128
  });
185
129
  test_1.test
186
130
  .stdout()
187
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
188
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
189
- .stub(IntegrationsPlatform, 'getIntegration', () => undefined)
190
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
191
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: false }))
131
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
132
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({}))
133
+ .stub(IntegrationsPlatform, 'getIntegration', stub => stub.returns(undefined))
134
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
135
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
136
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
137
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: false }))
192
138
  .command(['publish', '--registry-only', '--force'])
193
139
  .it('bypass user confirmation with --force is active', ctx => {
194
- (0, test_1.expect)(createIntegrationStub.calledOnce).to.be.true;
195
140
  (0, test_1.expect)(ctx.stdout).to.contain('created');
196
141
  });
197
142
  test_1.test
198
143
  .stdout()
199
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
200
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
201
- .stub(IntegrationsPlatform, 'getIntegration', () => undefined)
202
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
203
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
144
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
145
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({}))
146
+ .stub(IntegrationsPlatform, 'getIntegration', stub => stub.returns(undefined))
147
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
148
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
149
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
150
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: true }))
204
151
  .command(['publish', '--registry-only'])
205
152
  .it('creates the integration in the registry', ctx => {
206
- (0, test_1.expect)(createIntegrationStub.calledOnce).to.be.true;
207
153
  (0, test_1.expect)(ctx.stdout).to.contain('created');
208
154
  });
209
155
  test_1.test
210
156
  .stdout()
211
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
212
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({ name: 'a' }))
213
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => ({ name: 'a' }))
214
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
215
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
157
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
158
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'a' }))
159
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns({ name: 'a' }))
160
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
161
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
162
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
163
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: true }))
216
164
  .command(['publish', '--registry-only'])
217
165
  .it('updates the integration in the registry', ctx => {
218
- (0, test_1.expect)(createIntegrationStub.called).to.be.false;
219
- (0, test_1.expect)(updateIntegrationStub.calledOnce).to.be.true;
220
166
  (0, test_1.expect)(ctx.stdout).to.contain('updated');
221
167
  });
222
168
  test_1.test
223
169
  .stdout()
224
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
225
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
170
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
171
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
226
172
  authorizations: [{ type: 'custom', development: true }, { type: 'oauth2' }],
227
173
  }))
228
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
229
- // eslint-disable-next-line
230
- // @ts-ignore typing doesn't work here, for some reason.
231
- .stub(IntegrationsPlatform, 'createIntegration', (config) => config)
232
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
233
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
174
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
175
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
176
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
177
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
178
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: true }))
234
179
  .command(['publish', '--registry-only'])
235
180
  .it('filters out "development" authorizations', ctx => {
236
- (0, test_1.expect)(ctx.stdout).to.contain('oauth2');
237
- (0, test_1.expect)(ctx.stdout).to.not.contain('custom');
181
+ ctx.sandbox.assert.calledOnceWithMatch(
182
+ // @ts-expect-error syntax accepted by sinon.
183
+ IntegrationsPlatform.createIntegration, {
184
+ authorizations: [
185
+ {
186
+ type: 'oauth2',
187
+ instructionsImage: 'data:image/png;base64,',
188
+ instructionsMarkdown: '',
189
+ },
190
+ ],
191
+ });
192
+ // @ts-expect-error syntax accepted by sinon.
193
+ ctx.sandbox.assert.notCalled(IntegrationsPlatform.updateIntegration);
238
194
  });
239
195
  test_1.test
240
196
  .stdout()
241
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
242
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({ name: 'foo' }))
243
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
244
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
197
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
198
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'foo' }))
199
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
200
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
201
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
202
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
245
203
  .command(['publish', '--preview'])
246
204
  .it('preview the integration', ctx => {
247
205
  (0, test_1.expect)(ctx.stdout).to.contain('published');
248
206
  });
249
207
  test_1.test
250
208
  .stdout()
251
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
252
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({ name: 'foo', ui: { displayName: 'Foo' } }))
253
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
254
- // eslint-disable-next-line
255
- // @ts-ignore typing doesn't work here, for some reason.
256
- .stub(IntegrationConfiguration, 'writeConfiguration', configuration => {
257
- if (configuration.name === 'foo') {
258
- (0, test_1.expect)(configuration).to.deep.equal({
259
- name: 'foo',
260
- ui: {
261
- displayName: 'Foo',
262
- },
263
- });
264
- }
265
- else {
266
- (0, test_1.expect)(configuration).to.deep.equal({
267
- name: 'foo-preview-9c88',
268
- ui: {
269
- displayName: 'Foo - Preview - 9c88',
270
- },
271
- });
272
- }
273
- return configuration;
274
- })
275
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
209
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
210
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ name: 'foo', ui: { displayName: 'Foo' } }))
211
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
212
+ .stub(IntegrationConfiguration, 'writeConfiguration', stub => stub.returns(integration))
213
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
276
214
  .command(['publish', '--preview'])
277
215
  .it('preview the integration - override the display name', ctx => {
278
- (0, test_1.expect)(ctx.stdout).to.contain('published');
216
+ (0, test_1.expect)((0, styles_1.uncolorize)(ctx.stdout)).to.contain('foo-preview-9c88 is being published');
279
217
  });
280
218
  test_1.test
281
219
  .stdout()
282
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
283
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
284
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
285
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
220
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
221
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({}))
222
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
223
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
224
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
225
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
286
226
  .command(['publish', '--live-preview'])
287
227
  .it('live-preview the integration', ctx => {
288
228
  (0, test_1.expect)(ctx.stdout).to.contain('created');
289
229
  });
290
230
  test_1.test
291
231
  .stdout()
292
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
293
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({ ui: { displayName: 'Foo' } }))
294
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
295
- // eslint-disable-next-line
296
- // @ts-ignore typing doesn't work here, for some reason.
297
- .stub(IntegrationsPlatform, 'createIntegration', (config) => config)
298
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
232
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
233
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({ ui: { displayName: 'Foo' } }))
234
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
235
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
236
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
299
237
  .command(['publish', '--live-preview'])
300
238
  .it('live-preview the integration - override the display name', ctx => {
301
- (0, test_1.expect)(ctx.stdout).to.contain('Foo - Live Preview - 9c88');
239
+ ctx.sandbox.assert.calledOnceWithMatch(
240
+ // @ts-expect-error syntax accepted by sinon.
241
+ IntegrationsPlatform.createIntegration, {
242
+ ui: { displayName: 'Foo - Live Preview - 9c88' },
243
+ name: 'undefined-live-preview-9c88',
244
+ baseUrl: undefined,
245
+ });
302
246
  });
303
247
  test_1.test
248
+ .stdout()
304
249
  .stderr()
305
- .stub(GlobalConfiguration, 'read', () => ({}))
306
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
307
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
308
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
250
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({}))
251
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({}))
252
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
253
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
309
254
  .command(['publish'])
310
255
  .exit(-1)
311
256
  .it('missing api key', ctx => {
@@ -313,28 +258,26 @@ describe('Publish', () => {
313
258
  });
314
259
  test_1.test
315
260
  .stdout()
316
- .stub(GlobalConfiguration, 'read', () => {
317
- throw new errors_1.NoConfigurationFileError();
318
- })
319
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
261
+ .stub(GlobalConfiguration, 'read', stub => stub.throws(new errors_1.NoConfigurationFileError()))
262
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
320
263
  .command(['publish'])
321
264
  .exit(-1)
322
265
  .it('handles exception');
323
266
  test_1.test
324
267
  .stdout()
325
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
326
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
268
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
269
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
327
270
  name: 'myIntegration',
328
271
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'unito-secret-' } }],
329
272
  secrets: { secret1: 'unito-secret-', invalidSecret: 'Should never happen anyway' },
330
273
  }))
331
- .stub(IntegrationConfiguration, 'writeConfiguration', () => ({
274
+ .stub(IntegrationConfiguration, 'writeConfiguration', stub => stub.returns({
332
275
  name: 'myIntegration',
333
276
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'unito-secret-' } }],
334
277
  secrets: { secret1: 'unito-secret-', invalidSecret: 'Should never happen anyway' },
335
278
  }))
336
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
337
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
279
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
280
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
338
281
  .command(['publish', '--preview'])
339
282
  .it('reencrypts the clientSecret on preview', ctx => {
340
283
  (0, test_1.expect)(ctx.stdout).to.contain('Reencrypting oauth2:clientSecret');
@@ -343,14 +286,16 @@ describe('Publish', () => {
343
286
  });
344
287
  test_1.test
345
288
  .stdout()
346
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
347
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
289
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
290
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
348
291
  name: 'myIntegration',
349
292
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'unito-secret-' } }],
350
293
  secrets: { secret1: 'unito-secret-', invalidSecret: 'Should never happen anyway' },
351
294
  }))
352
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
353
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
295
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
296
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
297
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
298
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
354
299
  .command(['publish', '--live-preview'])
355
300
  .it('reencrypts the clientSecret on live-preview', ctx => {
356
301
  (0, test_1.expect)(ctx.stdout).to.contain('Reencrypting oauth2:clientSecret');
@@ -359,21 +304,23 @@ describe('Publish', () => {
359
304
  });
360
305
  test_1.test
361
306
  .stdout()
362
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
363
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
307
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
308
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
364
309
  name: 'myIntegration',
365
310
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'toto' } }],
366
311
  }))
367
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
368
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
312
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
313
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
314
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
315
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
369
316
  .command(['publish', '--live-preview'])
370
317
  .it('skips reencryption', ctx => {
371
318
  (0, test_1.expect)(ctx.stdout).to.contain('Skipping oauth2:clientSecret');
372
319
  });
373
320
  test_1.test
374
321
  .stdout()
375
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
376
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
322
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
323
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
377
324
  authorizations: [
378
325
  {
379
326
  name: 'foo',
@@ -381,9 +328,11 @@ describe('Publish', () => {
381
328
  },
382
329
  ],
383
330
  }))
384
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
385
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('foo')))
386
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
331
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
332
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
333
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
334
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('foo')))
335
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: true }))
387
336
  .command(['publish', '--registry-only'])
388
337
  .it('update assets', ctx => {
389
338
  (0, test_1.expect)(ctx.stdout).to.contain('image: <set>');
@@ -391,26 +340,8 @@ describe('Publish', () => {
391
340
  });
392
341
  test_1.test
393
342
  .stdout()
394
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
395
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
396
- authorizations: [
397
- {
398
- name: 'foo',
399
- method: 'custom',
400
- },
401
- ],
402
- }))
403
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
404
- .stub(FileSystem, 'getFileBuffer', () => Promise.reject())
405
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
406
- .command(['publish', '--registry-only'])
407
- .it('it logs error if file exceeds max size', ctx => {
408
- (0, test_1.expect)(ctx.stdout).to.contain('File exceeds the size limit');
409
- });
410
- test_1.test
411
- .stdout()
412
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
413
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
343
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
344
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
414
345
  authorizations: [
415
346
  {
416
347
  name: 'foo',
@@ -418,9 +349,11 @@ describe('Publish', () => {
418
349
  },
419
350
  ],
420
351
  }))
421
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
422
- .stub(FileSystem, 'getFileBuffer', () => null)
423
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
352
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
353
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(null))
354
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: true }))
355
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
356
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
424
357
  .command(['publish', '--registry-only'])
425
358
  .it('it defaults instructions to null if no file in assets folder', ctx => {
426
359
  (0, test_1.expect)(ctx.stdout).to.contain('image: <unset>');