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:
Adrien de Peretti authored and GitHub committed 2023-07-20 13:16:04 +02:00
1 parent 26e2f81c24
commit 4d326fbbdf
197 files changed
+1073 -4332

No files matched your search

@@ -0,0 +1,35 @@
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)
}