Skip to content

Commit

Permalink
Merge branch 'develop' into feat/admin-ext-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperkristensen authored Jan 9, 2025
2 parents ef26a32 + 6747a15 commit a703e88
Show file tree
Hide file tree
Showing 54 changed files with 1,573 additions and 272 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-experts-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

feat: add default retry strategy for redis
5 changes: 5 additions & 0 deletions .changeset/quick-buttons-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/pricing": patch
---

fix(pricing): PriceLists of type Sale no longer override default prices when the price list price is higher than the default price.
8 changes: 8 additions & 0 deletions .changeset/tiny-moles-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/medusa": patch
"@medusajs/test-utils": patch
"@medusajs/types": patch
"@medusajs/utils": patch
---

feat: remove dead code and refactor the logic of resolving plugins
166 changes: 166 additions & 0 deletions integration-tests/http/__tests__/product/store/product.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,89 @@ medusaIntegrationTestRunner({
expect(response.data.products).toEqual(expectation)
})

it("should list products with prices with a default price when the price list price is higher and the price list is of type SALE", async () => {
const priceList = (
await api.post(
`/admin/price-lists`,
{
title: "test price list",
description: "test",
status: PriceListStatus.ACTIVE,
type: PriceListType.SALE,
prices: [
{
amount: 3500,
currency_code: "usd",
variant_id: product.variants[0].id,
},
],
rules: { "customer.groups.id": [customerGroup.id] },
},
adminHeaders
)
).data.price_list

let response = await api.get(
`/store/products?fields=*variants.calculated_price&region_id=${region.id}`,
storeHeadersWithCustomer
)

const expectation = expect.arrayContaining([
expect.objectContaining({
id: product.id,
variants: [
expect.objectContaining({
calculated_price: {
id: expect.any(String),
is_calculated_price_price_list: false,
is_calculated_price_tax_inclusive: false,
calculated_amount: 3000,
raw_calculated_amount: {
value: "3000",
precision: 20,
},
is_original_price_price_list: false,
is_original_price_tax_inclusive: false,
original_amount: 3000,
raw_original_amount: {
value: "3000",
precision: 20,
},
currency_code: "usd",
calculated_price: {
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
original_price: {
id: expect.any(String),
price_list_id: null,
price_list_type: null,
min_quantity: null,
max_quantity: null,
},
},
}),
],
}),
])

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(3)
expect(response.data.products).toEqual(expectation)

// with only region_id
response = await api.get(
`/store/products?region_id=${region.id}`,
storeHeadersWithCustomer
)

expect(response.status).toEqual(200)
expect(response.data.products).toEqual(expectation)
})

it("should list products with prices with a override price list price", async () => {
const priceList = (
await api.post(
Expand Down Expand Up @@ -1254,6 +1337,89 @@ medusaIntegrationTestRunner({
expect(response.status).toEqual(200)
expect(response.data.products).toEqual(expectation)
})

it("should list products with prices with a override price list price even if the price list price is higher than the default price", async () => {
const priceList = (
await api.post(
`/admin/price-lists`,
{
title: "test price list",
description: "test",
status: PriceListStatus.ACTIVE,
type: PriceListType.OVERRIDE,
prices: [
{
amount: 35000,
currency_code: "usd",
variant_id: product.variants[0].id,
},
],
rules: { "customer.groups.id": [customerGroup.id] },
},
adminHeaders
)
).data.price_list

let response = await api.get(
`/store/products?fields=*variants.calculated_price&region_id=${region.id}`,
storeHeadersWithCustomer
)

const expectation = expect.arrayContaining([
expect.objectContaining({
id: product.id,
variants: [
expect.objectContaining({
calculated_price: {
id: expect.any(String),
is_calculated_price_price_list: true,
is_calculated_price_tax_inclusive: false,
calculated_amount: 35000,
raw_calculated_amount: {
value: "35000",
precision: 20,
},
is_original_price_price_list: true,
is_original_price_tax_inclusive: false,
original_amount: 35000,
raw_original_amount: {
value: "35000",
precision: 20,
},
currency_code: "usd",
calculated_price: {
id: expect.any(String),
price_list_id: priceList.id,
price_list_type: "override",
min_quantity: null,
max_quantity: null,
},
original_price: {
id: expect.any(String),
price_list_id: priceList.id,
price_list_type: "override",
min_quantity: null,
max_quantity: null,
},
},
}),
],
}),
])

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(3)
expect(response.data.products).toEqual(expectation)

// with only region_id
response = await api.get(
`/store/products?region_id=${region.id}`,
storeHeadersWithCustomer
)

expect(response.status).toEqual(200)
expect(response.data.products).toEqual(expectation)
})
})

describe("with inventory items", () => {
Expand Down
40 changes: 40 additions & 0 deletions packages/core/types/src/common/config-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,10 +922,50 @@ export type ConfigModule = {
featureFlags: Record<string, boolean | string | Record<string, boolean>>
}

type InternalModuleDeclarationOverride = InternalModuleDeclaration & {
/**
* Optional key to be used to identify the module, if not provided, it will be inferred from the module joiner config service name.
*/
key?: string
/**
* By default, modules are enabled, if provided as true, this will disable the module entirely.
*/
disable?: boolean
}

type ExternalModuleDeclarationOverride = ExternalModuleDeclaration & {
/**
* key to be used to identify the module, if not provided, it will be inferred from the module joiner config service name.
*/
key: string
/**
* By default, modules are enabled, if provided as true, this will disable the module entirely.
*/
disable?: boolean
}

/**
* The configuration accepted by the "defineConfig" helper
*/
export type InputConfig = Partial<
Omit<ConfigModule, "admin" | "modules"> & {
admin: Partial<ConfigModule["admin"]>
modules:
| Partial<
InternalModuleDeclarationOverride | ExternalModuleDeclarationOverride
>[]
/**
* @deprecated use the array instead
*/
| ConfigModule["modules"]
}
>

export type PluginDetails = {
resolve: string
name: string
id: string
options: Record<string, unknown>
version: string
modules?: InputConfig["modules"]
}
18 changes: 18 additions & 0 deletions packages/core/utils/src/common/__tests__/define-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -298,6 +301,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -462,6 +468,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -627,6 +636,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -780,6 +792,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -933,6 +948,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down
Loading

0 comments on commit a703e88

Please sign in to comment.