From 93cc0184774bcaa6b82ad3bdfadeeb661fcbc004 Mon Sep 17 00:00:00 2001 From: Geoffrey Testelin Date: Fri, 5 Mar 2021 15:12:18 +0100 Subject: [PATCH] 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] 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] 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> --- __tests__/main.spec.ts | 90 ++++++++++++++++++++++++++++++++++++++++-- src/interfaces/user.ts | 2 +- 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/__tests__/main.spec.ts b/__tests__/main.spec.ts index b6efe3bc..1fe15800 100644 --- a/__tests__/main.spec.ts +++ b/__tests__/main.spec.ts @@ -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'; @@ -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, @@ -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, @@ -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, @@ -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 => 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 => 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); +}); diff --git a/src/interfaces/user.ts b/src/interfaces/user.ts index 2394d4d0..4e454f6d 100644 --- a/src/interfaces/user.ts +++ b/src/interfaces/user.ts @@ -1,4 +1,4 @@ export interface IUser { - type: string; + type: string | 'User'; login: string; }