From 9a77946892497d76129ab96ad587e43828f69686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Tue, 7 May 2024 12:55:36 +0200 Subject: [PATCH] #1302: test for --keySuffix on CREATE --- .../query/testNew_query.query-meta.json | 11 +++++ .../query/testNew_query.query-meta.sql | 4 ++ .../automation/v1/queries/get-response.json | 6 +++ .../automation/v1/queries/post-response.json | 18 +++++++ ...eve-ContentType=queryactivity-response.xml | 48 +++++++++++++++++++ .../query/patch_keySuffix-expected.json | 11 +++++ .../query/patch_keySuffix-expected.sql | 4 ++ test/type.query.test.js | 45 +++++++++++++++++ test/utils.js | 10 ++-- 9 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 test/mockRoot/deploy/testInstance/_ParentBU_/query/testNew_query.query-meta.json create mode 100644 test/mockRoot/deploy/testInstance/_ParentBU_/query/testNew_query.query-meta.sql create mode 100644 test/resources/1111111/automation/v1/queries/get-response.json create mode 100644 test/resources/1111111/automation/v1/queries/post-response.json create mode 100644 test/resources/1111111/dataFolder/retrieve-ContentType=queryactivity-response.xml create mode 100644 test/resources/1111111/query/patch_keySuffix-expected.json create mode 100644 test/resources/1111111/query/patch_keySuffix-expected.sql diff --git a/test/mockRoot/deploy/testInstance/_ParentBU_/query/testNew_query.query-meta.json b/test/mockRoot/deploy/testInstance/_ParentBU_/query/testNew_query.query-meta.json new file mode 100644 index 000000000..688e58db5 --- /dev/null +++ b/test/mockRoot/deploy/testInstance/_ParentBU_/query/testNew_query.query-meta.json @@ -0,0 +1,11 @@ +{ + "name": "testNew_query", + "key": "testNew_query", + "description": "created on deploy", + "targetKey": "testExisting_dataExtensionShared", + "createdDate": "2022-04-26T15:21:16.453", + "modifiedDate": "2022-04-26T16:04:15.88", + "targetUpdateTypeName": "Overwrite", + "isFrozen": false, + "r__folder_Path": "Query" +} diff --git a/test/mockRoot/deploy/testInstance/_ParentBU_/query/testNew_query.query-meta.sql b/test/mockRoot/deploy/testInstance/_ParentBU_/query/testNew_query.query-meta.sql new file mode 100644 index 000000000..8020314ea --- /dev/null +++ b/test/mockRoot/deploy/testInstance/_ParentBU_/query/testNew_query.query-meta.sql @@ -0,0 +1,4 @@ +SELECT + SubscriberKey as testField +FROM + _Subscribers diff --git a/test/resources/1111111/automation/v1/queries/get-response.json b/test/resources/1111111/automation/v1/queries/get-response.json new file mode 100644 index 000000000..48f76672e --- /dev/null +++ b/test/resources/1111111/automation/v1/queries/get-response.json @@ -0,0 +1,6 @@ +{ + "count": 0, + "page": 1, + "pageSize": 50, + "items": [] +} diff --git a/test/resources/1111111/automation/v1/queries/post-response.json b/test/resources/1111111/automation/v1/queries/post-response.json new file mode 100644 index 000000000..566d55169 --- /dev/null +++ b/test/resources/1111111/automation/v1/queries/post-response.json @@ -0,0 +1,18 @@ +{ + "queryDefinitionId": "549f0568-607c-4940-afef-437965094d-keySuffix", + "name": "testNew_query", + "key": "testNew_query_DEV", + "description": "created on deploy", + "queryText": "SELECT\n SubscriberKey as testField\nFROM\n _Subscribers\n", + "targetName": "testExisting_dataExtensionShared", + "targetKey": "testExisting_dataExtensionShared", + "targetId": "21711373-72c1-ec11-b83b-shared", + "targetDescription": "", + "createdDate": "2022-04-26T15:21:16.453", + "modifiedDate": "2022-04-26T16:04:15.88", + "targetUpdateTypeId": 0, + "targetUpdateTypeName": "Overwrite", + "validatedQueryText": "SET NOCOUNT ON; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;\r\n\r\nINSERT INTO C518001158.[testDataExtension] ([testField])\r\nSELECT querydef.[testField]\r\nFROM (SELECT SubscriberKey as testField FROM C518001158._Subscribers ) AS querydef \r\nSELECT @rcInsert = @@ROWCOUNT;;\r\n", + "categoryId": 9991, + "isFrozen": false +} diff --git a/test/resources/1111111/dataFolder/retrieve-ContentType=queryactivity-response.xml b/test/resources/1111111/dataFolder/retrieve-ContentType=queryactivity-response.xml new file mode 100644 index 000000000..03d2eeac5 --- /dev/null +++ b/test/resources/1111111/dataFolder/retrieve-ContentType=queryactivity-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 + + + 1111111 + + + 2016-07-22T11:52:20.407 + 2016-07-22T11:52:20.407 + 9991 + + queryactivity_default + + + 0 + + + Query + + queryactivity + true + false + true + + + + diff --git a/test/resources/1111111/query/patch_keySuffix-expected.json b/test/resources/1111111/query/patch_keySuffix-expected.json new file mode 100644 index 000000000..a69695ef8 --- /dev/null +++ b/test/resources/1111111/query/patch_keySuffix-expected.json @@ -0,0 +1,11 @@ +{ + "name": "testNew_query", + "key": "testNew_query_DEV", + "description": "created on deploy", + "targetKey": "testExisting_dataExtensionShared", + "createdDate": "2022-04-26T15:21:16.453", + "modifiedDate": "2022-04-26T16:04:15.88", + "targetUpdateTypeName": "Overwrite", + "isFrozen": false, + "r__folder_Path": "Query" +} diff --git a/test/resources/1111111/query/patch_keySuffix-expected.sql b/test/resources/1111111/query/patch_keySuffix-expected.sql new file mode 100644 index 000000000..4148833c4 --- /dev/null +++ b/test/resources/1111111/query/patch_keySuffix-expected.sql @@ -0,0 +1,4 @@ +SELECT + SubscriberKey AS testField +FROM + _Subscribers diff --git a/test/type.query.test.js b/test/type.query.test.js index f001b7d55..a9bd98294 100644 --- a/test/type.query.test.js +++ b/test/type.query.test.js @@ -6,6 +6,7 @@ import chaiFiles from 'chai-files'; import cache from '../lib/util/cache.js'; import * as testUtils from './utils.js'; import handler from '../lib/index.js'; +import { Util } from '../lib/util/util.js'; chai.use(chaiFiles); const file = chaiFiles.file; @@ -381,6 +382,50 @@ describe('type: query', () => { return; }); + it('Should change the key during create with and --keySuffix', async () => { + handler.setOptions({ keySuffix: '_DEV' }); + const deployed = await handler.deploy( + 'testInstance/_ParentBU_', + ['query'], + ['testNew_query'] + ); + // THEN + assert.equal(process.exitCode, 0, 'deploy --keySuffix should not have thrown an error'); + assert.equal( + Object.keys(deployed['testInstance/_ParentBU_'].query).length, + 1, + 'returned number of keys does not correspond to number of expected fixed keys' + ); + assert.equal( + Object.keys(deployed['testInstance/_ParentBU_'].query)[0], + 'testNew_query_DEV', + 'returned keys do not correspond to expected fixed keys' + ); + const createCallout = Util.requestLog.find( + (item) => item.method === 'POST' && item.url === '/automation/v1/queries/' + ); + assert.equal( + createCallout?.data?.key, + 'testNew_query_DEV', + 'key in create callout was not as expected' + ); + + // confirm updated item + assert.deepEqual( + await testUtils.getActualJson('testNew_query_DEV', 'query', '_ParentBU_'), + await testUtils.getExpectedJson('1111111', 'query', 'patch_keySuffix'), + 'returned metadata was not equal expected for update query' + ); + + // check number of API calls + assert.equal( + testUtils.getAPIHistoryLength(), + 4, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + it('Should run fixKeys but not find fixable keys and hence stop', async () => { // WHEN handler.setOptions({ skipInteraction: { fixKeysReretrieve: false } }); diff --git a/test/utils.js b/test/utils.js index 02529d8b0..0d5d98de1 100644 --- a/test/utils.js +++ b/test/utils.js @@ -47,10 +47,11 @@ export function getActualDoc(customerKey, type, buName = 'testBU') { * @param {string} customerKey of metadata * @param {string} type of metadata * @param {string} ext file extension + * @param {string} [buName] used when we need to test on ParentBU * @returns {string} file path */ -export function getActualFile(customerKey, type, ext) { - return `./retrieve/testInstance/testBU/${type}/${customerKey}.${type}-meta.${ext}`; +export function getActualFile(customerKey, type, ext, buName = 'testBU') { + return `./retrieve/testInstance/${buName}/${type}/${customerKey}.${type}-meta.${ext}`; } /** * gets file from Deploy folder @@ -71,10 +72,11 @@ export function getActualDeployJson(customerKey, type, buName = 'testBU') { * @param {string} customerKey of metadata * @param {string} type of metadata * @param {string} ext file extension + * @param {string} [buName] used when we need to test on ParentBU * @returns {string} file path */ -export function getActualDeployFile(customerKey, type, ext) { - return `./deploy/testInstance/testBU/${type}/${customerKey}.${type}-meta.${ext}`; +export function getActualDeployFile(customerKey, type, ext, buName = 'testBU') { + return `./deploy/testInstance/${buName}/${type}/${customerKey}.${type}-meta.${ext}`; } /** * gets file from Template folder