Skip to content

Commit

Permalink
Add state
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Jun 22, 2023
1 parent 51c1847 commit 41108c8
Show file tree
Hide file tree
Showing 24 changed files with 15,129 additions and 7,867 deletions.
3 changes: 3 additions & 0 deletions __tests__/any-of-labels.spec.ts
Expand Up @@ -4,6 +4,7 @@ import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-option
import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
import {StateMock} from './classes/state-mock';

let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock;
Expand Down Expand Up @@ -1102,6 +1103,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(),
false,
!!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : []
)
Expand Down Expand Up @@ -1139,6 +1141,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
new StateMock(),
async p => (p === 1 ? this._issues : []),
async () => [],
async () => new Date().toDateString()
Expand Down
3 changes: 3 additions & 0 deletions __tests__/assignees.spec.ts
Expand Up @@ -3,6 +3,7 @@ import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-option
import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
import {alwaysFalseStateMock} from './classes/state-mock';

interface ITestData {
id: number;
Expand Down Expand Up @@ -35,6 +36,7 @@ describe('assignees options', (): void => {
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
isPullRequest,
undefined,
undefined,
Expand All @@ -48,6 +50,7 @@ describe('assignees options', (): void => {
const setProcessor = () => {
processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? testIssueList : []),
async () => [],
async () => new Date().toDateString()
Expand Down
4 changes: 3 additions & 1 deletion __tests__/classes/issues-processor-mock.ts
Expand Up @@ -3,10 +3,12 @@ import {IssuesProcessor} from '../../src/classes/issues-processor';
import {IComment} from '../../src/interfaces/comment';
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
import {IPullRequest} from '../../src/interfaces/pull-request';
import {IState} from '../../src/interfaces/state';

export class IssuesProcessorMock extends IssuesProcessor {
constructor(
options: IIssuesProcessorOptions,
state: IState,
getIssues?: (page: number) => Promise<Issue[]>,
listIssueComments?: (
issue: Issue,
Expand All @@ -18,7 +20,7 @@ export class IssuesProcessorMock extends IssuesProcessor {
) => Promise<string | undefined>,
getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void>
) {
super(options);
super(options, state);

if (getIssues) {
this.getIssues = getIssues;
Expand Down
24 changes: 24 additions & 0 deletions __tests__/classes/state-mock.ts
@@ -0,0 +1,24 @@
import {IState} from '../../src/interfaces/state';
import {IIssue} from '../../src/interfaces/issue';

export class StateMock implements IState {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
addIssueToProcessed(issue: IIssue) {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
isIssueProcessed(issue: IIssue) {
return false;
}

persist(): Promise<void> {
return Promise.resolve(undefined);
}

rehydrate(): Promise<void> {
return Promise.resolve(undefined);
}

reset() {}
}

export const alwaysFalseStateMock = new StateMock();
4 changes: 4 additions & 0 deletions __tests__/exempt-draft-pr.spec.ts
Expand Up @@ -5,6 +5,7 @@ import {IPullRequest} from '../src/interfaces/pull-request';
import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
import {alwaysFalseStateMock} from './classes/state-mock';

let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock;
Expand Down Expand Up @@ -45,6 +46,7 @@ describe('exempt-draft-pr option', (): void => {
issuesProcessor = issuesProcessorBuilder
.toStalePrs([
{
draft: true,
number: 20
}
])
Expand Down Expand Up @@ -84,6 +86,7 @@ class IssuesProcessorBuilder {
issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(),
!!issue.draft,
!!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : []
)
Expand Down Expand Up @@ -122,6 +125,7 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
alwaysFalseStateMock,
async p => (p === 1 ? this._issues : []),
async () => [],
async () => new Date().toDateString(),
Expand Down
1 change: 1 addition & 0 deletions __tests__/functions/generate-iissue.ts
Expand Up @@ -9,6 +9,7 @@ export function generateIIssue(
labels: [],
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
draft: false,
number: Math.round(Math.random() * 5000),
pull_request: null,
title: 'dummy-title',
Expand Down
2 changes: 2 additions & 0 deletions __tests__/functions/generate-issue.ts
Expand Up @@ -9,6 +9,7 @@ export function generateIssue(
title: string,
updatedAt: IsoDateString,
createdAt: IsoDateString = updatedAt,
draft = false,
isPullRequest = false,
labels: string[] = [],
isClosed = false,
Expand All @@ -24,6 +25,7 @@ export function generateIssue(
title,
created_at: createdAt,
updated_at: updatedAt,
draft: draft,
pull_request: isPullRequest ? {} : null,
state: isClosed ? 'closed' : 'open',
locked: isLocked,
Expand Down

0 comments on commit 41108c8

Please sign in to comment.