Skip to content

Commit

Permalink
#1302: test for --keySuffix on CREATE
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed May 7, 2024
1 parent de99de8 commit 9a77946
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
SubscriberKey as testField
FROM
_Subscribers
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"count": 0,
"page": 1,
"pageSize": 50,
"items": []
}
18 changes: 18 additions & 0 deletions test/resources/1111111/automation/v1/queries/post-response.json
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action>RetrieveResponse</wsa:Action>
<wsa:MessageID>urn:uuid:f36f3303-3b5a-4641-8109-b26447634d91</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:33983968-28c4-4379-bb5f-f80ae32eb988</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-32ecc81b-6020-473c-9e99-4b5338921220">
<wsu:Created>2022-04-19T20:03:41Z</wsu:Created>
<wsu:Expires>2022-04-19T20:08:41Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<OverallStatus>OK</OverallStatus>
<RequestID>02cd5ccb-8f84-4651-826f-71169eeecf05</RequestID>
<Results xsi:type="DataFolder">
<Client>
<ID>1111111</ID>
</Client>
<PartnerKey xsi:nil="true" />
<CreatedDate>2016-07-22T11:52:20.407</CreatedDate>
<ModifiedDate>2016-07-22T11:52:20.407</ModifiedDate>
<ID>9991</ID>
<ObjectID xsi:nil="true" />
<CustomerKey>queryactivity_default</CustomerKey>
<ParentFolder>
<PartnerKey xsi:nil="true" />
<ID>0</ID>
<ObjectID xsi:nil="true" />
</ParentFolder>
<Name>Query</Name>
<Description />
<ContentType>queryactivity</ContentType>
<IsActive>true</IsActive>
<IsEditable>false</IsEditable>
<AllowChildren>true</AllowChildren>
</Results>
</RetrieveResponseMsg>
</soap:Body>
</soap:Envelope>
11 changes: 11 additions & 0 deletions test/resources/1111111/query/patch_keySuffix-expected.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 4 additions & 0 deletions test/resources/1111111/query/patch_keySuffix-expected.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
SubscriberKey AS testField
FROM
_Subscribers
45 changes: 45 additions & 0 deletions test/type.query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 } });
Expand Down
10 changes: 6 additions & 4 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9a77946

Please sign in to comment.