feat(medusa): Claim customer orders (#2710)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
const jwt = require("jsonwebtoken")
|
||||
const path = require("path")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
|
||||
@@ -27,7 +27,7 @@ describe("[MEDUSA_FF_ORDER_EDITING] /admin/payment-collections", () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
const [process, connection] = await startServerWithEnvironment({
|
||||
cwd,
|
||||
env: { MEDUSA_FF_ORDER_EDITING: true }
|
||||
env: { MEDUSA_FF_ORDER_EDITING: true },
|
||||
})
|
||||
dbConnection = connection
|
||||
medusaProcess = process
|
||||
|
||||
@@ -1799,6 +1799,56 @@ describe("/store/carts", () => {
|
||||
expect(res.data.cart.payment_authorized_at).not.toBe(null)
|
||||
expect(res.data.cart.completed_at).not.toBe(null)
|
||||
})
|
||||
|
||||
it("completes cart with a non-customer and for a customer with the same email created later the order doesn't show up", async () => {
|
||||
const api = useApi()
|
||||
const customerEmail = "test-email-for-non-existent-customer@test.com"
|
||||
const product = await simpleProductFactory(dbConnection)
|
||||
|
||||
const region = await simpleRegionFactory(dbConnection, { tax_rate: 10 })
|
||||
|
||||
const cart = await simpleCartFactory(dbConnection, {
|
||||
customer: {
|
||||
email: customerEmail,
|
||||
has_account: false,
|
||||
},
|
||||
region: region.id,
|
||||
line_items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
unit_price: 1000,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
await api.post(`/store/carts/${cart.id}/payment-sessions`)
|
||||
|
||||
const completeRes = await api.post(`/store/carts/${cart.id}/complete`)
|
||||
|
||||
expect(completeRes.status).toEqual(200)
|
||||
|
||||
const customerResponse = await api.post("/store/customers", {
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
email: customerEmail,
|
||||
password: "test",
|
||||
})
|
||||
|
||||
const [authCookie] = customerResponse.headers["set-cookie"][0].split(";")
|
||||
|
||||
const customerOrdersResponse = await api
|
||||
.get("/store/customers/me/orders?status[]=completed", {
|
||||
headers: {
|
||||
Cookie: authCookie,
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
expect(customerOrdersResponse.status).toEqual(200)
|
||||
expect(customerOrdersResponse.data.orders.length).toEqual(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id/shipping-methods", () => {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
const jwt = require("jsonwebtoken")
|
||||
const path = require("path")
|
||||
const { Address, Customer, Order, Region } = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
const { simpleOrderFactory } = require("../../factories")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -28,6 +30,78 @@ describe("/store/customers", () => {
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("POST /store/customers/confirm-claim", () => {
|
||||
let orderId
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager
|
||||
await manager.insert(Customer, {
|
||||
id: "test_customer",
|
||||
first_name: "John",
|
||||
last_name: "Deere",
|
||||
email: "john@deere.com",
|
||||
password_hash:
|
||||
"c2NyeXB0AAEAAAABAAAAAVMdaddoGjwU1TafDLLlBKnOTQga7P2dbrfgf3fB+rCD/cJOMuGzAvRdKutbYkVpuJWTU39P7OpuWNkUVoEETOVLMJafbI8qs8Qx/7jMQXkN", // password matching "test"
|
||||
has_account: true,
|
||||
})
|
||||
|
||||
await manager.insert(Customer, {
|
||||
id: "test_customer-1",
|
||||
first_name: "John",
|
||||
last_name: "Deere",
|
||||
email: "john@deere.com",
|
||||
})
|
||||
|
||||
const order = await simpleOrderFactory(dbConnection, {
|
||||
customer: {
|
||||
id: "test_customer-1",
|
||||
},
|
||||
})
|
||||
orderId = order.id
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await doAfterEach()
|
||||
})
|
||||
|
||||
it("Successfully confirms a claim ", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const token = jwt.sign(
|
||||
{
|
||||
claimingCustomerId: "test_customer",
|
||||
orders: [orderId],
|
||||
},
|
||||
"test"
|
||||
)
|
||||
|
||||
const authResponse = await api.post("/store/auth", {
|
||||
email: "john@deere.com",
|
||||
password: "test",
|
||||
})
|
||||
|
||||
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
|
||||
|
||||
const authHeader = {
|
||||
headers: {
|
||||
Cookie: authCookie,
|
||||
},
|
||||
}
|
||||
|
||||
const ordersRes1 = await api.get(`/store/customers/me/orders`, authHeader)
|
||||
|
||||
expect(ordersRes1.data.orders.length).toEqual(0)
|
||||
|
||||
const response = await api.post("/store/orders/customer/confirm", {
|
||||
token,
|
||||
})
|
||||
expect(response.status).toBe(200)
|
||||
|
||||
const ordersRes2 = await api.get(`/store/customers/me/orders`, authHeader)
|
||||
|
||||
expect(ordersRes2.data.orders.length).toEqual(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /store/customers", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager
|
||||
|
||||
Reference in New Issue
Block a user