Files
medusa-store/integration-tests/api/helpers/product-seeder.js
2021-02-12 08:42:19 +01:00

69 lines
1.5 KiB
JavaScript

const {
ProductCollection,
ProductTag,
ProductType,
Region,
Product,
ShippingProfile,
ProductVariant,
} = require("@medusajs/medusa");
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
});
const coll = manager.create(ProductCollection, {
id: "test-collection",
title: "Test collection",
});
await manager.save(coll);
const tag = manager.create(ProductTag, {
id: "tag1",
value: "123",
});
await manager.save(tag);
const type = manager.create(ProductType, {
id: "test-type",
value: "test-type",
});
await manager.save(type);
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
});
await manager.insert(Product, {
id: "test-product",
title: "Test product",
profile_id: defaultProfile.id,
description: "test-product-description",
collection_id: "test-collection",
type: { id: "test-type", value: "test-type" },
tags: [
{ id: "tag1", value: "123" },
{ tag: "tag2", value: "456" },
],
options: [{ id: "test-option", title: "Default value" }],
});
await manager.insert(ProductVariant, {
id: "test-variant",
inventory_quantity: 10,
title: "Test variant",
product_id: "test-product",
prices: [{ id: "test-price", currency_code: "usd", amount: 100 }],
options: [{ id: "test-variant-option", value: "Default variant" }],
});
};