feat: Add Sales Channel Stock Location link (#6634)
This commit is contained in:
1 parent
a92cdeb01d
commit
4136b9da5f
7 files changed
+202
-6
No files matched your search
@@ -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",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -49,8 +49,14 @@ module.exports = {
|
|||||||
resolve: "@medusajs/cache-inmemory",
|
resolve: "@medusajs/cache-inmemory",
|
||||||
options: { ttl: 0 }, // Cache disabled
|
options: { ttl: 0 }, // Cache disabled
|
||||||
},
|
},
|
||||||
[Modules.STOCK_LOCATION]: true,
|
[Modules.STOCK_LOCATION]: {
|
||||||
[Modules.INVENTORY]: true,
|
resolve: "@medusajs/stock-location-next",
|
||||||
|
options: {},
|
||||||
|
},
|
||||||
|
[Modules.INVENTORY]: {
|
||||||
|
resolve: "@medusajs/inventory-next",
|
||||||
|
options: {},
|
||||||
|
},
|
||||||
[Modules.PRODUCT]: true,
|
[Modules.PRODUCT]: true,
|
||||||
[Modules.PRICING]: true,
|
[Modules.PRICING]: true,
|
||||||
[Modules.PROMOTION]: true,
|
[Modules.PROMOTION]: true,
|
||||||
|
|||||||
@@ -14,13 +14,14 @@
|
|||||||
"@medusajs/cache-inmemory": "workspace:*",
|
"@medusajs/cache-inmemory": "workspace:*",
|
||||||
"@medusajs/customer": "workspace:^",
|
"@medusajs/customer": "workspace:^",
|
||||||
"@medusajs/event-bus-local": "workspace:*",
|
"@medusajs/event-bus-local": "workspace:*",
|
||||||
"@medusajs/inventory": "workspace:^",
|
"@medusajs/inventory-next": "workspace:^",
|
||||||
"@medusajs/medusa": "workspace:*",
|
"@medusajs/medusa": "workspace:*",
|
||||||
"@medusajs/modules-sdk": "workspace:^",
|
"@medusajs/modules-sdk": "workspace:^",
|
||||||
"@medusajs/pricing": "workspace:^",
|
"@medusajs/pricing": "workspace:^",
|
||||||
"@medusajs/product": "workspace:^",
|
"@medusajs/product": "workspace:^",
|
||||||
"@medusajs/promotion": "workspace:^",
|
"@medusajs/promotion": "workspace:^",
|
||||||
"@medusajs/region": "workspace:^",
|
"@medusajs/region": "workspace:^",
|
||||||
|
"@medusajs/stock-location-next": "workspace:^",
|
||||||
"@medusajs/store": "workspace:^",
|
"@medusajs/store": "workspace:^",
|
||||||
"@medusajs/tax": "workspace:^",
|
"@medusajs/tax": "workspace:^",
|
||||||
"@medusajs/user": "workspace:^",
|
"@medusajs/user": "workspace:^",
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ export * from "./product-variant-inventory-item"
|
|||||||
export * from "./product-variant-price-set"
|
export * from "./product-variant-price-set"
|
||||||
export * from "./publishable-api-key-sales-channel"
|
export * from "./publishable-api-key-sales-channel"
|
||||||
export * from "./region-payment-provider"
|
export * from "./region-payment-provider"
|
||||||
|
export * from "./sales-channel-location"
|
||||||
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
|
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||||
|
import { LINKS } from "../links"
|
||||||
|
|
||||||
|
export const SalesChannelLocation: ModuleJoinerConfig = {
|
||||||
|
serviceName: LINKS.SalesChannelLocation,
|
||||||
|
isLink: true,
|
||||||
|
databaseConfig: {
|
||||||
|
tableName: "sales_channel_locations",
|
||||||
|
idPrefix: "scloc",
|
||||||
|
},
|
||||||
|
alias: [
|
||||||
|
{
|
||||||
|
name: ["sales_channel_location", "sales_channel_locations"],
|
||||||
|
args: {
|
||||||
|
entity: "LinkSalesChannelLocation",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
primaryKeys: ["id", "sales_channel_id", "location_id"],
|
||||||
|
relationships: [
|
||||||
|
{
|
||||||
|
serviceName: Modules.SALES_CHANNEL,
|
||||||
|
primaryKey: "id",
|
||||||
|
foreignKey: "sales_channel_id",
|
||||||
|
alias: "sales_channel",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceName: Modules.STOCK_LOCATION,
|
||||||
|
primaryKey: "id",
|
||||||
|
foreignKey: "location_id",
|
||||||
|
alias: "location",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
extends: [
|
||||||
|
{
|
||||||
|
serviceName: Modules.SALES_CHANNEL,
|
||||||
|
fieldAlias: {
|
||||||
|
locations: "locations_link.location",
|
||||||
|
},
|
||||||
|
relationship: {
|
||||||
|
serviceName: LINKS.SalesChannelLocation,
|
||||||
|
primaryKey: "sales_channel_id",
|
||||||
|
foreignKey: "id",
|
||||||
|
alias: "locations_link",
|
||||||
|
isList: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceName: Modules.STOCK_LOCATION,
|
||||||
|
fieldAlias: {
|
||||||
|
sales_channels: "sales_channels_link.sales_channel",
|
||||||
|
},
|
||||||
|
relationship: {
|
||||||
|
serviceName: LINKS.SalesChannelLocation,
|
||||||
|
primaryKey: "location_id",
|
||||||
|
foreignKey: "id",
|
||||||
|
alias: "sales_channels_link",
|
||||||
|
isList: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
@@ -32,6 +32,12 @@ export const LINKS = {
|
|||||||
Modules.PROMOTION,
|
Modules.PROMOTION,
|
||||||
"promotion_id"
|
"promotion_id"
|
||||||
),
|
),
|
||||||
|
SalesChannelLocation: composeLinkName(
|
||||||
|
Modules.SALES_CHANNEL,
|
||||||
|
"sales_channel_id",
|
||||||
|
Modules.STOCK_LOCATION,
|
||||||
|
"location_id"
|
||||||
|
),
|
||||||
|
|
||||||
// Internal services
|
// Internal services
|
||||||
ProductShippingProfile: composeLinkName(
|
ProductShippingProfile: composeLinkName(
|
||||||
|
|||||||
@@ -8311,7 +8311,7 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@medusajs/inventory-next@workspace:packages/inventory-next":
|
"@medusajs/inventory-next@workspace:^, @medusajs/inventory-next@workspace:packages/inventory-next":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@medusajs/inventory-next@workspace:packages/inventory-next"
|
resolution: "@medusajs/inventory-next@workspace:packages/inventory-next"
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -8843,7 +8843,7 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@medusajs/stock-location-next@workspace:packages/stock-location-next":
|
"@medusajs/stock-location-next@workspace:^, @medusajs/stock-location-next@workspace:packages/stock-location-next":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@medusajs/stock-location-next@workspace:packages/stock-location-next"
|
resolution: "@medusajs/stock-location-next@workspace:packages/stock-location-next"
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -31857,13 +31857,14 @@ __metadata:
|
|||||||
"@medusajs/cache-inmemory": "workspace:*"
|
"@medusajs/cache-inmemory": "workspace:*"
|
||||||
"@medusajs/customer": "workspace:^"
|
"@medusajs/customer": "workspace:^"
|
||||||
"@medusajs/event-bus-local": "workspace:*"
|
"@medusajs/event-bus-local": "workspace:*"
|
||||||
"@medusajs/inventory": "workspace:^"
|
"@medusajs/inventory-next": "workspace:^"
|
||||||
"@medusajs/medusa": "workspace:*"
|
"@medusajs/medusa": "workspace:*"
|
||||||
"@medusajs/modules-sdk": "workspace:^"
|
"@medusajs/modules-sdk": "workspace:^"
|
||||||
"@medusajs/pricing": "workspace:^"
|
"@medusajs/pricing": "workspace:^"
|
||||||
"@medusajs/product": "workspace:^"
|
"@medusajs/product": "workspace:^"
|
||||||
"@medusajs/promotion": "workspace:^"
|
"@medusajs/promotion": "workspace:^"
|
||||||
"@medusajs/region": "workspace:^"
|
"@medusajs/region": "workspace:^"
|
||||||
|
"@medusajs/stock-location-next": "workspace:^"
|
||||||
"@medusajs/store": "workspace:^"
|
"@medusajs/store": "workspace:^"
|
||||||
"@medusajs/tax": "workspace:^"
|
"@medusajs/tax": "workspace:^"
|
||||||
"@medusajs/types": "workspace:^"
|
"@medusajs/types": "workspace:^"
|
||||||
|
|||||||
Reference in new issue
Block a user