feat(medusa): Claim customer orders (#2710)

This commit is contained in:
Philip Korsholm
2022-12-08 17:48:49 +01:00
committed by GitHub
parent 86f9455d00
commit a6243618fe
36 changed files with 872 additions and 107 deletions
@@ -1,9 +1,9 @@
import { Customer } from "@medusajs/medusa"
import faker from "faker"
import { Customer } from "@medusajs/medusa"
import { Connection } from "typeorm"
import {
CustomerGroupFactoryData,
simpleCustomerGroupFactory
simpleCustomerGroupFactory,
} from "./simple-customer-group-factory"
export type CustomerFactoryData = {
@@ -28,7 +28,7 @@ export const simpleCustomerFactory = async (
const customerId = data.id || `simple-customer-${Math.random() * 1000}`
const c = manager.create(Customer, {
id: customerId,
email: data.email,
email: data.email ?? faker.internet.email(),
password_hash:
data.password_hash ??
"c2NyeXB0AAEAAAABAAAAAVMdaddoGjwU1TafDLLlBKnOTQga7P2dbrfgf3fB+rCD/cJOMuGzAvRdKutbYkVpuJWTU39P7OpuWNkUVoEETOVLMJafbI8qs8Qx/7jMQXkN", // password matching "test"
@@ -27,6 +27,10 @@ import {
SalesChannelFactoryData,
simpleSalesChannelFactory,
} from "./simple-sales-channel-factory"
import {
CustomerFactoryData,
simpleCustomerFactory,
} from "./simple-customer-factory"
export type OrderFactoryData = {
id?: string
@@ -34,6 +38,7 @@ export type OrderFactoryData = {
fulfillment_status?: FulfillmentStatus
region?: RegionFactoryData | string
email?: string | null
customer?: CustomerFactoryData | null
currency_code?: string
tax_rate?: number | null
line_items?: LineItemFactoryData[]
@@ -70,11 +75,10 @@ export const simpleOrderFactory = async (
}
const address = await simpleAddressFactory(connection, data.shipping_address)
const customerToSave = manager.create(Customer, {
email:
typeof data.email !== "undefined" ? data.email : faker.internet.email(),
const customer = await simpleCustomerFactory(connection, {
...data.customer,
email: data.email ?? undefined,
})
const customer = await manager.save(customerToSave)
let discounts = []
if (typeof data.discounts !== "undefined") {