Skip to content

Commit

Permalink
Set entityConfig true as default
Browse files Browse the repository at this point in the history
  • Loading branch information
norato committed Oct 9, 2019
1 parent ee1d059 commit 120a200
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EntityMetadataMap } from '@ngrx/data';
import { EntityMetadataMap, EntityDataModuleConfig } from '@ngrx/data';

const entityMetadata: EntityMetadataMap = {};

const pluralNames = { };

export const entityConfig = {
export const entityConfig: EntityDataModuleConfig = {
entityMetadata,
pluralNames
};
55 changes: 28 additions & 27 deletions modules/data/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@ describe('Data ng-add Schematic', () => {
expect(thrownError).toBeDefined();
});

it('should import EntityDataModuleWithoutEffects into a specified module', () => {
const options = {
...defaultOptions,
module: 'app.module.ts',
effects: false,
};
it('should add entity-metadata config to EntityDataModule', () => {
const options = { ...defaultOptions, effects: false, entityConfig: true };

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
expect(content).toMatch(
/import { EntityDataModuleWithoutEffects } from '@ngrx\/data'/
/import { entityConfig } from '.\/entity-metadata'/
);
expect(content).toMatch(
/EntityDataModuleWithoutEffects.forRoot\(entityConfig\)/
);
});

it('should register EntityDataModule in the provided module', () => {
const options = { ...defaultOptions };
it('should add entity-metadata config file', () => {
const options = { ...defaultOptions, entityConfig: true };

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
expect(content).toMatch(/EntityDataModule\n/);
expect(
tree.files.indexOf(`${projectPath}/src/app/entity-metadata.ts`)
).toBeGreaterThanOrEqual(0);
});

it('should add entity-metadata config to EntityDataModule', () => {
Expand All @@ -101,34 +101,35 @@ describe('Data ng-add Schematic', () => {
expect(content).toMatch(/EntityDataModule.forRoot\(entityConfig\)/);
});

it('should register EntityDataModuleWithoutEffects in the provided module', () => {
const options = { ...defaultOptions, effects: false };
it('should import EntityDataModuleWithoutEffects into a specified module', () => {
const options = {
...defaultOptions,
module: 'app.module.ts',
effects: false,
entityConfig: false,
};

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
expect(content).toMatch(/EntityDataModuleWithoutEffects\n/);
expect(content).toMatch(
/import { EntityDataModuleWithoutEffects } from '@ngrx\/data'/
);
});

it('should add entity-metadata config to EntityDataModule', () => {
const options = { ...defaultOptions, effects: false, entityConfig: true };
it('should register EntityDataModule in the provided module', () => {
const options = { ...defaultOptions, entityConfig: false };

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
expect(content).toMatch(
/import { entityConfig } from '.\/entity-metadata'/
);
expect(content).toMatch(
/EntityDataModuleWithoutEffects.forRoot\(entityConfig\)/
);
expect(content).toMatch(/EntityDataModule\n/);
});

it('should add entity-metadata config file', () => {
const options = { ...defaultOptions, entityConfig: true };
it('should register EntityDataModuleWithoutEffects in the provided module', () => {
const options = { ...defaultOptions, effects: false, entityConfig: false };

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
expect(
tree.files.indexOf(`${projectPath}/src/app/entity-metadata.ts`)
).toBeGreaterThanOrEqual(0);
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
expect(content).toMatch(/EntityDataModuleWithoutEffects\n/);
});

describe('Migration of ngrx-data', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/data/schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"entityConfig": {
"type": "boolean",
"default": false,
"default": true,
"description": "Create the Entity config file"
}
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ngrx.io/content/guide/data/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ng add @ngrx/data
* module - name of file containing the module that you wish to add the import for the `EntityDataModule` to. Can also include the relative path to the file. For example, `src/app/app.module.ts`.
* effects - if `false` it will use the `EntityDataModuleWithoutEffects` module instead of the default `EntityDataModule`.
* migrateNgRxData - if `true` it will replace the `ngrx-data` module with the `@ngrx/data` module.
* entityConfig - if `true` it will create and declare the `entity-metadata` file.
* entityConfig - if `false` it will not create and declare the `entity-metadata` file.

This command will automate the following steps:

Expand Down

0 comments on commit 120a200

Please sign in to comment.