Skip to content

Commit 7ac4589

Browse files
committed
refactor(model): add gender, occupation & nationality defaults
1 parent 87be7c5 commit 7ac4589

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

src/schema/common.schema.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import {
2+
PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA,
3+
PREDEFINE_NAMESPACE_PARTYGENDER,
4+
PREDEFINE_NAMESPACE_PARTYOCCUPATION,
5+
PREDEFINE_NAMESPACE_PARTYNATIONALITY,
6+
} from '@codetanzania/ewea-internals';
7+
import { DEFAULT_SEEDS } from '@codetanzania/ewea-common';
18
import { compact } from '@lykmapipo/common';
29
import { Point } from 'mongoose-geojson-schemas';
310
import { ObjectId, createSubSchema } from '@lykmapipo/mongoose-common';
@@ -275,6 +282,7 @@ export const area = {
275282
order: 3,
276283
default: 'NA',
277284
},
285+
default: DEFAULT_SEEDS[PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA],
278286
};
279287

280288
/**
@@ -352,7 +360,7 @@ export const gender = {
352360
order: 2,
353361
default: 'NA',
354362
},
355-
default: undefined,
363+
default: DEFAULT_SEEDS[PREDEFINE_NAMESPACE_PARTYGENDER],
356364
};
357365

358366
/**
@@ -392,7 +400,7 @@ export const occupation = {
392400
order: 2,
393401
default: 'NA',
394402
},
395-
default: undefined,
403+
default: DEFAULT_SEEDS[PREDEFINE_NAMESPACE_PARTYOCCUPATION],
396404
};
397405

398406
/**
@@ -432,7 +440,7 @@ export const nationality = {
432440
order: 2,
433441
default: 'NA',
434442
},
435-
default: undefined,
443+
default: DEFAULT_SEEDS[PREDEFINE_NAMESPACE_PARTYNATIONALITY],
436444
};
437445

438446
/**

test/integration/case.http.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@lykmapipo/mongoose-test-helpers';
1010
import { Predefine } from '@lykmapipo/predefine';
1111
import { createModels } from '@lykmapipo/file';
12-
import { seedCommons } from '@codetanzania/ewea-common';
12+
import { seedCommons, seedDefaults } from '@codetanzania/ewea-common';
1313
import { Party } from '@codetanzania/emis-stakeholder';
1414
import { Case, caseRouter } from '../../src';
1515

@@ -33,6 +33,7 @@ describe('Case Rest API', () => {
3333

3434
beforeEach(() => createModels());
3535

36+
before((done) => seedDefaults(done));
3637
before((done) => seedCommons(done));
3738
before((done) => create(area, done));
3839
before((done) => create(reporter, done));

test/integration/case.seed.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import { first } from 'lodash';
33
import { clear, expect } from '@lykmapipo/mongoose-test-helpers';
4-
import { seedCommons } from '@codetanzania/ewea-common';
4+
import { seedCommons, seedDefaults } from '@codetanzania/ewea-common';
55
import { Case } from '../../src';
66

77
describe('Case Seed', () => {
@@ -14,6 +14,7 @@ describe('Case Seed', () => {
1414
process.env.SEED_PATH = path.join(__dirname, '..', 'fixtures');
1515
});
1616

17+
before((done) => seedDefaults(done));
1718
before((done) => seedCommons(done));
1819

1920
it('should be able to seed', (done) => {

test/unit/case.schema.spec.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('Case Schema', () => {
2929
const pcr = Case.path('victim.pcr');
3030
const name = Case.path('victim.name');
3131
const mobile = Case.path('victim.mobile');
32+
const gender = Case.path('victim.gender');
3233
const occupation = Case.path('victim.occupation');
3334
const nationality = Case.path('victim.nationality');
3435
const nextOfKinName = Case.path('victim.nextOfKin.name');
@@ -85,6 +86,22 @@ describe('Case Schema', () => {
8586
expect(mobile.options.exportable).to.be.true;
8687
expect(mobile.options.fake).to.exist;
8788

89+
expect(gender).to.exist;
90+
expect(gender).to.be.instanceof(SchemaTypes.ObjectId);
91+
expect(gender.options).to.exist;
92+
expect(gender.options).to.be.an('object');
93+
expect(gender.options.type).to.exist;
94+
expect(gender.options.ref).to.exist;
95+
expect(gender.options.ref).to.be.equal(Predefine.MODEL_NAME);
96+
expect(gender.options.index).to.be.true;
97+
// expect(gender.options.required).to.be.true;
98+
expect(gender.options.exists).to.be.true;
99+
expect(gender.options.autopopulate).to.exist;
100+
expect(gender.options.taggable).to.exist;
101+
expect(gender.options.exportable).to.exist;
102+
expect(gender.options.aggregatable).to.exist;
103+
expect(gender.options.default).to.exist;
104+
88105
expect(occupation).to.exist;
89106
expect(occupation).to.be.instanceof(SchemaTypes.ObjectId);
90107
expect(occupation.options).to.exist;
@@ -99,7 +116,7 @@ describe('Case Schema', () => {
99116
expect(occupation.options.taggable).to.exist;
100117
expect(occupation.options.exportable).to.exist;
101118
expect(occupation.options.aggregatable).to.exist;
102-
expect(occupation.options.default).to.be.undefined;
119+
expect(occupation.options.default).to.exist;
103120

104121
expect(nationality).to.exist;
105122
expect(nationality).to.be.instanceof(SchemaTypes.ObjectId);
@@ -115,7 +132,7 @@ describe('Case Schema', () => {
115132
expect(nationality.options.taggable).to.exist;
116133
expect(nationality.options.exportable).to.exist;
117134
expect(nationality.options.aggregatable).to.exist;
118-
expect(nationality.options.default).to.be.undefined;
135+
expect(nationality.options.default).to.exist;
119136

120137
expect(nextOfKinName).to.exist;
121138
expect(nextOfKinName).to.be.instanceof(SchemaTypes.String);

0 commit comments

Comments
 (0)