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+ } ) ;
0 commit comments