-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/add-metadata-to-tax-calc
- Loading branch information
Showing
71 changed files
with
4,210 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@medusajs/types": patch | ||
"@medusajs/utils": patch | ||
--- | ||
|
||
feat: add optional fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@medusajs/inventory": patch | ||
--- | ||
|
||
Update reservation quantity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
233
integration-tests/http/__tests__/order/admin/transfer-flow.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.`, | ||
}) | ||
) | ||
}) | ||
}) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.