From 8008444ab3ff0e3d981861a2c2f554d2810ecec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Tue, 18 Jul 2023 17:31:07 +0200 Subject: [PATCH] #852: add test class for type importFile --- .../definitions/ImportFile.definition.js | 42 +++- ...stExisting_importFile.importFile-meta.json | 29 +++ .../testNew_importFile.importFile-meta.json | 29 +++ .../patch-response.json | 31 +++ .../automation/v1/imports/get-response.json | 2 +- .../automation/v1/imports/post-response.json | 30 +++ .../9999999/importFile/build-expected.json | 27 +++ .../9999999/importFile/get-expected.json | 29 +++ .../9999999/importFile/patch-expected.json | 29 +++ .../9999999/importFile/post-expected.json | 29 +++ .../9999999/importFile/template-expected.json | 27 +++ test/type.importFile.test.js | 187 ++++++++++++++++++ 12 files changed, 484 insertions(+), 7 deletions(-) create mode 100644 test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile.importFile-meta.json create mode 100644 test/mockRoot/deploy/testInstance/testBU/importFile/testNew_importFile.importFile-meta.json create mode 100644 test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b/patch-response.json create mode 100644 test/resources/9999999/automation/v1/imports/post-response.json create mode 100644 test/resources/9999999/importFile/build-expected.json create mode 100644 test/resources/9999999/importFile/get-expected.json create mode 100644 test/resources/9999999/importFile/patch-expected.json create mode 100644 test/resources/9999999/importFile/post-expected.json create mode 100644 test/resources/9999999/importFile/template-expected.json create mode 100644 test/type.importFile.test.js diff --git a/lib/metadataTypes/definitions/ImportFile.definition.js b/lib/metadataTypes/definitions/ImportFile.definition.js index b1938c785..a88063322 100644 --- a/lib/metadataTypes/definitions/ImportFile.definition.js +++ b/lib/metadataTypes/definitions/ImportFile.definition.js @@ -222,11 +222,41 @@ module.exports = { retrieving: true, template: true, }, - c__dataAction: { skipValidation: true }, - r__dataExtension_CustomerKey: { skipValidation: true }, - c__destinationType: { skipValidation: true }, - r__list_PathName: { skipValidation: true }, - r__fileLocation_name: { skipValidation: true }, - c__subscriberImportType: { skipValidation: true }, + c__dataAction: { + isCreateable: false, + isUpdateable: false, + retrieving: true, + template: true, + }, + r__dataExtension_CustomerKey: { + isCreateable: false, + isUpdateable: false, + retrieving: true, + template: true, + }, + c__destinationType: { + isCreateable: false, + isUpdateable: false, + retrieving: true, + template: true, + }, + r__list_PathName: { + isCreateable: false, + isUpdateable: false, + retrieving: true, + template: true, + }, + r__fileLocation_name: { + isCreateable: false, + isUpdateable: false, + retrieving: true, + template: true, + }, + c__subscriberImportType: { + isCreateable: false, + isUpdateable: false, + retrieving: true, + template: true, + }, }, }; diff --git a/test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile.importFile-meta.json b/test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile.importFile-meta.json new file mode 100644 index 000000000..70fdc604f --- /dev/null +++ b/test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile.importFile-meta.json @@ -0,0 +1,29 @@ +{ + "allowErrors": true, + "createdDate": "2022-11-09T05:32:30.533", + "customerKey": "testExisting_importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "updated on deploy", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "modifiedDate": "2022-11-17T07:13:03.95", + "name": "testExisting_importFile", + "sendEmailNotification": false, + "standardQuotedStrings": true, + "r__fileLocation_name": "ExactTarget Enhanced FTP", + "c__destinationType": "DataExtension", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "c__subscriberImportType": "DataExtension", + "c__dataAction": "AddUpdate" +} diff --git a/test/mockRoot/deploy/testInstance/testBU/importFile/testNew_importFile.importFile-meta.json b/test/mockRoot/deploy/testInstance/testBU/importFile/testNew_importFile.importFile-meta.json new file mode 100644 index 000000000..bf4bd6ad2 --- /dev/null +++ b/test/mockRoot/deploy/testInstance/testBU/importFile/testNew_importFile.importFile-meta.json @@ -0,0 +1,29 @@ +{ + "allowErrors": true, + "createdDate": "2022-11-09T05:32:30.533", + "customerKey": "testNew_importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "created via deploy", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "modifiedDate": "2022-11-17T07:13:03.95", + "name": "testNew_importFile", + "sendEmailNotification": false, + "standardQuotedStrings": true, + "r__fileLocation_name": "ExactTarget Enhanced FTP", + "c__destinationType": "DataExtension", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "c__subscriberImportType": "DataExtension", + "c__dataAction": "AddUpdate" +} diff --git a/test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b/patch-response.json b/test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b/patch-response.json new file mode 100644 index 000000000..09b433e8d --- /dev/null +++ b/test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b/patch-response.json @@ -0,0 +1,31 @@ +{ + "allowErrors": true, + "customerKey": "testExisting_importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "updated on deploy", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "name": "testExisting_importFile", + "sendEmailNotification": false, + "standardQuotedStrings": true, + "fileTransferLocationId": "41a5ded7-0d98-4910-a15f-d09e7ab0af24", + "destinationObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "destinationObjectTypeId": 310, + "subscriberImportTypeId": 255, + "updateTypeId": 0, + "importDefinitionId": "9d16f42c-2260-ed11-b849-48df37d1de8b", + "createdDate": "2022-11-09T05:53:03.243", + "destinationId": 0, + "modifiedDate": "2023-07-18T09:11:26.19" +} diff --git a/test/resources/9999999/automation/v1/imports/get-response.json b/test/resources/9999999/automation/v1/imports/get-response.json index d58fc438c..000537e3b 100644 --- a/test/resources/9999999/automation/v1/imports/get-response.json +++ b/test/resources/9999999/automation/v1/imports/get-response.json @@ -11,7 +11,7 @@ "dateFormatLocale": "en-US", "deleteFile": false, "description": "17.11.2022", - "destinationObjectId": "bf457cfa-ca04-ec11-b82d-48df37d1da95", + "destinationObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", "destinationId": 0, "destinationObjectTypeId": 310, "fieldMappings": [], diff --git a/test/resources/9999999/automation/v1/imports/post-response.json b/test/resources/9999999/automation/v1/imports/post-response.json new file mode 100644 index 000000000..7f8ce56ec --- /dev/null +++ b/test/resources/9999999/automation/v1/imports/post-response.json @@ -0,0 +1,30 @@ +{ + "allowErrors": true, + "customerKey": "testNew_importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "created via deploy", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "name": "testNew_importFile", + "sendEmailNotification": false, + "standardQuotedStrings": true, + "fileTransferLocationId": "41a5ded7-0d98-4910-a15f-d09e7ab0af24", + "destinationObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "destinationObjectTypeId": 310, + "subscriberImportTypeId": 255, + "updateTypeId": 0, + "createdDate": "2022-11-09T05:53:03.243", + "destinationId": 0, + "modifiedDate": "2023-07-18T09:11:26.19" +} diff --git a/test/resources/9999999/importFile/build-expected.json b/test/resources/9999999/importFile/build-expected.json new file mode 100644 index 000000000..a1e8feed7 --- /dev/null +++ b/test/resources/9999999/importFile/build-expected.json @@ -0,0 +1,27 @@ +{ + "allowErrors": true, + "c__dataAction": "AddUpdate", + "c__destinationType": "DataExtension", + "c__subscriberImportType": "DataExtension", + "customerKey": "testTemplated_importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "17.11.2022", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "name": "testTemplated_importFile", + "r__dataExtension_CustomerKey": "testTemplated_dataExtension", + "r__fileLocation_name": "ExactTarget Enhanced FTP", + "sendEmailNotification": false, + "standardQuotedStrings": true +} diff --git a/test/resources/9999999/importFile/get-expected.json b/test/resources/9999999/importFile/get-expected.json new file mode 100644 index 000000000..4175265c2 --- /dev/null +++ b/test/resources/9999999/importFile/get-expected.json @@ -0,0 +1,29 @@ +{ + "allowErrors": true, + "createdDate": "2022-11-09T05:32:30.533", + "customerKey": "testExisting_importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "17.11.2022", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "modifiedDate": "2022-11-17T07:13:03.95", + "name": "testExisting_importFile", + "sendEmailNotification": false, + "standardQuotedStrings": true, + "c__dataAction": "AddUpdate", + "c__destinationType": "DataExtension", + "c__subscriberImportType": "DataExtension", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "r__fileLocation_name": "ExactTarget Enhanced FTP" +} diff --git a/test/resources/9999999/importFile/patch-expected.json b/test/resources/9999999/importFile/patch-expected.json new file mode 100644 index 000000000..844d9dd59 --- /dev/null +++ b/test/resources/9999999/importFile/patch-expected.json @@ -0,0 +1,29 @@ +{ + "allowErrors": true, + "c__dataAction": "AddUpdate", + "c__destinationType": "DataExtension", + "c__subscriberImportType": "DataExtension", + "createdDate": "2022-11-09T05:53:03.243", + "customerKey": "testExisting_importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "updated on deploy", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "modifiedDate": "2023-07-18T09:11:26.19", + "name": "testExisting_importFile", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "r__fileLocation_name": "ExactTarget Enhanced FTP", + "sendEmailNotification": false, + "standardQuotedStrings": true +} diff --git a/test/resources/9999999/importFile/post-expected.json b/test/resources/9999999/importFile/post-expected.json new file mode 100644 index 000000000..0a9440dba --- /dev/null +++ b/test/resources/9999999/importFile/post-expected.json @@ -0,0 +1,29 @@ +{ + "allowErrors": true, + "c__dataAction": "AddUpdate", + "c__destinationType": "DataExtension", + "c__subscriberImportType": "DataExtension", + "createdDate": "2022-11-09T05:53:03.243", + "customerKey": "testNew_importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "created via deploy", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "modifiedDate": "2023-07-18T09:11:26.19", + "name": "testNew_importFile", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "r__fileLocation_name": "ExactTarget Enhanced FTP", + "sendEmailNotification": false, + "standardQuotedStrings": true +} diff --git a/test/resources/9999999/importFile/template-expected.json b/test/resources/9999999/importFile/template-expected.json new file mode 100644 index 000000000..6be382e91 --- /dev/null +++ b/test/resources/9999999/importFile/template-expected.json @@ -0,0 +1,27 @@ +{ + "allowErrors": true, + "c__dataAction": "AddUpdate", + "c__destinationType": "DataExtension", + "c__subscriberImportType": "DataExtension", + "customerKey": "{{{prefix}}}importFile", + "dateFormatLocale": "en-US", + "deleteFile": false, + "description": "17.11.2022", + "fieldMappingType": "InferFromColumnHeadings", + "fieldMappings": [], + "fileNamingPattern": "blabla", + "fileTransferLocationTypeId": 0, + "fileType": "CSV", + "filter": "", + "hasColumnHeader": true, + "isOrderedImport": true, + "isSequential": true, + "maxFileAgeHours": 0, + "maxFileAgeScheduleOffsetHours": 0, + "maxImportFrequencyHours": 0, + "name": "{{{prefix}}}importFile", + "r__dataExtension_CustomerKey": "{{{prefix}}}dataExtension", + "r__fileLocation_name": "ExactTarget Enhanced FTP", + "sendEmailNotification": false, + "standardQuotedStrings": true +} diff --git a/test/type.importFile.test.js b/test/type.importFile.test.js new file mode 100644 index 000000000..40a62c1b9 --- /dev/null +++ b/test/type.importFile.test.js @@ -0,0 +1,187 @@ +const chai = require('chai'); +const chaiFiles = require('chai-files'); +const assert = chai.assert; +chai.use(chaiFiles); +const cache = require('../lib/util/cache'); +const testUtils = require('./utils'); +const handler = require('../lib/index'); + +describe('type: importFile', () => { + beforeEach(() => { + testUtils.mockSetup(); + }); + afterEach(() => { + testUtils.mockReset(); + }); + + describe('Retrieve ================', () => { + it('Should retrieve a importFile', async () => { + // WHEN + await handler.retrieve('testInstance/testBU', ['importFile']); + // THEN + assert.equal(process.exitCode, false, 'retrieve should not have thrown an error'); + // get results from cache + const result = cache.getCache(); + assert.equal( + result.importFile ? Object.keys(result.importFile).length : 0, + 1, + 'only one importFile expected' + ); + assert.deepEqual( + await testUtils.getActualJson('testExisting_importFile', 'importFile'), + await testUtils.getExpectedJson('9999999', 'importFile', 'get'), + 'returned JSON was not equal expected' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 10, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + }); + describe('Deploy ================', () => { + beforeEach(() => { + testUtils.mockSetup(true); + }); + it('Should create & upsert a importFile', async () => { + // WHEN + + await handler.deploy('testInstance/testBU', ['importFile']); + // THEN + assert.equal(process.exitCode, false, 'deploy should not have thrown an error'); + // get results from cache + const result = cache.getCache(); + assert.equal( + result.importFile ? Object.keys(result.importFile).length : 0, + 2, + 'two importFiles expected' + ); + // confirm created item + assert.deepEqual( + await testUtils.getActualJson('testNew_importFile', 'importFile'), + await testUtils.getExpectedJson('9999999', 'importFile', 'post'), + 'returned new-JSON was not equal expected for insert importFile' + ); + // confirm updated item + assert.deepEqual( + await testUtils.getActualJson('testExisting_importFile', 'importFile'), + await testUtils.getExpectedJson('9999999', 'importFile', 'patch'), + 'returned existing-JSON was not equal expected for update importFile' + ); + // check number of API calls + assert.equal( + testUtils.getAPIHistoryLength(), + 12, + '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 importFile template via retrieveAsTemplate and build it', async () => { + // buildTemplate + const result = await handler.retrieveAsTemplate( + 'testInstance/testBU', + 'importFile', + ['testExisting_importFile'], + 'testSourceMarket' + ); + assert.equal(process.exitCode, false, 'buildTemplate should not have thrown an error'); + assert.equal( + result.importFile ? Object.keys(result.importFile).length : 0, + 1, + 'only one importFile expected' + ); + assert.deepEqual( + await testUtils.getActualTemplateJson('testExisting_importFile', 'importFile'), + await testUtils.getExpectedJson('9999999', 'importFile', 'template'), + 'returned template JSON was not equal expected' + ); + // buildDefinition + await handler.buildDefinition( + 'testInstance/testBU', + 'importFile', + 'testExisting_importFile', + 'testTargetMarket' + ); + assert.equal( + process.exitCode, + false, + 'buildDefinition should not have thrown an error' + ); + assert.deepEqual( + await testUtils.getActualDeployJson('testTemplated_importFile', 'importFile'), + await testUtils.getExpectedJson('9999999', 'importFile', 'build'), + 'returned deployment JSON was not equal expected' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 10, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + it('Should create a importFile template via buildTemplate and build it', async () => { + // download first before we test buildTemplate + await handler.retrieve('testInstance/testBU', ['importFile']); + // buildTemplate + const result = await handler.buildTemplate( + 'testInstance/testBU', + 'importFile', + ['testExisting_importFile'], + 'testSourceMarket' + ); + assert.equal(process.exitCode, false, 'buildTemplate should not have thrown an error'); + assert.equal( + result.importFile ? Object.keys(result.importFile).length : 0, + 1, + 'only one importFile expected' + ); + assert.deepEqual( + await testUtils.getActualTemplateJson('testExisting_importFile', 'importFile'), + await testUtils.getExpectedJson('9999999', 'importFile', 'template'), + 'returned template JSON was not equal expected' + ); + // buildDefinition + await handler.buildDefinition( + 'testInstance/testBU', + 'importFile', + 'testExisting_importFile', + 'testTargetMarket' + ); + assert.equal( + process.exitCode, + false, + 'buildDefinition should not have thrown an error' + ); + assert.deepEqual( + await testUtils.getActualDeployJson('testTemplated_importFile', 'importFile'), + await testUtils.getExpectedJson('9999999', 'importFile', 'build'), + 'returned deployment JSON was not equal expected' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 10, + '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', 'importFile', [ + 'testExisting_fileTranfer', + ]); + // THEN + assert.equal( + process.exitCode, + 1, + 'deleteByKey should have thrown an error due to lack of support' + ); + return; + }); + }); +});