Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dhis2 better regex #822

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/dhis2/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,10 @@ export function dv(dataElement, value) {
}

export function shouldUseNewTracker(resourceType) {
return /^(trackedEntityInstances|enrollments|relationships|events|trackedEntities|tracker\/(enrollments|relationships|events|trackedEntities))$/.test(
// return /^(trackedEntityInstances|enrollments|relationships|events|trackedEntities|tracker\/(enrollments|relationships|events|trackedEntities))$/.test(
// resourceType
// );
return /^(tracker\/|enrollments|relationships|events|trackedEntities)/.test(
resourceType
);
}
Expand Down
23 changes: 22 additions & 1 deletion packages/dhis2/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,43 @@ describe('get', () => {
});
});

describe('helperfunctions', () => {
describe.only('helperfunctions', () => {
it('should use the new tracker for enrollments', () => {
const result = shouldUseNewTracker('enrollments');
expect(result).to.be.true;
});

it('should use the new tracker for events', () => {
const result = shouldUseNewTracker('events');
expect(result).to.be.true;
});

it('should use the new tracker for relationships', () => {
const result = shouldUseNewTracker('relationships');
expect(result).to.be.true;
});

it('should use the new tracker for new tracker events', () => {
const result = shouldUseNewTracker('tracker/events');
expect(result).to.be.true;
});

it('should use the new tracker for trackedEntityInstance', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails right now, but I think it should pass.

I don't think we have support right now to map trackedEntityInstances to tracker/trackeEntities. But I think we should?

We support create('enrollments') and create ('trackedEntities'), so why not create ('trackedEntitiesInstances)?

const result = shouldUseNewTracker('trackedEntityInstance');
expect(result).to.be.true;
});

it('should use the new tracker for trackedEntities', () => {
const result = shouldUseNewTracker('trackedEntities');
expect(result).to.be.true;
});

it('should use the new tracker for new tracker generally', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Question mark on this actually.

create should take a resourceType - not a path. So create('enrollments'), not create('tracker/enrollments'). Because create has opinions and does stuff for you.

If you want a custom create with the new tracker, do post('tracker/enrollments')

// This resource type does not exist but this function doesn't know that!
const result = shouldUseNewTracker('tracker/something');
expect(result).to.be.true;
});

it('should use the old API for dataValueSets', () => {
const result = shouldUseNewTracker('dataValueSets');
expect(result).to.be.false;
Expand Down
Loading