From b0390323840aac8032d071304718efcbfed6e637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Thu, 16 May 2024 00:31:55 +0200 Subject: [PATCH] #1325: add test case for multi-type buildTemplate/buildDefinition --- test/general.test.js | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/test/general.test.js b/test/general.test.js index 735fb9c4d..be9751cd9 100644 --- a/test/general.test.js +++ b/test/general.test.js @@ -6,6 +6,7 @@ import chaiFiles from 'chai-files'; import * as testUtils from './utils.js'; import handler from '../lib/index.js'; chai.use(chaiFiles); +const file = chaiFiles.file; describe('GENERAL', () => { beforeEach(() => { @@ -284,6 +285,114 @@ describe('GENERAL', () => { ); }); }); + + describe('template --metadata ~~~', () => { + it('buildDefinition and buildTemplate multiple type with keys', async () => { + // download first before we test buildTemplate + await handler.retrieve('testInstance/testBU', ['automation', 'query']); + + const expectedApiCallsRetrieve = 25; + 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, + null, + '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( + file(testUtils.getActualTemplateFile('testExisting_query', 'query', 'sql')) + ).to.equal(file(testUtils.getExpectedFile('9999999', 'query', 'template', 'sql'))); + + // *** buildDefinition *** + const definitionResult = await handler.buildDefinition( + buName, + typeKeyCombo, + null, + 'testTargetMarket' + ); + assert.equal( + process.exitCode, + 0, + 'buildDefinition should not have thrown an error' + ); + + // check automation + assert.equal( + definitionResult.automation ? Object.keys(templateResult.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(templateResult.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( + file(testUtils.getActualDeployFile('testTemplated_query', 'query', 'sql')) + ).to.equal(file(testUtils.getExpectedFile('9999999', 'query', 'build', 'sql'))); + + assert.equal( + testUtils.getAPIHistoryLength() - expectedApiCallsRetrieve, + 0, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + }); + }); }); describe('without --metadata ================', () => {