From 45b86c355cd9efaf0487422c6676a34fa7e4796b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Wed, 19 Jul 2023 15:08:48 +0200 Subject: [PATCH] #846: add Deploy and Templating tests for dataExtract --- ...Existing_dataExtract.dataExtract-meta.json | 35 +++++ .../testNew_dataExtract.dataExtract-meta.json | 35 +++++ .../patch-response.json | 38 +++++ .../v1/dataextracts/post-response.json | 38 +++++ .../9999999/dataExtract/build-expected.json | 35 +++++ .../9999999/dataExtract/patch-expected.json | 37 +++++ .../9999999/dataExtract/post-expected.json | 37 +++++ .../dataExtract/template-expected.json | 35 +++++ test/type.dataExtract.test.js | 144 ++++++++++++++++++ 9 files changed, 434 insertions(+) create mode 100644 test/mockRoot/deploy/testInstance/testBU/dataExtract/testExisting_dataExtract.dataExtract-meta.json create mode 100644 test/mockRoot/deploy/testInstance/testBU/dataExtract/testNew_dataExtract.dataExtract-meta.json create mode 100644 test/resources/9999999/automation/v1/dataextracts/56c5370a-f988-4f36-b0ee-0f876573f6d7/patch-response.json create mode 100644 test/resources/9999999/automation/v1/dataextracts/post-response.json create mode 100644 test/resources/9999999/dataExtract/build-expected.json create mode 100644 test/resources/9999999/dataExtract/patch-expected.json create mode 100644 test/resources/9999999/dataExtract/post-expected.json create mode 100644 test/resources/9999999/dataExtract/template-expected.json diff --git a/test/mockRoot/deploy/testInstance/testBU/dataExtract/testExisting_dataExtract.dataExtract-meta.json b/test/mockRoot/deploy/testInstance/testBU/dataExtract/testExisting_dataExtract.dataExtract-meta.json new file mode 100644 index 000000000..9db8c5648 --- /dev/null +++ b/test/mockRoot/deploy/testInstance/testBU/dataExtract/testExisting_dataExtract.dataExtract-meta.json @@ -0,0 +1,35 @@ +{ + "name": "testExisting_dataExtract", + "key": "testExisting_dataExtract", + "description": "updated on deploy", + "r__dataExtractType_name": "Data Extension Extract", + "fileSpec": "testExisting-%%Year%%-%%Month%%-%%Day%%", + "intervalType": 0, + "dataFields": [ + { + "name": "ColumnDelimiter", + "type": "string", + "value": "," + }, + { + "name": "DECustomerKey", + "type": "string", + "value": "testExisting_dataExtension" + }, + { + "name": "HasColumnHeaders", + "type": "bool", + "value": "False" + }, + { + "name": "TextQualified", + "type": "bool", + "value": "False" + }, + { + "name": "UsesLineFeed", + "type": "bool", + "value": "False" + } + ] +} diff --git a/test/mockRoot/deploy/testInstance/testBU/dataExtract/testNew_dataExtract.dataExtract-meta.json b/test/mockRoot/deploy/testInstance/testBU/dataExtract/testNew_dataExtract.dataExtract-meta.json new file mode 100644 index 000000000..da5bcf6d4 --- /dev/null +++ b/test/mockRoot/deploy/testInstance/testBU/dataExtract/testNew_dataExtract.dataExtract-meta.json @@ -0,0 +1,35 @@ +{ + "name": "testNew_dataExtract", + "key": "testNew_dataExtract", + "description": "created via deploy", + "r__dataExtractType_name": "Data Extension Extract", + "fileSpec": "testNew-%%Year%%-%%Month%%-%%Day%%", + "intervalType": 0, + "dataFields": [ + { + "name": "ColumnDelimiter", + "type": "string", + "value": "," + }, + { + "name": "DECustomerKey", + "type": "string", + "value": "testExisting_dataExtension" + }, + { + "name": "HasColumnHeaders", + "type": "bool", + "value": "False" + }, + { + "name": "TextQualified", + "type": "bool", + "value": "False" + }, + { + "name": "UsesLineFeed", + "type": "bool", + "value": "False" + } + ] +} diff --git a/test/resources/9999999/automation/v1/dataextracts/56c5370a-f988-4f36-b0ee-0f876573f6d7/patch-response.json b/test/resources/9999999/automation/v1/dataextracts/56c5370a-f988-4f36-b0ee-0f876573f6d7/patch-response.json new file mode 100644 index 000000000..c57700a8f --- /dev/null +++ b/test/resources/9999999/automation/v1/dataextracts/56c5370a-f988-4f36-b0ee-0f876573f6d7/patch-response.json @@ -0,0 +1,38 @@ +{ + "dataExtractDefinitionId": "56c5370a-f988-4f36-b0ee-0f876573f6d7", + "name": "testExisting_dataExtract", + "key": "testExisting_dataExtract", + "description": "created via deploy", + "dataExtractTypeId": "bb94a04d-9632-4623-be47-daabc3f588a6", + "fileSpec": "testExisting-%%Year%%-%%Month%%-%%Day%%", + "createdBy": 700304523, + "modifiedBy": 700304523, + "intervalType": 0, + "dataFields": [ + { + "name": "ColumnDelimiter", + "type": "string", + "value": "," + }, + { + "name": "DECustomerKey", + "type": "string", + "value": "testExisting_dataExtension" + }, + { + "name": "HasColumnHeaders", + "type": "bool", + "value": "False" + }, + { + "name": "TextQualified", + "type": "bool", + "value": "False" + }, + { + "name": "UsesLineFeed", + "type": "bool", + "value": "False" + } + ] +} diff --git a/test/resources/9999999/automation/v1/dataextracts/post-response.json b/test/resources/9999999/automation/v1/dataextracts/post-response.json new file mode 100644 index 000000000..af6d1061f --- /dev/null +++ b/test/resources/9999999/automation/v1/dataextracts/post-response.json @@ -0,0 +1,38 @@ +{ + "dataExtractDefinitionId": "56c5370a-f988-4f36-b0ee-0f876573f6d7", + "name": "testNew_dataExtract", + "key": "testNew_dataExtract", + "description": "blabla", + "dataExtractTypeId": "bb94a04d-9632-4623-be47-daabc3f588a6", + "fileSpec": "testNew-%%Year%%-%%Month%%-%%Day%%", + "createdBy": 700304523, + "modifiedBy": 700304523, + "intervalType": 0, + "dataFields": [ + { + "name": "ColumnDelimiter", + "type": "string", + "value": "," + }, + { + "name": "DECustomerKey", + "type": "string", + "value": "testExisting_dataExtension" + }, + { + "name": "HasColumnHeaders", + "type": "bool", + "value": "False" + }, + { + "name": "TextQualified", + "type": "bool", + "value": "False" + }, + { + "name": "UsesLineFeed", + "type": "bool", + "value": "False" + } + ] +} diff --git a/test/resources/9999999/dataExtract/build-expected.json b/test/resources/9999999/dataExtract/build-expected.json new file mode 100644 index 000000000..a3586e8eb --- /dev/null +++ b/test/resources/9999999/dataExtract/build-expected.json @@ -0,0 +1,35 @@ +{ + "dataFields": [ + { + "name": "ColumnDelimiter", + "type": "string", + "value": "," + }, + { + "name": "DECustomerKey", + "type": "string", + "value": "testTemplated_dataExtension" + }, + { + "name": "HasColumnHeaders", + "type": "bool", + "value": "False" + }, + { + "name": "TextQualified", + "type": "bool", + "value": "False" + }, + { + "name": "UsesLineFeed", + "type": "bool", + "value": "False" + } + ], + "description": "blabla", + "fileSpec": "testExisting-%%Year%%-%%Month%%-%%Day%%", + "intervalType": 0, + "key": "testTemplated_dataExtract", + "name": "testTemplated_dataExtract", + "r__dataExtractType_name": "Data Extension Extract" +} diff --git a/test/resources/9999999/dataExtract/patch-expected.json b/test/resources/9999999/dataExtract/patch-expected.json new file mode 100644 index 000000000..3086b8c5e --- /dev/null +++ b/test/resources/9999999/dataExtract/patch-expected.json @@ -0,0 +1,37 @@ +{ + "createdBy": 700304523, + "dataFields": [ + { + "name": "ColumnDelimiter", + "type": "string", + "value": "," + }, + { + "name": "DECustomerKey", + "type": "string", + "value": "testExisting_dataExtension" + }, + { + "name": "HasColumnHeaders", + "type": "bool", + "value": "False" + }, + { + "name": "TextQualified", + "type": "bool", + "value": "False" + }, + { + "name": "UsesLineFeed", + "type": "bool", + "value": "False" + } + ], + "description": "created via deploy", + "fileSpec": "testExisting-%%Year%%-%%Month%%-%%Day%%", + "intervalType": 0, + "key": "testExisting_dataExtract", + "modifiedBy": 700304523, + "name": "testExisting_dataExtract", + "r__dataExtractType_name": "Data Extension Extract" +} diff --git a/test/resources/9999999/dataExtract/post-expected.json b/test/resources/9999999/dataExtract/post-expected.json new file mode 100644 index 000000000..5d6cbb8ca --- /dev/null +++ b/test/resources/9999999/dataExtract/post-expected.json @@ -0,0 +1,37 @@ +{ + "createdBy": 700304523, + "dataFields": [ + { + "name": "ColumnDelimiter", + "type": "string", + "value": "," + }, + { + "name": "DECustomerKey", + "type": "string", + "value": "testExisting_dataExtension" + }, + { + "name": "HasColumnHeaders", + "type": "bool", + "value": "False" + }, + { + "name": "TextQualified", + "type": "bool", + "value": "False" + }, + { + "name": "UsesLineFeed", + "type": "bool", + "value": "False" + } + ], + "description": "blabla", + "fileSpec": "testNew-%%Year%%-%%Month%%-%%Day%%", + "intervalType": 0, + "key": "testNew_dataExtract", + "modifiedBy": 700304523, + "name": "testNew_dataExtract", + "r__dataExtractType_name": "Data Extension Extract" +} diff --git a/test/resources/9999999/dataExtract/template-expected.json b/test/resources/9999999/dataExtract/template-expected.json new file mode 100644 index 000000000..a407ded63 --- /dev/null +++ b/test/resources/9999999/dataExtract/template-expected.json @@ -0,0 +1,35 @@ +{ + "dataFields": [ + { + "name": "ColumnDelimiter", + "type": "string", + "value": "," + }, + { + "name": "DECustomerKey", + "type": "string", + "value": "{{{prefix}}}dataExtension" + }, + { + "name": "HasColumnHeaders", + "type": "bool", + "value": "False" + }, + { + "name": "TextQualified", + "type": "bool", + "value": "False" + }, + { + "name": "UsesLineFeed", + "type": "bool", + "value": "False" + } + ], + "description": "blabla", + "fileSpec": "testExisting-%%Year%%-%%Month%%-%%Day%%", + "intervalType": 0, + "key": "{{{prefix}}}dataExtract", + "name": "{{{prefix}}}dataExtract", + "r__dataExtractType_name": "Data Extension Extract" +} diff --git a/test/type.dataExtract.test.js b/test/type.dataExtract.test.js index 6aa8f0757..6c2b3434e 100644 --- a/test/type.dataExtract.test.js +++ b/test/type.dataExtract.test.js @@ -40,4 +40,148 @@ describe('type: dataExtract', () => { return; }); }); + describe('Deploy ================', () => { + beforeEach(() => { + testUtils.mockSetup(true); + }); + it('Should create & upsert a dataExtract', async () => { + // WHEN + + await handler.deploy('testInstance/testBU', ['dataExtract']); + // THEN + assert.equal(process.exitCode, false, 'deploy should not have thrown an error'); + // get results from cache + const result = cache.getCache(); + assert.equal( + result.dataExtract ? Object.keys(result.dataExtract).length : 0, + 2, + 'two dataExtracts expected' + ); + // confirm created item + assert.deepEqual( + await testUtils.getActualJson('testNew_dataExtract', 'dataExtract'), + await testUtils.getExpectedJson('9999999', 'dataExtract', 'post'), + 'returned new-JSON was not equal expected for insert dataExtract' + ); + // confirm updated item + assert.deepEqual( + await testUtils.getActualJson('testExisting_dataExtract', 'dataExtract'), + await testUtils.getExpectedJson('9999999', 'dataExtract', 'patch'), + 'returned existing-JSON was not equal expected for update dataExtract' + ); + // check number of API calls + assert.equal( + testUtils.getAPIHistoryLength(), + 8, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + it('Should change the key during update via --changeKeyValue '); + }); + describe('Templating ================', () => { + it('Should create a dataExtract template via retrieveAsTemplate and build it', async () => { + // buildTemplate + const result = await handler.retrieveAsTemplate( + 'testInstance/testBU', + 'dataExtract', + ['testExisting_dataExtract'], + 'testSourceMarket' + ); + assert.equal(process.exitCode, false, 'buildTemplate should not have thrown an error'); + assert.equal( + result.dataExtract ? Object.keys(result.dataExtract).length : 0, + 1, + 'only one dataExtract expected' + ); + assert.deepEqual( + await testUtils.getActualTemplateJson('testExisting_dataExtract', 'dataExtract'), + await testUtils.getExpectedJson('9999999', 'dataExtract', 'template'), + 'returned template JSON was not equal expected' + ); + // buildDefinition + await handler.buildDefinition( + 'testInstance/testBU', + 'dataExtract', + 'testExisting_dataExtract', + 'testTargetMarket' + ); + assert.equal( + process.exitCode, + false, + 'buildDefinition should not have thrown an error' + ); + assert.deepEqual( + await testUtils.getActualDeployJson('testTemplated_dataExtract', 'dataExtract'), + await testUtils.getExpectedJson('9999999', 'dataExtract', 'build'), + 'returned deployment JSON was not equal expected' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 6, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + it('Should create a dataExtract template via buildTemplate and build it', async () => { + // download first before we test buildTemplate + await handler.retrieve('testInstance/testBU', ['dataExtract']); + // buildTemplate + const result = await handler.buildTemplate( + 'testInstance/testBU', + 'dataExtract', + ['testExisting_dataExtract'], + 'testSourceMarket' + ); + assert.equal(process.exitCode, false, 'buildTemplate should not have thrown an error'); + assert.equal( + result.dataExtract ? Object.keys(result.dataExtract).length : 0, + 1, + 'only one dataExtract expected' + ); + assert.deepEqual( + await testUtils.getActualTemplateJson('testExisting_dataExtract', 'dataExtract'), + await testUtils.getExpectedJson('9999999', 'dataExtract', 'template'), + 'returned template JSON was not equal expected' + ); + // buildDefinition + await handler.buildDefinition( + 'testInstance/testBU', + 'dataExtract', + 'testExisting_dataExtract', + 'testTargetMarket' + ); + assert.equal( + process.exitCode, + false, + 'buildDefinition should not have thrown an error' + ); + assert.deepEqual( + await testUtils.getActualDeployJson('testTemplated_dataExtract', 'dataExtract'), + await testUtils.getExpectedJson('9999999', 'dataExtract', 'build'), + 'returned deployment JSON was not equal expected' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 6, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + }); + describe('Delete ================', () => { + it('Should NOT delete the item', async () => { + // WHEN + await handler.deleteByKey('testInstance/testBU', 'dataExtract', [ + 'testExisting_fileTranfer', + ]); + // THEN + assert.equal( + process.exitCode, + 1, + 'deleteByKey should have thrown an error due to lack of support' + ); + return; + }); + }); });