Skip to content
Draft
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
9 changes: 8 additions & 1 deletion src/context/directory/handlers/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ async function dump(context: DirectoryContext) {
const flowFile = path.join(flowsFolder, sanitize(`${flow.name}.json`));
log.info(`Writing ${flowFile}`);

const removeKeysFromOutput = ['id', 'created_at', 'updated_at', 'submitted_at', 'embedded_at'];
const includeIdentifiers = Boolean(context.config.AUTH0_EXPORT_IDENTIFIERS);
const removeKeysFromOutput = [
...(!includeIdentifiers ? ['id'] : []),
'created_at',
'updated_at',
'submitted_at',
'embedded_at',
];
removeKeysFromOutput.forEach((key) => {
if (key in flow) {
delete flow[key];
Expand Down
7 changes: 6 additions & 1 deletion src/context/directory/handlers/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ async function dump(context: DirectoryContext) {
const formFile = path.join(formsFolder, sanitize(`${form.name}.json`));
log.info(`Writing ${formFile}`);

const removeKeysFromOutput = ['id', 'created_at', 'updated_at'];
const includeIdentifiers = Boolean(context.config.AUTH0_EXPORT_IDENTIFIERS);
const removeKeysFromOutput = [
...(!includeIdentifiers ? ['id'] : []),
'created_at',
'updated_at',
];
removeKeysFromOutput.forEach((key) => {
if (key in form) {
delete form[key];
Expand Down
9 changes: 8 additions & 1 deletion src/context/yaml/handlers/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ async function dump(context: YAMLContext): Promise<ParsedFlows> {
const jsonFile = path.join(pagesFolder, `${flowName}.json`);
log.info(`Writing ${jsonFile}`);

const removeKeysFromOutput = ['id', 'created_at', 'updated_at', 'submitted_at', 'embedded_at'];
const includeIdentifiers = Boolean(context.config.AUTH0_EXPORT_IDENTIFIERS);
const removeKeysFromOutput = [
...(!includeIdentifiers ? ['id'] : []),
'created_at',
'updated_at',
'submitted_at',
'embedded_at',
];
removeKeysFromOutput.forEach((key) => {
if (key in flow) {
delete flow[key];
Expand Down
7 changes: 6 additions & 1 deletion src/context/yaml/handlers/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ async function dump(context: YAMLContext): Promise<ParsedForms> {
const jsonFile = path.join(pagesFolder, `${formName}.json`);
log.info(`Writing ${jsonFile}`);

const removeKeysFromOutput = ['id', 'created_at', 'updated_at'];
const includeIdentifiers = Boolean(context.config.AUTH0_EXPORT_IDENTIFIERS);
const removeKeysFromOutput = [
...(!includeIdentifiers ? ['id'] : []),
'created_at',
'updated_at',
];
removeKeysFromOutput.forEach((key) => {
if (key in form) {
delete form[key];
Expand Down
33 changes: 33 additions & 0 deletions test/context/directory/flows.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,37 @@ describe('#directory context flows', () => {
context.assets.flows[1]
);
});

it('should dump flows with id when AUTH0_EXPORT_IDENTIFIERS is true', async () => {
const dir = path.join(testDataDir, 'directory', 'flowsDumpWithId');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: dir, AUTH0_EXPORT_IDENTIFIERS: true },
mockMgmtClient()
);

context.assets.flows = [{ id: 'flow-id-1', name: 'someFlow' }];

await handler.dump(context);
const flowsFolder = path.join(dir, constants.FLOWS_DIRECTORY);
expect(loadJSON(path.join(flowsFolder, 'someFlow.json'))).to.deep.equal({
id: 'flow-id-1',
name: 'someFlow',
});
});

it('should dump flows without id when AUTH0_EXPORT_IDENTIFIERS is false', async () => {
const dir = path.join(testDataDir, 'directory', 'flowsDumpNoId');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: dir, AUTH0_EXPORT_IDENTIFIERS: false },
mockMgmtClient()
);

context.assets.flows = [{ id: 'flow-id-1', name: 'someFlow' }];

await handler.dump(context);
const flowsFolder = path.join(dir, constants.FLOWS_DIRECTORY);
expect(loadJSON(path.join(flowsFolder, 'someFlow.json'))).to.deep.equal({ name: 'someFlow' });
});
});
33 changes: 33 additions & 0 deletions test/context/directory/forms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,37 @@ describe('#directory context forms', () => {
context.assets.forms[1]
);
});

it('should dump forms with id when AUTH0_EXPORT_IDENTIFIERS is true', async () => {
const dir = path.join(testDataDir, 'directory', 'formsDumpWithId');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: dir, AUTH0_EXPORT_IDENTIFIERS: true },
mockMgmtClient()
);

context.assets.forms = [{ id: 'form-id-1', name: 'someForm' }];

await handler.dump(context);
const formsFolder = path.join(dir, constants.FORMS_DIRECTORY);
expect(loadJSON(path.join(formsFolder, 'someForm.json'))).to.deep.equal({
id: 'form-id-1',
name: 'someForm',
});
});

it('should dump forms without id when AUTH0_EXPORT_IDENTIFIERS is false', async () => {
const dir = path.join(testDataDir, 'directory', 'formsDumpNoId');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: dir, AUTH0_EXPORT_IDENTIFIERS: false },
mockMgmtClient()
);

context.assets.forms = [{ id: 'form-id-1', name: 'someForm' }];

await handler.dump(context);
const formsFolder = path.join(dir, constants.FORMS_DIRECTORY);
expect(loadJSON(path.join(formsFolder, 'someForm.json'))).to.deep.equal({ name: 'someForm' });
});
});
36 changes: 36 additions & 0 deletions test/context/yaml/flows.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,40 @@ describe('#YAML context flows', () => {
JSON.parse(fs.readFileSync(path.join(flowsFolder, 'Sample Flow 2.json'), 'utf8'))
).to.deep.equal({ name: 'Sample Flow 2' });
});

it('should dump flows with id when AUTH0_EXPORT_IDENTIFIERS is true', async () => {
const dir = path.join(testDataDir, 'yaml', 'flowsWithId');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: path.join(dir, './test.yml'), AUTH0_EXPORT_IDENTIFIERS: true },
mockMgmtClient()
);

context.assets.flows = [{ id: 'flow-id-1', name: 'Sample Flow 1' }];

await handler.dump(context);
const flowsFolder = path.join(dir, 'flows');

expect(
JSON.parse(fs.readFileSync(path.join(flowsFolder, 'Sample Flow 1.json'), 'utf8'))
).to.deep.equal({ id: 'flow-id-1', name: 'Sample Flow 1' });
});

it('should dump flows without id when AUTH0_EXPORT_IDENTIFIERS is false', async () => {
const dir = path.join(testDataDir, 'yaml', 'flowsNoId');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: path.join(dir, './test.yml'), AUTH0_EXPORT_IDENTIFIERS: false },
mockMgmtClient()
);

context.assets.flows = [{ id: 'flow-id-1', name: 'Sample Flow 1' }];

await handler.dump(context);
const flowsFolder = path.join(dir, 'flows');

expect(
JSON.parse(fs.readFileSync(path.join(flowsFolder, 'Sample Flow 1.json'), 'utf8'))
).to.deep.equal({ name: 'Sample Flow 1' });
});
});
36 changes: 36 additions & 0 deletions test/context/yaml/forms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,40 @@ describe('#YAML context forms', () => {
JSON.parse(fs.readFileSync(path.join(formsFolder, 'Sample Form 2.json'), 'utf8'))
).to.deep.equal({ name: 'Sample Form 2' });
});

it('should dump forms with id when AUTH0_EXPORT_IDENTIFIERS is true', async () => {
const dir = path.join(testDataDir, 'yaml', 'formsWithId');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: path.join(dir, './test.yml'), AUTH0_EXPORT_IDENTIFIERS: true },
mockMgmtClient()
);

context.assets.forms = [{ id: 'form-id-1', name: 'Sample Form 1' }];

await handler.dump(context);
const formsFolder = path.join(dir, 'forms');

expect(
JSON.parse(fs.readFileSync(path.join(formsFolder, 'Sample Form 1.json'), 'utf8'))
).to.deep.equal({ id: 'form-id-1', name: 'Sample Form 1' });
});

it('should dump forms without id when AUTH0_EXPORT_IDENTIFIERS is false', async () => {
const dir = path.join(testDataDir, 'yaml', 'formsNoId');
cleanThenMkdir(dir);
const context = new Context(
{ AUTH0_INPUT_FILE: path.join(dir, './test.yml'), AUTH0_EXPORT_IDENTIFIERS: false },
mockMgmtClient()
);

context.assets.forms = [{ id: 'form-id-1', name: 'Sample Form 1' }];

await handler.dump(context);
const formsFolder = path.join(dir, 'forms');

expect(
JSON.parse(fs.readFileSync(path.join(formsFolder, 'Sample Form 1.json'), 'utf8'))
).to.deep.equal({ name: 'Sample Form 1' });
});
});