diff --git a/test/mockRoot/deploy/testInstance/testBU/script/testExisting_script.script-meta.json b/test/mockRoot/deploy/testInstance/testBU/script/testExisting_script.script-meta.json
new file mode 100644
index 000000000..cefd0e179
--- /dev/null
+++ b/test/mockRoot/deploy/testInstance/testBU/script/testExisting_script.script-meta.json
@@ -0,0 +1,6 @@
+{
+ "description": "updated on deploy",
+ "key": "testExisting_script",
+ "name": "testExisting_script",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/mockRoot/deploy/testInstance/testBU/script/testExisting_script.script-meta.ssjs b/test/mockRoot/deploy/testInstance/testBU/script/testExisting_script.script-meta.ssjs
new file mode 100644
index 000000000..e20d1ee2d
--- /dev/null
+++ b/test/mockRoot/deploy/testInstance/testBU/script/testExisting_script.script-meta.ssjs
@@ -0,0 +1 @@
+// dummy updated
diff --git a/test/mockRoot/deploy/testInstance/testBU/script/testNew_script.script-meta.json b/test/mockRoot/deploy/testInstance/testBU/script/testNew_script.script-meta.json
new file mode 100644
index 000000000..5a2f9b73a
--- /dev/null
+++ b/test/mockRoot/deploy/testInstance/testBU/script/testNew_script.script-meta.json
@@ -0,0 +1,6 @@
+{
+ "description": "created on deploy",
+ "key": "testNew_script",
+ "name": "testNew_script",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/mockRoot/deploy/testInstance/testBU/script/testNew_script.script-meta.ssjs b/test/mockRoot/deploy/testInstance/testBU/script/testNew_script.script-meta.ssjs
new file mode 100644
index 000000000..bbfd28311
--- /dev/null
+++ b/test/mockRoot/deploy/testInstance/testBU/script/testNew_script.script-meta.ssjs
@@ -0,0 +1 @@
+// dummy created
diff --git a/test/resources/9999999/automation/v1/scripts/39f6a488-20eb-4ba0-b0b9-023725b574e4/patch-response.json b/test/resources/9999999/automation/v1/scripts/39f6a488-20eb-4ba0-b0b9-023725b574e4/patch-response.json
new file mode 100644
index 000000000..bffec43f9
--- /dev/null
+++ b/test/resources/9999999/automation/v1/scripts/39f6a488-20eb-4ba0-b0b9-023725b574e4/patch-response.json
@@ -0,0 +1,10 @@
+{
+ "ssjsActivityId": "39f6a488-20eb-4ba0-b0b9-023725b574e4",
+ "name": "testExisting_script",
+ "key": "testExisting_script",
+ "description": "updated on deploy",
+ "script": "",
+ "categoryId": 304,
+ "createdDate": "2022-10-20T00:41:26.163",
+ "modifiedDate": "2022-10-20T00:41:26.163"
+}
diff --git a/test/resources/9999999/automation/v1/scripts/get-response.json b/test/resources/9999999/automation/v1/scripts/get-response.json
index d5830148f..d928b6361 100644
--- a/test/resources/9999999/automation/v1/scripts/get-response.json
+++ b/test/resources/9999999/automation/v1/scripts/get-response.json
@@ -8,8 +8,18 @@
"name": "testExisting_script",
"key": "testExisting_script",
"description": "",
- "script": "\n//dummy\n",
+ "categoryId": 304,
+ "createdDate": "2022-10-20T00:41:26.163",
+ "modifiedDate": "2022-10-20T00:41:26.163"
+ },
+ {
+ "ssjsActivityId": "39f6a488-20eb-4ba0-b0b9-noScriptTag",
+ "name": "testExisting_script_noScriptTag",
+ "key": "testExisting_script_noScriptTag",
+ "description": "",
+ "script": "// no script tag\n",
+ "categoryId": 304,
"createdDate": "2022-10-20T00:41:26.163",
"modifiedDate": "2022-10-20T00:41:26.163"
}
diff --git a/test/resources/9999999/automation/v1/scripts/post-response.json b/test/resources/9999999/automation/v1/scripts/post-response.json
new file mode 100644
index 000000000..aeeb66322
--- /dev/null
+++ b/test/resources/9999999/automation/v1/scripts/post-response.json
@@ -0,0 +1,10 @@
+{
+ "ssjsActivityId": "39f6a488-20eb-4ba0-b0b9-new",
+ "name": "testNew_script",
+ "key": "testNew_script",
+ "description": "created on deploy",
+ "script": "",
+ "categoryId": 304,
+ "createdDate": "2022-10-20T00:41:26.163",
+ "modifiedDate": "2022-10-20T00:41:26.163"
+}
diff --git a/test/resources/9999999/dataFolder/retrieve-ContentType=ssjsactivity-response.xml b/test/resources/9999999/dataFolder/retrieve-ContentType=ssjsactivity-response.xml
new file mode 100644
index 000000000..65f4ad08a
--- /dev/null
+++ b/test/resources/9999999/dataFolder/retrieve-ContentType=ssjsactivity-response.xml
@@ -0,0 +1,48 @@
+
+
+
+ RetrieveResponse
+ urn:uuid:f36f3303-3b5a-4641-8109-b26447634d91
+ urn:uuid:33983968-28c4-4379-bb5f-f80ae32eb988
+ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
+
+
+ 2022-04-19T20:03:41Z
+ 2022-04-19T20:08:41Z
+
+
+
+
+
+ OK
+ 02cd5ccb-8f84-4651-826f-71169eeecf05
+
+
+ 9999999
+
+
+ 2017-01-24T06:32:42.353
+ 2017-01-24T06:32:42.353
+ 304
+
+ SSJSActivity_default
+
+
+ 0
+
+
+ Scripts
+
+ SSJSActivity
+ true
+ false
+ true
+
+
+
+
diff --git a/test/resources/9999999/script/build-expected.json b/test/resources/9999999/script/build-expected.json
new file mode 100644
index 000000000..6daa00403
--- /dev/null
+++ b/test/resources/9999999/script/build-expected.json
@@ -0,0 +1,6 @@
+{
+ "description": "",
+ "key": "testTemplated_script",
+ "name": "testTemplated_script",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/script/build-expected.ssjs b/test/resources/9999999/script/build-expected.ssjs
new file mode 100644
index 000000000..27c4b7e5c
--- /dev/null
+++ b/test/resources/9999999/script/build-expected.ssjs
@@ -0,0 +1 @@
+//dummy
diff --git a/test/resources/9999999/script/get-expected.json b/test/resources/9999999/script/get-expected.json
new file mode 100644
index 000000000..6572bab64
--- /dev/null
+++ b/test/resources/9999999/script/get-expected.json
@@ -0,0 +1,8 @@
+{
+ "createdDate": "2022-10-20T00:41:26.163",
+ "description": "",
+ "key": "testExisting_script",
+ "modifiedDate": "2022-10-20T00:41:26.163",
+ "name": "testExisting_script",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/script/get-expected.ssjs b/test/resources/9999999/script/get-expected.ssjs
new file mode 100644
index 000000000..27c4b7e5c
--- /dev/null
+++ b/test/resources/9999999/script/get-expected.ssjs
@@ -0,0 +1 @@
+//dummy
diff --git a/test/resources/9999999/script/get_noScriptTag-expected.html b/test/resources/9999999/script/get_noScriptTag-expected.html
new file mode 100644
index 000000000..634388fcc
--- /dev/null
+++ b/test/resources/9999999/script/get_noScriptTag-expected.html
@@ -0,0 +1 @@
+// no script tag
diff --git a/test/resources/9999999/script/get_noScriptTag-expected.json b/test/resources/9999999/script/get_noScriptTag-expected.json
new file mode 100644
index 000000000..f6090804f
--- /dev/null
+++ b/test/resources/9999999/script/get_noScriptTag-expected.json
@@ -0,0 +1,8 @@
+{
+ "createdDate": "2022-10-20T00:41:26.163",
+ "description": "",
+ "key": "testExisting_script_noScriptTag",
+ "modifiedDate": "2022-10-20T00:41:26.163",
+ "name": "testExisting_script_noScriptTag",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/script/patch-expected.json b/test/resources/9999999/script/patch-expected.json
new file mode 100644
index 000000000..81f145a49
--- /dev/null
+++ b/test/resources/9999999/script/patch-expected.json
@@ -0,0 +1,8 @@
+{
+ "createdDate": "2022-10-20T00:41:26.163",
+ "description": "updated on deploy",
+ "key": "testExisting_script",
+ "modifiedDate": "2022-10-20T00:41:26.163",
+ "name": "testExisting_script",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/script/patch-expected.ssjs b/test/resources/9999999/script/patch-expected.ssjs
new file mode 100644
index 000000000..e20d1ee2d
--- /dev/null
+++ b/test/resources/9999999/script/patch-expected.ssjs
@@ -0,0 +1 @@
+// dummy updated
diff --git a/test/resources/9999999/script/post-expected.json b/test/resources/9999999/script/post-expected.json
new file mode 100644
index 000000000..a2389daac
--- /dev/null
+++ b/test/resources/9999999/script/post-expected.json
@@ -0,0 +1,8 @@
+{
+ "createdDate": "2022-10-20T00:41:26.163",
+ "description": "created on deploy",
+ "key": "testNew_script",
+ "modifiedDate": "2022-10-20T00:41:26.163",
+ "name": "testNew_script",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/script/post-expected.ssjs b/test/resources/9999999/script/post-expected.ssjs
new file mode 100644
index 000000000..bbfd28311
--- /dev/null
+++ b/test/resources/9999999/script/post-expected.ssjs
@@ -0,0 +1 @@
+// dummy created
diff --git a/test/resources/9999999/script/template-expected.json b/test/resources/9999999/script/template-expected.json
new file mode 100644
index 000000000..bd3ae9904
--- /dev/null
+++ b/test/resources/9999999/script/template-expected.json
@@ -0,0 +1,6 @@
+{
+ "description": "",
+ "key": "{{{prefix}}}script",
+ "name": "{{{prefix}}}script",
+ "r__folder_Path": "Scripts"
+}
diff --git a/test/resources/9999999/script/template-expected.ssjs b/test/resources/9999999/script/template-expected.ssjs
new file mode 100644
index 000000000..27c4b7e5c
--- /dev/null
+++ b/test/resources/9999999/script/template-expected.ssjs
@@ -0,0 +1 @@
+//dummy
diff --git a/test/type.script.test.js b/test/type.script.test.js
new file mode 100644
index 000000000..84202cfec
--- /dev/null
+++ b/test/type.script.test.js
@@ -0,0 +1,367 @@
+const chai = require('chai');
+const chaiFiles = require('chai-files');
+const assert = chai.assert;
+chai.use(chaiFiles);
+const expect = chai.expect;
+const file = chaiFiles.file;
+// const dir = chaiFiles.dir;
+const cache = require('../lib/util/cache');
+const testUtils = require('./utils');
+const handler = require('../lib/index');
+
+describe('type: script', () => {
+ beforeEach(() => {
+ testUtils.mockSetup();
+ });
+ afterEach(() => {
+ testUtils.mockReset();
+ });
+
+ describe('Retrieve ================', () => {
+ it('Should retrieve all scripts', async () => {
+ // WHEN
+ const retrieve = await handler.retrieve('testInstance/testBU', ['script']);
+ // THEN
+ assert.equal(process.exitCode, false, 'retrieve should not have thrown an error');
+
+ // retrieve result
+ assert.equal(
+ retrieve['testInstance/testBU'].script
+ ? Object.keys(retrieve['testInstance/testBU'].script).length
+ : 0,
+ 2,
+ 'only 2 scripts expected in retrieve response'
+ );
+
+ // get results from cache
+ const result = cache.getCache();
+ assert.equal(
+ result.script ? Object.keys(result.script).length : 0,
+ 2,
+ 'only 2 scripts expected'
+ );
+ // normal test
+ assert.deepEqual(
+ await testUtils.getActualJson('testExisting_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'get'),
+ 'returned metadata with correct key was not equal expected'
+ );
+ expect(file(testUtils.getActualFile('testExisting_script', 'script', 'html'))).to.not
+ .exist;
+ expect(file(testUtils.getActualFile('testExisting_script', 'script', 'ssjs'))).to.equal(
+ file(testUtils.getExpectedFile('9999999', 'script', 'get', 'ssjs'))
+ );
+
+ assert.deepEqual(
+ await testUtils.getActualJson('testExisting_script_noScriptTag', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'get_noScriptTag'),
+ 'returned metadata was not equal expected'
+ );
+ expect(
+ file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'html'))
+ ).to.equal(
+ file(testUtils.getExpectedFile('9999999', 'script', 'get_noScriptTag', 'html'))
+ );
+ expect(
+ file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'ssjs'))
+ ).to.not.exist;
+
+ assert.equal(
+ testUtils.getAPIHistoryLength(),
+ 3,
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
+ );
+ return;
+ });
+ it('Should retrieve one specific script by key', async () => {
+ // WHEN
+ await handler.retrieve('testInstance/testBU', ['script'], ['testExisting_script']);
+ // THEN
+ assert.equal(process.exitCode, false, 'retrieve should not have thrown an error');
+ // get results from cache
+ const result = cache.getCache();
+ assert.equal(
+ result.script ? Object.keys(result.script).length : 0,
+ 1,
+ 'only one script expected'
+ );
+ assert.deepEqual(
+ await testUtils.getActualJson('testExisting_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'get'),
+ 'returned metadata was not equal expected'
+ );
+ expect(file(testUtils.getActualFile('testExisting_script', 'script', 'html'))).to.not
+ .exist;
+ expect(file(testUtils.getActualFile('testExisting_script', 'script', 'ssjs'))).to.equal(
+ file(testUtils.getExpectedFile('9999999', 'script', 'get', 'ssjs'))
+ );
+
+ expect(
+ file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'json'))
+ ).to.not.exist;
+ expect(
+ file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'ssjs'))
+ ).to.not.exist;
+ expect(
+ file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'html'))
+ ).to.not.exist;
+
+ assert.equal(
+ testUtils.getAPIHistoryLength(),
+ 3,
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
+ );
+ return;
+ });
+ it('Should retrieve one specific script via --like', async () => {
+ // WHEN
+ handler.setOptions({ like: { key: '%Existing_script' } });
+ await handler.retrieve('testInstance/testBU', ['script']);
+
+ // THEN
+ assert.equal(process.exitCode, false, 'retrieve should not have thrown an error');
+
+ // get results from cache
+ const result = cache.getCache();
+ assert.equal(
+ result.script ? Object.keys(result.script).length : 0,
+ 2,
+ 'two scripts in cache expected'
+ );
+ assert.deepEqual(
+ await testUtils.getActualJson('testExisting_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'get'),
+ 'returned metadata was not equal expected'
+ );
+ expect(file(testUtils.getActualFile('testExisting_script', 'script', 'ssjs'))).to.equal(
+ file(testUtils.getExpectedFile('9999999', 'script', 'get', 'ssjs'))
+ );
+
+ expect(
+ file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'json'))
+ ).to.not.exist;
+ expect(
+ file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'ssjs'))
+ ).to.not.exist;
+ expect(
+ file(testUtils.getActualFile('testExisting_script_noScriptTag', 'script', 'html'))
+ ).to.not.exist;
+
+ assert.equal(
+ testUtils.getAPIHistoryLength(),
+ 3,
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
+ );
+ return;
+ });
+ it('Should not retrieve any script via --like and key due to a mismatching filter', async () => {
+ // WHEN
+ handler.setOptions({ like: { key: 'NotExisting_script' } });
+ await handler.retrieve('testInstance/testBU', ['script']);
+ // THEN
+ assert.equal(process.exitCode, false, 'retrieve should not have thrown an error');
+
+ // get results from cache
+ const result = cache.getCache();
+ assert.equal(
+ result.script ? Object.keys(result.script).length : 0,
+ 2,
+ 'two scripts in cache expected'
+ );
+
+ expect(file(testUtils.getActualFile('testExisting_script', 'script', 'ssjs'))).to.not
+ .exist;
+ assert.equal(
+ testUtils.getAPIHistoryLength(),
+ 3,
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
+ );
+ return;
+ });
+ });
+ describe('Deploy ================', () => {
+ beforeEach(() => {
+ testUtils.mockSetup(true);
+ });
+ it('Should create & upsert a script', async () => {
+ // WHEN
+ await handler.deploy('testInstance/testBU', ['script']);
+ // THEN
+ assert.equal(process.exitCode, false, 'deploy should not have thrown an error');
+ // get results from cache
+ const result = cache.getCache();
+ assert.equal(
+ result.script ? Object.keys(result.script).length : 0,
+ 3,
+ 'three scripts expected'
+ );
+ // confirm created item
+ assert.deepEqual(
+ await testUtils.getActualJson('testNew_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'post'),
+ 'returned metadata was not equal expected for insert script'
+ );
+ expect(file(testUtils.getActualFile('testNew_script', 'script', 'ssjs'))).to.equal(
+ file(testUtils.getExpectedFile('9999999', 'script', 'post', 'ssjs'))
+ );
+ // confirm updated item
+ assert.deepEqual(
+ await testUtils.getActualJson('testExisting_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'patch'),
+ 'returned metadata was not equal expected for insert script'
+ );
+ expect(file(testUtils.getActualFile('testExisting_script', 'script', 'ssjs'))).to.equal(
+ file(testUtils.getExpectedFile('9999999', 'script', 'patch', 'ssjs'))
+ );
+ // check number of API calls
+ assert.equal(
+ testUtils.getAPIHistoryLength(),
+ 5,
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
+ );
+ return;
+ });
+ });
+ describe('Templating ================', () => {
+ it('Should create a script template via retrieveAsTemplate and build it', async () => {
+ // GIVEN there is a template
+ const result = await handler.retrieveAsTemplate(
+ 'testInstance/testBU',
+ 'script',
+ ['testExisting_script'],
+ 'testSourceMarket'
+ );
+ // WHEN
+ assert.equal(
+ process.exitCode,
+ false,
+ 'retrieveAsTemplate should not have thrown an error'
+ );
+ assert.equal(
+ result.script ? Object.keys(result.script).length : 0,
+ 1,
+ 'only one script expected'
+ );
+ assert.deepEqual(
+ await testUtils.getActualTemplateJson('testExisting_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'template'),
+ 'returned template JSON of retrieveAsTemplate was not equal expected'
+ );
+ expect(
+ file(testUtils.getActualTemplateFile('testExisting_script', 'script', 'ssjs'))
+ ).to.equal(file(testUtils.getExpectedFile('9999999', 'script', 'template', 'ssjs')));
+ // THEN
+ await handler.buildDefinition(
+ 'testInstance/testBU',
+ 'script',
+ 'testExisting_script',
+ 'testTargetMarket'
+ );
+ assert.equal(
+ process.exitCode,
+ false,
+ 'buildDefinition should not have thrown an error'
+ );
+
+ assert.deepEqual(
+ await testUtils.getActualDeployJson('testTemplated_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'build'),
+ 'returned deployment JSON was not equal expected'
+ );
+ expect(
+ file(testUtils.getActualDeployFile('testTemplated_script', 'script', 'ssjs'))
+ ).to.equal(file(testUtils.getExpectedFile('9999999', 'script', 'build', 'ssjs')));
+
+ assert.equal(
+ testUtils.getAPIHistoryLength(),
+ 3,
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
+ );
+ return;
+ });
+ it('Should create a script template via buildTemplate and build it', async () => {
+ // download first before we test buildTemplate
+ await handler.retrieve('testInstance/testBU', ['script']);
+ // GIVEN there is a template
+ const result = await handler.buildTemplate(
+ 'testInstance/testBU',
+ 'script',
+ ['testExisting_script'],
+ 'testSourceMarket'
+ );
+ // WHEN
+ assert.equal(process.exitCode, false, 'buildTemplate should not have thrown an error');
+
+ assert.equal(
+ result.script ? Object.keys(result.script).length : 0,
+ 1,
+ 'only one script expected'
+ );
+ assert.deepEqual(
+ await testUtils.getActualTemplateJson('testExisting_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'template'),
+ 'returned template JSON of buildTemplate was not equal expected'
+ );
+ expect(
+ file(testUtils.getActualTemplateFile('testExisting_script', 'script', 'ssjs'))
+ ).to.equal(file(testUtils.getExpectedFile('9999999', 'script', 'template', 'ssjs')));
+ // THEN
+ await handler.buildDefinition(
+ 'testInstance/testBU',
+ 'script',
+ 'testExisting_script',
+ 'testTargetMarket'
+ );
+ assert.equal(
+ process.exitCode,
+ false,
+ 'buildDefinition should not have thrown an error'
+ );
+
+ assert.deepEqual(
+ await testUtils.getActualDeployJson('testTemplated_script', 'script'),
+ await testUtils.getExpectedJson('9999999', 'script', 'build'),
+ 'returned deployment JSON was not equal expected'
+ );
+ expect(
+ file(testUtils.getActualDeployFile('testTemplated_script', 'script', 'ssjs'))
+ ).to.equal(file(testUtils.getExpectedFile('9999999', 'script', 'build', 'ssjs')));
+
+ assert.equal(
+ testUtils.getAPIHistoryLength(),
+ 3,
+ 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
+ );
+ return;
+ });
+ });
+ describe('Delete ================', () => {});
+ describe('CI/CD ================', () => {
+ it('Should return a list of files based on their type and key', async () => {
+ // WHEN
+ const fileList = await handler.getFilesToCommit('testInstance/testBU', 'script', [
+ 'testExisting_script',
+ ]);
+ // THEN
+ assert.equal(
+ process.exitCode,
+ false,
+ 'getFilesToCommit should not have thrown an error'
+ );
+ assert.equal(fileList.length, 3, 'expected only 3 file paths (html, json, ssjs)');
+
+ assert.equal(
+ fileList[0].split('\\').join('/'),
+ 'retrieve/testInstance/testBU/script/testExisting_script.script-meta.json',
+ 'wrong JSON path'
+ );
+ assert.equal(
+ fileList[1].split('\\').join('/'),
+ 'retrieve/testInstance/testBU/script/testExisting_script.script-meta.ssjs',
+ 'wrong JSON path'
+ );
+ return;
+ });
+ });
+ describe('Execute ================', () => {});
+});