feat(medusa,stock-location,inventory): Integration tests (#3149)
This commit is contained in:
@@ -12,9 +12,9 @@ export const buildLevelsByInventoryItemId = (
|
||||
inventoryLevels: InventoryLevelDTO[],
|
||||
locationIds: string[]
|
||||
) => {
|
||||
const filteredLevels = inventoryLevels.filter((level) =>
|
||||
locationIds?.includes(level.location_id)
|
||||
)
|
||||
const filteredLevels = inventoryLevels.filter((level) => {
|
||||
return !locationIds.length || locationIds.includes(level.location_id)
|
||||
})
|
||||
|
||||
return filteredLevels.reduce((acc, level) => {
|
||||
acc[level.inventory_item_id] = acc[level.inventory_item_id] ?? []
|
||||
@@ -58,6 +58,7 @@ export const joinLevels = async (
|
||||
locationIds,
|
||||
inventoryService
|
||||
)
|
||||
|
||||
return inventoryItems.map((inventoryItem) => ({
|
||||
...inventoryItem,
|
||||
location_levels: levelsByItemId[inventoryItem.id] || [],
|
||||
|
||||
@@ -82,12 +82,7 @@ export const createVariantTransaction = async (
|
||||
const productVariantServiceTx = productVariantService.withTransaction(manager)
|
||||
|
||||
async function createVariant(variantInput: CreateProductVariantInput) {
|
||||
const variant = await productVariantServiceTx.create(
|
||||
productId,
|
||||
variantInput
|
||||
)
|
||||
|
||||
return { variant }
|
||||
return await productVariantServiceTx.create(productId, variantInput)
|
||||
}
|
||||
|
||||
async function removeVariant(variant: ProductVariant) {
|
||||
@@ -101,7 +96,7 @@ export const createVariantTransaction = async (
|
||||
return
|
||||
}
|
||||
|
||||
const inventoryItem = await inventoryServiceTx!.createInventoryItem({
|
||||
return await inventoryServiceTx!.createInventoryItem({
|
||||
sku: variant.sku,
|
||||
origin_country: variant.origin_country,
|
||||
hs_code: variant.hs_code,
|
||||
@@ -112,8 +107,6 @@ export const createVariantTransaction = async (
|
||||
height: variant.height,
|
||||
width: variant.width,
|
||||
})
|
||||
|
||||
return { inventoryItem }
|
||||
}
|
||||
|
||||
async function removeInventoryItem(inventoryItem: InventoryItemDTO) {
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
export const InventoryServiceMock = {
|
||||
withTransaction: function () {
|
||||
return this
|
||||
},
|
||||
|
||||
listInventoryItems: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
listReservationItems: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
listInventoryLevels: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
retrieveInventoryItem: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
retrieveInventoryLevel: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
createReservationItem: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
createInventoryItem: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
createInventoryLevel: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
updateInventoryLevel: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
updateInventoryItem: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
updateReservationItem: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
deleteReservationItemsByLineItem: jest
|
||||
.fn()
|
||||
.mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
deleteReservationItem: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
deleteInventoryItem: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
deleteInventoryLevel: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
adjustInventory: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
confirmInventory: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
|
||||
retrieveAvailableQuantity: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve(10)
|
||||
}),
|
||||
|
||||
retrieveStockedQuantity: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve(9)
|
||||
}),
|
||||
|
||||
retrieveReservedQuantity: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve(1)
|
||||
}),
|
||||
}
|
||||
|
||||
const mock = jest.fn().mockImplementation(() => {
|
||||
return InventoryServiceMock
|
||||
})
|
||||
|
||||
export default mock
|
||||
@@ -0,0 +1,46 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
|
||||
export const StockLocationServiceMock = {
|
||||
withTransaction: function () {
|
||||
return this
|
||||
},
|
||||
|
||||
retrieve: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve({
|
||||
id: id,
|
||||
name: "stock location 1 name",
|
||||
})
|
||||
}),
|
||||
update: jest.fn().mockImplementation((id, data) => {
|
||||
return Promise.resolve({ id, ...data })
|
||||
}),
|
||||
|
||||
listAndCount: jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve([
|
||||
[
|
||||
{
|
||||
id: IdMap.getId("stock_location_1"),
|
||||
name: "stock location 1 name",
|
||||
},
|
||||
],
|
||||
1,
|
||||
])
|
||||
}),
|
||||
|
||||
create: jest.fn().mockImplementation((data) => {
|
||||
return Promise.resolve({
|
||||
id: id,
|
||||
...data,
|
||||
})
|
||||
}),
|
||||
|
||||
delete: jest.fn().mockImplementation((id, config) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
}
|
||||
|
||||
const mock = jest.fn().mockImplementation(() => {
|
||||
return StockLocationServiceMock
|
||||
})
|
||||
|
||||
export default mock
|
||||
@@ -69,11 +69,17 @@ class SalesChannelLocationService extends TransactionBaseService {
|
||||
const salesChannel = await this.salesChannelService_
|
||||
.withTransaction(manager)
|
||||
.retrieve(salesChannelId)
|
||||
const stockLocation = await this.stockLocationService.retrieve(locationId)
|
||||
|
||||
const stockLocationId = locationId
|
||||
|
||||
if (this.stockLocationService) {
|
||||
const stockLocation = await this.stockLocationService.retrieve(locationId)
|
||||
locationId = stockLocation.id
|
||||
}
|
||||
|
||||
const salesChannelLocation = manager.create(SalesChannelLocation, {
|
||||
sales_channel_id: salesChannel.id,
|
||||
location_id: stockLocation.id,
|
||||
location_id: stockLocationId,
|
||||
})
|
||||
|
||||
await manager.save(salesChannelLocation)
|
||||
|
||||
@@ -209,7 +209,6 @@ export type CreateInventoryItemInput = {
|
||||
}
|
||||
|
||||
export type CreateReservationItemInput = {
|
||||
type?: string
|
||||
line_item_id?: string
|
||||
inventory_item_id: string
|
||||
location_id: string
|
||||
|
||||
Reference in New Issue
Block a user