Skip to content

Commit

Permalink
chore(order): dml (#10292)
Browse files Browse the repository at this point in the history
* ../../core/types/src/dml/index.ts

* ../../core/types/src/dml/index.ts

* fix: relationships mapping

* handle nullable foreign keys types

* handle nullable foreign keys types

* handle nullable foreign keys types

* continue to update product category repository

* fix all product category repositories issues

* fix product category service types

* fix product module service types

* fix product module service types

* fix repository template type

* refactor: use a singleton DMLToMikroORM factory instance

Since the MikroORM MetadataStorage is global, we will also have to turn DML
to MikroORM entities conversion use a global bucket as well

* refactor: update product module to use DML in tests

* wip: tests

* WIP product linkable fixes

* continue type fixing and start test fixing

* test: fix more tests

* fix repository

* fix pivot table computaion + fix mikro orm repository

* fix many to many management and configuration

* fix many to many management and configuration

* fix many to many management and configuration

* update product tag relation configuration

* Introduce experimental dml hooks to fix some issues with categories

* more fixes

* fix product tests

* add missing id prefixes

* fix product category handle management

* test: fix more failing tests

* test: make it all green

* test: fix breaking tests

* fix: build issues

* fix: build issues

* fix: more breaking tests

* refactor: fix issues after merge

* refactor: fix issues after merge

* refactor: surpress types error

* test: fix DML failing tests

* improve many to many inference + tests

* Wip fix columns from product entity

* remove product model before create hook and manage handle validation and transformation at the service level

* test: fix breaking unit tests

* fix: product module service to not update handle on product update

* fix define link and joiner config

* test: fix joiner config test

* test: fix joiner config test

* fix joiner config primary keys

* Fix joiner config builder

* Fix joiner config builder

* test: remove only modifier from test

* refactor: remove hooks usage from product collection

* refactor: remove hooks usage from product-option

* refactor: remove hooks usage for computing category handle

* refactor: remove hooks usage from productCategory model

* refactor: remove hooks from DML

* refactor: remove cruft

* order dml

* cleanup

* re add foerign key indexes

* wip

* chore: remove unused types

* wip

* changes

* rm raw

* autoincrement

* wip

* rel

* refactor: cleanup

* migration and models configuration adjustments

* cleanup

* number searchable

* fix random ordering

* fix

* test: fix product-category tests

* test: update breaking DML tests

* test: array assertion to not care about ordering

* fix: temporarily apply id ordering for products

* types

* wip

* WIP type improvements

* update order models

* partially fix types temporarely

* rel

* fix: recursive type issue

* improve type inference breaks

* improve type inference breaks

* update models

* rm nullable

* default value

* repository

* update default value handling

* fix unit tests

* WIP

* toMikroORM

* fix relations

* cascades

* fix

* experimental dml hooks

* rm migration

* serial

* nullable autoincrement

* fix model

* model changes

* fix one to one DML

* order test

* fix addresses

* fix unit tests

* Re align dml entity name inference

* update model table name config

* update model table name config

* revert

* update return relation

* WIP

* hasOne

* models

* fix

* model

* initial commit

* cart service

* order module

* utils unit test

* index engine

* changeset

* merge

* fix hasOne with fk

* update

* free text filter per entity

* tests

* prod category

* property string many to many

* fix big number

* link modules migration set names

* merge

* shipping option rules

* serializer

* unit test

* fix test mikro orm init

* fix test mikro orm init

* Maintain merge object properties

* fix test mikro orm init

* prevent unit test from connecting to db

* wip

* fix test

* fix test

* link test

* schema

* models

* auto increment

* hook

* model hooks

* order

* wip

* orm version

* request return field

* fix return configuration on order model

* workflows

* core flows

* unit test

* test

* base repo

* test

* base repo

* test fix

* inventory move

* locking inventory

* test

* free text fix

* rm timeout mock

* migrate fulfillment values

* v6.4.3

* cleanup

* link-modules update sql

* revert test

* remove fake timers

---------

Co-authored-by: adrien2p <[email protected]>
Co-authored-by: Harminder Virk <[email protected]>
Co-authored-by: Oli Juhl <[email protected]>
  • Loading branch information
4 people authored Jan 21, 2025
1 parent 05c8a67 commit cc73802
Show file tree
Hide file tree
Showing 178 changed files with 6,175 additions and 7,564 deletions.
41 changes: 41 additions & 0 deletions .changeset/fair-ants-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
"@medusajs/locking-postgres": minor
"@medusajs/workflow-engine-inmemory": minor
"@medusajs/workflow-engine-redis": minor
"@medusajs/stock-location": minor
"@medusajs/sales-channel": minor
"@medusajs/link-modules": minor
"@medusajs/notification": minor
"@medusajs/fulfillment": minor
"@medusajs/orchestration": minor
"@medusajs/workflows-sdk": minor
"@medusajs/test-utils": minor
"@medusajs/inventory": minor
"@medusajs/promotion": minor
"@medusajs/modules-sdk": minor
"@medusajs/currency": minor
"@medusajs/customer": minor
"@medusajs/core-flows": minor
"@medusajs/api-key": minor
"@medusajs/locking": minor
"@medusajs/payment": minor
"@medusajs/pricing": minor
"@medusajs/product": minor
"@medusajs/cli": minor
"@medusajs/framework": minor
"@medusajs/region": minor
"integration-tests-http": minor
"@medusajs/index": minor
"@medusajs/order": minor
"@medusajs/store": minor
"@medusajs/auth": minor
"@medusajs/cart": minor
"@medusajs/file": minor
"@medusajs/user": minor
"@medusajs/tax": minor
"@medusajs/types": minor
"@medusajs/utils": minor
"@medusajs/medusa": minor
---

chore: upgrade to mikro-orm 6
6 changes: 3 additions & 3 deletions integration-tests/http/__tests__/cart/store/cart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ medusaIntegrationTestRunner({
rules: [
{
attribute: "enabled_in_store",
value: '"true"',
value: "true",
operator: "eq",
},
{
Expand Down Expand Up @@ -1779,7 +1779,7 @@ medusaIntegrationTestRunner({
rules: [
{
attribute: "enabled_in_store",
value: '"true"',
value: "true",
operator: "eq",
},
{
Expand Down Expand Up @@ -2150,7 +2150,7 @@ medusaIntegrationTestRunner({
rules: [
{
attribute: "enabled_in_store",
value: '"true"',
value: "true",
operator: "eq",
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ medusaIntegrationTestRunner({
await api
.post("/admin/customer-groups", payload, adminHeaders)
.catch((err) => {
console.log(err)
// BREAKING: Duplicate error is now 400
expect(err.response.status).toEqual(400)
expect(err.response.data.type).toEqual("invalid_data")
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/http/__tests__/exchanges/exchanges.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
ContainerRegistrationKeys,
Modules,
RuleOperator,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../helpers/create-admin-user"
import { setupTaxStructure } from "../../../modules/__tests__/fixtures/tax"

jest.setTimeout(30000)
jest.setTimeout(300000)

medusaIntegrationTestRunner({
testSuite: ({ dbConnection, getContainer, api }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ClaimType, Modules, RuleOperator } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import { ClaimType, Modules, RuleOperator } from "@medusajs/utils"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
import { setupTaxStructure } from "../../../../modules/__tests__/fixtures"
import { createOrderSeeder } from "../../fixtures/order"

jest.setTimeout(30000)
jest.setTimeout(300000)

medusaIntegrationTestRunner({
testSuite: ({ dbConnection, getContainer, api }) => {
Expand Down Expand Up @@ -268,6 +268,7 @@ medusaIntegrationTestRunner({
{
items: [
{
title: "new ITEM",
variant_id: order.items[0].variant_id,
quantity: 1,
},
Expand Down Expand Up @@ -480,6 +481,7 @@ medusaIntegrationTestRunner({
{
items: [
{
title: "Test item 2",
variant_id: order.items[0].variant_id,
quantity: 1,
},
Expand Down Expand Up @@ -551,7 +553,7 @@ medusaIntegrationTestRunner({
})
)

inboundItem = orderResult.items[0]
inboundItem = orderResult.items[1]

await api.post(
`/admin/claims/${claimWithInboundAndOutbound.id}/inbound/items`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ medusaIntegrationTestRunner({
sales_channel_id: expect.stringContaining("sc_"),
currency_code: "usd",
region_id: expect.stringContaining("reg_"),
shipping_address: null,
item_total: 0,
total: 0,
email: null,
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/modules/__tests__/link-modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getMigrationPlanner, initialize } from "@medusajs/link-modules"
import { MedusaModule } from "@medusajs/modules-sdk"
import { ModuleJoinerConfig } from "@medusajs/types"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import { ModuleJoinerConfig } from "@medusajs/types"

jest.setTimeout(5000000)

Expand Down Expand Up @@ -74,6 +74,7 @@ medusaIntegrationTestRunner({

const planner = getMigrationPlanner(dbConfig, linkDefinition)
await planner.executePlan(await planner.createPlan())

links = await initialize(dbConfig, linkDefinition)
})

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/modules/__tests__/order/draft-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ medusaIntegrationTestRunner({
summary: expect.objectContaining({
// TODO: add summary fields
}),
items: [
items: expect.arrayContaining([
expect.objectContaining({
title: "Test variant",
subtitle: "Test product",
Expand Down Expand Up @@ -335,7 +335,7 @@ medusaIntegrationTestRunner({
value: "1",
}),
}),
],
]),
shipping_address: expect.objectContaining({
last_name: "Test",
address_1: "Test",
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/modules/__tests__/order/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ medusaIntegrationTestRunner({
metadata: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
billing_address: {
id: expect.any(String),
Expand All @@ -379,6 +380,7 @@ medusaIntegrationTestRunner({
metadata: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
shipping_methods: [
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createShippingOptionsWorkflow,
orderClaimRequestItemReturnWorkflow,
} from "@medusajs/core-flows"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
FulfillmentWorkflow,
IOrderModuleService,
Expand All @@ -19,7 +20,6 @@ import {
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"

jest.setTimeout(500000)

Expand Down Expand Up @@ -186,7 +186,7 @@ async function prepareDataFixtures({ container }) {
{
attribute: "is_return",
operator: RuleOperator.EQ,
value: '"true"',
value: "true",
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
orderExchangeAddNewItemWorkflow,
orderExchangeRequestItemReturnWorkflow,
} from "@medusajs/core-flows"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
FulfillmentWorkflow,
IRegionModuleService,
Expand All @@ -21,7 +22,6 @@ import {
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"

jest.setTimeout(500000)

Expand Down Expand Up @@ -234,7 +234,7 @@ async function prepareDataFixtures({ container }) {
{
attribute: "is_return",
operator: RuleOperator.EQ,
value: '"true"',
value: "true",
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
beginReturnOrderWorkflow,
createShippingOptionsWorkflow,
} from "@medusajs/core-flows"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
FulfillmentWorkflow,
IOrderModuleService,
Expand All @@ -17,7 +18,6 @@ import {
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"

jest.setTimeout(500000)

Expand Down Expand Up @@ -187,7 +187,7 @@ async function prepareDataFixtures({ container }) {
{
attribute: "is_return",
operator: RuleOperator.EQ,
value: '"true"',
value: "true",
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createShippingOptionsWorkflow,
} from "@medusajs/core-flows"
import { RemoteLink } from "@medusajs/modules-sdk"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
FulfillmentSetDTO,
FulfillmentWorkflow,
Expand All @@ -21,7 +22,6 @@ import {
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"

jest.setTimeout(500000)

Expand Down Expand Up @@ -190,7 +190,7 @@ async function prepareDataFixtures({ container }) {
{
attribute: "is_return",
operator: RuleOperator.EQ,
value: '"true"',
value: "true",
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createOrderFulfillmentWorkflow,
createShippingOptionsWorkflow,
} from "@medusajs/core-flows"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
FulfillmentWorkflow,
IOrderModuleService,
Expand All @@ -20,7 +21,6 @@ import {
Modules,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"

jest.setTimeout(500000)

Expand Down Expand Up @@ -305,12 +305,15 @@ async function createOrderFixture({ container, product, location }) {

const inventoryModule = container.resolve(Modules.INVENTORY)

const itemWithInventory = order.items!.find(
(o) => o.variant_sku === variantSkuWithInventory
)!
const reservation = await inventoryModule.createReservationItems([
{
line_item_id: order.items![0].id,
line_item_id: itemWithInventory.id,
inventory_item_id: inventoryItem.id,
location_id: location.id,
quantity: order.items![0].quantity,
quantity: itemWithInventory.quantity,
},
])

Expand Down Expand Up @@ -440,7 +443,6 @@ medusaIntegrationTestRunner({
id: order.id,
},
fields: [
"*",
"items.*",
"shipping_methods.*",
"total",
Expand All @@ -458,14 +460,15 @@ medusaIntegrationTestRunner({
)!

expect(orderFulfillAfterCancelled.fulfillments).toHaveLength(1)
expect(orderFulfillItemWithInventory.detail.fulfilled_quantity).toEqual(
0
)
expect(
orderFulfillItemWithInventory.detail.fulfilled_quantity.valueOf()
).toEqual(0)

const stockAvailabilityAfterCancelled =
await inventoryModule.retrieveStockedQuantity(inventoryItem.id, [
location.id,
])

expect(stockAvailabilityAfterCancelled.valueOf()).toEqual(2)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createOrderShipmentWorkflow,
createShippingOptionsWorkflow,
} from "@medusajs/core-flows"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
FulfillmentWorkflow,
IOrderModuleService,
Expand All @@ -20,7 +21,6 @@ import {
RuleOperator,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"

jest.setTimeout(500000)

Expand Down Expand Up @@ -177,7 +177,7 @@ async function prepareDataFixtures({ container }) {
{
attribute: "is_return",
operator: RuleOperator.EQ,
value: '"true"',
value: "true",
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ medusaIntegrationTestRunner({
throwOnError: false,
})

expect(error.error.message).toEqual(`Order id not found: ${order.id}`)
expect(error.error.message).toEqual(
`Return id not found: ${returnOrder.id}`
)
})

it("should throw an error if order change does not exist", async () => {
Expand Down
Loading

0 comments on commit cc73802

Please sign in to comment.