Fix test cases to return the right pagination

This commit is contained in:
Ross Brodbeck 2020-04-16 13:36:59 -04:00
parent 6c28e8b071
commit 420680dd9b
2 changed files with 52 additions and 10 deletions

View File

@ -13,11 +13,14 @@ function generateIssue(
id: number,
title: string,
updatedAt: string,
isPullRequest: boolean = false
isPullRequest: boolean = false,
labels: string[] = []
): Issue {
return {
number: id,
labels: [],
labels: labels.map(l => {
return {name: l};
}),
title: title,
updated_at: updatedAt,
pull_request: isPullRequest ? {} : null
@ -49,19 +52,58 @@ test('empty issue list results in 1 operation', async () => {
expect(operationsLeft).toEqual(99);
});
test('processing an issue with no label will not make it stale', async () => {
test('processing an issue with no label will make it stale', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', Date.now().toString())
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z')
];
const processor = new IssueProcessor(
DefaultProcessorOptions,
async () => TestIssueList
async (p) => p == 1 ? TestIssueList : []
);
// process our fake issue list
const operationsLeft = await processor.processIssues(1);
await processor.processIssues(1);
// processing an empty issue list should result in 1 operation
expect(operationsLeft).toBeLessThan(100);
expect(processor.staleIssues.length).toEqual(1);
expect(processor.closedIssues.length).toEqual(0);
});
test('processing a stale issue will close it', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'])
];
const processor = new IssueProcessor(
DefaultProcessorOptions,
async (p) => p == 1 ? TestIssueList : []
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toEqual(0);
expect(processor.closedIssues.length).toEqual(1);
});
test('exempt issue labels will not be marked stale', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [
'Exempt'
])
];
let opts = DefaultProcessorOptions;
opts.exemptIssueLabels = 'Exempt';
const processor = new IssueProcessor(
DefaultProcessorOptions,
async (p) => p == 1 ? TestIssueList : []
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toEqual(0);
expect(processor.closedIssues.length).toEqual(0);
});

View File

@ -53,15 +53,15 @@ export class IssueProcessor {
if (getIssues) {
this.getIssues = getIssues;
}
}
async processIssues(page: number = 1): Promise<number> {
if (this.options.debugOnly) {
core.warning(
'Executing in debug mode. Debug output will be written but no issues will be processed.'
);
}
}
async processIssues(page: number = 1): Promise<number> {
if (this.operationsLeft <= 0) {
core.warning('Reached max number of operations to process. Exiting.');
return 0;