Skip to content

Commit

Permalink
Merge branch 'develop' into fix/add-metadata-to-tax-calc
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Nov 19, 2024
2 parents bd84b75 + 39e81d8 commit 314fc80
Show file tree
Hide file tree
Showing 71 changed files with 4,210 additions and 113 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-parents-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/types": patch
"@medusajs/utils": patch
---

feat: add optional fields
5 changes: 5 additions & 0 deletions .changeset/curvy-spies-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/inventory": patch
---

Update reservation quantity
6 changes: 6 additions & 0 deletions .changeset/neat-geese-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"@medusajs/core-flows": patch
---

Refactor/finish rename order
6 changes: 6 additions & 0 deletions .changeset/selfish-poems-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/payment": patch
"@medusajs/payment-stripe": patch
---

fix(payment): Idempotent cancellation and proper creationg fail handling
9 changes: 9 additions & 0 deletions .changeset/wet-ears-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@medusajs/auth": patch
"@medusajs/fulfillment": patch
"@medusajs/locking": patch
"@medusajs/notification": patch
"@medusajs/payment": patch
---

chore(): Update module provider retrieval error message and type
233 changes: 233 additions & 0 deletions integration-tests/http/__tests__/order/admin/transfer-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
adminHeaders,
createAdminUser,
generatePublishableKey,
generateStoreHeaders,
} from "../../../../helpers/create-admin-user"
import { createOrderSeeder } from "../../fixtures/order"

jest.setTimeout(300000)

medusaIntegrationTestRunner({
testSuite: ({ dbConnection, getContainer, api }) => {
let order
let customer
let user
let storeHeaders

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

user = (await createAdminUser(dbConnection, adminHeaders, container)).user
const publishableKey = await generatePublishableKey(container)
storeHeaders = generateStoreHeaders({ publishableKey })

const seeders = await createOrderSeeder({ api, container })

const registeredCustomerToken = (
await api.post("/auth/customer/emailpass/register", {
email: "[email protected]",
password: "password",
})
).data.token

customer = (
await api.post(
"/store/customers",
{
email: "[email protected]",
},
{
headers: {
Authorization: `Bearer ${registeredCustomerToken}`,
...storeHeaders.headers,
},
}
)
).data.customer

order = seeders.order
})

describe("Transfer Order flow", () => {
it("should pass order transfer flow from admin successfully", async () => {
// 1. Admin requests order transfer for a customer with an account
await api.post(
`/admin/orders/${order.id}/transfer`,
{
customer_id: customer.id,
},
adminHeaders
)

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

// 2. Order still belongs to the guest customer since the transfer hasn't been accepted yet
expect(orderResult.email).toEqual("[email protected]")
expect(orderResult.customer_id).not.toEqual(customer.id)

const 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,
}),
})
)

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({
change_type: "transfer",
status: "requested",
requested_by: user.id,
created_by: user.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: "[email protected]",
}),
}),
]),
})
)

// 3. Guest customer who received the token accepts the transfer
await api.post(
`/store/orders/${order.id}/transfer/accept`,
{ token: orderChangesResult[0].actions[0].details.token },
{
headers: {
...storeHeaders.headers,
},
}
)

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

expect(finalOrderResult.email).toEqual("[email protected]")
// 4. Customer account is now associated with the order (email on the order is still as original, guest email)
expect(finalOrderResult.customer_id).toEqual(customer.id)
})

it("should fail to request order transfer to a guest customer", async () => {
const customer = (
await api.post(
"/admin/customers",
{
first_name: "guest",
email: "[email protected]",
},
adminHeaders
)
).data.customer

const err = await api
.post(
`/admin/orders/${order.id}/transfer`,
{
customer_id: customer.id,
},
adminHeaders
)
.catch((e) => e)

expect(err.response.status).toBe(400)
expect(err.response.data).toEqual(
expect.objectContaining({
type: "invalid_data",
message: `Cannot transfer order: ${order.id} to a guest customer account: [email protected]`,
})
)
})

it("should fail to accept order transfer with invalid token", async () => {
await api.post(
`/admin/orders/${order.id}/transfer`,
{
customer_id: customer.id,
},
adminHeaders
)

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({
change_type: "transfer",
status: "requested",
requested_by: user.id,
created_by: user.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: "[email protected]",
}),
}),
]),
})
)

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

expect(err.response.status).toBe(400)
expect(err.response.data).toEqual(
expect.objectContaining({
type: "not_allowed",
message: `Invalid token.`,
})
)
})
})
},
})
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, pl } from "date-fns/locale"
import { de, enUS, pl, tr } from "date-fns/locale"
import { Language } from "./types"

export const languages: Language[] = [
Expand All @@ -20,4 +20,10 @@ export const languages: Language[] = [
ltr: true,
date_locale: pl,
},
{
code: "tr",
display_name: "Türkçe",
ltr: true,
date_locale: tr,
},
]
4 changes: 4 additions & 0 deletions packages/admin/dashboard/src/i18n/translations/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import de from "./de.json"
import en from "./en.json"
import pl from "./pl.json"
import tr from "./tr.json"

export default {
en: {
Expand All @@ -12,4 +13,7 @@ export default {
pl: {
translation: pl,
},
tr: {
translation: tr,
},
}
Loading

0 comments on commit 314fc80

Please sign in to comment.