feat: Add Sales Channel Stock Location link (#6634)

This commit is contained in:
Oli Juhl
2024-03-08 15:26:26 +01:00
committed by GitHub
parent a92cdeb01d
commit 4136b9da5f
7 changed files with 202 additions and 6 deletions
@@ -0,0 +1,118 @@
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import {
ISalesChannelModuleService,
IStockLocationService,
} from "@medusajs/types"
import { remoteQueryObjectFromString } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ getContainer }) => {
describe("Cart links", () => {
let appContainer
let scService: ISalesChannelModuleService
let locationService: IStockLocationService
let remoteQuery, remoteLink
beforeAll(async () => {
appContainer = getContainer()
scService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL)
locationService = appContainer.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
remoteQuery = appContainer.resolve("remoteQuery")
remoteLink = appContainer.resolve("remoteLink")
})
it("should query carts, sales channels, customers, regions with remote query", async () => {
const scWebshop = await scService.create({
name: "Webshop",
})
const scCphStore = await scService.create({
name: "CPH store",
})
const scNycStore = await scService.create({
name: "NYC store",
})
const euWarehouse = await locationService.create({
name: "EU Warehouse",
})
const usWarehouse = await locationService.create({
name: "US Warehouse",
})
await remoteLink.create([
{
[Modules.SALES_CHANNEL]: {
sales_channel_id: scWebshop.id,
},
[Modules.STOCK_LOCATION]: {
location_id: euWarehouse.id,
},
},
{
[Modules.SALES_CHANNEL]: {
sales_channel_id: scCphStore.id,
},
[Modules.STOCK_LOCATION]: {
location_id: euWarehouse.id,
},
},
{
[Modules.SALES_CHANNEL]: {
sales_channel_id: scNycStore.id,
},
[Modules.STOCK_LOCATION]: {
location_id: usWarehouse.id,
},
},
])
const euStockLocationChannelQuery = remoteQueryObjectFromString({
entryPoint: "stock_locations",
fields: ["id", "name", "sales_channels.id", "sales_channels.name"],
variables: { id: euWarehouse.id },
})
const usStockLocationChannelQuery = remoteQueryObjectFromString({
entryPoint: "stock_locations",
fields: ["id", "name", "sales_channels.id", "sales_channels.name"],
variables: { id: usWarehouse.id },
})
const euLocations = await remoteQuery(euStockLocationChannelQuery)
const usLocations = await remoteQuery(usStockLocationChannelQuery)
expect(euLocations.length).toBe(1)
expect(euLocations).toEqual([
expect.objectContaining({
id: euWarehouse.id,
sales_channels: [
expect.objectContaining({ id: scWebshop.id }),
expect.objectContaining({ id: scCphStore.id }),
],
name: "EU Warehouse",
}),
])
expect(usLocations.length).toBe(1)
expect(usLocations).toEqual([
expect.objectContaining({
id: usWarehouse.id,
sales_channels: [expect.objectContaining({ id: scNycStore.id })],
name: "US Warehouse",
}),
])
})
})
},
})
+8 -2
View File
@@ -49,8 +49,14 @@ module.exports = {
resolve: "@medusajs/cache-inmemory",
options: { ttl: 0 }, // Cache disabled
},
[Modules.STOCK_LOCATION]: true,
[Modules.INVENTORY]: true,
[Modules.STOCK_LOCATION]: {
resolve: "@medusajs/stock-location-next",
options: {},
},
[Modules.INVENTORY]: {
resolve: "@medusajs/inventory-next",
options: {},
},
[Modules.PRODUCT]: true,
[Modules.PRICING]: true,
[Modules.PROMOTION]: true,
+2 -1
View File
@@ -14,13 +14,14 @@
"@medusajs/cache-inmemory": "workspace:*",
"@medusajs/customer": "workspace:^",
"@medusajs/event-bus-local": "workspace:*",
"@medusajs/inventory": "workspace:^",
"@medusajs/inventory-next": "workspace:^",
"@medusajs/medusa": "workspace:*",
"@medusajs/modules-sdk": "workspace:^",
"@medusajs/pricing": "workspace:^",
"@medusajs/product": "workspace:^",
"@medusajs/promotion": "workspace:^",
"@medusajs/region": "workspace:^",
"@medusajs/stock-location-next": "workspace:^",
"@medusajs/store": "workspace:^",
"@medusajs/tax": "workspace:^",
"@medusajs/user": "workspace:^",