Files
medusa-store/integration-tests/factories/simple-shipping-profile-factory.ts
T
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

36 lines
928 B
TypeScript

import { ShippingProfile, ShippingProfileType } from "@medusajs/medusa"
import faker from "faker"
import { Connection } from "typeorm"
export type ShippingProfileFactoryData = {
id?: string
name?: string
type?: ShippingProfileType
metadata?: Record<string, unknown>
}
export const simpleShippingProfileFactory = async (
connection: Connection,
data: ShippingOptionFactoryData = {},
seed?: number
): Promise<ShippingProfile> => {
if (typeof seed !== "undefined") {
faker.seed(seed)
}
const manager = connection.manager
const shippingProfileData = {
id: data.id ?? `simple-sp-${Math.random() * 1000}`,
name: data.name || `sp-${Math.random() * 1000}`,
type: data.type || ShippingProfileType.DEFAULT,
metadata: data.metadata,
products: [],
shipping_options: [],
}
const created = manager.create(ShippingProfile, shippingProfileData)
return await manager.save(created)
}