Skip to content

Commit

Permalink
DXCDT-377: E2E test cases for keyword presevation (#753)
Browse files Browse the repository at this point in the history
* Renaming load to loadAssetsFromLocal

* Renaming load to loadAssetsFromAuth0

* integrating into export process

* Adding config interpreter

* Disabling keyword replacement in certain cases

* Fixing directory load

* More forgiving lookup logic if properties and/or addresses do not exist

* Fixing directory load again

* Adding case that would have previously tripped up process

* Adding e2e tests for keyword preservation

* Removing old tests, updating recordings, removing console. logs

* Commenting-out test to fix later on

* Fixing workdirectory for e2e tests

* Adding eventual cases for auxillary files

* Adding TODO

* Update test/e2e/testdata/should-preserve-keywords/yaml/tenant.yaml

* Update test/e2e/recordings/should-preserve-keywords-for-directory-format.json

* Update test/e2e/recordings/should-preserve-keywords-for-yaml-format.json

---------

Co-authored-by: Will Vedder <[email protected]>
Co-authored-by: Sergiu Ghitea <[email protected]>
  • Loading branch information
3 people authored Feb 23, 2023
1 parent 02db7d6 commit 36087d1
Show file tree
Hide file tree
Showing 8 changed files with 1,059 additions and 1 deletion.
83 changes: 82 additions & 1 deletion test/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from 'chai';
import path from 'path';
import fs from 'fs';
import { copySync } from 'fs-extra';
import { getFiles, existsMustBeDir } from '../../src/utils';
import { load as yamlLoad } from 'js-yaml';
import { setupRecording, testNameToWorkingDirectory } from './e2e-utils';
import { dump, deploy } from '../../src';
import exp from 'constants';
import { AssetTypes } from '../../src/types';

const shouldUseRecordings = process.env['AUTH0_HTTP_RECORDINGS'] === 'lockdown';
Expand Down Expand Up @@ -358,3 +358,84 @@ describe('#end-to-end keyword replacement', function () {
recordingDone();
});
});

describe('keyword preservation', () => {
const config = {
AUTH0_DOMAIN,
AUTH0_CLIENT_ID,
AUTH0_CLIENT_SECRET,
AUTH0_ACCESS_TOKEN,
AUTH0_PRESERVE_KEYWORDS: true,
AUTH0_INCLUDED_ONLY: ['tenant', 'emailTemplates'] as AssetTypes[],
AUTH0_KEYWORD_REPLACE_MAPPINGS: {
TENANT_NAME: 'This tenant name should be preserved',
DOMAIN: 'travel0.com',
LANGUAGES: ['en', 'es'],
},
};

it('should preserve keywords for yaml format', async function () {
const workDirectory = testNameToWorkingDirectory(this.test?.title);

const { recordingDone } = await setupRecording(this.test?.title);

await deploy({
input_file: `${__dirname}/testdata/should-preserve-keywords/yaml/tenant.yaml`,
config,
});

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

await dump({
output_folder: workDirectory,
format: 'yaml',
config,
});

const yaml = yamlLoad(fs.readFileSync(path.join(workDirectory, 'tenant.yaml')));
expect(yaml.tenant.friendly_name).to.equal('##TENANT_NAME##');
expect(yaml.tenant.support_email).to.equal('support@##DOMAIN##');
expect(yaml.tenant.support_url).to.equal('https://##DOMAIN##/support');
// 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

recordingDone();
});

it('should preserve keywords for directory format', async function () {
const workDirectory = testNameToWorkingDirectory(this.test?.title);

const { recordingDone } = await setupRecording(this.test?.title);

await deploy({
input_file: `${__dirname}/testdata/should-preserve-keywords/directory`,
config,
});

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

await dump({
output_folder: workDirectory,
format: 'directory',
config,
});

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

expect(json.friendly_name).to.equal('##TENANT_NAME##');
expect(json.enabled_locales).to.equal('@@LANGUAGES@@');
expect(json.support_email).to.equal('support@##DOMAIN##');
expect(json.support_url).to.equal('https://##DOMAIN##/support');

// 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

recordingDone();
});
});
Loading

0 comments on commit 36087d1

Please sign in to comment.