chore: Move factories and helpers to a better place (#4551)
* chore: Move factories and helpers to a better place * align factory product variant * fix factory cart * add simple store fac * fix tests * fix tests * fix * fix cart seeder
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { DataSource } from "typeorm"
|
||||
import { Payment } from "@medusajs/medusa"
|
||||
|
||||
export type PaymentFactoryData = {
|
||||
provider_id?: string
|
||||
order?: string
|
||||
cart?: string
|
||||
data?: any
|
||||
amount?: number
|
||||
currency_code?: string
|
||||
captured?: Date | boolean
|
||||
}
|
||||
|
||||
export const simplePaymentFactory = async (
|
||||
dataSource: DataSource,
|
||||
data: PaymentFactoryData,
|
||||
_?: number
|
||||
): Promise<Payment> => {
|
||||
const manager = dataSource.manager
|
||||
|
||||
let captured_at = data.captured
|
||||
if (typeof captured_at === "boolean") {
|
||||
if (captured_at) {
|
||||
captured_at = new Date()
|
||||
} else {
|
||||
captured_at = null
|
||||
}
|
||||
} else if (typeof captured_at === "undefined") {
|
||||
captured_at = null
|
||||
}
|
||||
|
||||
const address = manager.create(Payment, {
|
||||
provider_id: data.provider_id ?? "test-pay",
|
||||
order_id: data.order,
|
||||
cart_id: data.cart,
|
||||
data: data.data ?? {},
|
||||
amount: data.amount ?? 1000,
|
||||
currency_code: data.currency_code ?? "usd",
|
||||
captured_at,
|
||||
})
|
||||
|
||||
return await manager.save(address)
|
||||
}
|
||||
Reference in New Issue
Block a user