Skip to content

Commit

Permalink
Contacts should be created with "type": "health_center" instead of "c…
Browse files Browse the repository at this point in the history
…ontact_type": "health_center" (#71)

Dashboard integrity for eCHIS Uganda
  • Loading branch information
kennsippell authored Feb 14, 2024
1 parent a79a372 commit e6161a3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cht-user-management",
"version": "1.0.11",
"version": "1.0.12",
"main": "dist/index.js",
"dependencies": {
"@fastify/autoload": "^5.8.0",
Expand Down
18 changes: 14 additions & 4 deletions src/services/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,28 @@ export default class Place {
}, {});
};

const contactAttributes = (contactType: string) => {
const RESERVED_CONTACT_TYPES = ['district_hospital', 'health_center', 'clinic', 'person'];

if (RESERVED_CONTACT_TYPES.includes(contactType)) {
return { type: contactType };
}

return {
type: 'contact',
contact_type: contactType,
};
};
return {
...filteredProperties(this.properties),
...contactAttributes(this.type.name),
_id: this.isReplacement ? this.resolvedHierarchy[0]?.id : this.id,
type: 'contact',
contact_type: this.type.name,
parent: this.resolvedHierarchy[1]?.id,
user_attribution,
contact: {
...filteredProperties(this.contact.properties),
...contactAttributes(this.contact.type.contact_type),
name: this.contact.name,
type: 'contact',
contact_type: this.contact.type.contact_type,
user_attribution,
}
};
Expand Down
28 changes: 27 additions & 1 deletion test/services/place.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';

import Place from '../../src/services/place';
import { mockSimpleContactType } from '../mocks';
import { mockSimpleContactType, mockValidContactType } from '../mocks';
import RemotePlaceResolver from '../../src/lib/remote-place-resolver';

describe('service place.ts', () => {
Expand Down Expand Up @@ -109,4 +109,30 @@ describe('service place.ts', () => {
const actual = place.generateUsername();
expect(actual).to.eq('migwani_itoloni');
});

it('asChtPayload uses contact_type by default', () => {
const contactType = mockValidContactType('string', undefined);
Object.freeze(contactType);

const place = new Place(contactType);
const actual = place.asChtPayload('usr');
expect(actual.type).to.eq('contact');
expect(actual.contact.type).to.eq('contact');
expect(actual.contact_type).to.eq(contactType.name);
});

it('#46 - asChtPayload should use type:health_center instead of contact_type:health_center', () => {
const contactType = mockValidContactType('string', undefined);
contactType.name = 'health_center';
contactType.contact_type = 'person';
Object.freeze(contactType);

const place = new Place(contactType);
const actual = place.asChtPayload('usr');
expect(actual.type).to.eq(contactType.name);
expect(actual.contact_type).to.be.undefined;

expect(actual.contact.type).to.eq(contactType.contact_type);
expect(actual.contact.contact_type).to.be.undefined;
});
});

0 comments on commit e6161a3

Please sign in to comment.