Skip to content

Commit cbeccf7

Browse files
committed
fix: rename jsddk functions and added tests
Closes #15068
1 parent 8259579 commit cbeccf7

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { http, HttpResponse } from "msw"
2+
import { setupServer } from "msw/node"
3+
import { describe, afterEach, it, beforeEach } from "node:test"
4+
import { Client } from "../client"
5+
import { Store } from "../store"
6+
import { StoreCartResponse } from "@medusajs/types"
7+
8+
const baseUrl = "https://someurl.com"
9+
const cartId = "cart-id"
10+
11+
// This is just a network-layer mocking, it doesn't start an actual server
12+
const server = setupServer(
13+
http.post(`${baseUrl}/store/carts/*/promotions`, ({ request, params, cookies }) => {
14+
return HttpResponse.json({
15+
test: "addPromotions",
16+
});
17+
}),
18+
http.delete(`${baseUrl}/store/carts/*/promotions`, ({ request, params, cookies }) => {
19+
return HttpResponse.json({
20+
test: "removePromotions",
21+
});
22+
}),
23+
24+
http.all("*", ({ request, params, cookies }) => {
25+
return new HttpResponse(null, {
26+
status: 404,
27+
statusText: "Not Found",
28+
})
29+
})
30+
)
31+
32+
describe("Store", () => {
33+
let client: Client
34+
let store: Store
35+
beforeEach(() => {
36+
client = new Client({
37+
baseUrl,
38+
})
39+
store = new Store(client)
40+
server.listen()
41+
})
42+
afterEach(() => {
43+
server.resetHandlers();
44+
server.close();
45+
})
46+
47+
describe("cart", () => {
48+
it("should expose a function to add a promtion to a cart", async () => {
49+
const resp = await store.cart.addPromotions(cartId, { promo_codes: ["promo-1", "promo-2"] });
50+
expect(resp).toEqual({
51+
test: "addPromotions",
52+
})
53+
});
54+
55+
it("should expose a function to remove a promtion from a cart", async () => {
56+
const resp = await store.cart.removePromotions(cartId, { promo_codes: ["promo-1", "promo-2"] });
57+
expect(resp).toEqual({
58+
test: "removePromotions",
59+
})
60+
});
61+
62+
});
63+
});

packages/core/js-sdk/src/store/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,14 @@ export class Store {
757757
* The method sends a request to the [Add Promotion Code](https://docs.medusajs.com/api/store#carts_postcartsidpromotions) API route.
758758
*
759759
* @example
760-
* sdk.store.cart.addPromotionCodes("cart_123", {
760+
* sdk.store.cart.addPromotions("cart_123", {
761761
* promo_codes: ["20OFF"]
762762
* })
763763
* .then(({ cart }) => {
764764
* console.log(cart)
765765
* })
766766
*/
767-
addPromotionCodes: async (
767+
addPromotions: async (
768768
cartId: string,
769769
body: HttpTypes.StoreCartAddPromotion,
770770
query?: SelectParams,
@@ -786,14 +786,14 @@ export class Store {
786786
* The method sends a request to the [Remove Promotion Code](https://docs.medusajs.com/api/store#carts_deletecartsidpromotions) API route.
787787
*
788788
* @example
789-
* sdk.store.cart.removePromotionCodes("cart_123", {
789+
* sdk.store.cart.removePromotions("cart_123", {
790790
* promo_codes: ["20OFF"]
791791
* })
792792
* .then(({ cart }) => {
793793
* console.log(cart)
794794
* })
795795
*/
796-
removePromotionCodes: async (
796+
removePromotions: async (
797797
cartId: string,
798798
body: HttpTypes.StoreCartRemovePromotion,
799799
query?: SelectParams,

0 commit comments

Comments
 (0)