Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add-disabled-tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperkristensen authored Nov 25, 2024
2 parents 23d52ba + 1659c9b commit 0e119b8
Show file tree
Hide file tree
Showing 59 changed files with 2,181 additions and 660 deletions.
7 changes: 7 additions & 0 deletions .changeset/flat-mugs-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@medusajs/dashboard": patch
"@medusajs/product": patch
"@medusajs/types": patch
---

feat(dashboard): Allow re-ordering product images
5 changes: 5 additions & 0 deletions .changeset/spotty-eagles-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/admin-vite-plugin": patch
---

fix(admin-vite-plugin): Move @babel/types to dependencies from devDependencies to make it compatible with Yarn PnP
336 changes: 328 additions & 8 deletions integration-tests/http/__tests__/order/admin/transfer-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,54 @@ medusaIntegrationTestRunner({
expect(finalOrderResult.customer_id).toEqual(customer.id)
})

it("should cancel an order transfer request from admin successfully", async () => {
await api.post(
`/admin/orders/${order.id}/transfer`,
{
customer_id: customer.id,
},
adminHeaders
)

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

let orderPreviewResult = (
await api.get(`/admin/orders/${order.id}/preview`, adminHeaders)
).data.order

expect(orderPreviewResult).toEqual(
expect.objectContaining({
customer_id: customer.id,
order_change: expect.objectContaining({
change_type: "transfer",
status: "requested",
requested_by: user.id,
}),
})
)

await api.post(
`/admin/orders/${order.id}/transfer/cancel`,
{},
adminHeaders
)

orderPreviewResult = (
await api.get(`/admin/orders/${order.id}/preview`, adminHeaders)
).data.order

expect(orderPreviewResult.order_change).not.toBeDefined()

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

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

it("should fail to request order transfer to a guest customer", async () => {
const customer = (
await api.post(
Expand Down Expand Up @@ -238,13 +286,9 @@ medusaIntegrationTestRunner({
let storeHeaders
let signInToken

let orderModule

beforeEach(async () => {
const container = getContainer()

orderModule = await container.resolve(Modules.ORDER)

const publishableKey = await generatePublishableKey(container)
storeHeaders = generateStoreHeaders({ publishableKey })

Expand Down Expand Up @@ -301,10 +345,12 @@ medusaIntegrationTestRunner({
expect(storeOrder.email).toEqual("tony@stark-industries.com")
expect(storeOrder.customer_id).not.toEqual(customer.id)

const orderChanges = await orderModule.listOrderChanges(
{ order_id: order.id },
{ relations: ["actions"] }
)
const orderChanges = (
await api.get(
`/admin/orders/${order.id}/changes?fields=*actions`,
adminHeaders
)
).data.order_changes

expect(orderChanges.length).toEqual(1)
expect(orderChanges[0]).toEqual(
Expand Down Expand Up @@ -344,6 +390,280 @@ medusaIntegrationTestRunner({
// 4. Customer account is now associated with the order (email on the order is still as original, guest email)
expect(finalOrder.customer_id).toEqual(customer.id)
})

it("should cancel a customer transfer request as an admin", async () => {
await api.post(
`/store/orders/${order.id}/transfer/request`,
{},
{
headers: {
authorization: `Bearer ${signInToken}`,
...storeHeaders.headers,
},
}
)

let orderChanges = (
await api.get(
`/admin/orders/${order.id}/changes?fields=*actions`,
adminHeaders
)
).data.order_changes

expect(orderChanges.length).toEqual(1)
expect(orderChanges[0]).toEqual(
expect.objectContaining({
change_type: "transfer",
status: "requested",
requested_by: customer.id,
created_by: customer.id,
confirmed_by: null,
confirmed_at: null,
declined_by: null,
actions: expect.arrayContaining([
expect.objectContaining({
version: 2,
action: "TRANSFER_CUSTOMER",
reference: "customer",
reference_id: customer.id,
details: expect.objectContaining({
token: expect.any(String),
original_email: "tony@stark-industries.com",
}),
}),
]),
})
)

// Admin cancels the transfer request
await api.post(
`/admin/orders/${order.id}/transfer/cancel`,
{},
adminHeaders
)

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

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

it("customer should be able to cancel their own transfer request", async () => {
await api.post(
`/store/orders/${order.id}/transfer/request`,
{},
{
headers: {
authorization: `Bearer ${signInToken}`,
...storeHeaders.headers,
},
}
)

let orderChanges = (
await api.get(
`/admin/orders/${order.id}/changes?fields=*actions`,
adminHeaders
)
).data.order_changes

expect(orderChanges.length).toEqual(1)
expect(orderChanges[0]).toEqual(
expect.objectContaining({
change_type: "transfer",
status: "requested",
requested_by: customer.id,
created_by: customer.id,
confirmed_by: null,
confirmed_at: null,
declined_by: null,
actions: expect.arrayContaining([
expect.objectContaining({
version: 2,
action: "TRANSFER_CUSTOMER",
reference: "customer",
reference_id: customer.id,
details: expect.objectContaining({
token: expect.any(String),
original_email: "tony@stark-industries.com",
}),
}),
]),
})
)

await api.post(
`/store/orders/${order.id}/transfer/cancel`,
{},
{
headers: {
authorization: `Bearer ${signInToken}`,
...storeHeaders.headers,
},
}
)

orderChanges = (
await api.get(
`/admin/orders/${order.id}/changes?fields=*actions`,
adminHeaders
)
).data.order_changes

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

it("original customer should be able to decline a transfer request", async () => {
await api.post(
`/store/orders/${order.id}/transfer/request`,
{},
{
headers: {
authorization: `Bearer ${signInToken}`,
...storeHeaders.headers,
},
}
)

let orderChanges = (
await api.get(
`/admin/orders/${order.id}/changes?fields=*actions`,
adminHeaders
)
).data.order_changes

expect(orderChanges.length).toEqual(1)
expect(orderChanges[0]).toEqual(
expect.objectContaining({
change_type: "transfer",
status: "requested",
requested_by: customer.id,
created_by: customer.id,
confirmed_by: null,
confirmed_at: null,
declined_by: null,
actions: expect.arrayContaining([
expect.objectContaining({
version: 2,
action: "TRANSFER_CUSTOMER",
reference: "customer",
reference_id: customer.id,
details: expect.objectContaining({
token: expect.any(String),
original_email: "tony@stark-industries.com",
}),
}),
]),
})
)

await api.post(
`/store/orders/${order.id}/transfer/decline`,
{ token: orderChanges[0].actions[0].details.token },
{
headers: {
...storeHeaders.headers,
},
}
)

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

expect(orderChanges.length).toEqual(1)
expect(orderChanges[0]).toEqual(
expect.objectContaining({
change_type: "transfer",
status: "declined",
requested_by: customer.id,
created_by: customer.id,
declined_at: expect.any(String),
})
)
})

it("shound not decline a transfer request without proper token", async () => {
await api.post(
`/store/orders/${order.id}/transfer/request`,
{},
{
headers: {
authorization: `Bearer ${signInToken}`,
...storeHeaders.headers,
},
}
)

let orderChanges = (
await api.get(
`/admin/orders/${order.id}/changes?fields=*actions`,
adminHeaders
)
).data.order_changes

expect(orderChanges.length).toEqual(1)
expect(orderChanges[0]).toEqual(
expect.objectContaining({
change_type: "transfer",
status: "requested",
requested_by: customer.id,
created_by: customer.id,
confirmed_by: null,
confirmed_at: null,
declined_by: null,
actions: expect.arrayContaining([
expect.objectContaining({
version: 2,
action: "TRANSFER_CUSTOMER",
reference: "customer",
reference_id: customer.id,
details: expect.objectContaining({
token: expect.any(String),
original_email: "tony@stark-industries.com",
}),
}),
]),
})
)

const error = await api
.post(
`/store/orders/${order.id}/transfer/decline`,
{ token: "fake-token" },
{
headers: {
...storeHeaders.headers,
},
}
)
.catch((e) => e)

expect(error.response.status).toBe(400)
expect(error.response.data).toEqual(
expect.objectContaining({
type: "not_allowed",
message: "Invalid token.",
})
)

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

expect(orderChanges.length).toEqual(1)
expect(orderChanges[0]).toEqual(
expect.objectContaining({
change_type: "transfer",
status: "requested",
declined_at: null,
})
)
})
})
},
})
Loading

0 comments on commit 0e119b8

Please sign in to comment.