feat(core-flows, fulfillment): validate shipping options to stock locations (#8291)

what:

- validate shipping options to stock locations

RESOLVES CC-232
This commit is contained in:
Riqwan Thamir
2024-07-26 14:26:26 +02:00
committed by GitHub
parent 74d0d166b3
commit 91c17651f1
23 changed files with 607 additions and 18 deletions

View File

@@ -1480,6 +1480,36 @@ medusaIntegrationTestRunner({
})
it("should add shipping method to cart", async () => {
const stockLocation = (
await api.post(
`/admin/stock-locations`,
{ name: "test location" },
adminHeaders
)
).data.stock_location
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: stockLocation.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
])
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: stockLocation.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const shippingOption = await fulfillmentModule.createShippingOptions({
name: "Test shipping option",
service_zone_id: fulfillmentSet.service_zones[0].id,

View File

@@ -1930,6 +1930,28 @@ medusaIntegrationTestRunner({
)
).data.product
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: stockLocation.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
])
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: stockLocation.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
shippingOption = (
await api.post(
`/admin/shipping-options`,

View File

@@ -8,6 +8,10 @@ import {
Modules,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../helpers/create-admin-user"
jest.setTimeout(50000)
@@ -15,13 +19,12 @@ const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ getContainer }) => {
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Region and Payment Providers", () => {
let appContainer
let fulfillmentModule: IFulfillmentModuleService
let pricingModule: IPricingModuleService
let remoteQuery
let remoteLink
beforeAll(async () => {
appContainer = getContainer()
@@ -32,7 +35,7 @@ medusaIntegrationTestRunner({
remoteQuery = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_QUERY
)
remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await createAdminUser(dbConnection, adminHeaders, getContainer())
})
it("should query shipping option and price set link with remote query", async () => {
@@ -44,6 +47,38 @@ medusaIntegrationTestRunner({
name: "Test",
type: "test-type",
})
const remoteLink = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
const location = (
await api.post(
`/admin/stock-locations`,
{ name: "Test location" },
adminHeaders
)
).data.stock_location
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
])
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const serviceZone = await fulfillmentModule.createServiceZones({
name: "Test",
fulfillment_set_id: fulfillmentSet.id,

View File

@@ -130,6 +130,17 @@ export async function prepareDataFixtures({ container }) {
},
])
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const shippingOptionData: FulfillmentWorkflow.CreateShippingOptionsWorkflowInput =
{
name: "Shipping option",

View File

@@ -117,6 +117,17 @@ async function prepareDataFixtures({ container }) {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {

View File

@@ -43,6 +43,7 @@ async function prepareDataFixtures({ container }) {
const pricingModule = container.resolve(ModuleRegistrationName.PRICING)
const inventoryModule = container.resolve(ModuleRegistrationName.INVENTORY)
const customerService = container.resolve(ModuleRegistrationName.CUSTOMER)
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const customer = await customerService.createCustomers({
first_name: "joe",
@@ -98,6 +99,17 @@ async function prepareDataFixtures({ container }) {
},
})
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const [product] = await productModule.createProducts([
{
title: "Test product",
@@ -150,8 +162,6 @@ async function prepareDataFixtures({ container }) {
},
])
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {

View File

@@ -115,6 +115,17 @@ async function prepareDataFixtures({ container }) {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {

View File

@@ -42,6 +42,7 @@ async function prepareDataFixtures({ container }) {
const productModule = container.resolve(ModuleRegistrationName.PRODUCT)
const pricingModule = container.resolve(ModuleRegistrationName.PRICING)
const inventoryModule = container.resolve(ModuleRegistrationName.INVENTORY)
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const shippingProfile = await fulfillmentService.createShippingProfiles({
name: "test",
@@ -92,6 +93,17 @@ async function prepareDataFixtures({ container }) {
},
})
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const [product] = await productModule.createProducts([
{
title: "Test product",
@@ -117,8 +129,6 @@ async function prepareDataFixtures({ container }) {
},
])
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {

View File

@@ -124,6 +124,17 @@ async function prepareDataFixtures({ container }) {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {

View File

@@ -118,6 +118,17 @@ async function prepareDataFixtures({ container }) {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {

View File

@@ -29,7 +29,6 @@ medusaIntegrationTestRunner({
beforeEach(async () => {
fixtures = await prepareDataFixtures({ container })
order = await createOrderFixture({
container,
product: fixtures.product,

View File

@@ -126,9 +126,6 @@ medusaIntegrationTestRunner({
stock_location_id: stockLocation.id,
},
},
])
await remoteLinkService.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: stockLocation.id,
@@ -137,6 +134,14 @@ medusaIntegrationTestRunner({
fulfillment_set_id: fulfillmentSet.id,
},
},
{
[Modules.STOCK_LOCATION]: {
stock_location_id: stockLocation.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
shippingOption = (

View File

@@ -16,6 +16,7 @@ import {
import {
ContainerRegistrationKeys,
ModuleRegistrationName,
Modules,
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
@@ -151,6 +152,37 @@ medusaIntegrationTestRunner({
},
],
})
const stockLocationModule = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const location = await stockLocationModule.createStockLocations({
name: "Europe",
})
const remoteLink = container.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
})
it("should create, update and delete rules in batch", async () => {

View File

@@ -10,6 +10,7 @@ import {
import {
ContainerRegistrationKeys,
ModuleRegistrationName,
Modules,
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
@@ -57,6 +58,37 @@ medusaIntegrationTestRunner({
},
],
})
const stockLocationModule = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const location = await stockLocationModule.createStockLocations({
name: "Europe",
})
const remoteLink = container.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
})
it("should create shipping options and prices", async () => {

View File

@@ -13,6 +13,7 @@ import {
import {
ContainerRegistrationKeys,
ModuleRegistrationName,
Modules,
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
@@ -60,6 +61,37 @@ medusaIntegrationTestRunner({
},
],
})
const stockLocationModule = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const location = await stockLocationModule.createStockLocations({
name: "Europe",
})
const remoteLink = container.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
})
it("should delete shipping options", async () => {

View File

@@ -14,6 +14,7 @@ import {
import {
ContainerRegistrationKeys,
ModuleRegistrationName,
Modules,
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
@@ -61,6 +62,37 @@ medusaIntegrationTestRunner({
},
],
})
const stockLocationModule = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const location = await stockLocationModule.createStockLocations({
name: "Europe",
})
const remoteLink = container.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
})
it("should update shipping options", async () => {