mcdev
Version:
Accenture Salesforce Marketing Cloud DevTools
1,146 lines (1,055 loc) • 118 kB
JavaScript
import * as chai from 'chai';
const assert = chai.assert;
const expect = chai.expect;
import chaiFiles from 'chai-files';
import * as testUtils from './utils.js';
import handler from '../lib/index.js';
chai.use(chaiFiles);
describe('GENERAL', () => {
beforeEach(() => {
testUtils.mockSetup();
});
afterEach(() => {
testUtils.mockReset();
});
describe('ReplaceContentBlockByX ================', () => {
describe('with types specified ================', () => {
it('Should replace references with ContentBlockByName w/o deploy', async () => {
handler.setOptions({ skipDeploy: true });
// WHEN
const replace = await handler.replaceCbReference(
'testInstance/testBU',
{
journey: null,
senderProfile: null,
},
'name'
);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
// retrieve result
assert.deepEqual(
replace['testInstance/testBU'].journey,
['testExisting_journey_Quicksend'],
'should have found the right journeys that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].senderProfile,
['testExisting_senderProfile_rcb'],
'should have found the right senderProfiles that need updating'
);
// check if conversions happened
assert.deepEqual(
await testUtils.getActualJson('testExisting_journey_Quicksend', 'journey'),
await testUtils.getExpectedJson('9999999', 'journey', 'get-quicksend-rcb-name'),
'returned JSON was not equal expected'
);
assert.deepEqual(
await testUtils.getActualJson(
'testExisting_senderProfile_rcb',
'senderProfile'
),
await testUtils.getExpectedJson('9999999', 'senderProfile', 'get-rcb-name'),
'returned JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
44,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should replace references with ContentBlockById w/o deploy', async () => {
handler.setOptions({ skipDeploy: true });
// WHEN
const replace = await handler.replaceCbReference(
'testInstance/testBU',
{
journey: null,
senderProfile: null,
},
'id'
);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
// retrieve result
assert.deepEqual(
replace['testInstance/testBU'].journey,
['testExisting_journey_Quicksend'],
'should have found the right journeys that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].senderProfile,
['testExisting_senderProfile_rcb'],
'should have found the right senderProfiles that need updating'
);
// check if conversions happened
assert.deepEqual(
await testUtils.getActualJson('testExisting_journey_Quicksend', 'journey'),
await testUtils.getExpectedJson('9999999', 'journey', 'get-quicksend-rcb-id'),
'returned JSON was not equal expected'
);
assert.deepEqual(
await testUtils.getActualJson(
'testExisting_senderProfile_rcb',
'senderProfile'
),
await testUtils.getExpectedJson('9999999', 'senderProfile', 'get-rcb-id'),
'returned JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
44,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should replace references with ContentBlockByKey w/o deploy', async () => {
handler.setOptions({ skipDeploy: true });
// WHEN
const replace = await handler.replaceCbReference(
'testInstance/testBU',
{
journey: null,
senderProfile: null,
},
'key'
);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
// retrieve result
assert.deepEqual(
replace['testInstance/testBU'].journey,
['testExisting_journey_Quicksend'],
'should have found the right assets that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].senderProfile,
['testExisting_senderProfile_rcb'],
'should have found the right senderProfiles that need updating'
);
// check if conversions happened
assert.deepEqual(
await testUtils.getActualJson('testExisting_journey_Quicksend', 'journey'),
await testUtils.getExpectedJson('9999999', 'journey', 'get-quicksend-rcb-key'),
'returned JSON was not equal expected'
);
assert.deepEqual(
await testUtils.getActualJson(
'testExisting_senderProfile_rcb',
'senderProfile'
),
await testUtils.getExpectedJson('9999999', 'senderProfile', 'get-rcb-key'),
'returned JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
44,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
});
describe('without types specified ================', () => {
it('Should replace references with ContentBlockByName w/o deploy', async () => {
handler.setOptions({ skipDeploy: true });
// WHEN
const replace = await handler.replaceCbReference(
'testInstance/testBU',
undefined,
'name'
);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
// retrieve result
assert.deepEqual(
replace['testInstance/testBU'].asset,
[
'testExisting_asset_htmlblock',
'testExisting_htmlblock1',
'testExisting_htmlblock 3 spaces',
'testExisting_asset_message',
],
'should have found the right assets that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].journey,
['testExisting_journey_Quicksend'],
'should have found the right assets that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].script,
[
'testExisting_script_ampscript',
'testExisting_script_ampincluded',
'testExisting_script_mixed',
],
'should have found the right scripts that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].senderProfile,
['testExisting_senderProfile_rcb'],
'should have found the right senderProfiles that need updating'
);
// check if conversions happened
assert.deepEqual(
await testUtils.getActualJson('testExisting_journey_Quicksend', 'journey'),
await testUtils.getExpectedJson('9999999', 'journey', 'get-quicksend-rcb-name'),
'returned JSON was not equal expected'
);
assert.deepEqual(
await testUtils.getActualJson(
'testExisting_senderProfile_rcb',
'senderProfile'
),
await testUtils.getExpectedJson('9999999', 'senderProfile', 'get-rcb-name'),
'returned JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
80,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should replace references with ContentBlockById w/o deploy', async () => {
handler.setOptions({ skipDeploy: true });
// WHEN
const replace = await handler.replaceCbReference(
'testInstance/testBU',
undefined,
'id'
);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
// retrieve result
assert.deepEqual(
replace['testInstance/testBU'].asset,
[
'testExisting_htmlblock1',
'testExisting_htmlblock 3 spaces',
'testExisting_asset_message',
],
'should have found the right assets that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].journey,
['testExisting_journey_Quicksend'],
'should have found the right assets that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].script,
['testExisting_script_ampscript', 'testExisting_script_mixed'],
'should have found the right scripts that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].senderProfile,
['testExisting_senderProfile_rcb'],
'should have found the right senderProfiles that need updating'
);
// check if conversions happened
assert.deepEqual(
await testUtils.getActualJson('testExisting_journey_Quicksend', 'journey'),
await testUtils.getExpectedJson('9999999', 'journey', 'get-quicksend-rcb-id'),
'returned JSON was not equal expected'
);
assert.deepEqual(
await testUtils.getActualJson(
'testExisting_senderProfile_rcb',
'senderProfile'
),
await testUtils.getExpectedJson('9999999', 'senderProfile', 'get-rcb-id'),
'returned JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
80,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should replace references with ContentBlockByKey w/o deploy', async () => {
handler.setOptions({ skipDeploy: true });
// WHEN
const replace = await handler.replaceCbReference(
'testInstance/testBU',
undefined,
'key'
);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
// retrieve result
assert.deepEqual(
replace['testInstance/testBU'].asset,
[
'testExisting_asset_htmlblock',
'testExisting_htmlblock1',
'testExisting_asset_message',
],
'should have found the right assets that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].journey,
['testExisting_journey_Quicksend'],
'should have found the right assets that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].script,
['testExisting_script_ampscript', 'testExisting_script_ampincluded'],
'should have found the right scripts that need updating'
);
assert.deepEqual(
replace['testInstance/testBU'].senderProfile,
['testExisting_senderProfile_rcb'],
'should have found the right senderProfiles that need updating'
);
// check if conversions happened
assert.deepEqual(
await testUtils.getActualJson('testExisting_journey_Quicksend', 'journey'),
await testUtils.getExpectedJson('9999999', 'journey', 'get-quicksend-rcb-key'),
'returned JSON was not equal expected'
);
assert.deepEqual(
await testUtils.getActualJson(
'testExisting_senderProfile_rcb',
'senderProfile'
),
await testUtils.getExpectedJson('9999999', 'senderProfile', 'get-rcb-key'),
'returned JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
80,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
});
});
describe('with --metadata ================', () => {
describe('retrieve --metadata ~~~', () => {
it('retrieve single type without keys', async () => {
const argvMetadata = ['dataExtract'];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
const result = await handler.retrieve(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
const retrievedTypes = Object.keys(result[buName]);
assert.equal(retrievedTypes.length, 1, 'retrieve should have returned 1 type');
assert.equal(
retrievedTypes[0],
'dataExtract',
'retrieve should have returned 1 type'
);
assert.equal(
testUtils.getAPIHistoryLength(),
9,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('retrieve multiple type without keys', async () => {
const argvMetadata = ['dataExtension', 'senderProfile'];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
const result = await handler.retrieve(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
const retrievedTypes = Object.keys(result[buName]);
assert.equal(retrievedTypes.length, 2, 'retrieve should have returned 2 types');
assert.equal(
retrievedTypes[0],
'dataExtension',
'retrieve should have returned dataExtension'
);
assert.equal(
retrievedTypes[1],
'senderProfile',
'retrieve should have returned senderProfile'
);
assert.equal(
Object.keys(result[buName]['senderProfile']).length,
3,
'retrieve should have returned 3 senderProfile'
);
assert.equal(
testUtils.getAPIHistoryLength(),
10,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('retrieve multiple type with keys', async () => {
const argvMetadata = [
'dataExtension',
'dataExtract:wrong-key',
'senderProfile:Default',
'query:testExisting_query',
'query:key:testExisting_query2',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
const result = await handler.retrieve(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error');
const retrievedTypes = Object.keys(result[buName]);
assert.equal(retrievedTypes.length, 4, 'retrieve should have returned 4 types');
assert.equal(
retrievedTypes.includes('dataExtension'),
true,
'retrieve should have returned dataExtension'
);
assert.equal(
retrievedTypes.includes('dataExtract'),
true,
'retrieve should have returned dataExtract'
);
assert.equal(
retrievedTypes.includes('senderProfile'),
true,
'retrieve should have returned senderProfile'
);
assert.equal(
retrievedTypes.includes('query'),
true,
'retrieve should have returned query'
);
assert.equal(
Object.keys(result[buName]['dataExtension']).length,
8,
'retrieve should have returned 7 dataExtension'
);
assert.equal(
Object.keys(result[buName]['dataExtract']).length,
0,
'retrieve should have returned 0 dataExtracts'
);
assert.equal(
Object.keys(result[buName]['senderProfile']).length,
1,
'retrieve should have returned 1 senderProfile'
);
assert.equal(
Object.keys(result[buName]['query']).length,
2,
'retrieve should have returned 2 query'
);
assert.equal(
testUtils.getAPIHistoryLength(),
18,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
});
describe('deploy --metadata ~~~', () => {
beforeEach(() => {
testUtils.mockSetup(true);
});
it('deploy single type without keys', async () => {
const argvMetadata = ['dataExtract'];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
const result = await handler.deploy(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 0, 'deploy should not have thrown an error');
const deployedTypes = Object.keys(result[buName]);
assert.equal(deployedTypes.length, 1, 'deploy should have returned 1 type');
assert.equal(deployedTypes[0], 'dataExtract', 'deploy should have returned 1 type');
assert.equal(
testUtils.getAPIHistoryLength(),
13,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('deploy multiple type without keys', async () => {
const argvMetadata = ['dataExtension', 'senderProfile'];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
const result = await handler.deploy(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 0, 'deploy should not have thrown an error');
const deployedTypes = Object.keys(result[buName]);
assert.equal(deployedTypes.length, 2, 'deploy should have returned 2 types');
assert.equal(
deployedTypes[0],
'dataExtension',
'deploy should have returned dataExtension'
);
assert.equal(
deployedTypes[1],
'senderProfile',
'deploy should have returned senderProfile'
);
assert.equal(
Object.keys(result[buName]['dataExtension']).length,
2,
'deploy should have returned 2 dataExtension'
);
assert.equal(
Object.keys(result[buName]['senderProfile']).length,
2,
'deploy should have returned 2 senderProfile'
);
assert.equal(
testUtils.getAPIHistoryLength(),
20,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('deploy multiple type with keys', async () => {
const argvMetadata = [
'dataExtension',
'dataExtract:wrong-key',
'senderProfile:testExisting_senderProfile',
'query:testExisting_query',
'query:key:wrong-key2',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
const result = await handler.deploy(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 0, 'deploy should not have thrown an error');
const deployedTypes = Object.keys(result[buName]);
assert.equal(deployedTypes.length, 3, 'deploy should have returned 3 types');
assert.equal(
deployedTypes.includes('dataExtension'),
true,
'deploy should have returned dataExtension'
);
assert.equal(
deployedTypes.includes('dataExtract'),
false,
'deploy should have returned dataExtract'
);
assert.equal(
deployedTypes.includes('senderProfile'),
true,
'deploy should have returned senderProfile'
);
assert.equal(
deployedTypes.includes('query'),
true,
'deploy should have returned query'
);
assert.equal(
Object.keys(result[buName]['dataExtension']).length,
2,
'deploy should have returned 2 dataExtension'
);
assert.equal(
Object.keys(result[buName]['senderProfile']).length,
1,
'deploy should have returned 1 senderProfile'
);
assert.equal(
Object.keys(result[buName]['query']).length,
1,
'deploy should have returned 1 query'
);
assert.equal(
testUtils.getAPIHistoryLength(),
19,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('deploy multiple type with keys and --noUpdate', async () => {
handler.setOptions({ noUpdate: true });
const argvMetadata = [
'dataExtension',
'dataExtract:wrong-key',
'senderProfile:testExisting_senderProfile',
'query:testExisting_query',
'query:key:wrong-key2',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
const result = await handler.deploy(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 0, 'deploy should not have thrown an error');
const deployedTypes = Object.keys(result[buName]);
assert.equal(deployedTypes.length, 3, 'deploy should have returned 3 types');
assert.equal(
deployedTypes.includes('dataExtension'),
true,
'deploy should have returned dataExtension'
);
assert.equal(
deployedTypes.includes('dataExtract'),
false,
'deploy should have returned dataExtract'
);
assert.equal(
deployedTypes.includes('senderProfile'),
true,
'deploy should have returned senderProfile'
);
assert.equal(
deployedTypes.includes('query'),
true,
'deploy should have returned query'
);
assert.equal(
Object.keys(result[buName]['dataExtension']).length,
1,
'deploy should have returned 1 dataExtension'
);
assert.equal(
Object.keys(result[buName]['senderProfile']).length,
0,
'deploy should have returned 0 senderProfile'
);
assert.equal(
Object.keys(result[buName]['query']).length,
0,
'deploy should have returned 0 query'
);
assert.equal(
testUtils.getAPIHistoryLength(),
16,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('skip deploy event with bad filename or bad extension', async () => {
testUtils.copyToDeploy('event-deploy', 'event');
const argvMetadata = [
'event:testNew_event_badExtension',
'event:testNew_event_badName',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
const buName = 'testInstance/testBU';
await handler.deploy(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 1, 'deploy should not have thrown an error');
assert.equal(
testUtils.getAPIHistoryLength(),
0,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('skip deploy asset with bad filename or bad extension', async () => {
testUtils.copyToDeploy('asset-deploy', 'asset');
const argvMetadata = [
'asset:testNew_asset_badExtension',
'asset:testNew_asset_badName',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
const buName = 'testInstance/testBU';
await handler.deploy(buName, typeKeyCombo);
// THEN
assert.equal(process.exitCode, 1, 'deploy should have thrown an error');
assert.equal(
testUtils.getAPIHistoryLength(),
0,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('skip deploy based on validation rule "filterPrefixByBu" with --fix without error', async () => {
testUtils.copyToDeploy('asset-deploy2', 'asset');
testUtils.copyToDeploy('dataExtension-deploy', 'dataExtension');
const buName = 'testInstance/testBU';
handler.setOptions({ fix: true });
await handler.deploy(buName, {
asset: ['testBlacklist_asset_htmlblock'],
dataExtension: ['testBlacklist_dataExtension'],
});
// THEN
assert.equal(process.exitCode, 0, 'deploy should not have thrown an error');
assert.equal(
testUtils.getAPIHistoryLength(),
8,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('skip deploy based on validation rule "filterPrefixByBu" without --fix but with error', async () => {
testUtils.copyToDeploy('asset-deploy2', 'asset');
testUtils.copyToDeploy('dataExtension-deploy', 'dataExtension');
const buName = 'testInstance/testBU';
await handler.deploy(buName, {
asset: ['testBlacklist_asset_htmlblock'],
dataExtension: ['testBlacklist_dataExtension'],
});
// THEN
assert.equal(process.exitCode, 1, 'deploy should have thrown an error');
assert.equal(
testUtils.getAPIHistoryLength(),
8,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
});
describe('template --metadata ~~~', () => {
it('buildTemplate + buildDefinition for multiple types with keys', async () => {
// download first before we test buildTemplate
await handler.retrieve('testInstance/testBU', ['automation', 'query']);
const expectedApiCallsRetrieve = 35;
assert.equal(
testUtils.getAPIHistoryLength(),
expectedApiCallsRetrieve,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
// preparation
const argvMetadata = [
'automation:testExisting_automation',
'query:testExisting_query',
'query:bad',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
// *** buildTemplate ***
const templateResult = await handler.buildTemplate(
buName,
typeKeyCombo,
undefined,
['testSourceMarket']
);
assert.equal(process.exitCode, 0, 'buildTemplate should not have thrown an error');
// check automation
assert.equal(
templateResult.automation ? Object.keys(templateResult.automation).length : 0,
1,
'only one automation expected'
);
assert.deepEqual(
await testUtils.getActualTemplateJson('testExisting_automation', 'automation'),
await testUtils.getExpectedJson('9999999', 'automation', 'template'),
'returned template was not equal expected'
);
// check query
assert.equal(
templateResult.query ? Object.keys(templateResult.query).length : 0,
1,
'only one query expected'
);
assert.deepEqual(
await testUtils.getActualTemplateJson('testExisting_query', 'query'),
await testUtils.getExpectedJson('9999999', 'query', 'template'),
'returned template JSON of retrieveAsTemplate was not equal expected'
);
expect(
await testUtils.getActualTemplateFile('testExisting_query', 'query', 'sql')
).to.equal(await testUtils.getExpectedFile('9999999', 'query', 'template', 'sql'));
// *** buildDefinition ***
const definitionResult = await handler.buildDefinition(
buName,
typeKeyCombo,
undefined,
['testTargetMarket']
);
assert.equal(
process.exitCode,
0,
'buildDefinition should not have thrown an error'
);
// check automation
assert.equal(
definitionResult.automation
? Object.keys(definitionResult.automation).length
: 0,
1,
'only one automation expected'
);
assert.deepEqual(
await testUtils.getActualDeployJson('testTemplated_automation', 'automation'),
await testUtils.getExpectedJson('9999999', 'automation', 'build'),
'returned deployment file was not equal expected'
);
// check query
assert.equal(
definitionResult.query ? Object.keys(definitionResult.query).length : 0,
1,
'only one query expected'
);
assert.deepEqual(
await testUtils.getActualDeployJson('testTemplated_query', 'query'),
await testUtils.getExpectedJson('9999999', 'query', 'build'),
'returned deployment JSON was not equal expected'
);
expect(
await testUtils.getActualDeployFile('testTemplated_query', 'query', 'sql')
).to.equal(await testUtils.getExpectedFile('9999999', 'query', 'build', 'sql'));
assert.equal(
testUtils.getAPIHistoryLength() - expectedApiCallsRetrieve,
0,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('buildTemplate + buildDefinition for multiple types with keys and --retrieve', async () => {
const expectedApiCallsRetrieve = 32;
// preparation
const argvMetadata = [
'automation:testExisting_automation',
'query:testExisting_query',
'query:bad',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
handler.setOptions({ retrieve: true });
// *** buildTemplate ***
const templateResult = await handler.buildTemplate(
buName,
typeKeyCombo,
undefined,
['testSourceMarket']
);
assert.equal(process.exitCode, 0, 'buildTemplate should not have thrown an error');
// check automation
assert.equal(
templateResult.automation ? Object.keys(templateResult.automation).length : 0,
1,
'only one automation expected'
);
assert.deepEqual(
await testUtils.getActualTemplateJson('testExisting_automation', 'automation'),
await testUtils.getExpectedJson('9999999', 'automation', 'template'),
'returned template was not equal expected'
);
// check query
assert.equal(
templateResult.query ? Object.keys(templateResult.query).length : 0,
1,
'only one query expected'
);
assert.deepEqual(
await testUtils.getActualTemplateJson('testExisting_query', 'query'),
await testUtils.getExpectedJson('9999999', 'query', 'template'),
'returned template JSON of retrieveAsTemplate was not equal expected'
);
expect(
await testUtils.getActualTemplateFile('testExisting_query', 'query', 'sql')
).to.equal(await testUtils.getExpectedFile('9999999', 'query', 'template', 'sql'));
// *** buildDefinition ***
const definitionResult = await handler.buildDefinition(
buName,
typeKeyCombo,
undefined,
['testTargetMarket']
);
assert.equal(
process.exitCode,
0,
'buildDefinition should not have thrown an error'
);
// check automation
assert.equal(
definitionResult.automation
? Object.keys(definitionResult.automation).length
: 0,
1,
'only one automation expected'
);
assert.deepEqual(
await testUtils.getActualDeployJson('testTemplated_automation', 'automation'),
await testUtils.getExpectedJson('9999999', 'automation', 'build'),
'returned deployment file was not equal expected'
);
// check query
assert.equal(
definitionResult.query ? Object.keys(definitionResult.query).length : 0,
1,
'only one query expected'
);
assert.deepEqual(
await testUtils.getActualDeployJson('testTemplated_query', 'query'),
await testUtils.getExpectedJson('9999999', 'query', 'build'),
'returned deployment JSON was not equal expected'
);
expect(
await testUtils.getActualDeployFile('testTemplated_query', 'query', 'sql')
).to.equal(await testUtils.getExpectedFile('9999999', 'query', 'build', 'sql'));
assert.equal(
testUtils.getAPIHistoryLength(),
expectedApiCallsRetrieve,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('buildTemplate + buildDefinition for multiple types with keys and --dependencies', async () => {
// download first before we test buildTemplate
await handler.retrieve('testInstance/testBU');
const expectedApiCallsRetrieve = 101;
assert.equal(
testUtils.getAPIHistoryLength(),
expectedApiCallsRetrieve,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
// preparation
const argvMetadata = [
'automation:testExisting_automation',
'query:testExisting_query',
'query:bad',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
// set skipInteraction to true to skip re-retrieving question
handler.setOptions({ dependencies: true, skipInteraction: true });
// *** buildTemplate ***
const templateResult = await handler.buildTemplate(
buName,
typeKeyCombo,
undefined,
['testSourceMarket']
);
assert.equal(process.exitCode, 0, 'buildTemplate should not have thrown an error');
// check type list
assert.deepEqual(
Object.keys(templateResult),
[
'automation',
'dataExtension',
'dataExtract',
'domainVerification',
'emailSend',
'fileTransfer',
'importFile',
'query',
'script',
'sendClassification',
'senderProfile',
'verification',
],
'did not create deployment packages for all relevant types'
);
// check automation
assert.equal(
templateResult.automation ? Object.keys(templateResult.automation).length : 0,
1,
'only one automation expected'
);
assert.deepEqual(
await testUtils.getActualTemplateJson('testExisting_automation', 'automation'),
await testUtils.getExpectedJson('9999999', 'automation', 'template'),
'returned template was not equal expected'
);
// check query
assert.equal(
templateResult.query ? Object.keys(templateResult.query).length : 0,
1,
'only one query expected'
);
assert.deepEqual(
await testUtils.getActualTemplateJson('testExisting_query', 'query'),
await testUtils.getExpectedJson('9999999', 'query', 'template'),
'returned template JSON of retrieveAsTemplate was not equal expected'
);
expect(
await testUtils.getActualTemplateFile('testExisting_query', 'query', 'sql')
).to.equal(await testUtils.getExpectedFile('9999999', 'query', 'template', 'sql'));
// *** buildDefinition ***
const definitionResult = await handler.buildDefinition(
buName,
typeKeyCombo,
undefined,
['testTargetMarket']
);
assert.equal(
process.exitCode,
0,
'buildDefinition should not have thrown an error'
);
// check automation
assert.equal(
definitionResult.automation
? Object.keys(definitionResult.automation).length
: 0,
1,
'only one automation expected'
);
assert.deepEqual(
await testUtils.getActualDeployJson('testTemplated_automation', 'automation'),
await testUtils.getExpectedJson('9999999', 'automation', 'build'),
'returned deployment file was not equal expected'
);
// check query
assert.equal(
definitionResult.query ? Object.keys(definitionResult.query).length : 0,
1,
'only one query expected'
);
assert.deepEqual(
await testUtils.getActualDeployJson('testTemplated_query', 'query'),
await testUtils.getExpectedJson('9999999', 'query', 'build'),
'returned deployment JSON was not equal expected'
);
expect(
await testUtils.getActualDeployFile('testTemplated_query', 'query', 'sql')
).to.equal(await testUtils.getExpectedFile('9999999', 'query', 'build', 'sql'));
assert.equal(
testUtils.getAPIHistoryLength() - expectedApiCallsRetrieve,
4,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
});
it('buildTemplate + buildDefinition for multiple types with keys and --dependencies and --retrieve', async () => {
// preparation
const argvMetadata = [
'automation:testExisting_automation',
'query:testExisting_query',
'query:bad',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
assert.notEqual(
typeof typeKeyCombo,
'undefined',
'typeKeyCombo should not be undefined'
);
const buName = 'testInstance/testBU';
handler.setOptions({ dependencies: true, retrieve: true });
// *** buildTemplate ***
const templateResult = await handler.buildTemplate(
buName,
typeKeyCombo,
undefined,
['testSourceMarket']
);
assert.equal(process.exitCode, 0, 'buildTemplate should not have thrown an error');
// check type list
assert.deepEqual(
Object.ke