Skip to content

Commit

Permalink
Merge branch 'develop' into feat/cart-dml
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage authored Dec 3, 2024
2 parents ed93ffa + e8f4f7e commit 833c775
Show file tree
Hide file tree
Showing 37 changed files with 3,768 additions and 136 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-news-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---

fix(dashboard): Fix broken number input in adjust inventory form
5 changes: 5 additions & 0 deletions .changeset/five-crews-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---

fix(dashboard): Add default value to inventory item combobox
8 changes: 8 additions & 0 deletions integration-tests/http/__tests__/fixtures/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ export async function createOrderSeeder({
province: "ny",
postal_code: "94016",
},
billing_address: {
address_1: "test billing address 1",
address_2: "test billing address 2",
city: "ny",
country_code: "us",
province: "ny",
postal_code: "94016",
},
sales_channel_id: salesChannel.id,
items: [
{ quantity: 1, variant_id: product.variants[0].id },
Expand Down
276 changes: 276 additions & 0 deletions integration-tests/http/__tests__/order/admin/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,282 @@ medusaIntegrationTestRunner({
await createAdminUser(dbConnection, adminHeaders, container)
})

describe("POST /orders/:id", () => {
beforeEach(async () => {
seeder = await createOrderSeeder({
api,
container: getContainer(),
})
order = seeder.order

order = (
await api.get(`/admin/orders/${order.id}?fields=+email`, adminHeaders)
).data.order
})

it("should update shipping address on an order (by creating a new Address record)", async () => {
const addressBefore = order.shipping_address

const response = await api.post(
`/admin/orders/${order.id}`,
{
shipping_address: {
city: "New New York",
address_1: "New Main street 123",
},
},
adminHeaders
)

expect(response.data.order.shipping_address.id).not.toEqual(
addressBefore.id
) // new addres created
expect(response.data.order.shipping_address).toEqual(
expect.objectContaining({
customer_id: addressBefore.customer_id,
company: addressBefore.company,
first_name: addressBefore.first_name,
last_name: addressBefore.last_name,
address_1: "New Main street 123",
address_2: addressBefore.address_2,
city: "New New York",
country_code: addressBefore.country_code,
province: addressBefore.province,
postal_code: addressBefore.postal_code,
phone: addressBefore.phone,
})
)

const orderChangesResult = (
await api.get(`/admin/orders/${order.id}/changes`, adminHeaders)
).data.order_changes

expect(orderChangesResult.length).toEqual(1)
expect(orderChangesResult[0]).toEqual(
expect.objectContaining({
version: 1,
change_type: "update_order",
status: "confirmed",
confirmed_at: expect.any(String),
actions: expect.arrayContaining([
expect.objectContaining({
version: 1,
applied: true,
reference_id: addressBefore.id,
reference: "shipping_address",
action: "UPDATE_ORDER_PROPERTIES",
details: {
city: "New New York",
address_1: "New Main street 123",
},
}),
]),
})
)
})

it("should fail to update shipping address if country code has been changed", async () => {
const response = await api
.post(
`/admin/orders/${order.id}`,
{
shipping_address: {
country_code: "HR",
},
},
adminHeaders
)
.catch((e) => e)

expect(response.response.status).toBe(400)
expect(response.response.data.message).toBe(
"Country code cannot be changed"
)

const orderChangesResult = (
await api.get(`/admin/orders/${order.id}/changes`, adminHeaders)
).data.order_changes

expect(orderChangesResult.length).toEqual(0)
})

it("should update billing address on an order (by creating a new Address record)", async () => {
const addressBefore = order.billing_address

const response = await api.post(
`/admin/orders/${order.id}`,
{
billing_address: {
city: "New New York",
address_1: "New Main street 123",
},
},
adminHeaders
)

expect(response.data.order.billing_address.id).not.toEqual(
addressBefore.id
) // new addres created
expect(response.data.order.billing_address).toEqual(
expect.objectContaining({
customer_id: addressBefore.customer_id,
company: addressBefore.company,
first_name: addressBefore.first_name,
last_name: addressBefore.last_name,
address_1: "New Main street 123",
address_2: addressBefore.address_2,
city: "New New York",
country_code: addressBefore.country_code,
province: addressBefore.province,
postal_code: addressBefore.postal_code,
phone: addressBefore.phone,
})
)

const orderChangesResult = (
await api.get(`/admin/orders/${order.id}/changes`, adminHeaders)
).data.order_changes

expect(orderChangesResult.length).toEqual(1)
expect(orderChangesResult[0]).toEqual(
expect.objectContaining({
version: 1,
change_type: "update_order",
status: "confirmed",
confirmed_at: expect.any(String),
actions: expect.arrayContaining([
expect.objectContaining({
version: 1,
applied: true,
reference_id: addressBefore.id,
reference: "billing_address",
action: "UPDATE_ORDER_PROPERTIES",
details: {
city: "New New York",
address_1: "New Main street 123",
},
}),
]),
})
)
})

it("should fail to update billing address if country code has been changed", async () => {
const response = await api
.post(
`/admin/orders/${order.id}`,
{
billing_address: {
country_code: "HR",
},
},
adminHeaders
)
.catch((e) => e)

expect(response.response.status).toBe(400)
expect(response.response.data.message).toBe(
"Country code cannot be changed"
)

const orderChangesResult = (
await api.get(`/admin/orders/${order.id}/changes`, adminHeaders)
).data.order_changes

expect(orderChangesResult.length).toEqual(0)
})

it("should update orders email and shipping address and create 2 change records", async () => {
const response = await api.post(
`/admin/orders/${order.id}?fields=+email,*shipping_address`,
{
email: "new-email@example.com",
shipping_address: {
address_1: "New Main street 123",
},
},
adminHeaders
)

expect(response.data.order.email).toBe("new-email@example.com")
expect(response.data.order.shipping_address.id).not.toEqual(
order.shipping_address.id
)
expect(response.data.order.shipping_address).toEqual(
expect.objectContaining({
address_1: "New Main street 123",
})
)

const orderChangesResult = (
await api.get(`/admin/orders/${order.id}/changes`, adminHeaders)
).data.order_changes

expect(orderChangesResult.length).toEqual(2)
expect(orderChangesResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
version: 1,
change_type: "update_order",
status: "confirmed",
confirmed_at: expect.any(String),
actions: expect.arrayContaining([
expect.objectContaining({
version: 1,
applied: true,
reference_id: order.shipping_address.id,
reference: "shipping_address",
action: "UPDATE_ORDER_PROPERTIES",
details: {
address_1: "New Main street 123",
},
}),
]),
}),
expect.objectContaining({
version: 1,
change_type: "update_order",
status: "confirmed",
confirmed_at: expect.any(String),
actions: expect.arrayContaining([
expect.objectContaining({
version: 1,
applied: true,
reference_id: order.email,
reference: "email",
action: "UPDATE_ORDER_PROPERTIES",
details: {
email: "new-email@example.com",
},
}),
]),
}),
])
)
})

it("should fail to update email if it is invalid", async () => {
const response = await api
.post(
`/admin/orders/${order.id}`,
{
email: "invalid-email",
},
adminHeaders
)
.catch((e) => e)

expect(response.response.status).toBe(400)
expect(response.response.data.message).toBe("The email is not valid")

const orderChangesResult = (
await api.get(`/admin/orders/${order.id}/changes`, adminHeaders)
).data.order_changes

expect(orderChangesResult.length).toEqual(0)
})
})

describe("POST /orders/:id/fulfillments", () => {
beforeEach(async () => {
const stockChannelOverride = (
Expand Down
11 changes: 7 additions & 4 deletions packages/admin/dashboard/src/hooks/api/products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,15 @@ export const useUpdateProductVariantsBatch = (

export const useProductVariantsInventoryItemsBatch = (
productId: string,
options?: UseMutationOptions<any, FetchError, any>
options?: UseMutationOptions<
HttpTypes.AdminBatchProductVariantInventoryItemResponse,
FetchError,
HttpTypes.AdminBatchProductVariantInventoryItemRequest
>
) => {
return useMutation({
mutationFn: (
payload: HttpTypes.AdminBatchProductVariantInventoryItemRequest
) => sdk.admin.product.batchVariantInventoryItems(productId, payload),
mutationFn: (payload) =>
sdk.admin.product.batchVariantInventoryItems(productId, payload),
onSuccess: (data: any, variables: any, context: any) => {
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() })
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.details() })
Expand Down
1 change: 1 addition & 0 deletions packages/admin/dashboard/src/hooks/use-combobox-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const useComboboxData = <
enabled: !!defaultValue,
})


const { data, ...rest } = useInfiniteQuery({
queryKey: [...queryKey, query],
queryFn: async ({ pageParam = 0 }) => {
Expand Down
8 changes: 7 additions & 1 deletion packages/admin/dashboard/src/i18n/languages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { de, enUS, es, fr, pl, ptBR, th, tr } from "date-fns/locale"
import { de, enUS, es, fr, it, pl, ptBR, th, tr } from "date-fns/locale"
import { Language } from "./types"

export const languages: Language[] = [
Expand Down Expand Up @@ -26,6 +26,12 @@ export const languages: Language[] = [
ltr: true,
date_locale: fr,
},
{
code: "it",
display_name: "Italiano",
ltr: true,
date_locale: it,
},
{
code: "pl",
display_name: "Polski",
Expand Down
22 changes: 22 additions & 0 deletions packages/admin/dashboard/src/i18n/translations/$schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,27 @@
],
"additionalProperties": false
},
"adjustInventory": {
"type": "object",
"properties": {
"errors": {
"type": "object",
"properties": {
"stockedQuantity": {
"type": "string"
}
},
"required": [
"stockedQuantity"
],
"additionalProperties": false
}
},
"required": [
"errors"
],
"additionalProperties": false
},
"toast": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3300,6 +3321,7 @@
"editItemDetails",
"create",
"reservation",
"adjustInventory",
"toast"
],
"additionalProperties": false
Expand Down
Loading

0 comments on commit 833c775

Please sign in to comment.