Skip to content

Commit

Permalink
fix: automatically add fieldsToFlatten property for mongoose projec…
Browse files Browse the repository at this point in the history
…ts to the generated files (#212)
  • Loading branch information
olesyakorovina authored Aug 4, 2021
1 parent bdbfdc5 commit 08b5661
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/services/dumper/templates/app/forest/collection.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ collection('{{ table }}', {
actions: [],
fields: [],
segments: [],
{{#if isMongoDB }}fieldsToFlatten: [],{{/if}}
});
15 changes: 15 additions & 0 deletions test/services/analyzer/dumper-mongo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,19 @@ describe('services > dumper > MongoDB', () => {
cleanOutput();
});
});

describe('/forest folder', () => {
it('should add `fieldsToFlatten` property in the generated file', async () => {
expect.assertions(1);

const context = buildContext();
const dumper = getDumper(context);
await dumper.dump(simpleModel, CONFIG);
const generatedFile = fs.readFileSync(`${appRoot}/test-output/mongo/forest/films.js`, 'utf8');
const expectedFile = fs.readFileSync(`${__dirname}/expected/mongo/dumper-output/forest-simple.expected.js`, 'utf8');

expect(generatedFile).toStrictEqual(expectedFile);
cleanOutput();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { collection } = require('forest-express-mongoose');

// This file allows you to add to your Forest UI:
// - Smart actions: https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions
// - Smart fields: https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields
// - Smart relationships: https://docs.forestadmin.com/documentation/reference-guide/relationships/create-a-smart-relationship
// - Smart segments: https://docs.forestadmin.com/documentation/reference-guide/segments/smart-segments
collection('films', {
actions: [],
fields: [],
segments: [],
fieldsToFlatten: [],
});

0 comments on commit 08b5661

Please sign in to comment.