feat(MED-131): send fake test response for an order
This commit is contained in:
@@ -30,8 +30,8 @@ async function createProductCategories({
|
||||
}: {
|
||||
medusa: Medusa;
|
||||
}) {
|
||||
const existingProductCategories = await medusa.admin.productCategory.list();
|
||||
const parentCategory = existingProductCategories.product_categories.find(({ handle }) => handle === SYNLAB_SERVICES_CATEGORY_HANDLE);
|
||||
const { product_categories: existingProductCategories } = await medusa.admin.productCategory.list();
|
||||
const parentCategory = existingProductCategories.find(({ handle }) => handle === SYNLAB_SERVICES_CATEGORY_HANDLE);
|
||||
|
||||
if (!parentCategory) {
|
||||
throw new Error('Parent category not found');
|
||||
@@ -46,7 +46,7 @@ async function createProductCategories({
|
||||
for (const analysisGroup of analysisGroups) {
|
||||
console.info(`Processing analysis group '${analysisGroup.name}'`);
|
||||
|
||||
const isExisting = existingProductCategories.product_categories.find(({ name }) => name === analysisGroup.name);
|
||||
const isExisting = existingProductCategories.find(({ name }) => name === analysisGroup.name);
|
||||
const isNewlyCreated = createdCategories.find(({ name }) => name === analysisGroup.name);
|
||||
if (isExisting || isNewlyCreated) {
|
||||
console.info(`Analysis group '${analysisGroup.name}' already exists`);
|
||||
@@ -68,6 +68,28 @@ async function createProductCategories({
|
||||
}
|
||||
}
|
||||
|
||||
async function getChildProductCategories({
|
||||
medusa,
|
||||
}: {
|
||||
medusa: Medusa;
|
||||
}) {
|
||||
const { product_categories: allCategories } = await medusa.admin.productCategory.list();
|
||||
const childCategories = allCategories.filter(({ parent_category_id }) => parent_category_id !== null);
|
||||
return childCategories;
|
||||
}
|
||||
|
||||
async function deleteProductCategories({
|
||||
medusa,
|
||||
categories,
|
||||
}: {
|
||||
medusa: Medusa;
|
||||
categories: AdminProductCategory[];
|
||||
}) {
|
||||
for (const category of categories) {
|
||||
await medusa.admin.productCategory.delete(category.id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In case a reset is needed
|
||||
*/
|
||||
@@ -76,14 +98,12 @@ async function deleteProducts({
|
||||
}: {
|
||||
medusa: Medusa;
|
||||
}) {
|
||||
const { product_categories: allCategories } = await medusa.admin.productCategory.list();
|
||||
const { products: existingProducts } = await medusa.admin.product.list({
|
||||
category_id: allCategories.map(({ id }) => id),
|
||||
fields: 'id,collection_id',
|
||||
limit: 1000,
|
||||
});
|
||||
|
||||
for (const product of existingProducts) {
|
||||
await medusa.admin.product.delete(product.id);
|
||||
}
|
||||
await Promise.all(existingProducts.filter((a) => !a.collection_id).map(({ id }) => medusa.admin.product.delete(id)));
|
||||
}
|
||||
|
||||
async function getAnalysisPackagesType() {
|
||||
@@ -145,7 +165,7 @@ async function createProducts({
|
||||
medusa.admin.product.list({
|
||||
category_id: allCategories.map(({ id }) => id),
|
||||
}),
|
||||
getAnalysisElements(),
|
||||
getAnalysisElements({}),
|
||||
getAnalysisPackagesType(),
|
||||
getProductDefaultFields({ medusa }),
|
||||
])
|
||||
@@ -169,7 +189,7 @@ async function createProducts({
|
||||
continue;
|
||||
}
|
||||
|
||||
const createResponse = await medusa.admin.product.create({
|
||||
await medusa.admin.product.create({
|
||||
title: name,
|
||||
handle: `analysis-element-${analysisElement.id}`,
|
||||
categories: [{ id: category.id }],
|
||||
@@ -194,7 +214,6 @@ async function createProducts({
|
||||
],
|
||||
type_id: analysisPackagesType.id,
|
||||
});
|
||||
console.info(`Successfully created product, id=${createResponse.product.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +223,8 @@ export default async function syncAnalysisGroupsStore() {
|
||||
try {
|
||||
await createProductCategories({ medusa });
|
||||
|
||||
// const categories = await getChildProductCategories({ medusa });
|
||||
// await deleteProductCategories({ medusa, categories });
|
||||
// await deleteProducts({ medusa });
|
||||
// return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user