Skip to content

Commit

Permalink
extended tests and simplified regex
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Nov 14, 2024
1 parent 177a64a commit f16c600
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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', () => {
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', () => {
// 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

0 comments on commit f16c600

Please sign in to comment.