-
Notifications
You must be signed in to change notification settings - Fork 159
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
Changes from all commits
2eb7e09
74d55d1
93aae5a
95b4bed
3c82769
90f8758
4bea2cd
8fc8498
e8c7b98
df66ab0
4db97a1
f1f6a40
6149064
f5c7596
a6153f0
ce3eba0
39ab7a7
1b9a065
2212901
32a7da8
7387b88
a88ca39
8e7e7cd
771dd53
608698c
517d471
8b4368b
e83257a
ce74a1b
2a4ee58
0759f6e
62e2267
fd7f896
20e26a2
72c4b7d
cb68fe5
c397bbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,14 @@ export default class YAMLContext { | |
mappings: KeywordMappings; | ||
mgmtClient: Auth0APIClient; | ||
assets: Assets; | ||
disableKeywordReplacement: boolean; | ||
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
//@ts-ignore because the assets property gets filled out throughout | ||
this.assets = {}; | ||
|
@@ -50,11 +52,15 @@ export default class YAMLContext { | |
// try load not relative to yaml file | ||
toLoad = f; | ||
} | ||
return loadFileAndReplaceKeywords(path.resolve(toLoad), this.mappings); | ||
return loadFileAndReplaceKeywords(path.resolve(toLoad), { | ||
mappings: this.mappings, | ||
disableKeywordReplacement: this.disableKeywordReplacement, | ||
}); | ||
} | ||
|
||
async loadAssetsFromLocal(opts = { disableKeywordReplacement: false }) { | ||
// Allow to send object/json directly | ||
this.disableKeywordReplacement = opts.disableKeywordReplacement; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only location where |
||
if (typeof this.configFile === 'object') { | ||
this.assets = this.configFile; | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { expect } from 'chai'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { copySync } from 'fs-extra'; | ||
import { copySync, emptyDirSync } from 'fs-extra'; | ||
import { getFiles, existsMustBeDir } from '../../src/utils'; | ||
import { load as yamlLoad } from 'js-yaml'; | ||
import { setupRecording, testNameToWorkingDirectory } from './e2e-utils'; | ||
|
@@ -384,8 +384,32 @@ describe('keyword preservation', () => { | |
config, | ||
}); | ||
|
||
//Dumping without keyword preservation so we can assert that remote values will overwrite local values | ||
await dump({ | ||
output_folder: workDirectory, | ||
format: 'yaml', | ||
config: { | ||
...config, | ||
AUTH0_PRESERVE_KEYWORDS: false, | ||
}, | ||
}); | ||
const yamlWithoutPreservation = yamlLoad( | ||
fs.readFileSync(path.join(workDirectory, 'tenant.yaml')) | ||
); | ||
expect(yamlWithoutPreservation.tenant.friendly_name).to.equal( | ||
'This tenant name should be preserved' | ||
); | ||
expect(yamlWithoutPreservation.tenant.support_email).to.equal('support@travel0.com'); | ||
expect(yamlWithoutPreservation.tenant.support_url).to.equal('https://travel0.com/support'); | ||
expect( | ||
yamlWithoutPreservation.emailTemplates.find(({ template }) => template === 'welcome_email') | ||
.resultUrl | ||
).to.equal('https://travel0.com/welcome'); | ||
|
||
emptyDirSync(workDirectory); | ||
copySync(`${__dirname}/testdata/should-preserve-keywords/yaml`, workDirectory); //It is necessary to copy directory contents to work directory to prevent overwriting of Git-committed files | ||
|
||
//This dump will attempt to preserve keywords | ||
await dump({ | ||
output_folder: workDirectory, | ||
format: 'yaml', | ||
|
@@ -402,10 +426,10 @@ describe('keyword preservation', () => { | |
|
||
// expect(yaml.tenant.enabled_locales).to.equal('@@LANGUAGES@@'); TODO: enable @@ARRAY@@ keyword preservation in yaml formats | ||
|
||
// const emailTemplateHTML = fs | ||
// .readFileSync(path.join(workDirectory, 'emailTemplates', 'welcome_email.html')) | ||
// .toString(); | ||
// expect(emailTemplateHTML).to.contain('##TENANT##'); TODO: enable keyword preservation in auxillary template files | ||
const emailTemplateHTML = fs | ||
.readFileSync(path.join(workDirectory, 'emailTemplates', 'welcome_email.html')) | ||
.toString(); | ||
expect(emailTemplateHTML).to.contain('##TENANT_NAME##'); | ||
|
||
recordingDone(); | ||
}); | ||
|
@@ -420,8 +444,39 @@ describe('keyword preservation', () => { | |
config, | ||
}); | ||
|
||
//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); | ||
Comment on lines
+447
to
+476
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
copySync(`${__dirname}/testdata/should-preserve-keywords/directory`, workDirectory); //It is necessary to copy directory contents to work directory to prevent overwriting of Git-committed files | ||
|
||
//This dump will attempt to preserve keywords | ||
await dump({ | ||
output_folder: workDirectory, | ||
format: 'directory', | ||
|
@@ -442,10 +497,10 @@ describe('keyword preservation', () => { | |
expect(emailTemplateJson.resultUrl).to.equal('https://##DOMAIN##/welcome'); | ||
expect(emailTemplateJson.subject).to.not.equal('##THIS_SHOULD_NOT_BE_PRESERVED##'); | ||
|
||
// const emailTemplateHTML = fs | ||
// .readFileSync(path.join(workDirectory, 'emailTemplates', 'welcome_email.html')) | ||
// .toString(); | ||
// expect(emailTemplateHTML).to.contain('##TENANT##'); TODO: enable keyword preservation in auxillary template files | ||
const emailTemplateHTML = fs | ||
.readFileSync(path.join(workDirectory, 'emailTemplates', 'welcome_email.html')) | ||
.toString(); | ||
expect(emailTemplateHTML).to.contain('##TENANT_NAME##'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This E2E assertion proves that this functionality works 🎉 |
||
|
||
recordingDone(); | ||
}); | ||
|
There was a problem hiding this comment.
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.