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.
feat(client): allow to add multiple cart items (#1599)
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 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
32 changes: 32 additions & 0 deletions
32
docs/landing/resources/api/shopware-6-client.addcartitems.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,32 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@shopware-pwa/shopware-6-client](./shopware-6-client.md) > [addCartItems](./shopware-6-client.addcartitems.md) | ||
|
||
## addCartItems() function | ||
|
||
> 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. | ||
> | ||
Adds multiple items to the cart. Accepts every type of cart item. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare function addCartItems(items: Partial<LineItem>[], contextInstance?: ShopwareApiInstance): Promise<any>; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| items | Partial<LineItem>\[\] | | | ||
| contextInstance | [ShopwareApiInstance](./shopware-6-client.shopwareapiinstance.md) | | | ||
|
||
<b>Returns:</b> | ||
|
||
Promise<any> | ||
|
||
## Exceptions | ||
|
||
ClientApiError | ||
|
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
43 changes: 43 additions & 0 deletions
43
packages/shopware-6-client/__tests__/services/CartService/addCartItems.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,43 @@ | ||
import { addCartItems } from "../../../src"; | ||
import { defaultInstance } from "../../../src/apiService"; | ||
|
||
jest.mock("../../../src/apiService"); | ||
const mockedApiInstance = defaultInstance as jest.Mocked< | ||
typeof defaultInstance | ||
>; | ||
|
||
describe("CartService - addCartItems", () => { | ||
const mockedPost = jest.fn(); | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
mockedApiInstance.invoke = { | ||
post: mockedPost, | ||
} as any; | ||
}); | ||
|
||
it("should call valid endpoint and return a cart", async () => { | ||
mockedPost.mockResolvedValueOnce({ | ||
data: {}, | ||
}); | ||
|
||
await addCartItems([ | ||
{ | ||
type: "product", | ||
}, | ||
{ | ||
type: "credit", | ||
}, | ||
]); | ||
expect(mockedPost).toBeCalledTimes(1); | ||
expect(mockedPost).toBeCalledWith("/store-api/checkout/cart/line-item", { | ||
items: [ | ||
{ | ||
type: "product", | ||
}, | ||
{ | ||
type: "credit", | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
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
9318e98
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: