mcdev 5.1.0 → 5.2.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 (192) hide show
  1. package/.eslintrc.json +4 -4
  2. package/.github/ISSUE_TEMPLATE/bug.yml +1 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +2 -2
  4. package/.github/workflows/coverage-develop-branch.yml +0 -2
  5. package/.github/workflows/coverage-main-branch.yml +0 -2
  6. package/.github/workflows/coverage.yml +0 -2
  7. package/.husky/post-checkout +1 -0
  8. package/.husky/post-merge +1 -0
  9. package/.vscode/extensions.json +4 -0
  10. package/docs/dist/documentation.md +633 -286
  11. package/lib/Deployer.js +25 -25
  12. package/lib/MetadataTypeDefinitions.js +1 -1
  13. package/lib/MetadataTypeInfo.js +1 -1
  14. package/lib/Retriever.js +1 -1
  15. package/lib/cli.js +159 -9
  16. package/lib/index.js +395 -95
  17. package/lib/metadataTypes/Asset.js +10 -11
  18. package/lib/metadataTypes/AttributeGroup.js +76 -2
  19. package/lib/metadataTypes/AttributeSet.js +260 -0
  20. package/lib/metadataTypes/Automation.js +413 -96
  21. package/lib/metadataTypes/DataExtension.js +2 -2
  22. package/lib/metadataTypes/DataExtensionField.js +1 -1
  23. package/lib/metadataTypes/Event.js +2 -3
  24. package/lib/metadataTypes/Folder.js +1 -1
  25. package/lib/metadataTypes/Journey.js +5 -6
  26. package/lib/metadataTypes/MetadataType.js +149 -49
  27. package/lib/metadataTypes/MobileKeyword.js +8 -8
  28. package/lib/metadataTypes/MobileMessage.js +5 -5
  29. package/lib/metadataTypes/Query.js +26 -10
  30. package/lib/metadataTypes/Script.js +3 -3
  31. package/lib/metadataTypes/TransactionalSMS.js +5 -5
  32. package/lib/metadataTypes/TriggeredSend.js +25 -50
  33. package/lib/metadataTypes/User.js +7 -4
  34. package/lib/metadataTypes/definitions/AttributeGroup.definition.js +117 -106
  35. package/lib/metadataTypes/definitions/{SetDefinition.definition.js → AttributeSet.definition.js} +54 -27
  36. package/lib/metadataTypes/definitions/Automation.definition.js +22 -15
  37. package/lib/metadataTypes/definitions/ImportFile.definition.js +36 -6
  38. package/lib/metadataTypes/definitions/TriggeredSend.definition.js +1 -0
  39. package/lib/util/cache.js +9 -4
  40. package/lib/util/cli.js +40 -0
  41. package/lib/util/file.js +2 -2
  42. package/lib/util/init.js +84 -0
  43. package/lib/util/util.js +121 -13
  44. package/package.json +11 -11
  45. package/test/mockRoot/.mcdevrc.json +1 -1
  46. package/test/mockRoot/deploy/testInstance/testBU/automation/testExisting_automation.automation-meta.json +1 -2
  47. package/test/mockRoot/deploy/testInstance/testBU/automation/testNew_automation.automation-meta.json +5 -6
  48. package/test/mockRoot/deploy/testInstance/testBU/dataExtract/testExisting_dataExtract.dataExtract-meta.json +35 -0
  49. package/test/mockRoot/deploy/testInstance/testBU/dataExtract/testNew_dataExtract.dataExtract-meta.json +35 -0
  50. package/test/mockRoot/deploy/testInstance/testBU/fileTransfer/testExisting_fileTransfer.fileTransfer-meta.json +17 -0
  51. package/test/mockRoot/deploy/testInstance/testBU/fileTransfer/testNew_fileTransfer.fileTransfer-meta.json +17 -0
  52. package/test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile.importFile-meta.json +29 -0
  53. package/test/mockRoot/deploy/testInstance/testBU/importFile/testNew_importFile.importFile-meta.json +29 -0
  54. package/test/mockRoot/deploy/testInstance/testBU/query/testExisting_query_fixKeys.query-meta.json +11 -0
  55. package/test/mockRoot/deploy/testInstance/testBU/query/testExisting_query_fixKeys.query-meta.sql +6 -0
  56. package/test/mockRoot/deploy/testInstance/testBU/script/testExisting_script.script-meta.json +6 -0
  57. package/test/mockRoot/deploy/testInstance/testBU/script/testExisting_script.script-meta.ssjs +1 -0
  58. package/test/mockRoot/deploy/testInstance/testBU/script/testNew_script.script-meta.json +6 -0
  59. package/test/mockRoot/deploy/testInstance/testBU/script/testNew_script.script-meta.ssjs +1 -0
  60. package/test/mockRoot/deploy/testInstance/testBU/triggeredSend/testExisting_triggeredSend.triggeredSend-meta.json +29 -0
  61. package/test/mockRoot/deploy/testInstance/testBU/triggeredSend/testNew_triggeredSend.triggeredSend-meta.json +29 -0
  62. package/test/resourceFactory.js +77 -12
  63. package/test/resources/1111111/accountUser/retrieve-ActiveFlag=falseANDCustomerKey=testExisting_userANDEmaillike@-response.xml +27 -0
  64. package/test/resources/1111111/accountUser/retrieve-ActiveFlag=falseANDEmaillike@-response.xml +156 -0
  65. package/test/resources/1111111/accountUser/retrieve-ActiveFlag=trueANDEmailisNullORNamelikeapp userANDMustChangePassword=false-response.xml +87 -0
  66. package/test/resources/1111111/accountUser/retrieve-ActiveFlag=trueANDEmaillike@-response.xml +156 -0
  67. package/test/resources/1111111/accountUser/retrieve-CustomerKey=testExisting_userANDActiveFlag=trueANDEmailisNullORNamelikeapp userANDMustChangePassword=false-response.xml +27 -0
  68. package/test/resources/1111111/accountUserAccount/retrieve-AccountUser.AccountUserID=700301950-response.xml +60 -0
  69. package/test/resources/1111111/user/retrieve-expected.md +4 -2
  70. package/test/resources/9999999/attributeGroup/retrieve-expected.json +25 -0
  71. package/test/resources/9999999/attributeSet/retrieve-expected.json +748 -0
  72. package/test/resources/9999999/automation/build-expected.json +1 -2
  73. package/test/resources/9999999/automation/create-expected.json +7 -8
  74. package/test/resources/9999999/automation/create-testNew_automation-expected.md +4 -4
  75. package/test/resources/9999999/automation/patch_fixKeys-pause-expected.json +44 -0
  76. package/test/resources/9999999/automation/patch_fixKeys-schedule-expected.json +44 -0
  77. package/test/resources/9999999/automation/perform-08afb0e2-b00a-4c88-ad2e-1f7f8788c560-response.xml +42 -0
  78. package/test/resources/9999999/automation/perform-08afb0e2-b00a-4c88-fixKey_pause-response.xml +42 -0
  79. package/test/resources/9999999/automation/perform-08afb0e2-b00a-4c88-fixKey_schedule-response.xml +42 -0
  80. package/test/resources/9999999/automation/perform-a8afb0e2-b00a-4c88-ad2e-1f7f8788c560-response.xml +42 -0
  81. package/test/resources/9999999/automation/retrieve-expected.json +1 -2
  82. package/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md +2 -2
  83. package/test/resources/9999999/automation/schedule-08afb0e2-b00a-4c88-ad2e-1f7f8788c560-response.xml +52 -0
  84. package/test/resources/9999999/automation/schedule-08afb0e2-b00a-4c88-ad2e-pause-response.xml +38 -0
  85. package/test/resources/9999999/automation/schedule-08afb0e2-b00a-4c88-fixKey_pause-response.xml +52 -0
  86. package/test/resources/9999999/automation/schedule-08afb0e2-b00a-4c88-fixKey_schedule-response.xml +52 -0
  87. package/test/resources/9999999/automation/schedule-a8afb0e2-b00a-4c88-ad2e-1f7f8788c560-response.xml +52 -0
  88. package/test/resources/9999999/automation/template-expected.json +1 -2
  89. package/test/resources/9999999/automation/update-expected.json +1 -2
  90. package/test/resources/9999999/automation/update-testExisting_automation-expected.md +2 -2
  91. package/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-pause/get-response.json +85 -0
  92. package/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-pause/patch-response.json +85 -0
  93. package/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-fixKey_pause/get-response.json +85 -0
  94. package/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-fixKey_pause/patch-response.json +85 -0
  95. package/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-fixKey_schedule/get-response.json +85 -0
  96. package/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-fixKey_schedule/patch-response.json +85 -0
  97. package/test/resources/9999999/automation/v1/automations/a8afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json +1 -1
  98. package/test/resources/9999999/automation/v1/automations/post-response.json +20 -19
  99. package/test/resources/9999999/automation/v1/dataextracts/56c5370a-f988-4f36-b0ee-0f876573f6d7/patch-response.json +38 -0
  100. package/test/resources/9999999/automation/v1/dataextracts/post-response.json +38 -0
  101. package/test/resources/9999999/automation/v1/dataextracttypes/get-response.json +50 -0
  102. package/test/resources/9999999/automation/v1/filetransfers/72c328ac-f5b0-4e37-91d3-a775666f15a6/patch-response.json +18 -0
  103. package/test/resources/9999999/automation/v1/filetransfers/post-response.json +18 -0
  104. package/test/resources/9999999/automation/v1/ftplocations/get-response.json +18 -0
  105. package/test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b/patch-response.json +31 -0
  106. package/test/resources/9999999/automation/v1/imports/get-response.json +1 -1
  107. package/test/resources/9999999/automation/v1/imports/post-response.json +30 -0
  108. package/test/resources/9999999/automation/v1/queries/549f0568-607c-4940-afef-437965094dae/actions/start/post-response.txt +1 -0
  109. package/test/resources/9999999/automation/v1/queries/549f0568-607c-4940-afef-437965094dat_fixKeys/get-response.json +17 -0
  110. package/test/resources/9999999/automation/v1/queries/549f0568-607c-4940-afef-437965094dat_fixKeys/patch-response.json +18 -0
  111. package/test/resources/9999999/automation/v1/queries/get-response.json +18 -1
  112. package/test/resources/9999999/automation/v1/scripts/39f6a488-20eb-4ba0-b0b9-023725b574e4/patch-response.json +10 -0
  113. package/test/resources/9999999/automation/v1/scripts/get-response.json +12 -2
  114. package/test/resources/9999999/automation/v1/scripts/post-response.json +10 -0
  115. package/test/resources/9999999/dataExtension/retrieve-Name=testExisting_dataExtension-response.xml +52 -0
  116. package/test/resources/9999999/dataExtensionField/retrieve-DataExtension.CustomerKey=testExisting_dataExtension-response.xml +98 -0
  117. package/test/resources/9999999/dataExtensionField/retrieve-DataExtension.CustomerKey=testNew_dataExtensionORDataExtension.CustomerKey=testExisting_dataExtension-response.xml +99 -0
  118. package/test/resources/9999999/dataExtract/build-expected.json +35 -0
  119. package/test/resources/9999999/dataExtract/get-expected.json +39 -0
  120. package/test/resources/9999999/dataExtract/patch-expected.json +37 -0
  121. package/test/resources/9999999/dataExtract/post-expected.json +37 -0
  122. package/test/resources/9999999/dataExtract/template-expected.json +35 -0
  123. package/test/resources/9999999/dataFolder/retrieve-ContentType=contextual_suppression_listORContentType=publicationORContentType=suppression_listORContentType=mysubsORContentType=list-response.xml +136 -0
  124. package/test/resources/9999999/dataFolder/retrieve-ContentType=ssjsactivity-response.xml +48 -0
  125. package/test/resources/9999999/dataFolder/retrieve-ContentType=triggered_send_journeybuilderORContentType=triggered_sendORContentType=hidden-response.xml +276 -0
  126. package/test/resources/9999999/dataFolder/retrieve-response.xml +23 -0
  127. package/test/resources/9999999/email/retrieve-response.xml +203 -0
  128. package/test/resources/9999999/fileTransfer/build-expected.json +15 -0
  129. package/test/resources/9999999/fileTransfer/get-expected.json +17 -0
  130. package/test/resources/9999999/fileTransfer/patch-expected.json +17 -0
  131. package/test/resources/9999999/fileTransfer/post-expected.json +17 -0
  132. package/test/resources/9999999/fileTransfer/template-expected.json +15 -0
  133. package/test/resources/9999999/hub/v1/contacts/schema/attributeGroups/get-response.json +585 -0
  134. package/test/resources/9999999/hub/v1/contacts/schema/setDefinitions/get-response.json +19807 -0
  135. package/test/resources/9999999/importFile/build-expected.json +27 -0
  136. package/test/resources/9999999/importFile/get-expected.json +29 -0
  137. package/test/resources/9999999/importFile/patch-expected.json +29 -0
  138. package/test/resources/9999999/importFile/post-expected.json +29 -0
  139. package/test/resources/9999999/importFile/template-expected.json +27 -0
  140. package/test/resources/9999999/program/retrieve-CustomerKey=testExisting_automation_fixKey_pause-response.xml +32 -0
  141. package/test/resources/9999999/program/retrieve-CustomerKey=testExisting_automation_fixKey_schedule-response.xml +32 -0
  142. package/test/resources/9999999/program/retrieve-CustomerKey=testExisting_automation_fixedKey_paused-response.xml +32 -0
  143. package/test/resources/9999999/program/retrieve-CustomerKey=testExisting_automation_fixedKey_scheduled-response.xml +32 -0
  144. package/test/resources/9999999/program/retrieve-CustomerKey=testExisting_automation_pause-response.xml +30 -0
  145. package/test/resources/9999999/program/retrieve-response.xml +21 -3
  146. package/test/resources/9999999/query/patch_fixKeys-expected.json +11 -0
  147. package/test/resources/9999999/query/patch_fixKeys-expected.sql +6 -0
  148. package/test/resources/9999999/queryDefinition/retrieve-CustomerKey=testExisting_query_fixKeysANDStatus=Active-response.xml +30 -0
  149. package/test/resources/9999999/queryDefinition/retrieve-CustomerKey=testExisting_query_fixedKeysANDStatus=Active-response.xml +30 -0
  150. package/test/resources/9999999/queryDefinition/retrieve-CustomerKey=testNew_queryANDStatus=Active-response.xml +30 -0
  151. package/test/resources/9999999/script/build-expected.json +6 -0
  152. package/test/resources/9999999/script/build-expected.ssjs +1 -0
  153. package/test/resources/9999999/script/get-expected.json +8 -0
  154. package/test/resources/9999999/script/get-expected.ssjs +1 -0
  155. package/test/resources/9999999/script/get_noScriptTag-expected.html +1 -0
  156. package/test/resources/9999999/script/get_noScriptTag-expected.json +8 -0
  157. package/test/resources/9999999/script/patch-expected.json +8 -0
  158. package/test/resources/9999999/script/patch-expected.ssjs +1 -0
  159. package/test/resources/9999999/script/post-expected.json +8 -0
  160. package/test/resources/9999999/script/post-expected.ssjs +1 -0
  161. package/test/resources/9999999/script/template-expected.json +6 -0
  162. package/test/resources/9999999/script/template-expected.ssjs +1 -0
  163. package/test/resources/9999999/triggeredSend/build-expected.json +29 -0
  164. package/test/resources/9999999/triggeredSend/get-expected.json +29 -0
  165. package/test/resources/9999999/triggeredSend/patch-expected.json +29 -0
  166. package/test/resources/9999999/triggeredSend/post-expected.json +29 -0
  167. package/test/resources/9999999/triggeredSend/template-expected.json +29 -0
  168. package/test/resources/9999999/triggeredSendDefinition/create-response.xml +75 -0
  169. package/test/resources/9999999/triggeredSendDefinition/delete-response.xml +36 -0
  170. package/test/resources/9999999/triggeredSendDefinition/{retrieve-response.xml → retrieve-TriggeredSendStatusINNew,Active,Inactive,Moved,Canceled-response.xml} +4 -4
  171. package/test/resources/9999999/triggeredSendDefinition/update-response.xml +74 -0
  172. package/test/type.attributeGroup.test.js +55 -0
  173. package/test/type.attributeSet.test.js +55 -0
  174. package/test/type.automation.test.js +638 -11
  175. package/test/type.dataExtension.test.js +0 -1
  176. package/test/type.dataExtract.test.js +187 -0
  177. package/test/type.fileTransfer.test.js +185 -0
  178. package/test/type.importFile.test.js +186 -0
  179. package/test/type.mobileKeyword.test.js +0 -1
  180. package/test/type.query.test.js +464 -13
  181. package/test/type.script.test.js +367 -0
  182. package/test/type.triggeredSend.test.js +152 -0
  183. package/test/type.user.test.js +22 -10
  184. package/test/utils.js +4 -1
  185. package/lib/metadataTypes/SetDefinition.js +0 -37
  186. /package/test/resources/1111111/accountUser/{retrieve-response.xml → retrieve-ActiveFlag=trueANDCustomerKey=testExisting_userANDEmaillike@-response.xml} +0 -0
  187. /package/test/resources/1111111/accountUserAccount/{retrieve-response.xml → retrieve-AccountUser.AccountUserIDIN700301950,700301951,7471228-response.xml} +0 -0
  188. /package/test/resources/1111111/businessUnit/{retrieve-response.xml → retrieve-ID=1111111-response.xml} +0 -0
  189. /package/test/resources/1111111/list/{retrieve-response.xml → retrieve-CustomerKey=All SubscribersORListName=All Subscribers-response.xml} +0 -0
  190. /package/test/resources/1111111/role/{retrieve-response.xml → retrieve-IsPrivate=false-response.xml} +0 -0
  191. /package/test/resources/9999999/emailSendDefinition/{retrieve-response.xml → retrieve-IsPlatformObject=falseANDDescriptionnotEqualsSFSendDefinition-response.xml} +0 -0
  192. /package/test/resources/9999999/queryDefinition/{retrieve-response.xml → retrieve-CustomerKey=testExisting_queryANDStatus=Active-response.xml} +0 -0
@@ -27,8 +27,8 @@ describe('type: automation', () => {
27
27
  const result = cache.getCache();
28
28
  assert.equal(
29
29
  result.automation ? Object.keys(result.automation).length : 0,
30
- 1,
31
- 'only one automation expected'
30
+ 4,
31
+ 'only four automations expected'
32
32
  );
33
33
  assert.deepEqual(
34
34
  await testUtils.getActualJson('testExisting_automation', 'automation'),
@@ -50,7 +50,7 @@ describe('type: automation', () => {
50
50
 
51
51
  assert.equal(
52
52
  testUtils.getAPIHistoryLength(),
53
- 14,
53
+ 17,
54
54
  'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
55
55
  );
56
56
  return;
@@ -62,16 +62,25 @@ describe('type: automation', () => {
62
62
  });
63
63
  it('Should create & update a automation', async () => {
64
64
  // WHEN
65
- await handler.deploy('testInstance/testBU', ['automation']);
65
+ const deployResult = await handler.deploy('testInstance/testBU', ['automation']);
66
66
  // THEN
67
67
  assert.equal(process.exitCode, false, 'deploy should not have thrown an error');
68
68
 
69
- // get results from cache
70
- const result = cache.getCache();
69
+ // check how many items were deployed
71
70
  assert.equal(
72
- result.automation ? Object.keys(result.automation).length : 0,
71
+ deployResult['testInstance/testBU']?.automation
72
+ ? Object.keys(deployResult['testInstance/testBU']?.automation).length
73
+ : 0,
73
74
  2,
74
- 'two automations expected'
75
+ 'two automations to be deployed'
76
+ );
77
+
78
+ // get results from cache
79
+ const cacheResult = cache.getCache();
80
+ assert.equal(
81
+ cacheResult.automation ? Object.keys(cacheResult.automation).length : 0,
82
+ 5,
83
+ 'three automations expected'
75
84
  );
76
85
  // insert
77
86
  assert.deepEqual(
@@ -111,12 +120,437 @@ describe('type: automation', () => {
111
120
 
112
121
  assert.equal(
113
122
  testUtils.getAPIHistoryLength(),
114
- 15,
123
+ 16,
124
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
125
+ );
126
+ return;
127
+ });
128
+ it('Should update & schedule an automation with --schedule option', async () => {
129
+ // WHEN
130
+ handler.setOptions({ schedule: true });
131
+ const deployed = await handler.deploy(
132
+ 'testInstance/testBU',
133
+ ['automation'],
134
+ ['testExisting_automation', 'testNew_automation']
135
+ );
136
+ // THEN
137
+ assert.equal(
138
+ process.exitCode,
139
+ false,
140
+ 'deploy with --execute should not have thrown an error'
141
+ );
142
+
143
+ // get results from cache
144
+ const cached = cache.getCache();
145
+ assert.equal(
146
+ cached.automation ? Object.keys(cached.automation).length : 0,
147
+ 5,
148
+ 'five cached automation expected'
149
+ );
150
+ assert.equal(
151
+ deployed['testInstance/testBU'].automation
152
+ ? Object.keys(deployed['testInstance/testBU'].automation).length
153
+ : 0,
154
+ 2,
155
+ 'two deployed automation expected'
156
+ );
157
+ assert.equal(
158
+ deployed['testInstance/testBU'].automation
159
+ ? Object.keys(deployed['testInstance/testBU'].automation)[0]
160
+ : null,
161
+ 'testNew_automation',
162
+ 'expected specific automation to have been deployed'
163
+ );
164
+ assert.equal(
165
+ deployed['testInstance/testBU'].automation
166
+ ? Object.keys(deployed['testInstance/testBU'].automation)[1]
167
+ : null,
168
+ 'testExisting_automation',
169
+ 'expected specific automation to have been deployed'
170
+ );
171
+
172
+ // update
173
+ assert.deepEqual(
174
+ await testUtils.getActualJson('testExisting_automation', 'automation'),
175
+ await testUtils.getExpectedJson('9999999', 'automation', 'update'),
176
+ 'returned metadata was not equal expected for update'
177
+ );
178
+ // check if MD file was created and equals expectations
179
+ expect(file(testUtils.getActualDoc('testExisting_automation', 'automation'))).to.equal(
180
+ file(
181
+ testUtils.getExpectedFile(
182
+ '9999999',
183
+ 'automation',
184
+ 'update-testExisting_automation',
185
+ 'md'
186
+ )
187
+ )
188
+ );
189
+
190
+ assert.equal(
191
+ testUtils.getAPIHistoryLength(),
192
+ 24,
193
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
194
+ );
195
+ return;
196
+ });
197
+ it('Should update & runOnce an automation with --execute option', async () => {
198
+ // WHEN
199
+ handler.setOptions({ execute: true });
200
+ const deployed = await handler.deploy(
201
+ 'testInstance/testBU',
202
+ ['automation'],
203
+ ['testExisting_automation', 'testNew_automation']
204
+ );
205
+ // THEN
206
+ assert.equal(
207
+ process.exitCode,
208
+ false,
209
+ 'deploy with --execute should not have thrown an error'
210
+ );
211
+
212
+ // get results from cache
213
+ const cached = cache.getCache();
214
+ assert.equal(
215
+ cached.automation ? Object.keys(cached.automation).length : 0,
216
+ 5,
217
+ 'five cached automation expected'
218
+ );
219
+ assert.equal(
220
+ deployed['testInstance/testBU'].automation
221
+ ? Object.keys(deployed['testInstance/testBU'].automation).length
222
+ : 0,
223
+ 2,
224
+ 'two deployed automation expected'
225
+ );
226
+ assert.equal(
227
+ deployed['testInstance/testBU'].automation
228
+ ? Object.keys(deployed['testInstance/testBU'].automation)[0]
229
+ : null,
230
+ 'testNew_automation',
231
+ 'expected specific automation to have been deployed'
232
+ );
233
+ assert.equal(
234
+ deployed['testInstance/testBU'].automation
235
+ ? Object.keys(deployed['testInstance/testBU'].automation)[1]
236
+ : null,
237
+ 'testExisting_automation',
238
+ 'expected specific automation to have been deployed'
239
+ );
240
+ // update
241
+ assert.deepEqual(
242
+ await testUtils.getActualJson('testExisting_automation', 'automation'),
243
+ await testUtils.getExpectedJson('9999999', 'automation', 'update'),
244
+ 'returned metadata was not equal expected for update'
245
+ );
246
+ // check if MD file was created and equals expectations
247
+ expect(file(testUtils.getActualDoc('testExisting_automation', 'automation'))).to.equal(
248
+ file(
249
+ testUtils.getExpectedFile(
250
+ '9999999',
251
+ 'automation',
252
+ 'update-testExisting_automation',
253
+ 'md'
254
+ )
255
+ )
256
+ );
257
+
258
+ assert.equal(
259
+ testUtils.getAPIHistoryLength(),
260
+ 20,
261
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
262
+ );
263
+ return;
264
+ });
265
+ });
266
+ describe('FixKeys ================', () => {
267
+ beforeEach(() => {
268
+ testUtils.mockSetup(true);
269
+ });
270
+ it('Should run fixKeys but not find fixable keys and hence stop', async () => {
271
+ // WHEN
272
+ handler.setOptions({ skipInteraction: { fixKeysReretrieve: false } });
273
+ const resultFixKeys = await handler.fixKeys('testInstance/testBU', 'automation', [
274
+ 'testExisting_automation',
275
+ ]);
276
+ // THEN
277
+ assert.equal(process.exitCode, false, 'fixKeys should not have thrown an error');
278
+ // check which keys were fixed
279
+ assert.equal(
280
+ resultFixKeys['testInstance/testBU'].length,
281
+ 0,
282
+ 'expected to find no keys to be fixed'
283
+ );
284
+
285
+ // get results from cache
286
+ const result = cache.getCache();
287
+ assert.equal(
288
+ result.automation ? Object.keys(result.automation).length : 0,
289
+ 1,
290
+ 'one automation expected'
291
+ );
292
+ // check number of API calls
293
+ assert.equal(
294
+ testUtils.getAPIHistoryLength(),
295
+ 14,
296
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
297
+ );
298
+ return;
299
+ });
300
+ it('Should fixKeys by key w/o re-retrieving, auto-schedule', async () => {
301
+ // WHEN
302
+ handler.setOptions({ skipInteraction: { fixKeysReretrieve: false } });
303
+ const resultFixKeys = await handler.fixKeys('testInstance/testBU', 'automation', [
304
+ 'testExisting_automation_fixKey_schedule',
305
+ 'testExisting_automation',
306
+ ]);
307
+ assert.equal(
308
+ resultFixKeys['testInstance/testBU'].length,
309
+ 1,
310
+ 'returned number of keys does not correspond to number of expected fixed keys'
311
+ );
312
+ assert.equal(
313
+ resultFixKeys['testInstance/testBU'][0],
314
+ 'testExisting_automation_fixedKey_scheduled',
315
+ 'returned keys do not correspond to expected fixed keys'
316
+ );
317
+ // THEN
318
+ assert.equal(process.exitCode, false, 'fixKeys should not have thrown an error');
319
+ // confirm updated item
320
+ assert.deepEqual(
321
+ await testUtils.getActualJson(
322
+ 'testExisting_automation_fixedKey_scheduled',
323
+ 'automation'
324
+ ),
325
+ await testUtils.getExpectedJson('9999999', 'automation', 'patch_fixKeys-schedule'),
326
+ 'returned metadata was not equal expected for update automation'
327
+ );
328
+ expect(
329
+ file(
330
+ testUtils.getActualDoc(
331
+ 'testExisting_automation_fixedKey_scheduled',
332
+ 'automation'
333
+ )
334
+ )
335
+ ).to.exist;
336
+ // check number of API calls
337
+ assert.equal(
338
+ testUtils.getAPIHistoryLength(),
339
+ 29,
340
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
341
+ );
342
+ return;
343
+ });
344
+ it('Should fixKeys by key w/o re-retrieving, auto-schedule and then --execute', async () => {
345
+ // WHEN
346
+ handler.setOptions({ skipInteraction: { fixKeysReretrieve: false }, execute: true });
347
+ const resultFixKeys = await handler.fixKeys('testInstance/testBU', 'automation', [
348
+ 'testExisting_automation_fixKey_schedule',
349
+ 'testExisting_automation',
350
+ ]);
351
+ assert.equal(
352
+ resultFixKeys['testInstance/testBU'].length,
353
+ 1,
354
+ 'returned number of keys does not correspond to number of expected fixed keys'
355
+ );
356
+ assert.equal(
357
+ resultFixKeys['testInstance/testBU'][0],
358
+ 'testExisting_automation_fixedKey_scheduled',
359
+ 'returned keys do not correspond to expected fixed keys'
360
+ );
361
+ // THEN
362
+ assert.equal(process.exitCode, false, 'fixKeys should not have thrown an error');
363
+ // confirm updated item
364
+ assert.deepEqual(
365
+ await testUtils.getActualJson(
366
+ 'testExisting_automation_fixedKey_scheduled',
367
+ 'automation'
368
+ ),
369
+ await testUtils.getExpectedJson('9999999', 'automation', 'patch_fixKeys-schedule'),
370
+ 'returned metadata was not equal expected for update automation'
371
+ );
372
+ expect(
373
+ file(
374
+ testUtils.getActualDoc(
375
+ 'testExisting_automation_fixedKey_scheduled',
376
+ 'automation'
377
+ )
378
+ )
379
+ ).to.exist;
380
+ // check number of API calls
381
+ assert.equal(
382
+ testUtils.getAPIHistoryLength(),
383
+ 31,
384
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
385
+ );
386
+ return;
387
+ });
388
+ it('Should fixKeys by key w/o re-retrieving, auto-schedule and then --schedule', async () => {
389
+ // WHEN
390
+ handler.setOptions({ skipInteraction: { fixKeysReretrieve: false }, schedule: true });
391
+ const resultFixKeys = await handler.fixKeys('testInstance/testBU', 'automation', [
392
+ 'testExisting_automation_fixKey_schedule',
393
+ 'testExisting_automation',
394
+ ]);
395
+ assert.equal(
396
+ resultFixKeys['testInstance/testBU'].length,
397
+ 1,
398
+ 'returned number of keys does not correspond to number of expected fixed keys'
399
+ );
400
+ assert.equal(
401
+ resultFixKeys['testInstance/testBU'][0],
402
+ 'testExisting_automation_fixedKey_scheduled',
403
+ 'returned keys do not correspond to expected fixed keys'
404
+ );
405
+ // THEN
406
+ assert.equal(process.exitCode, false, 'fixKeys should not have thrown an error');
407
+ // confirm updated item
408
+ assert.deepEqual(
409
+ await testUtils.getActualJson(
410
+ 'testExisting_automation_fixedKey_scheduled',
411
+ 'automation'
412
+ ),
413
+ await testUtils.getExpectedJson('9999999', 'automation', 'patch_fixKeys-schedule'),
414
+ 'returned metadata was not equal expected for update automation'
415
+ );
416
+ expect(
417
+ file(
418
+ testUtils.getActualDoc(
419
+ 'testExisting_automation_fixedKey_scheduled',
420
+ 'automation'
421
+ )
422
+ )
423
+ ).to.exist;
424
+ // check number of API calls
425
+ assert.equal(
426
+ testUtils.getAPIHistoryLength(),
427
+ 32,
428
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
429
+ );
430
+ return;
431
+ });
432
+ it('Should fixKeys by key w/o re-retrieving, deploy paused', async () => {
433
+ // WHEN
434
+ handler.setOptions({ skipInteraction: { fixKeysReretrieve: false } });
435
+ const resultFixKeys = await handler.fixKeys('testInstance/testBU', 'automation', [
436
+ 'testExisting_automation_fixKey_pause',
437
+ ]);
438
+ assert.equal(
439
+ resultFixKeys['testInstance/testBU'].length,
440
+ 1,
441
+ 'returned number of keys does not correspond to number of expected fixed keys'
442
+ );
443
+ assert.equal(
444
+ resultFixKeys['testInstance/testBU'][0],
445
+ 'testExisting_automation_fixedKey_paused',
446
+ 'returned keys do not correspond to expected fixed keys'
447
+ );
448
+ // THEN
449
+ assert.equal(process.exitCode, false, 'fixKeys should not have thrown an error');
450
+ // confirm updated item
451
+ assert.deepEqual(
452
+ await testUtils.getActualJson(
453
+ 'testExisting_automation_fixedKey_paused',
454
+ 'automation'
455
+ ),
456
+ await testUtils.getExpectedJson('9999999', 'automation', 'patch_fixKeys-pause'),
457
+ 'returned metadata was not equal expected for update automation'
458
+ );
459
+ expect(
460
+ file(
461
+ testUtils.getActualDoc('testExisting_automation_fixedKey_paused', 'automation')
462
+ )
463
+ ).to.exist;
464
+ // check number of API calls
465
+ assert.equal(
466
+ testUtils.getAPIHistoryLength(),
467
+ 26,
468
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
469
+ );
470
+ return;
471
+ });
472
+ it('Should fixKeys by key w/o re-retrieving, deploy paused and then --execute', async () => {
473
+ // WHEN
474
+ handler.setOptions({ skipInteraction: { fixKeysReretrieve: false }, execute: true });
475
+ const resultFixKeys = await handler.fixKeys('testInstance/testBU', 'automation', [
476
+ 'testExisting_automation_fixKey_pause',
477
+ 'testExisting_automation',
478
+ ]);
479
+ assert.equal(
480
+ resultFixKeys['testInstance/testBU'].length,
481
+ 1,
482
+ 'returned number of keys does not correspond to number of expected fixed keys'
483
+ );
484
+ assert.equal(
485
+ resultFixKeys['testInstance/testBU'][0],
486
+ 'testExisting_automation_fixedKey_paused',
487
+ 'returned keys do not correspond to expected fixed keys'
488
+ );
489
+ // THEN
490
+ assert.equal(process.exitCode, false, 'fixKeys should not have thrown an error');
491
+ // confirm updated item
492
+ assert.deepEqual(
493
+ await testUtils.getActualJson(
494
+ 'testExisting_automation_fixedKey_paused',
495
+ 'automation'
496
+ ),
497
+ await testUtils.getExpectedJson('9999999', 'automation', 'patch_fixKeys-pause'),
498
+ 'returned metadata was not equal expected for update automation'
499
+ );
500
+ expect(
501
+ file(
502
+ testUtils.getActualDoc('testExisting_automation_fixedKey_paused', 'automation')
503
+ )
504
+ ).to.exist;
505
+ // check number of API calls
506
+ assert.equal(
507
+ testUtils.getAPIHistoryLength(),
508
+ 30,
509
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
510
+ );
511
+ return;
512
+ });
513
+ it('Should fixKeys by key w/o re-retrieving, deploy paused and then --schedule', async () => {
514
+ // WHEN
515
+ handler.setOptions({ skipInteraction: { fixKeysReretrieve: false }, schedule: true });
516
+ const resultFixKeys = await handler.fixKeys('testInstance/testBU', 'automation', [
517
+ 'testExisting_automation_fixKey_pause',
518
+ 'testExisting_automation',
519
+ ]);
520
+ assert.equal(
521
+ resultFixKeys['testInstance/testBU'].length,
522
+ 1,
523
+ 'returned number of keys does not correspond to number of expected fixed keys'
524
+ );
525
+ assert.equal(
526
+ resultFixKeys['testInstance/testBU'][0],
527
+ 'testExisting_automation_fixedKey_paused',
528
+ 'returned keys do not correspond to expected fixed keys'
529
+ );
530
+ // THEN
531
+ assert.equal(process.exitCode, false, 'fixKeys should not have thrown an error');
532
+ // confirm updated item
533
+ assert.deepEqual(
534
+ await testUtils.getActualJson(
535
+ 'testExisting_automation_fixedKey_paused',
536
+ 'automation'
537
+ ),
538
+ await testUtils.getExpectedJson('9999999', 'automation', 'patch_fixKeys-pause'),
539
+ 'returned metadata was not equal expected for update automation'
540
+ );
541
+ expect(
542
+ file(
543
+ testUtils.getActualDoc('testExisting_automation_fixedKey_paused', 'automation')
544
+ )
545
+ ).to.exist;
546
+ // check number of API calls
547
+ assert.equal(
548
+ testUtils.getAPIHistoryLength(),
549
+ 32,
115
550
  'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
116
551
  );
117
552
  return;
118
553
  });
119
- it('Should change the key during update via --changeKeyValue');
120
554
  });
121
555
  describe('Templating ================', () => {
122
556
  it('Should create a automation template via retrieveAsTemplate and build it', async () => {
@@ -210,7 +644,7 @@ describe('type: automation', () => {
210
644
  );
211
645
  assert.equal(
212
646
  testUtils.getAPIHistoryLength(),
213
- 14,
647
+ 17,
214
648
  'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
215
649
  );
216
650
  return;
@@ -256,4 +690,197 @@ describe('type: automation', () => {
256
690
  return;
257
691
  });
258
692
  });
693
+ describe('Schedule ================', () => {
694
+ it('Should schedule an automation by key', async () => {
695
+ const executedKeys = await handler.schedule('testInstance/testBU', 'automation', [
696
+ 'testExisting_automation',
697
+ ]);
698
+ assert.equal(process.exitCode, false, 'execute should not have thrown an error');
699
+ assert.equal(
700
+ executedKeys['testInstance/testBU']?.length,
701
+ 1,
702
+ 'returned number of keys does not correspond to number of expected fixed keys'
703
+ );
704
+ assert.equal(
705
+ executedKeys['testInstance/testBU'][0],
706
+ 'testExisting_automation',
707
+ 'returned keys do not correspond to expected fixed keys'
708
+ );
709
+ return;
710
+ });
711
+ it('Should schedule an automation selected via --like', async () => {
712
+ handler.setOptions({ like: { key: 'testExist%automation' } });
713
+ const executedKeys = await handler.schedule('testInstance/testBU', 'automation');
714
+ assert.equal(process.exitCode, false, 'execute should not have thrown an error');
715
+ assert.equal(
716
+ executedKeys['testInstance/testBU']?.length,
717
+ 1,
718
+ 'returned number of keys does not correspond to number of expected fixed keys'
719
+ );
720
+ assert.equal(
721
+ executedKeys['testInstance/testBU'][0],
722
+ 'testExisting_automation',
723
+ 'returned keys do not correspond to expected fixed keys'
724
+ );
725
+ return;
726
+ });
727
+ it('Should not schedule executing an automation because key and --like was specified', async () => {
728
+ handler.setOptions({ like: { key: 'testExisting%' } });
729
+ const executedKeys = await handler.schedule('testInstance/testBU', 'automation', [
730
+ 'testExisting_automation',
731
+ ]);
732
+ assert.equal(process.exitCode, true, 'execute should have thrown an error');
733
+ assert.equal(
734
+ Object.keys(executedKeys).length,
735
+ 0,
736
+ 'automation was not supposed to be executed'
737
+ );
738
+ return;
739
+ });
740
+ });
741
+ describe('Execute ================', () => {
742
+ it('Should execute --schedule an automation by key', async () => {
743
+ handler.setOptions({ schedule: true });
744
+ const executedKeys = await handler.execute('testInstance/testBU', 'automation', [
745
+ 'testExisting_automation',
746
+ ]);
747
+ assert.equal(process.exitCode, false, 'execute should not have thrown an error');
748
+ assert.equal(
749
+ executedKeys['testInstance/testBU']?.length,
750
+ 1,
751
+ 'returned number of keys does not correspond to number of expected fixed keys'
752
+ );
753
+ assert.equal(
754
+ executedKeys['testInstance/testBU'][0],
755
+ 'testExisting_automation',
756
+ 'returned keys do not correspond to expected fixed keys'
757
+ );
758
+ return;
759
+ });
760
+ it('Should execute --schedule an automation selected via --like', async () => {
761
+ handler.setOptions({ like: { key: 'testExist%automation' }, schedule: true });
762
+ const executedKeys = await handler.execute('testInstance/testBU', 'automation');
763
+ assert.equal(process.exitCode, false, 'execute should not have thrown an error');
764
+ assert.equal(
765
+ executedKeys['testInstance/testBU']?.length,
766
+ 1,
767
+ 'returned number of keys does not correspond to number of expected fixed keys'
768
+ );
769
+ assert.equal(
770
+ executedKeys['testInstance/testBU'][0],
771
+ 'testExisting_automation',
772
+ 'returned keys do not correspond to expected fixed keys'
773
+ );
774
+ return;
775
+ });
776
+ it('Should not execute --schedule executing an automation because key and --like was specified', async () => {
777
+ handler.setOptions({ like: { key: 'testExisting%' }, schedule: true });
778
+ const executedKeys = await handler.execute('testInstance/testBU', 'automation', [
779
+ 'testExisting_automation',
780
+ ]);
781
+ assert.equal(process.exitCode, true, 'execute should have thrown an error');
782
+ assert.equal(
783
+ Object.keys(executedKeys).length,
784
+ 0,
785
+ 'automation was not supposed to be executed'
786
+ );
787
+ return;
788
+ });
789
+ it('Should runOnce an automation by key', async () => {
790
+ const executedKeys = await handler.execute('testInstance/testBU', 'automation', [
791
+ 'testExisting_automation',
792
+ ]);
793
+ assert.equal(process.exitCode, false, 'execute should not have thrown an error');
794
+ assert.equal(
795
+ executedKeys['testInstance/testBU']?.length,
796
+ 1,
797
+ 'automation was supposed to be executed'
798
+ );
799
+ assert.equal(
800
+ executedKeys['testInstance/testBU'][0],
801
+ 'testExisting_automation',
802
+ 'returned keys do not correspond to expected fixed keys'
803
+ );
804
+ return;
805
+ });
806
+ it('Should runOnce an automation selected via --like', async () => {
807
+ handler.setOptions({ like: { key: 'testExist%automation' } });
808
+ const executedKeys = await handler.execute('testInstance/testBU', 'automation');
809
+ assert.equal(process.exitCode, false, 'execute should not have thrown an error');
810
+ assert.equal(
811
+ executedKeys['testInstance/testBU']?.length,
812
+ 1,
813
+ 'automation was supposed to be executed'
814
+ );
815
+ assert.equal(
816
+ executedKeys['testInstance/testBU'][0],
817
+ 'testExisting_automation',
818
+ 'returned keys do not correspond to expected fixed keys'
819
+ );
820
+
821
+ return;
822
+ });
823
+ it('Should not runOnce executing an automation because key and --like was specified', async () => {
824
+ handler.setOptions({ like: { key: 'testExisting%' } });
825
+ const executedKeys = await handler.execute('testInstance/testBU', 'automation', [
826
+ 'testExisting_automation',
827
+ ]);
828
+ assert.equal(process.exitCode, true, 'execute should have thrown an error');
829
+ assert.equal(
830
+ Object.keys(executedKeys).length,
831
+ 0,
832
+ 'automation was not supposed to be executed'
833
+ );
834
+
835
+ return;
836
+ });
837
+ });
838
+ describe('Pause ================', () => {
839
+ it('Should pause a automation by key', async () => {
840
+ const pausedKeys = await handler.pause('testInstance/testBU', 'automation', [
841
+ 'testExisting_automation_pause',
842
+ ]);
843
+ assert.equal(process.exitCode, false, 'pause should not have thrown an error');
844
+ assert.equal(
845
+ pausedKeys['testInstance/testBU']?.length,
846
+ 1,
847
+ 'returned number of keys does not correspond to number of expected fixed keys'
848
+ );
849
+ assert.equal(
850
+ pausedKeys['testInstance/testBU'][0],
851
+ 'testExisting_automation_pause',
852
+ 'returned keys do not correspond to expected fixed keys'
853
+ );
854
+ return;
855
+ });
856
+ it('Should pause a automation selected via --like', async () => {
857
+ handler.setOptions({ like: { key: 'testExisting_a%n_pause' } });
858
+ const pausedKeys = await handler.pause('testInstance/testBU', 'automation');
859
+ assert.equal(process.exitCode, false, 'pause should not have thrown an error');
860
+ assert.equal(
861
+ pausedKeys['testInstance/testBU']?.length,
862
+ 1,
863
+ 'returned number of keys does not correspond to number of expected fixed keys'
864
+ );
865
+ assert.equal(
866
+ pausedKeys['testInstance/testBU'][0],
867
+ 'testExisting_automation_pause',
868
+ 'returned keys do not correspond to expected fixed keys'
869
+ );
870
+ return;
871
+ });
872
+ it('Should not pause automation because key and --like was specified', async () => {
873
+ handler.setOptions({ like: { key: 'testExisting_a%n_pause' } });
874
+ const pausedKeys = await handler.pause('testInstance/testBU', 'automation', [
875
+ 'testExisting_automation_pause',
876
+ ]);
877
+ assert.equal(process.exitCode, true, 'pause should have thrown an error');
878
+ assert.equal(
879
+ Object.keys(pausedKeys).length,
880
+ 0,
881
+ 'returned number of keys does not correspond to number of expected fixed keys'
882
+ );
883
+ return;
884
+ });
885
+ });
259
886
  });