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:
1 parent
26e2f81c24
commit
4d326fbbdf
197 files changed
+1073
-4332
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { SalesChannel, Store } from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { DataSource, IsNull, Not } from "typeorm"
|
||||
|
||||
export type StoreFactoryData = {
|
||||
swap_link_template?: string
|
||||
}
|
||||
|
||||
export const simpleStoreFactory = async (
|
||||
dataSource: DataSource,
|
||||
data: StoreFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<Store | undefined> => {
|
||||
if (typeof seed !== "undefined") {
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = dataSource.manager
|
||||
const stores = await manager.find(Store, { where: { id: Not(IsNull()) } })
|
||||
const store = stores[0]
|
||||
|
||||
if (!store) {
|
||||
return
|
||||
}
|
||||
|
||||
store.swap_link_template = data.swap_link_template ?? "something/{cart_id}"
|
||||
|
||||
await manager.insert(SalesChannel, {
|
||||
id: "test-channel",
|
||||
name: "Default",
|
||||
})
|
||||
|
||||
const storeToSave = await manager.save(store)
|
||||
|
||||
await manager.query(
|
||||
`update store set default_sales_channel_id = 'test-channel' where id = '${
|
||||
storeToSave!.id
|
||||
}'`
|
||||
)
|
||||
|
||||
return storeToSave!
|
||||
}
|
||||
Reference in new issue
Block a user