add unit tests
This commit is contained in:
parent
853e6fde5c
commit
9d282d6587
|
@ -4,6 +4,7 @@ import {IComment} from '../../src/interfaces/comment';
|
||||||
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
|
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
|
||||||
import {IPullRequest} from '../../src/interfaces/pull-request';
|
import {IPullRequest} from '../../src/interfaces/pull-request';
|
||||||
import {IState} from '../../src/interfaces/state/state';
|
import {IState} from '../../src/interfaces/state/state';
|
||||||
|
import {IIssueEvent} from '../../src/interfaces/issue-event';
|
||||||
|
|
||||||
export class IssuesProcessorMock extends IssuesProcessor {
|
export class IssuesProcessorMock extends IssuesProcessor {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -18,7 +19,8 @@ export class IssuesProcessorMock extends IssuesProcessor {
|
||||||
issue: Issue,
|
issue: Issue,
|
||||||
label: string
|
label: string
|
||||||
) => Promise<string | undefined>,
|
) => Promise<string | undefined>,
|
||||||
getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void>
|
getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void>,
|
||||||
|
getIssueEvents?: (issue: Issue) => Promise<IIssueEvent[]>
|
||||||
) {
|
) {
|
||||||
super(options, state);
|
super(options, state);
|
||||||
|
|
||||||
|
@ -37,5 +39,9 @@ export class IssuesProcessorMock extends IssuesProcessor {
|
||||||
if (getPullRequest) {
|
if (getPullRequest) {
|
||||||
this.getPullRequest = getPullRequest;
|
this.getPullRequest = getPullRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getIssueEvents) {
|
||||||
|
this.getIssueEvents = getIssueEvents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options';
|
||||||
|
import {DefaultProcessorOptions} from './constants/default-processor-options';
|
||||||
|
import {Issue} from '../src/classes/issue';
|
||||||
|
import {generateIssue} from './functions/generate-issue';
|
||||||
|
import {IssuesProcessorMock} from './classes/issues-processor-mock';
|
||||||
|
import {alwaysFalseStateMock} from './classes/state-mock';
|
||||||
|
import {IIssueEvent} from '../src/interfaces/issue-event';
|
||||||
|
|
||||||
|
const opts: IIssuesProcessorOptions = {
|
||||||
|
...DefaultProcessorOptions,
|
||||||
|
daysBeforeClose: 0
|
||||||
|
};
|
||||||
|
const testIssueList = async (page: number): Promise<Issue[]> => {
|
||||||
|
return page == 1
|
||||||
|
? [
|
||||||
|
generateIssue(opts, 1, 'Issue 1', '2020-01-01T17:00:00Z'),
|
||||||
|
generateIssue(opts, 2, 'Issue 2', '2020-01-01T17:00:00Z')
|
||||||
|
]
|
||||||
|
: [];
|
||||||
|
};
|
||||||
|
|
||||||
|
const pinnedEvent: IIssueEvent = {
|
||||||
|
created_at: '2020-01-01T17:00:00Z',
|
||||||
|
event: 'pinned',
|
||||||
|
label: {}
|
||||||
|
};
|
||||||
|
const unpinnedEvent: IIssueEvent = {
|
||||||
|
created_at: '2020-01-01T17:00:00Z',
|
||||||
|
event: 'unpinned',
|
||||||
|
label: {}
|
||||||
|
};
|
||||||
|
describe('exempt-pinned-issues options', (): void => {
|
||||||
|
it('pinned issues should be skipped if exemptPinnedIssues true', async () => {
|
||||||
|
const processor = new IssuesProcessorMock(
|
||||||
|
{...opts, exemptPinnedIssues: true},
|
||||||
|
alwaysFalseStateMock,
|
||||||
|
testIssueList,
|
||||||
|
async () => [],
|
||||||
|
async () => new Date().toDateString(),
|
||||||
|
async (issue: Issue) => undefined,
|
||||||
|
async (issue: Issue) => (issue.number === 1 ? [pinnedEvent] : [])
|
||||||
|
);
|
||||||
|
await processor.processIssues(1);
|
||||||
|
expect(processor.staleIssues).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pinned issues should not be skipped if exemptPinnedIssues false', async () => {
|
||||||
|
const processor = new IssuesProcessorMock(
|
||||||
|
{...opts, exemptPinnedIssues: false},
|
||||||
|
alwaysFalseStateMock,
|
||||||
|
testIssueList,
|
||||||
|
async () => [],
|
||||||
|
async () => new Date().toDateString(),
|
||||||
|
async (issue: Issue) => undefined,
|
||||||
|
async (issue: Issue) => (issue.number === 1 ? [pinnedEvent] : [])
|
||||||
|
);
|
||||||
|
await processor.processIssues(1);
|
||||||
|
expect(processor.staleIssues).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pinned issues should not be skipped if exemptPinnedIssues true but it was unpinned', async () => {
|
||||||
|
const processor = new IssuesProcessorMock(
|
||||||
|
{...opts, exemptPinnedIssues: true},
|
||||||
|
alwaysFalseStateMock,
|
||||||
|
testIssueList,
|
||||||
|
async () => [],
|
||||||
|
async () => new Date().toDateString(),
|
||||||
|
async (issue: Issue) => undefined,
|
||||||
|
async (issue: Issue) =>
|
||||||
|
issue.number === 1 ? [unpinnedEvent, pinnedEvent] : []
|
||||||
|
);
|
||||||
|
await processor.processIssues(1);
|
||||||
|
expect(processor.staleIssues).toHaveLength(2);
|
||||||
|
});
|
||||||
|
it('pinned issues should not be skipped if exemptPinnedIssues true and it was unpinned and pinned', async () => {
|
||||||
|
const processor = new IssuesProcessorMock(
|
||||||
|
{...opts, exemptPinnedIssues: true},
|
||||||
|
alwaysFalseStateMock,
|
||||||
|
testIssueList,
|
||||||
|
async () => [],
|
||||||
|
async () => new Date().toDateString(),
|
||||||
|
async (issue: Issue) => undefined,
|
||||||
|
async (issue: Issue) =>
|
||||||
|
issue.number === 1 ? [pinnedEvent, unpinnedEvent, pinnedEvent] : []
|
||||||
|
);
|
||||||
|
await processor.processIssues(1);
|
||||||
|
expect(processor.staleIssues).toHaveLength(1);
|
||||||
|
});
|
||||||
|
});
|
|
@ -195,7 +195,7 @@ export class IssuesProcessor {
|
||||||
|
|
||||||
private _lastIssueEvents: IIssueEvent[] = [];
|
private _lastIssueEvents: IIssueEvent[] = [];
|
||||||
private _lastIssueEventsIssueId = -1;
|
private _lastIssueEventsIssueId = -1;
|
||||||
async getIssueEvents(issue: Issue): Promise<IIssueEvent[]> {
|
private async getIssueEvents(issue: Issue): Promise<IIssueEvent[]> {
|
||||||
if (issue.number !== this._lastIssueEventsIssueId) {
|
if (issue.number !== this._lastIssueEventsIssueId) {
|
||||||
const options = this.client.rest.issues.listEvents.endpoint.merge({
|
const options = this.client.rest.issues.listEvents.endpoint.merge({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
|
|
Loading…
Reference in New Issue