Skip to content

Commit

Permalink
test(stats): add more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Jan 29, 2022
1 parent 7e1ed99 commit 9f7700d
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 6 deletions.
136 changes: 136 additions & 0 deletions tests/issues/batches-of-issues.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { IGithubApiLabel } from '@github/api/labels/interfaces/github-api-label.interface';
import { IGithubApiTimelineItemsIssueLabeledEvents } from '@github/api/timeline-items/interfaces/github-api-timeline-items-issue-labeled-events.interface';
import { FakeIssuesProcessor } from '@tests/utils/fake-issues-processor';
import { DateTime } from 'luxon';
import { createHydratedMock } from 'ts-auto-mock';

/**
* Perfect to test the pagination
Expand All @@ -23,4 +27,136 @@ describe(`Batch of issues`, (): void => {
});
});
});

describe(`when more than 20 issues are stale and should be closed (two batches)`, (): void => {
beforeEach((): void => {
issueSut = new FakeIssuesProcessor({
issueDaysBeforeClose: 30,
issueStaleLabel: `stale`,
})
.addIssues(22, {
labels: {
nodes: [
createHydratedMock<IGithubApiLabel>({
name: `stale`, // Already stale
}),
],
totalCount: 1,
},
locked: false,
updatedAt: DateTime.utc(2021).toISO({
includeOffset: false,
}), // No update since last stale
})
.mockTimelineItemsIssueLabeledEventQuery(
(): Promise<IGithubApiTimelineItemsIssueLabeledEvents> =>
Promise.resolve(
createHydratedMock<IGithubApiTimelineItemsIssueLabeledEvents>({
repository: {
issue: {
timelineItems: {
filteredCount: 1,
nodes: [
{
createdAt: DateTime.utc(2021).toISO({
includeOffset: false,
}), // Last stale
label: createHydratedMock<IGithubApiLabel>({
name: `stale`,
}),
},
],
pageCount: 1,
},
},
},
})
)
);
});

it(`should not remove the stale state on the issues`, async (): Promise<void> => {
expect.assertions(11);

await issueSut.process();

issueSut.expect({
addedIssuesCommentsCount: 22,
alreadyStaleIssuesCount: 22,
calledApiIssuesMutationsCount: 44, // 22 comments + 22 close
calledApiIssuesQueriesCount: 24, // 2 batch loaded + 22 loaded labels events
closedIssuesCount: 22,
processedIssuesCount: 22,
});
});
});

describe(`when more than 20 issues are stale and should stay stale (two batches)`, (): void => {
beforeEach((): void => {
issueSut = new FakeIssuesProcessor({
issueDaysBeforeClose: 30,
issueStaleLabel: `stale`,
})
.addIssues(22, {
labels: {
nodes: [
createHydratedMock<IGithubApiLabel>({
name: `stale`, // Already stale
}),
],
totalCount: 1,
},
locked: false,
updatedAt: DateTime.now()
.minus({
day: 21,
})
.toISO({
includeOffset: false,
}), // No update since last stale
})
.mockTimelineItemsIssueLabeledEventQuery(
(): Promise<IGithubApiTimelineItemsIssueLabeledEvents> =>
Promise.resolve(
createHydratedMock<IGithubApiTimelineItemsIssueLabeledEvents>({
repository: {
issue: {
timelineItems: {
filteredCount: 1,
nodes: [
{
createdAt: DateTime.now()
.minus({
day: 20,
})
.toISO({
includeOffset: false,
}), // Last stale
label: createHydratedMock<IGithubApiLabel>({
name: `stale`,
}),
},
],
pageCount: 1,
},
},
},
})
)
);
});

it(`should not remove the stale state on the issues`, async (): Promise<void> => {
expect.assertions(11);

await issueSut.process();

issueSut.expect({
alreadyStaleIssuesCount: 22,
calledApiIssuesQueriesCount: 24, // 2 batch loaded + 22 loaded labels events
processedIssuesCount: 22,
unalteredIssuesCount: 22,
});
});
});
});
4 changes: 2 additions & 2 deletions tests/issues/issue-stale-not-updated.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe(`Issue stale not updated`, (): void => {
describe(`when an issue is stale and was not recently updated`, (): void => {
beforeEach((): void => {
issueSut = new FakeIssuesProcessor({
issueDaysBeforeStale: 30,
issueDaysBeforeClose: 30,
issueStaleLabel: `stale`,
})
.addIssue({
Expand Down Expand Up @@ -54,7 +54,7 @@ describe(`Issue stale not updated`, (): void => {
);
});

it(`should not remove the stale state on the issue`, async (): Promise<void> => {
it(`should close the issue`, async (): Promise<void> => {
expect.assertions(11);

await issueSut.process();
Expand Down
136 changes: 136 additions & 0 deletions tests/pull-requests/batches-of-pull-requests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { IGithubApiLabel } from '@github/api/labels/interfaces/github-api-label.interface';
import { IGithubApiTimelineItemsPullRequestLabeledEvents } from '@github/api/timeline-items/interfaces/github-api-timeline-items-pull-request-labeled-events.interface';
import { FakePullRequestsProcessor } from '@tests/utils/fake-pull-requests-processor';
import { DateTime } from 'luxon';
import { createHydratedMock } from 'ts-auto-mock';

/**
* Perfect to test the pagination
Expand All @@ -23,4 +27,136 @@ describe(`Batch of pull requests`, (): void => {
});
});
});

describe(`when more than 20 pull requests are stale and should be closed (two batches)`, (): void => {
beforeEach((): void => {
pullRequestSut = new FakePullRequestsProcessor({
pullRequestDaysBeforeClose: 30,
pullRequestStaleLabel: `stale`,
})
.addPullRequests(22, {
labels: {
nodes: [
createHydratedMock<IGithubApiLabel>({
name: `stale`, // Already stale
}),
],
totalCount: 1,
},
locked: false,
updatedAt: DateTime.utc(2021).toISO({
includeOffset: false,
}), // No update since last stale
})
.mockTimelineItemsPullRequestLabeledEventQuery(
(): Promise<IGithubApiTimelineItemsPullRequestLabeledEvents> =>
Promise.resolve(
createHydratedMock<IGithubApiTimelineItemsPullRequestLabeledEvents>({
repository: {
pullRequest: {
timelineItems: {
filteredCount: 1,
nodes: [
{
createdAt: DateTime.utc(2021).toISO({
includeOffset: false,
}), // Last stale
label: createHydratedMock<IGithubApiLabel>({
name: `stale`,
}),
},
],
pageCount: 1,
},
},
},
})
)
);
});

it(`should not remove the stale state on the pull requests`, async (): Promise<void> => {
expect.assertions(13);

await pullRequestSut.process();

pullRequestSut.expect({
addedPullRequestsCommentsCount: 22,
alreadyStalePullRequestsCount: 22,
calledApiPullRequestsMutationsCount: 44, // 22 comments + 22 close
calledApiPullRequestsQueriesCount: 24, // 2 batch loaded + 22 loaded labels events
closedPullRequestsCount: 22,
processedPullRequestsCount: 22,
});
});
});

describe(`when more than 20 pull requests are stale and should stay stale (two batches)`, (): void => {
beforeEach((): void => {
pullRequestSut = new FakePullRequestsProcessor({
pullRequestDaysBeforeClose: 30,
pullRequestStaleLabel: `stale`,
})
.addPullRequests(22, {
labels: {
nodes: [
createHydratedMock<IGithubApiLabel>({
name: `stale`, // Already stale
}),
],
totalCount: 1,
},
locked: false,
updatedAt: DateTime.now()
.minus({
day: 21,
})
.toISO({
includeOffset: false,
}), // No update since last stale
})
.mockTimelineItemsPullRequestLabeledEventQuery(
(): Promise<IGithubApiTimelineItemsPullRequestLabeledEvents> =>
Promise.resolve(
createHydratedMock<IGithubApiTimelineItemsPullRequestLabeledEvents>({
repository: {
pullRequest: {
timelineItems: {
filteredCount: 1,
nodes: [
{
createdAt: DateTime.now()
.minus({
day: 20,
})
.toISO({
includeOffset: false,
}), // Last stale
label: createHydratedMock<IGithubApiLabel>({
name: `stale`,
}),
},
],
pageCount: 1,
},
},
},
})
)
);
});

it(`should not remove the stale state on the pull requests`, async (): Promise<void> => {
expect.assertions(13);

await pullRequestSut.process();

pullRequestSut.expect({
alreadyStalePullRequestsCount: 22,
calledApiPullRequestsQueriesCount: 24, // 2 batch loaded + 22 loaded labels events
processedPullRequestsCount: 22,
unalteredPullRequestsCount: 22,
});
});
});
});
8 changes: 4 additions & 4 deletions tests/pull-requests/issue-stale-not-updated.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { FakePullRequestsProcessor } from '@tests/utils/fake-pull-requests-proce
import { DateTime } from 'luxon';
import { createHydratedMock } from 'ts-auto-mock';

describe(`Pull request stale not updated`, (): void => {
describe(`Issue stale not updated`, (): void => {
let pullRequestSut: FakePullRequestsProcessor;

describe(`when a pull request is stale and was not recently updated`, (): void => {
describe(`when a issue is stale and was not recently updated`, (): void => {
beforeEach((): void => {
pullRequestSut = new FakePullRequestsProcessor({
pullRequestDaysBeforeStale: 30,
pullRequestDaysBeforeClose: 30,
pullRequestStaleLabel: `stale`,
})
.addPullRequest({
Expand Down Expand Up @@ -54,7 +54,7 @@ describe(`Pull request stale not updated`, (): void => {
);
});

it(`should not remove the stale state on the pull request`, async (): Promise<void> => {
it(`should close the issue`, async (): Promise<void> => {
expect.assertions(13);

await pullRequestSut.process();
Expand Down

0 comments on commit 9f7700d

Please sign in to comment.