This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: patzick <13100280+patzick@users.noreply.github.com>
- Loading branch information
Showing
13 changed files
with
369 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
docs/landing/resources/api/composables.iusecart.carterrors.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@shopware-pwa/composables](./composables.md) > [IUseCart](./composables.iusecart.md) > [cartErrors](./composables.iusecart.carterrors.md) | ||
|
||
## IUseCart.cartErrors property | ||
|
||
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. | ||
> | ||
<b>Signature:</b> | ||
|
||
```typescript | ||
cartErrors: ComputedRef<EntityError[]>; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @beta | ||
*/ | ||
export enum ErrorLevel { | ||
NOTICE = 0, | ||
WARNING = 10, | ||
ERROR = 20, | ||
} | ||
|
||
/** | ||
* @beta | ||
*/ | ||
export interface EntityError { | ||
id: string; | ||
name: string; | ||
quantity: number; | ||
message: string; | ||
code: number; | ||
key: string; | ||
level: ErrorLevel | number; | ||
messageKey: | ||
| "product-stock-reached" | ||
| "product-out-of-stock" | ||
| "product-not-found" | ||
| "purchase-steps-quantity" | ||
| string; | ||
} |
76 changes: 76 additions & 0 deletions
76
packages/composables/__tests__/helpers/errorHandler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { broadcastErrors } from "../../src/internalHelpers/errorHandler"; | ||
import * as Composables from "@shopware-pwa/composables"; | ||
import { EntityError } from "@shopware-pwa/commons/interfaces/models/common/EntityError"; | ||
jest.mock("@shopware-pwa/composables"); | ||
const mockedComposables = Composables as jest.Mocked<typeof Composables>; | ||
jest.spyOn(console, "error"); | ||
describe("composables errorHandler", () => { | ||
const broadcastMock = jest.fn(); | ||
|
||
beforeEach(() => { | ||
mockedComposables.getApplicationContext.mockImplementation(() => { | ||
return {} as any; | ||
}); | ||
mockedComposables.useIntercept.mockImplementation(() => { | ||
return { | ||
broadcast: broadcastMock, | ||
} as any; | ||
}); | ||
}); | ||
describe("broadcastErrors", () => { | ||
it("should do nothing if some of arguments does not match the interface", () => { | ||
broadcastErrors(undefined as any, "testMethod", {} as any); | ||
expect(broadcastMock).toBeCalledTimes(0); | ||
}); | ||
it("should broadcast errors if any provided", () => { | ||
const errors: EntityError[] = [ | ||
{ | ||
id: "someId", | ||
name: "product-stock-reached", | ||
quantity: 1, | ||
message: "you reached the available quantity of the product", | ||
code: 10, | ||
key: "product-stock-reached-someId", | ||
level: 0, | ||
messageKey: "product-stock-reached", | ||
}, | ||
{ | ||
id: "someId", | ||
name: "product-stock-reached", | ||
quantity: 1, | ||
message: "you reached the available quantity of the product", | ||
code: 30, | ||
key: "product-stock-reached-someId", | ||
level: 10, | ||
messageKey: "product-stock-reached", | ||
}, | ||
{ | ||
id: "someId", | ||
name: "product-stock-reached", | ||
quantity: 1, | ||
message: "you reached the available quantity of the product", | ||
code: 10, | ||
key: "product-stock-reached-someId", | ||
level: 20, | ||
messageKey: "product-stock-reached", | ||
}, | ||
]; | ||
broadcastErrors(errors, "testMethod", {} as any); | ||
expect(broadcastMock).toBeCalledTimes(3); | ||
expect(broadcastMock).toBeCalledWith("notice", { | ||
inputParams: {}, | ||
methodName: "testMethod", | ||
notice: { | ||
code: 10, | ||
id: "someId", | ||
key: "product-stock-reached-someId", | ||
level: 0, | ||
message: "you reached the available quantity of the product", | ||
messageKey: "product-stock-reached", | ||
name: "product-stock-reached", | ||
quantity: 1, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
90dc4c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: