Skip to content

Commit

Permalink
fix(#123): Target date default to Now (#516)
Browse files Browse the repository at this point in the history
This fix changes the target emitter to default to now when the config target date is null or is a function that returns null.
  • Loading branch information
elvisdorkenoo authored Dec 6, 2022
1 parent fe9d3ba commit 312219e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nools/target-emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function targetEmitter(targets, c, Utils, Target, emit) {

function determineDate(targetConfig, Utils, c, r) {
if (typeof targetConfig.date === 'function') {
return targetConfig.date(c, r);
return targetConfig.date(c, r) || Utils.now().getTime();
}

if (targetConfig.date === undefined || targetConfig.date === 'now') {
if (targetConfig.date === undefined || targetConfig.date === null || targetConfig.date === 'now') {
return Utils.now().getTime();
}

Expand Down
21 changes: 21 additions & 0 deletions test/nools/target-emitter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ describe('target emitter', () => {
]);
});

it('should default to "now" if target date is a function returning null', () => {
// given
const target = aPersonBasedTarget();
target.date = () => null ;
// and
const config = {
c: personWithoutReports(),
targets: [ target ],
tasks: [],
};

// when
const emitted = runNoolsLib(config).emitted;

// then
assert.deepEqual(emitted, [
{ _id: 'c-2~pT-1', _type: 'target', date: TEST_DATE },
{ _type: '_complete', _id: true },
]);
});

it('should not emit if appliesToType doesnt match', () => {
// given
const target = aPersonBasedTarget();
Expand Down

0 comments on commit 312219e

Please sign in to comment.