feat(core-flows,types,pricing,medusa): Products API can create prices with rules (#7796)
* chore: Products API can create prices with rules * chore: fix tests * chore: cleanup * chore: address comments
This commit is contained in:
@@ -1227,6 +1227,64 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a product variant with price rules", async () => {
|
||||
await api.post(
|
||||
`/admin/pricing/rule-types`,
|
||||
{
|
||||
name: "Region",
|
||||
rule_attribute: "region_id",
|
||||
default_priority: 1,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/products",
|
||||
{
|
||||
title: "Test create",
|
||||
variants: [
|
||||
{
|
||||
title: "Price with rules",
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
rules: { region_id: "eur" },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const priceIdSelector = /^price_*/
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.product).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.stringMatching(/^prod_*/),
|
||||
variants: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.stringMatching(/^variant_*/),
|
||||
title: "Price with rules",
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.stringMatching(priceIdSelector),
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
variant_id: expect.stringMatching(/^variant_*/),
|
||||
rules: { region_id: "eur" },
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a product that is not discountable", async () => {
|
||||
const payload = {
|
||||
title: "Test",
|
||||
|
||||
@@ -96,11 +96,20 @@ medusaIntegrationTestRunner({
|
||||
|
||||
describe("updates a variant's default prices (ignores prices associated with a Price List)", () => {
|
||||
it("successfully updates a variant's default prices by changing an existing price (currency_code)", async () => {
|
||||
await api.post(
|
||||
`/admin/pricing/rule-types`,
|
||||
{ name: "Region", rule_attribute: "region_id", default_priority: 1 },
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const data = {
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 1500,
|
||||
rules: {
|
||||
region_id: "na",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -115,6 +124,7 @@ medusaIntegrationTestRunner({
|
||||
baseProduct.variants[0].prices.find((p) => p.currency_code === "usd")
|
||||
.amount
|
||||
).toEqual(100)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({
|
||||
product: expect.objectContaining({
|
||||
@@ -126,6 +136,7 @@ medusaIntegrationTestRunner({
|
||||
expect.objectContaining({
|
||||
amount: 1500,
|
||||
currency_code: "usd",
|
||||
rules: { region_id: "na" },
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user