Skip to content

Commit

Permalink
Fix issue close/stale dates (#72)
Browse files Browse the repository at this point in the history
Added tests to confirm behavior.
  • Loading branch information
hross committed May 19, 2020
1 parent 71d46bf commit 5ce6b77
Show file tree
Hide file tree
Showing 3 changed files with 1,156 additions and 1,193 deletions.
61 changes: 61 additions & 0 deletions __tests__/main.test.ts
Expand Up @@ -504,3 +504,64 @@ test('stale label should be removed if a comment was added to a stale issue', as
expect(processor.staleIssues.length).toEqual(0);
expect(processor.removedLabelIssues.length).toEqual(1);
});

test('stale issues should not be closed until after the closed number of days', async () => {
let lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 5);
const TestIssueList: Issue[] = [
generateIssue(
1,
'An issue that should be marked stale but not closed',
lastUpdate.toString(),
false
)
];

const opts = DefaultProcessorOptions;
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 1; // closes after 6 days

const processor = new IssueProcessor(
opts,
async p => (p == 1 ? TestIssueList : []),
async (num, dt) => [],
async (issue, label) => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.closedIssues.length).toEqual(0);
expect(processor.staleIssues.length).toEqual(1);
});

test('stale issues should be closed if the closed nubmer of days (additive) is also passed', async () => {
let lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 7);
const TestIssueList: Issue[] = [
generateIssue(
1,
'An issue that should be stale and closed',
lastUpdate.toString(),
false,
['Stale']
)
];

const opts = DefaultProcessorOptions;
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 1; // closes after 6 days

const processor = new IssueProcessor(
opts,
async p => (p == 1 ? TestIssueList : []),
async (num, dt) => [],
async (issue, label) => new Date().toDateString()
);

// process our fake issue list
await processor.processIssues(1);

expect(processor.closedIssues.length).toEqual(1);
expect(processor.staleIssues.length).toEqual(0);
});

0 comments on commit 5ce6b77

Please sign in to comment.