@unito/integration-cli 0.57.1 → 0.58.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 (115) hide show
  1. package/dist/.eslintrc.d.ts +6 -0
  2. package/dist/.eslintrc.js +9 -2
  3. package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/src/index.ts +1 -3
  4. package/dist/src/commands/activity.d.ts +2 -2
  5. package/dist/src/commands/activity.js +2 -2
  6. package/dist/src/commands/dev.d.ts +8 -4
  7. package/dist/src/commands/dev.js +42 -5
  8. package/dist/src/commands/encrypt.d.ts +1 -1
  9. package/dist/src/commands/encrypt.js +1 -1
  10. package/dist/src/commands/init.d.ts +1 -1
  11. package/dist/src/commands/init.js +3 -3
  12. package/dist/src/commands/invite.d.ts +1 -1
  13. package/dist/src/commands/invite.js +2 -2
  14. package/dist/src/commands/login.d.ts +1 -1
  15. package/dist/src/commands/login.js +1 -1
  16. package/dist/src/commands/oauth2.d.ts +3 -3
  17. package/dist/src/commands/oauth2.js +19 -14
  18. package/dist/src/commands/publish.d.ts +2 -2
  19. package/dist/src/commands/publish.js +12 -12
  20. package/dist/src/commands/test.js +32 -8
  21. package/dist/src/commands/upgrade.js +3 -3
  22. package/dist/src/errors.d.ts +8 -0
  23. package/dist/src/errors.js +35 -18
  24. package/dist/src/resources/configuration.js +0 -2
  25. package/dist/src/resources/credentials.d.ts +3 -0
  26. package/dist/src/resources/credentials.js +26 -0
  27. package/dist/src/resources/integrations.d.ts +1 -0
  28. package/dist/src/resources/integrations.js +37 -2
  29. package/dist/src/resources/oauth2Helper.d.ts +4 -0
  30. package/dist/src/resources/oauth2Helper.js +30 -0
  31. package/dist/src/services/integrationsPlatform.d.ts +1 -0
  32. package/dist/src/services/integrationsPlatform.js +5 -1
  33. package/dist/src/services/oauth2Helper.d.ts +78 -3
  34. package/dist/src/services/oauth2Helper.js +229 -29
  35. package/dist/test/commands/activity.test.js +12 -9
  36. package/dist/test/commands/dev.test.js +59 -10
  37. package/dist/test/commands/encrypt.test.js +6 -7
  38. package/dist/test/commands/init.test.js +7 -9
  39. package/dist/test/commands/invite.test.js +11 -11
  40. package/dist/test/commands/login.test.js +20 -23
  41. package/dist/test/commands/oauth2.test.js +6 -2
  42. package/dist/test/commands/publish.test.js +152 -218
  43. package/dist/test/commands/test.test.js +65 -13
  44. package/dist/test/commands/upgrade.test.js +4 -6
  45. package/dist/test/errors.test.js +36 -36
  46. package/dist/test/helpers/integrations.d.ts +26 -0
  47. package/dist/test/helpers/integrations.js +25 -0
  48. package/dist/test/helpers/styles.d.ts +1 -0
  49. package/dist/test/helpers/styles.js +8 -0
  50. package/dist/test/oauth2Helper/oauth2Helper.test.js +112 -128
  51. package/dist/test/resources/configuration.test.js +24 -24
  52. package/dist/test/resources/decryption.test.js +9 -9
  53. package/dist/test/resources/globalConfiguration.test.js +4 -4
  54. package/dist/test/resources/integrations.test.js +37 -0
  55. package/dist/test/resources/oauth2Helper.test.js +55 -0
  56. package/dist/test/services/integrationsPlatform.test.js +20 -20
  57. package/oclif.manifest.json +64 -9
  58. package/package.json +10 -14
  59. package/dist/integrationGenerator/errors.d.ts +0 -2
  60. package/dist/integrationGenerator/errors.js +0 -6
  61. package/dist/integrationGenerator/index.d.ts +0 -2
  62. package/dist/integrationGenerator/index.js +0 -5
  63. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.dockerignore +0 -3
  64. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.eslintrc.js +0 -74
  65. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.nvmrc +0 -1
  66. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierignore +0 -1
  67. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierrc +0 -7
  68. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.unito.json +0 -1
  69. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/Dockerfile +0 -38
  70. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/README.md +0 -21
  71. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/index.ts +0 -94
  72. package/dist/integrationGenerator/integrationBoilerplate/package.json +0 -43
  73. package/dist/integrationGenerator/integrationBoilerplate/src/logger.ts +0 -55
  74. package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/additionalLoggingContext.ts +0 -22
  75. package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/correlationId.ts +0 -13
  76. package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/credentials.ts +0 -38
  77. package/dist/integrationGenerator/integrationBoilerplate/src/request.ts +0 -59
  78. package/dist/integrationGenerator/integrationBoilerplate/src/routes/index.ts +0 -11
  79. package/dist/integrationGenerator/integrationBoilerplate/src/routes/me.ts +0 -15
  80. package/dist/integrationGenerator/integrationBoilerplate/src/routes/root.ts +0 -12
  81. package/dist/integrationGenerator/integrationBoilerplate/tsconfig.json +0 -37
  82. package/dist/integrationGenerator/src/index.d.ts +0 -1
  83. package/dist/integrationGenerator/src/index.js +0 -5
  84. package/dist/integrationGenerator/src/resources/index.d.ts +0 -1
  85. package/dist/integrationGenerator/src/resources/index.js +0 -5
  86. package/dist/integrationGenerator/src/resources/integration.d.ts +0 -9
  87. package/dist/integrationGenerator/src/resources/integration.js +0 -60
  88. package/dist/integrationGenerator/test/resources/integration.test.js +0 -51
  89. package/dist/src/oauth2Helper/oauth2Helper.d.ts +0 -63
  90. package/dist/src/oauth2Helper/oauth2Helper.js +0 -235
  91. package/dist/src/oauth2Helper/types.d.ts +0 -22
  92. package/dist/src/oauth2Helper/types.js +0 -2
  93. package/dist/test/mocha.hooks.d.ts +0 -2
  94. package/dist/test/mocha.hooks.js +0 -37
  95. package/dist/test/services/oauth2Helper.test.js +0 -85
  96. /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.dockerignore +0 -0
  97. /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.eslintrc.js +0 -0
  98. /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.nvmrc +0 -0
  99. /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.prettierignore +0 -0
  100. /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.prettierrc +0 -0
  101. /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.unito.json +0 -0
  102. /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/Dockerfile +0 -0
  103. /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/README.md +0 -0
  104. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/package.json +0 -0
  105. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/logger.ts +0 -0
  106. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/additionalLoggingContext.ts +0 -0
  107. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/correlationId.ts +0 -0
  108. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/credentials.ts +0 -0
  109. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/request.ts +0 -0
  110. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/index.ts +0 -0
  111. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/me.ts +0 -0
  112. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/root.ts +0 -0
  113. /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/tsconfig.json +0 -0
  114. /package/dist/{integrationGenerator/test/resources/integration.test.d.ts → test/resources/integrations.test.d.ts} +0 -0
  115. /package/dist/test/{services → resources}/oauth2Helper.test.d.ts +0 -0
@@ -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,27 @@ 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
+ .stderr()
262
+ .stub(GlobalConfiguration, 'read', stub => stub.throws(new errors_1.NoConfigurationFileError()))
263
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
320
264
  .command(['publish'])
321
265
  .exit(-1)
322
266
  .it('handles exception');
323
267
  test_1.test
324
268
  .stdout()
325
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
326
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
269
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
270
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
327
271
  name: 'myIntegration',
328
272
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'unito-secret-' } }],
329
273
  secrets: { secret1: 'unito-secret-', invalidSecret: 'Should never happen anyway' },
330
274
  }))
331
- .stub(IntegrationConfiguration, 'writeConfiguration', () => ({
275
+ .stub(IntegrationConfiguration, 'writeConfiguration', stub => stub.returns({
332
276
  name: 'myIntegration',
333
277
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'unito-secret-' } }],
334
278
  secrets: { secret1: 'unito-secret-', invalidSecret: 'Should never happen anyway' },
335
279
  }))
336
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
337
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
280
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
281
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
338
282
  .command(['publish', '--preview'])
339
283
  .it('reencrypts the clientSecret on preview', ctx => {
340
284
  (0, test_1.expect)(ctx.stdout).to.contain('Reencrypting oauth2:clientSecret');
@@ -343,14 +287,16 @@ describe('Publish', () => {
343
287
  });
344
288
  test_1.test
345
289
  .stdout()
346
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
347
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
290
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
291
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
348
292
  name: 'myIntegration',
349
293
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'unito-secret-' } }],
350
294
  secrets: { secret1: 'unito-secret-', invalidSecret: 'Should never happen anyway' },
351
295
  }))
352
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
353
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
296
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
297
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
298
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
299
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
354
300
  .command(['publish', '--live-preview'])
355
301
  .it('reencrypts the clientSecret on live-preview', ctx => {
356
302
  (0, test_1.expect)(ctx.stdout).to.contain('Reencrypting oauth2:clientSecret');
@@ -359,21 +305,23 @@ describe('Publish', () => {
359
305
  });
360
306
  test_1.test
361
307
  .stdout()
362
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
363
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
308
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
309
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
364
310
  name: 'myIntegration',
365
311
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'toto' } }],
366
312
  }))
367
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
368
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
313
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
314
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
315
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
316
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('')))
369
317
  .command(['publish', '--live-preview'])
370
318
  .it('skips reencryption', ctx => {
371
319
  (0, test_1.expect)(ctx.stdout).to.contain('Skipping oauth2:clientSecret');
372
320
  });
373
321
  test_1.test
374
322
  .stdout()
375
- .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
376
- .stub(IntegrationConfiguration, 'getConfiguration', () => ({
323
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
324
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
377
325
  authorizations: [
378
326
  {
379
327
  name: 'foo',
@@ -381,9 +329,11 @@ describe('Publish', () => {
381
329
  },
382
330
  ],
383
331
  }))
384
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
385
- .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('foo')))
386
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
332
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
333
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
334
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
335
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(Buffer.from('foo')))
336
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: true }))
387
337
  .command(['publish', '--registry-only'])
388
338
  .it('update assets', ctx => {
389
339
  (0, test_1.expect)(ctx.stdout).to.contain('image: <set>');
@@ -391,26 +341,8 @@ describe('Publish', () => {
391
341
  });
392
342
  test_1.test
393
343
  .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', () => ({
344
+ .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
345
+ .stub(IntegrationConfiguration, 'getConfiguration', stub => stub.returns({
414
346
  authorizations: [
415
347
  {
416
348
  name: 'foo',
@@ -418,9 +350,11 @@ describe('Publish', () => {
418
350
  },
419
351
  ],
420
352
  }))
421
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
422
- .stub(FileSystem, 'getFileBuffer', () => null)
423
- .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
353
+ .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.returns(undefined))
354
+ .stub(FileSystem, 'getFileBuffer', stub => stub.resolves(null))
355
+ .stub(inquirer_1.default, 'prompt', stub => stub.resolves({ proceed: true }))
356
+ .stub(IntegrationsPlatform, 'createIntegration', stub => stub.resolves(integration))
357
+ .stub(IntegrationsPlatform, 'updateIntegration', stub => stub.resolves(integration))
424
358
  .command(['publish', '--registry-only'])
425
359
  .it('it defaults instructions to null if no file in assets folder', ctx => {
426
360
  (0, test_1.expect)(ctx.stdout).to.contain('image: <unset>');