Skip to content

Commit a1356dc

Browse files
committed
test: construct ApiError subclasses via fromBody in fixtures
1 parent ccd7381 commit a1356dc

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

packages/cli-core/src/commands/doctor/doctor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ describe("checkLinkedAppExists", () => {
346346
const ctx = createMockContext({
347347
token: "test_token",
348348
profile: mockProfile,
349-
applicationError: new PlapiError(404, "Not found"),
349+
applicationError: PlapiError.fromBody(404, "Not found"),
350350
});
351351
const result = await checkLinkedAppExists(ctx);
352352
expectCheck(result, {

packages/cli-core/src/commands/link/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ describe("link", () => {
587587
test("shows picker with only create option when listApplications fails with 500", async () => {
588588
mockIsAgent.mockReturnValue(false);
589589
mockGetToken.mockResolvedValue("token");
590-
mockListApplications.mockRejectedValue(new PlapiError(500, "Internal Server Error"));
590+
mockListApplications.mockRejectedValue(PlapiError.fromBody(500, "Internal Server Error"));
591591
mockSearch.mockImplementation(
592592
async (config: {
593593
source: (term: string | undefined) => { name: string; value: string }[];
@@ -622,7 +622,7 @@ describe("link", () => {
622622
test("propagates listApplications errors that are not 5xx", async () => {
623623
mockIsAgent.mockReturnValue(false);
624624
mockGetToken.mockResolvedValue("token");
625-
mockListApplications.mockRejectedValue(new PlapiError(401, "Unauthorized"));
625+
mockListApplications.mockRejectedValue(PlapiError.fromBody(401, "Unauthorized"));
626626

627627
await expect(runLink()).rejects.toBeInstanceOf(PlapiError);
628628
});
@@ -1248,7 +1248,7 @@ describe("link", () => {
12481248
mockListApplications.mockResolvedValue([mockApp]);
12491249
mockSearch.mockResolvedValue("__create_new__");
12501250
mockInput.mockResolvedValue("My App");
1251-
mockCreateApplication.mockRejectedValue(new PlapiError(422, "Unprocessable Entity"));
1251+
mockCreateApplication.mockRejectedValue(PlapiError.fromBody(422, "Unprocessable Entity"));
12521252

12531253
await expect(link()).rejects.toBeInstanceOf(PlapiError);
12541254
expect(mockSetProfile).not.toHaveBeenCalled();
@@ -1265,7 +1265,7 @@ describe("link", () => {
12651265
name: "My App",
12661266
instances: [],
12671267
});
1268-
mockFetchApplication.mockRejectedValue(new PlapiError(503, "Service Unavailable"));
1268+
mockFetchApplication.mockRejectedValue(PlapiError.fromBody(503, "Service Unavailable"));
12691269

12701270
await expect(link()).rejects.toBeInstanceOf(PlapiError);
12711271
expect(mockSetProfile).not.toHaveBeenCalled();

packages/cli-core/src/commands/users/create.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe("users create", () => {
171171
test("prints raw BAPI validation errors to stdout for machine use", async () => {
172172
mockHandleBapiError.mockImplementation((error: unknown) => error instanceof BapiError);
173173
mockBapiRequest.mockRejectedValue(
174-
new BapiError(
174+
BapiError.fromBody(
175175
422,
176176
JSON.stringify({
177177
errors: [

packages/cli-core/src/lib/bapi-command.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("bapi-command", () => {
4343
const handled = await captured.run(() =>
4444
Promise.resolve(
4545
handleBapiError(
46-
new BapiError(
46+
BapiError.fromBody(
4747
422,
4848
JSON.stringify({
4949
errors: [

0 commit comments

Comments
 (0)