Skip to content

Commit

Permalink
fix: ensure reletion populations
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Feb 26, 2020
1 parent ac6d93e commit 29ac0b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { join, stringify } from '@lykmapipo/common';

// population options
export const POPULATION_MAX_DEPTH = 1;

export const POPULATION_DEFAULT = { maxDepth: POPULATION_MAX_DEPTH };

export const OPTION_PARTY_AUTOPOPULATE = {
select: { name: 1, email: 1, mobile: 1, abbreviation: 1 },
maxDepth: POPULATION_MAX_DEPTH,
};

// model names
export const MODEL_NAME_PREDEFINE = 'Predefine';
export const MODEL_NAME_UNIT = 'Predefine';
Expand Down Expand Up @@ -209,9 +219,21 @@ export const PREDEFINE_RELATIONS = {
indicator: { ref: 'Predefine', namespace: 'EventIndicator' },
topic: { ref: 'Predefine', namespace: 'EventTopic' },
unit: { ref: 'Predefine', namespace: 'Unit' },
agencies: { ref: 'Party', array: true },
focals: { ref: 'Party', array: true },
custodians: { ref: 'Party', array: true },
agencies: {
ref: 'Party',
array: true,
autopopulate: OPTION_PARTY_AUTOPOPULATE,
},
focals: {
ref: 'Party',
array: true,
autopopulate: OPTION_PARTY_AUTOPOPULATE,
},
custodians: {
ref: 'Party',
array: true,
autopopulate: OPTION_PARTY_AUTOPOPULATE,
},
};

// party relations
Expand Down Expand Up @@ -256,10 +278,6 @@ export const EVENT_CHANGELOG_RELATIONS = {
template: { ref: 'Predefine', namespace: 'NotificationTemplate' },
};

// population options
export const POPULATION_MAX_DEPTH = 1;
export const POPULATION_DEFAULT = { maxDepth: POPULATION_MAX_DEPTH };

// setup env
process.env.PREDEFINE_NAMESPACES = join(PREDEFINE_NAMESPACES, ',');
process.env.PREDEFINE_RELATIONS_IGNORED = join(PREDEFINE_NAMESPACES, ',');
Expand Down
5 changes: 5 additions & 0 deletions test/unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import {
// population
POPULATION_MAX_DEPTH,
POPULATION_DEFAULT,
OPTION_PARTY_AUTOPOPULATE,
} from '../src';

describe('internals', () => {
Expand Down Expand Up @@ -436,6 +437,10 @@ describe('internals', () => {
it('should expose population options', () => {
expect(POPULATION_MAX_DEPTH).to.be.equal(1);
expect(POPULATION_DEFAULT).to.be.eql({ maxDepth: POPULATION_MAX_DEPTH });
expect(OPTION_PARTY_AUTOPOPULATE).to.be.eql({
select: { name: 1, email: 1, mobile: 1, abbreviation: 1 },
maxDepth: POPULATION_MAX_DEPTH,
});
});

it('should set predefine namespaces', () => {
Expand Down

0 comments on commit 29ac0b7

Please sign in to comment.