Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/1857 re-retrieve sendClassification after deploy to get created and modified date #1963

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/DataExtract.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions @types/lib/metadataTypes/SendClassification.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/SendClassification.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/metadataTypes/DataExtract.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class DataExtract extends MetadataType {
delete metadata.r__dataExtractType_name;
return metadata;
}

/**
* Gets executed after deployment of metadata type
*
Expand All @@ -146,7 +147,9 @@ class DataExtract extends MetadataType {
*/
static async postDeployTasks(upsertResults) {
// re-retrieve all upserted items to ensure we have all fields (createdDate and modifiedDate are otherwise not present)
Util.logger.debug('Retrieving all dataExtracts post-deploy to ensure we have all fields');
Util.logger.debug(
`Caching all ${this.definition.type} post-deploy to ensure we have all fields`
);
const typeCache = await this.retrieveForCache();
// update values in upsertResults with retrieved values before saving to disk
for (const key of Object.keys(upsertResults)) {
Expand Down
20 changes: 20 additions & 0 deletions lib/metadataTypes/SendClassification.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ class SendClassification extends MetadataType {
return metadata;
}

/**
* Gets executed after deployment of metadata type
*
* @param {MetadataTypeMap} upsertResults metadata mapped by their keyField as returned by update/create
* @returns {Promise.<void>} -
*/
static async postDeployTasks(upsertResults) {
// re-retrieve all upserted items to ensure we have all fields (createdDate and modifiedDate are otherwise not present)
Util.logger.debug(
`Caching all ${this.definition.type} post-deploy to ensure we have all fields`
);
const typeCache = await this.retrieveForCache();
// update values in upsertResults with retrieved values before saving to disk
for (const key of Object.keys(upsertResults)) {
if (typeCache.metadata[key]) {
upsertResults[key] = typeCache.metadata[key];
}
}
}

/**
* manages post retrieve steps
*
Expand Down
22 changes: 12 additions & 10 deletions test/resourceFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ if (Util.isRunViaVSCodeExtension) {
export const tWarn = `${color.bgYellow}${color.fgBlack}TEST-WARNING${color.reset}`;
export const tError = `${color.bgRed}${color.fgBlack}TEST-ERROR${color.reset}`;

const loadingFile = 'loading server file:///';

/**
* gets mock SOAP metadata for responding
*
Expand All @@ -55,7 +57,7 @@ async function loadSOAPRecords(mcdevAction, type, mid, filter, QueryAllAccounts)
const testPath = path.join('test', 'resources', mid.toString(), type, mcdevAction);
const filterPath = getFilterPath(filter, QueryAllAccounts);
if (await fs.pathExists(testPath + filterPath + '-response.xml')) {
console.log('loading ' + projectRoot + testPath + filterPath + '-response.xml'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPath + filterPath + '-response.xml'); // eslint-disable-line no-console
return fs.readFile(testPath + filterPath + '-response.xml', {
encoding: 'utf8',
});
Expand All @@ -71,7 +73,7 @@ async function loadSOAPRecords(mcdevAction, type, mid, filter, QueryAllAccounts)
);
/* eslint-enable no-console */
}
console.log('loading ' + projectRoot + testPath + '-response.xml'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPath + '-response.xml'); // eslint-disable-line no-console
return fs.readFile(testPath + '-response.xml', {
encoding: 'utf8',
});
Expand Down Expand Up @@ -334,10 +336,10 @@ export const handleRESTRequest = async (config) => {
);
response.items = response.items.filter((def) => def.name == filterName);
response.count = response.items.length;
console.log('loading ' + projectRoot + testPathFilter + '.json'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPathFilter + '.json'); // eslint-disable-line no-console
return [200, JSON.stringify(response)];
} else {
console.log('loading ' + projectRoot + testPathFilter + '.json'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPathFilter + '.json'); // eslint-disable-line no-console
return [
200,
await fs.readFile(testPathFilter + '.json', {
Expand All @@ -346,23 +348,23 @@ export const handleRESTRequest = async (config) => {
];
}
} else if (testPathFilter && (await fs.pathExists(testPathFilter + '.txt'))) {
console.log('loading ' + projectRoot + testPathFilter + '.txt'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPathFilter + '.txt'); // eslint-disable-line no-console
return [
200,
await fs.readFile(testPathFilter + '.txt', {
encoding: 'utf8',
}),
];
} else if (testPathFilterBody && (await fs.pathExists(testPathFilterBody + '.json'))) {
console.log('loading ' + projectRoot + testPathFilterBody + '.json'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPathFilterBody + '.json'); // eslint-disable-line no-console
return [
200,
await fs.readFile(testPathFilterBody + '.json', {
encoding: 'utf8',
}),
];
} else if (testPathFilterBody && (await fs.pathExists(testPathFilterBody + '.txt'))) {
console.log('loading ' + projectRoot + testPathFilterBody + '.txt'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPathFilterBody + '.txt'); // eslint-disable-line no-console
return [
200,
await fs.readFile(testPathFilterBody + '.txt', {
Expand Down Expand Up @@ -403,10 +405,10 @@ export const handleRESTRequest = async (config) => {
);
response.items = response.items.filter((def) => def.name == filterName);
response.count = response.items.length;
console.log('loading ' + projectRoot + testPath + '.json'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPath + '.json'); // eslint-disable-line no-console
return [200, JSON.stringify(response)];
} else {
console.log('loading ' + projectRoot + testPath + '.json'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPath + '.json'); // eslint-disable-line no-console

return [
200,
Expand Down Expand Up @@ -438,7 +440,7 @@ export const handleRESTRequest = async (config) => {
);
/* eslint-enable no-console */
}
console.log('loading ' + projectRoot + testPath + '.txt'); // eslint-disable-line no-console
console.log(loadingFile + projectRoot + testPath + '.txt'); // eslint-disable-line no-console
return [
200,
await fs.readFile(testPath + '.txt', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"CreatedDate": "2016-08-31T11:29:00",
"ModifiedDate": "2024-04-15T15:33:00",
"CustomerKey": "testExisting_sendClassification",
"Name": "testExisting_sendClassification",
"Description": "updated on deploy",
"Description": "",
"c__classification": "Commercial",
"r__senderProfile_key": "testExisting_senderProfile",
"r__deliveryProfile_key": "Default"
Expand Down
2 changes: 1 addition & 1 deletion test/type.sendClassification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('type: sendClassification', () => {
// check number of API calls
assert.equal(
testUtils.getAPIHistoryLength(),
5,
6,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
Expand Down
6 changes: 5 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
} from './resourceFactory.js';
const authResources = File.readJsonSync(path.join(__dirname, './resources/auth.json'));

const loadingFile = 'loading expected file:///' + __dirname.split(path.sep).join('/');

/**
* gets file from Retrieve folder
*
Expand Down Expand Up @@ -160,7 +162,9 @@ export function getActualTemplateFile(customerKey, type, ext) {
* @returns {Promise.<string>} file in JSON form
*/
export function getExpectedJson(mid, type, action) {
return File.readJSON(`./test/resources/${mid}/${type}/${action}-expected.json`);
const path = `/resources/${mid}/${type}/${action}-expected.json`;
console.log(loadingFile + path); // eslint-disable-line no-console
return File.readJSON(`./test` + path);
}

/**
Expand Down
Loading