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

test: add more coverage for the stale label behaviour (#352) #16

Closed
wants to merge 7 commits 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: |
npm install
npm ci
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
Expand Down
104 changes: 59 additions & 45 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __tests__/constants/default-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
exemptAllAssignees: false,
exemptAllIssueAssignees: undefined,
exemptAllPrAssignees: undefined,
enableStatistics: false
enableStatistics: true
});
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