test(medusa): Fix test pipelines
This commit is contained in:
1 parent
f5edaf51ea
commit
9b5354502f
4 files changed
+8
-49
No files matched your search
@@ -98,7 +98,7 @@ Object {
|
|||||||
"payment_authorized_at": null,
|
"payment_authorized_at": null,
|
||||||
"payment_id": null,
|
"payment_id": null,
|
||||||
"region_id": "test-region",
|
"region_id": "test-region",
|
||||||
"shipping_address_id": StringMatching /\\^addr_\\*/,
|
"shipping_address_id": "test-shipping-address",
|
||||||
"type": "swap",
|
"type": "swap",
|
||||||
"updated_at": Any<String>,
|
"updated_at": Any<String>,
|
||||||
},
|
},
|
||||||
@@ -274,7 +274,7 @@ Object {
|
|||||||
"payment_authorized_at": null,
|
"payment_authorized_at": null,
|
||||||
"payment_id": null,
|
"payment_id": null,
|
||||||
"region_id": "test-region",
|
"region_id": "test-region",
|
||||||
"shipping_address_id": StringMatching /\\^addr_\\*/,
|
"shipping_address_id": "test-shipping-address",
|
||||||
"type": "swap",
|
"type": "swap",
|
||||||
"updated_at": Any<String>,
|
"updated_at": Any<String>,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,18 +1,7 @@
|
|||||||
const path = require("path")
|
const path = require("path")
|
||||||
const {
|
const {
|
||||||
Region,
|
|
||||||
Order,
|
|
||||||
Customer,
|
|
||||||
ShippingProfile,
|
ShippingProfile,
|
||||||
Product,
|
|
||||||
ProductVariant,
|
|
||||||
MoneyAmount,
|
|
||||||
LineItem,
|
|
||||||
Payment,
|
|
||||||
Cart,
|
|
||||||
ShippingMethod,
|
|
||||||
ShippingOption,
|
ShippingOption,
|
||||||
Swap,
|
|
||||||
} = require("@medusajs/medusa")
|
} = require("@medusajs/medusa")
|
||||||
|
|
||||||
const setupServer = require("../../../helpers/setup-server")
|
const setupServer = require("../../../helpers/setup-server")
|
||||||
@@ -137,7 +126,7 @@ describe("/store/carts", () => {
|
|||||||
type: "swap",
|
type: "swap",
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
shipping_address_id: expect.stringMatching(/^addr_*/),
|
shipping_address_id: "test-shipping-address",
|
||||||
metadata: {
|
metadata: {
|
||||||
swap_id: expect.stringMatching(/^swap_*/),
|
swap_id: expect.stringMatching(/^swap_*/),
|
||||||
},
|
},
|
||||||
@@ -221,7 +210,7 @@ describe("/store/carts", () => {
|
|||||||
cart: {
|
cart: {
|
||||||
id: expect.stringMatching(/^cart_*/),
|
id: expect.stringMatching(/^cart_*/),
|
||||||
billing_address_id: "test-billing-address",
|
billing_address_id: "test-billing-address",
|
||||||
shipping_address_id: expect.stringMatching(/^addr_*/),
|
shipping_address_id: "test-shipping-address",
|
||||||
type: "swap",
|
type: "swap",
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
|
import { getManager } from "typeorm"
|
||||||
import { MedusaError } from "medusa-core-utils"
|
import { MedusaError } from "medusa-core-utils"
|
||||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||||
import CartService from "../cart"
|
import CartService from "../cart"
|
||||||
import { InventoryServiceMock } from "../__mocks__/inventory"
|
import { InventoryServiceMock } from "../__mocks__/inventory"
|
||||||
import { LineItemAdjustmentServiceMock } from "../__mocks__/line-item-adjustment"
|
import { LineItemAdjustmentServiceMock } from "../__mocks__/line-item-adjustment"
|
||||||
|
import { CartRepository } from "../../repositories/cart"
|
||||||
|
|
||||||
const eventBusService = {
|
const eventBusService = {
|
||||||
emit: jest.fn(),
|
emit: jest.fn(),
|
||||||
@@ -276,39 +278,6 @@ describe("CartService", () => {
|
|||||||
expect(cartRepository.save).toHaveBeenCalledTimes(1)
|
expect(cartRepository.save).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("successfully creates a cart with a shipping address id but no shippings_address", async () => {
|
|
||||||
await cartService.create({
|
|
||||||
region_id: IdMap.getId("testRegion"),
|
|
||||||
email: "email@test.com",
|
|
||||||
shipping_address_id: "test_shipping_address",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(eventBusService.emit).toHaveBeenCalledTimes(1)
|
|
||||||
expect(eventBusService.emit).toHaveBeenCalledWith(
|
|
||||||
"cart.created",
|
|
||||||
expect.any(Object)
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(cartRepository.create).toHaveBeenCalledTimes(1)
|
|
||||||
expect(cartRepository.create).toHaveBeenCalledWith(expect.objectContaining({
|
|
||||||
region_id: IdMap.getId("testRegion"),
|
|
||||||
shipping_address: {
|
|
||||||
id: "test_shipping_address",
|
|
||||||
first_name: "LeBron",
|
|
||||||
last_name: "James",
|
|
||||||
address_1: "Dunk St",
|
|
||||||
city: "Dunkville",
|
|
||||||
province: "CA",
|
|
||||||
postal_code: "12345",
|
|
||||||
country_code: "us",
|
|
||||||
},
|
|
||||||
customer_id: IdMap.getId("customer"),
|
|
||||||
email: "email@test.com"
|
|
||||||
}))
|
|
||||||
|
|
||||||
expect(cartRepository.save).toHaveBeenCalledTimes(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("creates a cart with a prefilled shipping address but a country not part of the region", async () => {
|
it("creates a cart with a prefilled shipping address but a country not part of the region", async () => {
|
||||||
const res = cartService.create({
|
const res = cartService.create({
|
||||||
region_id: IdMap.getId("testRegion"),
|
region_id: IdMap.getId("testRegion"),
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import InventoryService from "./inventory"
|
|||||||
import CustomShippingOptionService from "./custom-shipping-option"
|
import CustomShippingOptionService from "./custom-shipping-option"
|
||||||
import LineItemAdjustmentService from "./line-item-adjustment"
|
import LineItemAdjustmentService from "./line-item-adjustment"
|
||||||
import { LineItemRepository } from "../repositories/line-item"
|
import { LineItemRepository } from "../repositories/line-item"
|
||||||
|
import { raw } from "express"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
@@ -417,7 +418,7 @@ class CartService extends BaseService {
|
|||||||
"Shipping country not in region"
|
"Shipping country not in region"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
rawCart.shipping_address = addr
|
rawCart.shipping_address_id = data.shipping_address_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user