Skip to content

Commit f195aff

Browse files
committed
Updating tests
1 parent 337878f commit f195aff

File tree

3 files changed

+85
-66
lines changed

3 files changed

+85
-66
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/task/src/repos/gitHubReposInvoker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ export default class GitHubReposInvoker extends BaseReposInvoker {
197197
error instanceof RequestError &&
198198
(error.status as StatusCodes) ===
199199
StatusCodes.UNPROCESSABLE_ENTITY &&
200-
(error.message.includes("is too big") || error.message.includes("diff is too large"))
200+
(error.message.includes("is too big") ||
201+
error.message.includes("diff is too large"))
201202
) {
202203
this._logger.logInfo(
203204
"GitHub createReviewComment() threw a 422 error related to a large diff. Ignoring as this is expected.",

src/task/tests/repos/gitHubReposInvoker.spec.ts

Lines changed: 77 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,73 +1542,85 @@ describe("gitHubReposInvoker.ts", (): void => {
15421542
verify(logger.logDebug("null")).once();
15431543
});
15441544

1545-
it("should succeed when a HTTP 422 error occurs due to having a too large path diff", async (): Promise<void> => {
1546-
// Arrange
1547-
when(octokitWrapper.initialize(any())).thenCall(
1548-
(options: OctokitOptions): void => {
1549-
assert.equal(options.auth, "PAT");
1550-
assert.equal(options.userAgent, expectedUserAgent);
1551-
assert.notEqual(options.log, null);
1552-
assert.notEqual(options.log?.debug, null);
1553-
assert.notEqual(options.log?.info, null);
1554-
assert.notEqual(options.log?.warn, null);
1555-
assert.notEqual(options.log?.error, null);
1556-
},
1557-
);
1558-
const error: RequestError = createRequestError(
1559-
StatusCodes.UNPROCESSABLE_ENTITY,
1560-
'Validation Failed: {"resource":"PullRequestReviewComment","code":"custom","field":"pull_request_review_thread.diff_entry","message":"file.ts is too big"}',
1561-
);
1562-
when(
1563-
octokitWrapper.createReviewComment(
1564-
"microsoft",
1565-
"PR-Metrics",
1566-
12345,
1567-
"Content",
1568-
"file.ts",
1569-
"sha54321",
1570-
),
1571-
).thenCall((): void => {
1572-
throw error;
1573-
});
1574-
const gitHubReposInvoker: GitHubReposInvoker = new GitHubReposInvoker(
1575-
instance(gitInvoker),
1576-
instance(logger),
1577-
instance(octokitWrapper),
1578-
instance(runnerInvoker),
1579-
);
1545+
{
1546+
const testCases: string[] = [
1547+
"file.ts is too big",
1548+
"file.ts diff is too large",
1549+
];
15801550

1581-
// Act
1582-
await gitHubReposInvoker.createComment("Content", "file.ts");
1551+
testCases.forEach((message: string): void => {
1552+
it(`should succeed when a HTTP 422 error occurs due to: '${message}'`, async (): Promise<void> => {
1553+
// Arrange
1554+
when(octokitWrapper.initialize(any())).thenCall(
1555+
(options: OctokitOptions): void => {
1556+
assert.equal(options.auth, "PAT");
1557+
assert.equal(options.userAgent, expectedUserAgent);
1558+
assert.notEqual(options.log, null);
1559+
assert.notEqual(options.log?.debug, null);
1560+
assert.notEqual(options.log?.info, null);
1561+
assert.notEqual(options.log?.warn, null);
1562+
assert.notEqual(options.log?.error, null);
1563+
},
1564+
);
1565+
const errorMessage = `Validation Failed: {"resource":"PullRequestReviewComment","code":"custom","field":"pull_request_review_thread.diff_entry","message":"${message}"}`;
1566+
const error: RequestError = createRequestError(
1567+
StatusCodes.UNPROCESSABLE_ENTITY,
1568+
errorMessage,
1569+
);
1570+
when(
1571+
octokitWrapper.createReviewComment(
1572+
"microsoft",
1573+
"PR-Metrics",
1574+
12345,
1575+
"Content",
1576+
"file.ts",
1577+
"sha54321",
1578+
),
1579+
).thenCall((): void => {
1580+
throw error;
1581+
});
1582+
const gitHubReposInvoker: GitHubReposInvoker = new GitHubReposInvoker(
1583+
instance(gitInvoker),
1584+
instance(logger),
1585+
instance(octokitWrapper),
1586+
instance(runnerInvoker),
1587+
);
15831588

1584-
// Assert
1585-
verify(octokitWrapper.initialize(any())).once();
1586-
verify(
1587-
octokitWrapper.listCommits("microsoft", "PR-Metrics", 12345, 1),
1588-
).once();
1589-
verify(
1590-
octokitWrapper.createReviewComment(
1591-
"microsoft",
1592-
"PR-Metrics",
1593-
12345,
1594-
"Content",
1595-
"file.ts",
1596-
"sha54321",
1597-
),
1598-
).once();
1599-
verify(logger.logDebug("* GitHubReposInvoker.createComment()")).once();
1600-
verify(logger.logDebug("* GitHubReposInvoker.initialize()")).once();
1601-
verify(
1602-
logger.logDebug("* GitHubReposInvoker.initializeForAzureDevOps()"),
1603-
).once();
1604-
verify(logger.logDebug("* GitHubReposInvoker.getCommitId()")).once();
1605-
verify(
1606-
logger.logInfo(
1607-
"GitHub createReviewComment() threw a 422 error related to a large diff. Ignoring as this is expected.",
1608-
),
1609-
).once();
1610-
verify(logger.logErrorObject(error)).once();
1611-
});
1589+
// Act
1590+
await gitHubReposInvoker.createComment("Content", "file.ts");
1591+
1592+
// Assert
1593+
verify(octokitWrapper.initialize(any())).once();
1594+
verify(
1595+
octokitWrapper.listCommits("microsoft", "PR-Metrics", 12345, 1),
1596+
).once();
1597+
verify(
1598+
octokitWrapper.createReviewComment(
1599+
"microsoft",
1600+
"PR-Metrics",
1601+
12345,
1602+
"Content",
1603+
"file.ts",
1604+
"sha54321",
1605+
),
1606+
).once();
1607+
verify(
1608+
logger.logDebug("* GitHubReposInvoker.createComment()"),
1609+
).once();
1610+
verify(logger.logDebug("* GitHubReposInvoker.initialize()")).once();
1611+
verify(
1612+
logger.logDebug("* GitHubReposInvoker.initializeForAzureDevOps()"),
1613+
).once();
1614+
verify(logger.logDebug("* GitHubReposInvoker.getCommitId()")).once();
1615+
verify(
1616+
logger.logInfo(
1617+
"GitHub createReviewComment() threw a 422 error related to a large diff. Ignoring as this is expected.",
1618+
),
1619+
).once();
1620+
verify(logger.logErrorObject(error)).once();
1621+
});
1622+
});
1623+
}
16121624

16131625
{
16141626
const testCases: HttpError[] = [

0 commit comments

Comments
 (0)