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

* docs(only-labels): enhance the docs and fix duplicate (#341)

* docs(only-labels): remove duplicated option and improve descriptions

a bad rebase happend

* docs(readme): use a multi-line array and remove the optional column

the option column was not helpful since each value is optional
the multi-line array will allow to have a better UI in small devices and basically in GitHub too due to the max-width

* style(readme): break line for the statistics

* docs(readme): add a better description for the ascending option

* docs(action): add missing punctuation

* build(deps-dev): bump @typescript-eslint/eslint-plugin (#342)

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.15.2 to 4.16.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.16.1/packages/eslint-plugin)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump @octokit/rest from 18.3.0 to 18.3.2 (#350)

Bumps [@octokit/rest](https://github.com/octokit/rest.js) from 18.3.0 to 18.3.2.
- [Release notes](https://github.com/octokit/rest.js/releases)
- [Commits](https://github.com/octokit/rest.js/compare/v18.3.0...v18.3.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* test: add more coverage to make sure to understand how the stale label works

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
Geoffrey Testelin 2021-03-05 15:12:18 +01:00 committed by GitHub
parent b80d40901f
commit 93cc018477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import * as github from '@actions/github'; import * as github from '@actions/github';
import {Issue} from '../src/classes/issue'; import {Issue} from '../src/classes/issue';
import {IComment} from '../src/interfaces/comment';
import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options';
import {IssuesProcessorMock} from './classes/issues-processor-mock'; import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
@ -2105,7 +2106,7 @@ test('processing a previously closed issue with a close label will remove the cl
staleIssueLabel: 'stale' staleIssueLabel: 'stale'
}; };
const now: Date = new Date(); 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[] = [ const TestIssueList: Issue[] = [
generateIssue( generateIssue(
opts, opts,
@ -2141,7 +2142,7 @@ test('processing a closed issue with a close label will not remove the close lab
staleIssueLabel: 'stale' staleIssueLabel: 'stale'
}; };
const now: Date = new Date(); 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[] = [ const TestIssueList: Issue[] = [
generateIssue( generateIssue(
opts, opts,
@ -2177,7 +2178,7 @@ test('processing a locked issue with a close label will not remove the close lab
staleIssueLabel: 'stale' staleIssueLabel: 'stale'
}; };
const now: Date = new Date(); 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[] = [ const TestIssueList: Issue[] = [
generateIssue( generateIssue(
opts, opts,
@ -2204,3 +2205,86 @@ test('processing a locked issue with a close label will not remove the close lab
expect(processor.removedLabelIssues).toHaveLength(0); 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);
});

View File

@ -1,4 +1,4 @@
export interface IUser { export interface IUser {
type: string; type: string | 'User';
login: string; login: string;
} }