Files
medusa-store/integration-tests/factories/simple-payment-factory.ts
Adrien de Peretti 4d326fbbdf 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
2023-07-20 13:16:04 +02:00

44 lines
999 B
TypeScript

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