feat(medusa,stock-location,inventory): Integration tests (#3149)

This commit is contained in:
Carlos R. L. Rodrigues
2023-02-06 09:02:43 -03:00
committed by GitHub
parent 71fdd28198
commit 923ccece24
17 changed files with 2019 additions and 32 deletions
@@ -223,8 +223,12 @@ export default class InventoryLevelService extends TransactionBaseService {
*/
async getStockedQuantity(
inventoryItemId: string,
locationIds: string[]
locationIds: string[] | string
): Promise<number> {
if (!Array.isArray(locationIds)) {
locationIds = [locationIds]
}
const manager = this.getManager()
const levelRepository = manager.getRepository(InventoryLevel)
@@ -235,7 +239,7 @@ export default class InventoryLevelService extends TransactionBaseService {
.andWhere("location_id IN (:...locationIds)", { locationIds })
.getRawOne()
return result.quantity
return parseFloat(result.quantity)
}
/**
@@ -246,8 +250,12 @@ export default class InventoryLevelService extends TransactionBaseService {
*/
async getAvailableQuantity(
inventoryItemId: string,
locationIds: string[]
locationIds: string[] | string
): Promise<number> {
if (!Array.isArray(locationIds)) {
locationIds = [locationIds]
}
const manager = this.getManager()
const levelRepository = manager.getRepository(InventoryLevel)
@@ -258,7 +266,7 @@ export default class InventoryLevelService extends TransactionBaseService {
.andWhere("location_id IN (:...locationIds)", { locationIds })
.getRawOne()
return result.quantity
return parseFloat(result.quantity)
}
/**
@@ -269,8 +277,12 @@ export default class InventoryLevelService extends TransactionBaseService {
*/
async getReservedQuantity(
inventoryItemId: string,
locationIds: string[]
locationIds: string[] | string
): Promise<number> {
if (!Array.isArray(locationIds)) {
locationIds = [locationIds]
}
const manager = this.getManager()
const levelRepository = manager.getRepository(InventoryLevel)
@@ -281,6 +293,6 @@ export default class InventoryLevelService extends TransactionBaseService {
.andWhere("location_id IN (:...locationIds)", { locationIds })
.getRawOne()
return result.quantity
return parseFloat(result.quantity)
}
}
@@ -173,8 +173,31 @@ export default class ReservationItemService extends TransactionBaseService {
const shouldUpdateQuantity =
isDefined(data.quantity) && data.quantity !== item.quantity
const shouldUpdateLocation =
isDefined(data.location_id) &&
isDefined(data.quantity) &&
data.location_id !== item.location_id
const ops: Promise<unknown>[] = []
if (shouldUpdateQuantity) {
if (shouldUpdateLocation) {
ops.push(
this.inventoryLevelService_
.withTransaction(manager)
.adjustReservedQuantity(
item.inventory_item_id,
item.location_id,
item.quantity * -1
),
this.inventoryLevelService_
.withTransaction(manager)
.adjustReservedQuantity(
item.inventory_item_id,
data.location_id!,
data.quantity!
)
)
} else if (shouldUpdateQuantity) {
const quantityDiff = data.quantity! - item.quantity
ops.push(
this.inventoryLevelService_