Skip to content

Commit

Permalink
test: add more coverage for the stale label behaviour (actions#352) (#15
Browse files Browse the repository at this point in the history
)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
C0ZEN and dependabot[bot] authored Mar 5, 2021
1 parent 5a8ec1e commit 6c29691
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 159 deletions.
90 changes: 87 additions & 3 deletions __tests__/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as github from '@actions/github';
import {Issue} from '../src/classes/issue';
import {IComment} from '../src/interfaces/comment';
import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options';
import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
Expand Down Expand Up @@ -2105,7 +2106,7 @@ test('processing a previously closed issue with a close label will remove the cl
staleIssueLabel: 'stale'
};
const now: Date = new Date();
const oneWeekAgo: Date = new Date(now.getDate() - 7);
const oneWeekAgo: Date = new Date(now.setDate(now.getDate() - 7));
const TestIssueList: Issue[] = [
generateIssue(
opts,
Expand Down Expand Up @@ -2141,7 +2142,7 @@ test('processing a closed issue with a close label will not remove the close lab
staleIssueLabel: 'stale'
};
const now: Date = new Date();
const oneWeekAgo: Date = new Date(now.getDate() - 7);
const oneWeekAgo: Date = new Date(now.setDate(now.getDate() - 7));
const TestIssueList: Issue[] = [
generateIssue(
opts,
Expand Down Expand Up @@ -2177,7 +2178,7 @@ test('processing a locked issue with a close label will not remove the close lab
staleIssueLabel: 'stale'
};
const now: Date = new Date();
const oneWeekAgo: Date = new Date(now.getDate() - 7);
const oneWeekAgo: Date = new Date(now.setDate(now.getDate() - 7));
const TestIssueList: Issue[] = [
generateIssue(
opts,
Expand All @@ -2204,3 +2205,86 @@ test('processing a locked issue with a close label will not remove the close lab

expect(processor.removedLabelIssues).toHaveLength(0);
});

test('processing an issue stale since less than the daysBeforeStale with a stale label created after daysBeforeClose should close the issue', async () => {
expect.assertions(3);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
staleIssueLabel: 'stale-label',
daysBeforeStale: 30,
daysBeforeClose: 7,
closeIssueMessage: 'close message',
removeStaleWhenUpdated: false
};
const now: Date = new Date();
const updatedAt: Date = new Date(now.setDate(now.getDate() - 9));
const labelCreatedAt: Date = new Date(now.setDate(now.getDate() - 17));
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A real issue example; see https://github.com/actions/stale/issues/351',
updatedAt.toDateString(),
new Date(2021, 0, 16).toDateString(),
false,
['stale-label'], // This was the problem for the user BTW, the issue was re-opened without removing the previous stale label
false,
false
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]),
async () => labelCreatedAt.toDateString()
);

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

expect(processor.removedLabelIssues).toHaveLength(0);
expect(processor.deletedBranchIssues).toHaveLength(0);
expect(processor.closedIssues).toHaveLength(1); // Expected at 0 by the user
});

test('processing an issue stale since less than the daysBeforeStale without a stale label should close the issue', async () => {
expect.assertions(3);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
staleIssueLabel: 'stale-label',
daysBeforeStale: 30,
daysBeforeClose: 7,
closeIssueMessage: 'close message',
removeStaleWhenUpdated: false
};
const now: Date = new Date();
const updatedAt: Date = new Date(now.setDate(now.getDate() - 9));
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A real issue example; see https://github.com/actions/stale/issues/351 but without the old stale label from the previous close',
updatedAt.toDateString(),
new Date(2021, 0, 16).toDateString(),
false,
[],
false,
false
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]),
async () => new Date().toDateString()
);

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

expect(processor.removedLabelIssues).toHaveLength(0);
expect(processor.deletedBranchIssues).toHaveLength(0);
expect(processor.closedIssues).toHaveLength(0);
});
Loading

0 comments on commit 6c29691

Please sign in to comment.