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

DXCDT-384: Keyword preservation in auxiliary files #758

Merged
merged 37 commits into from
Mar 1, 2023

Conversation

willvedd
Copy link
Contributor

@willvedd willvedd commented Mar 1, 2023

🔧 Changes

Up to now, the keyword preservation only operated on properties that were directly defined in the resource configuration files, but not auxiliary files such as email HTML templates and action JS files, which are defined in a separate file. This limitation existed because the loadFileAndReplaceKeywords function, a fundamental building block of this repo, was always designed to replace keywords by default. However, in the context of keyword preservation, it is necessary to retrieve the "raw" files. This PR enables keyword preservation for auxiliary files too with a logic change in loadFileAndReplaceKeywords which bifurcates the functionality and disables keyword replacement depending on the operating context.

📚 References

Related Keyword Preservation RFC: #688

🔬 Testing

Added several new E2E test assertions. Updated loadFileAndReplaceKeywords function unit tests.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

willvedd and others added 30 commits February 21, 2023 15:35
…ort' into fix-make-keyword-preservation-more-flexible
…to DXCDT-382-standardize-resource-identifiers
@willvedd willvedd requested a review from a team as a code owner March 1, 2023 17:23
Comment on lines +43 to +46
{
mappings: context.mappings,
disableKeywordReplacement: context.disableKeywordReplacement,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the diffs in this PR are due to the changing function signature of loadFileAndReplaceKeywords which adds an option to disable keyword replacement.


constructor(config: Config, mgmtClient) {
this.configFile = config.AUTH0_INPUT_FILE;
this.config = config;
this.mappings = config.AUTH0_KEYWORD_REPLACE_MAPPINGS || {};
this.mgmtClient = mgmtClient;
this.disableKeywordReplacement = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, keyword replacement is enabled (not disabled). This configuration value is only enabled during the keyword preservation stage.

}

async loadAssetsFromLocal(opts = { disableKeywordReplacement: false }) {
// Allow to send object/json directly
this.disableKeywordReplacement = opts.disableKeywordReplacement;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only location where disableKeywordReplacement is set to true.

Comment on lines +447 to +476
//Dumping without keyword preservation so we can assert that remote values will overwrite local values
await dump({
output_folder: workDirectory,
format: 'directory',
config: {
...config,
AUTH0_PRESERVE_KEYWORDS: false,
},
});

const jsonWithoutPreservation = JSON.parse(
fs.readFileSync(path.join(workDirectory, 'tenant.json')).toString()
);

expect(jsonWithoutPreservation.friendly_name).to.equal('This tenant name should be preserved');
expect(jsonWithoutPreservation.enabled_locales).to.deep.equal(['en', 'es']);
expect(jsonWithoutPreservation.support_email).to.equal('support@travel0.com');
expect(jsonWithoutPreservation.support_url).to.equal('https://travel0.com/support');

const emailTemplateJsonWithoutPreservation = JSON.parse(
fs.readFileSync(path.join(workDirectory, 'emails', 'welcome_email.json')).toString()
);

expect(emailTemplateJsonWithoutPreservation.resultUrl).to.equal('https://travel0.com/welcome');

expect(
fs.readFileSync(path.join(workDirectory, 'emails', 'welcome_email.html')).toString()
).to.contain('This tenant name should be preserved');

emptyDirSync(workDirectory);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new E2E assertions are to ensure that keyword replacement worked when keyword preservation disabled. Otherwise, false positives could occur during testing.

const emailTemplateHTML = fs
.readFileSync(path.join(workDirectory, 'emailTemplates', 'welcome_email.html'))
.toString();
expect(emailTemplateHTML).to.contain('##TENANT_NAME##');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This E2E assertion proves that this functionality works 🎉

@codecov-commenter
Copy link

codecov-commenter commented Mar 1, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change

Comparison is base (247193f) 84.07% compared to head (c397bbe) 84.08%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #758   +/-   ##
=======================================
  Coverage   84.07%   84.08%           
=======================================
  Files         115      115           
  Lines        3510     3512    +2     
  Branches      670      670           
=======================================
+ Hits         2951     2953    +2     
  Misses        322      322           
  Partials      237      237           
Impacted Files Coverage Δ
src/context/directory/handlers/branding.ts 87.75% <ø> (ø)
src/context/directory/handlers/emailTemplates.ts 80.55% <ø> (ø)
src/context/directory/handlers/pages.ts 82.92% <ø> (ø)
src/context/yaml/handlers/branding.ts 86.66% <ø> (ø)
src/context/directory/handlers/clients.ts 93.93% <100.00%> (ø)
src/context/directory/handlers/connections.ts 97.50% <100.00%> (ø)
src/context/directory/handlers/databases.ts 83.63% <100.00%> (ø)
src/context/directory/index.ts 90.32% <100.00%> (ø)
src/context/yaml/index.ts 85.26% <100.00%> (+0.31%) ⬆️
src/tools/utils.ts 95.86% <100.00%> (+0.03%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@willvedd willvedd merged commit bdc06aa into master Mar 1, 2023
@willvedd willvedd deleted the DXCDT-384-keyword-replacement-in-auxillary-files branch March 1, 2023 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants