Skip to content

Commit

Permalink
#1325: add test case for multi-type buildTemplate/buildDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed May 15, 2024
1 parent c482414 commit b039032
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions test/general.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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 ================', () => {
Expand Down

0 comments on commit b039032

Please sign in to comment.