Files
medusa-store/integration-tests/factories/simple-gift-card-factory.ts
mortenengel 11fb523051 feat(medusa, admin-ui): Improve gift card application (#4944)
Fix for the problems identified in issue #4892 

Bugfix: admin-ui order summary no longer uses gift card total from order when displaying how much has been withdrawn from each giftcard.

Bugfix(?): no longer keep applying gift cards (at 0 value) when sufficient balance has been reached

Feature: multiple giftcards are now applied in ordered fashion. First by end_date (supports null), then by remaining balance. In order to ensure that customers ends up with as long lasting and few remaining gift cards as possible after the transaction.
2023-09-07 16:56:36 +00:00

38 lines
789 B
TypeScript

import { GiftCard } from "@medusajs/medusa"
import faker from "faker"
import { DataSource } from "typeorm"
export type GiftCardFactoryData = {
id?: string
code?: string
region_id: string
value: number
balance: number
tax_rate?: number
ends_at?: Date
}
export const simpleGiftCardFactory = async (
dataSource: DataSource,
data: GiftCardFactoryData,
seed?: number
): Promise<GiftCard> => {
if (typeof seed !== "undefined") {
faker.seed(seed)
}
const manager = dataSource.manager
const toSave = manager.create(GiftCard, {
id: data.id,
code: data.code ?? "TESTGCCODE",
region_id: data.region_id,
value: data.value,
balance: data.balance,
tax_rate: data.tax_rate,
ends_at: data.ends_at
})
return await manager.save(toSave)
}