From f9a4527c948143ea3b2fc2a6925df5d402c80774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Wed, 24 Apr 2024 13:51:05 +0200 Subject: [PATCH] #1275: add deploy tests and rework retrieve tests with/out --metadata --- test/general.test.js | 529 ++++++++++++++++++++++++++++++++----------- 1 file changed, 391 insertions(+), 138 deletions(-) diff --git a/test/general.test.js b/test/general.test.js index 2db42befd..20ecdd413 100644 --- a/test/general.test.js +++ b/test/general.test.js @@ -16,154 +16,407 @@ describe('GENERAL', () => { testUtils.mockReset(); }); - describe('--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'); - }); + 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'); - 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, 1, 'retrieve should have returned 1 type'); + assert.equal( + retrievedTypes[0], + 'dataExtract', + 'retrieve should have returned 1 type' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 6, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + }); - 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, - 2, - 'retrieve should have returned 2 senderProfile' - ); + 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, + 2, + 'retrieve should have returned 2 senderProfile' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 6, + '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, + 1, + 'retrieve should have returned 1 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(), + 12, + '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'); + describe('deploy --metadata ~~~', () => { + beforeEach(() => { + testUtils.mockSetup(true); + }); - 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, - 1, - 'retrieve should have returned 1 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' - ); + 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(), + 8, + '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(), + 14, + '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(), + 15, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + }); }); }); describe('without --metadata ================', () => { - it('retrieve multiple type with keys', async () => { - const buName = 'testInstance/testBU'; - const result = await handler.retrieve( - buName, - ['dataExtract', 'senderProfile'], - ['wrong-key', 'Default'] - ); - // THEN - assert.equal(process.exitCode, 0, 'retrieve should not have thrown an error'); + describe('retrieve without --metadata ~~~', () => { + it('retrieve multiple type with keys', async () => { + const buName = 'testInstance/testBU'; + const result = await handler.retrieve( + buName, + ['dataExtract', 'senderProfile'], + ['wrong-key', 'Default'] + ); + // 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.includes('dataExtract'), - true, - 'retrieve should have returned dataExtract' - ); - assert.equal( - retrievedTypes.includes('senderProfile'), - true, - 'retrieve should have returned senderProfile' - ); - 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' - ); + const retrievedTypes = Object.keys(result[buName]); + assert.equal(retrievedTypes.length, 2, 'retrieve should have returned 2 types'); + assert.equal( + retrievedTypes.includes('dataExtract'), + true, + 'retrieve should have returned dataExtract' + ); + assert.equal( + retrievedTypes.includes('senderProfile'), + true, + 'retrieve should have returned senderProfile' + ); + 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( + testUtils.getAPIHistoryLength(), + 8, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + }); + }); + + describe('deploy without --metadata ~~~', () => { + beforeEach(() => { + testUtils.mockSetup(true); + }); + + it('deploy multiple type without keys', async () => { + const argvMetadata = ['dataExtension', 'senderProfile']; + const buName = 'testInstance/testBU'; + const result = await handler.deploy(buName, argvMetadata); + // 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(), + 14, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + }); + + it('deploy multiple type with keys', async () => { + const buName = 'testInstance/testBU'; + const result = await handler.deploy( + buName, + ['dataExtension', 'dataExtract', 'senderProfile', 'query'], + ['wrong-key', 'wrong-key2', 'testExisting_senderProfile', 'testExisting_query'] + ); + // 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.includes('dataExtension'), + false, + '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]['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(), + 9, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + }); }); });