Skip to content

Commit

Permalink
Merge branch 'v0.61.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	examples/minimal/.meteor/versions
#	packages/core-products/.versions
#	packages/core-products/package.js
#	packages/platform/.versions
#	packages/platform/package.js
  • Loading branch information
pozylon committed May 25, 2021
2 parents f4555ec + 98bb308 commit 17efe3d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
8 changes: 8 additions & 0 deletions packages/core-products/db/products/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ Products.createProduct = (
{ locale, title, type, sequence, authorId, ...productData },
{ autopublish = false } = {}
) => {
if (productData._id) {
// Remove deleted product by _id before creating a new one.
Products.permanentlyRemoveDeletedProduct({ productId: productData._id });
}
const productId = Products.insert({
created: new Date(),
type: ProductTypes[type],
Expand Down Expand Up @@ -268,6 +272,10 @@ Products.removeBundleItem = ({ productId, index }) => {
return result;
};

Products.permanentlyRemoveDeletedProduct = ({ productId }) => {
Products.remove({ status: ProductStatus.DELETED, _id: productId });
};

Products.removeProduct = ({ productId }) => {
const product = Products.findOne({ _id: productId });
switch (product.status) {
Expand Down
12 changes: 2 additions & 10 deletions packages/platform/bulk-importer/handlers/product/remove.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { ProductStatus, Products } from 'meteor/unchained:core-products';
import { Products } from 'meteor/unchained:core-products';

export default async function removeProduct(payload, { logger }) {
const { _id } = payload;
logger.debug('remove product');
Products.update(
{ _id },
{
$set: {
status: ProductStatus.DELETED,
updated: new Date(),
},
}
);
Products.removeProduct({ productId: _id });
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { ProductMedia, Media } from 'meteor/unchained:core-products';

const upsertAsset = async (asset) => {
const { _id, ...assetData } = asset;

try {
const assetObject = await Media.insertWithRemoteURL(asset);
const assetObject = await Media.insertWithRemoteURL({
fileId: _id,
...assetData,
});
if (!assetObject) throw new Error('Media not created');
return assetObject;
} catch (e) {
const { _id, ...assetData } = asset;
Media.update({ _id }, { $set: assetData });
return Media.findOne({ _id });
}
Expand Down
51 changes: 48 additions & 3 deletions tests/bulk-importer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Bulk Importer', () => {
});

describe('Import Products', () => {
it('adds 1 Product CREATE event and 1 UPDATE event', async () => {
it('adds 1 Product CREATE event and 1 UPDATE event, followed by DELETE & CREATE again', async () => {
const { data: { addWork } = {} } = await graphqlFetch({
query: /* GraphQL */ `
mutation addWork($input: JSON) {
Expand Down Expand Up @@ -179,6 +179,51 @@ describe('Bulk Importer', () => {
],
},
},
{
entity: 'PRODUCT',
operation: 'REMOVE',
payload: {
_id: 'A',
},
},
{
entity: 'PRODUCT',
operation: 'CREATE',
payload: {
_id: 'A',
specification: {
tags: ['awesome2'],
type: 'SimpleProduct',
published: '2020-01-01T00:00Z',
commerce: {
salesUnit: 'ST',
salesQuantityPerUnit: '1',
defaultOrderQuantity: '6',
pricing: [
{
isTaxable: true,
isNetPrice: true,
countryCode: 'CH',
currencyCode: 'CHF',
amount: 10000,
},
],
},
meta: {},
content: {
de: {
vendor: 'Herstellername',
brand: 'Marke',
title: 'Produktname',
slug: 'produktname',
subtitle: 'Short description',
description: 'Long description',
labels: ['Neu'],
},
},
},
},
},
],
},
},
Expand All @@ -188,8 +233,8 @@ describe('Bulk Importer', () => {
const Products = db.collection('products');

const result = await intervalUntilTimeout(async () => {
const product = await Products.findOne({ _id: 'A' });
return product?.tags.includes('awesome');
const product = await Products.findOne({ tags: 'awesome2' });
return !!product;
}, 3000);

expect(result).toBe(true);
Expand Down

0 comments on commit 17efe3d

Please sign in to comment.