feat: Add support for shipping options prices update (#7028)

This commit is contained in:
Adrien de Peretti
2024-04-11 18:34:55 +02:00
committed by GitHub
parent 51acd1da5b
commit c78915c7c5
13 changed files with 450 additions and 77 deletions
@@ -856,8 +856,14 @@ medusaIntegrationTestRunner({
expect(response.data.values.length).toEqual(2)
expect(response.data.values).toEqual(
expect.arrayContaining([
{ label: "Afghanistan", value: "af" },
{ label: "Albania", value: "al" },
{
label: "Andorra",
value: "ad",
},
{
label: "United Arab Emirates",
value: "ae",
},
])
)
@@ -264,7 +264,7 @@ medusaIntegrationTestRunner({
})
})
it("should create a shipping option successfully", async () => {
it("should update a shipping option successfully", async () => {
const shippingOptionPayload = {
name: "Test shipping option",
service_zone_id: fulfillmentSet.service_zones[0].id,
@@ -295,15 +295,44 @@ medusaIntegrationTestRunner({
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.shipping_option).toEqual(
const shippingOptionId = response.data.shipping_option.id
const eurPrice = response.data.shipping_option.prices.find(
(p) => p.currency_code === "eur"
)
const updateShippingOptionPayload = {
id: shippingOptionId,
name: "Updated shipping option",
provider_id: "manual_test-provider",
price_type: "flat",
prices: [
{
currency_code: "dkk",
amount: 10,
},
{
id: eurPrice.id,
amount: 10000,
},
],
}
const updateResponse = await api.post(
`/admin/shipping-options/${shippingOptionId}`,
updateShippingOptionPayload,
adminHeaders
)
expect(updateResponse.status).toEqual(200)
expect(updateResponse.data.shipping_option.prices).toHaveLength(2)
expect(updateResponse.data.shipping_option).toEqual(
expect.objectContaining({
id: expect.any(String),
name: shippingOptionPayload.name,
name: updateShippingOptionPayload.name,
provider: expect.objectContaining({
id: shippingOptionPayload.provider_id,
}),
price_type: shippingOptionPayload.price_type,
price_type: updateShippingOptionPayload.price_type,
type: expect.objectContaining({
id: expect.any(String),
label: shippingOptionPayload.type.label,
@@ -315,13 +344,15 @@ medusaIntegrationTestRunner({
prices: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
currency_code: "usd",
amount: 1000,
currency_code: "dkk",
rules_count: 0,
amount: 10,
}),
expect.objectContaining({
id: expect.any(String),
currency_code: "eur",
amount: 1000,
rules_count: 1,
amount: 10000,
}),
]),
rules: expect.arrayContaining([
@@ -97,6 +97,10 @@ medusaIntegrationTestRunner({
region_id: region.id,
amount: 100,
},
{
currency_code: "dkk",
amount: 1000,
},
],
rules: [
{
@@ -111,26 +115,11 @@ medusaIntegrationTestRunner({
input: [shippingOptionData],
})
const updateData: UpdateShippingOptionsWorkflowInput = {
id: result[0].id,
name: "Test shipping option",
price_type: "flat",
type: {
code: "manual-type",
label: "Manual Type",
description: "Manual Type Description",
},
}
await updateShippingOptionsWorkflow(container).run({
input: [updateData],
})
const remoteQuery = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY
)
const remoteQueryObject = remoteQueryObjectFromString({
let remoteQueryObject = remoteQueryObjectFromString({
entryPoint: "shipping_option",
variables: {
id: result[0].id,
@@ -155,10 +144,50 @@ medusaIntegrationTestRunner({
const [createdShippingOption] = await remoteQuery(remoteQueryObject)
const prices = createdShippingOption.prices
delete createdShippingOption.prices
const usdPrice = createdShippingOption.prices.find((price) => {
return price.currency_code === "usd"
})
expect(createdShippingOption).toEqual(
const dkkPrice = createdShippingOption.prices.find((price) => {
return price.currency_code === "dkk"
})
const updateData: UpdateShippingOptionsWorkflowInput = {
id: createdShippingOption.id,
name: "Test shipping option",
price_type: "flat",
type: {
code: "manual-type",
label: "Manual Type",
description: "Manual Type Description",
},
prices: [
// We keep the usd price as is
// update the dkk price to 100
// delete the third price eur
// create a new eur one instead
usdPrice,
{
...dkkPrice,
amount: 100,
},
{
region_id: region.id,
amount: 1000,
},
],
}
await updateShippingOptionsWorkflow(container).run({
input: [updateData],
})
const [updatedShippingOption] = await remoteQuery(remoteQueryObject)
const prices = updatedShippingOption.prices
delete updatedShippingOption.prices
expect(updatedShippingOption).toEqual(
expect.objectContaining({
id: result[0].id,
name: updateData.name,
@@ -178,7 +207,7 @@ medusaIntegrationTestRunner({
})
)
expect(prices).toHaveLength(2)
expect(prices).toHaveLength(3)
expect(prices).toContainEqual(
expect.objectContaining({
currency_code: "usd",
@@ -188,8 +217,13 @@ medusaIntegrationTestRunner({
expect(prices).toContainEqual(
expect.objectContaining({
currency_code: "eur",
amount: 1000,
})
)
expect(prices).toContainEqual(
expect.objectContaining({
currency_code: "dkk",
amount: 100,
rules_count: 1,
})
)
})