Skip to content

Commit

Permalink
Merge pull request #20 from shopware/fix-digital-product-fixture
Browse files Browse the repository at this point in the history
fix: Refactor digital product and order fixture
  • Loading branch information
Phil23 authored Jun 3, 2024
2 parents 31c3f4c + c277755 commit 4b53a77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/data-fixtures/Order/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ export const OrderData = base.extend<FixtureTypes>({

// Delete order after the test is done
const cleanupResponse = await AdminApiContext.delete(`./order/${order.id}`);
expect(cleanupResponse.ok()).toBeTruthy();
expect(cleanupResponse.status()).toBeLessThan(500);
},
});
70 changes: 9 additions & 61 deletions src/data-fixtures/Product/DigitalProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,7 @@ import type { FixtureTypes } from '../../types/FixtureTypes';
import type { components } from '@shopware/api-client/admin-api-types';

export const DigitalProductData = base.extend<FixtureTypes>({
DigitalProductData: async ({ IdProvider, AdminApiContext, SalesChannelBaseConfig, DefaultSalesChannel }, use) => {

// Generate unique IDs
const { id: productId, uuid: productUuid } = IdProvider.getIdPair();
const productName = `Digital_Product_test_${productId}`;

// Create product
const productResponse = await AdminApiContext.post('./product?_response', {
data: {
active: true,
stock: 10,
taxId: SalesChannelBaseConfig.taxId,
id: productUuid,
name: productName,
productNumber: 'Product-' + productId,
price: [
{
currencyId: SalesChannelBaseConfig.eurCurrencyId,
gross: 10,
linked: false,
net: 8.4,
},
],
purchasePrices: [
{
currencyId: SalesChannelBaseConfig.eurCurrencyId,
gross: 8,
linked: false,
net: 6.7,
},
],
visibilities: [
{
salesChannelId: DefaultSalesChannel.salesChannel.id,
visibility: 30,
},
],
categories: [
{
id: DefaultSalesChannel.salesChannel.navigationCategoryId,
},
],
},
});
expect(productResponse.ok()).toBeTruthy();

const { data: productData } = (await productResponse.json()) as { data: components['schemas']['Product'] };
DigitalProductData: async ({ ProductData, IdProvider, AdminApiContext }, use) => {

// Create new Media resource in the default folder for digital product media
const newMediaResource = await AdminApiContext.post('./media?_response', {
Expand All @@ -75,7 +29,7 @@ export const DigitalProductData = base.extend<FixtureTypes>({

const productDownloadResponse = await AdminApiContext.post(`./product-download?_response`, {
data: {
productId: productData.id,
productId: ProductData.id,
mediaId: newMediaId,
},
});
Expand All @@ -84,7 +38,7 @@ export const DigitalProductData = base.extend<FixtureTypes>({
const { data: productDownload } = await productDownloadResponse.json();

const returnData = {
product: productData,
product: ProductData,
fileContent,
}

Expand All @@ -95,13 +49,11 @@ export const DigitalProductData = base.extend<FixtureTypes>({
const orderSearchResponse = await AdminApiContext.post('./search/order', {
data: {
limit: 10,
filter: [
{
type: 'equals',
field: 'lineItems.productId',
value: productData.id,
},
],
filter: [{
type: 'equals',
field: 'lineItems.productId',
value: ProductData.id,
}],
},
});
expect(orderSearchResponse.ok()).toBeTruthy();
Expand All @@ -111,7 +63,7 @@ export const DigitalProductData = base.extend<FixtureTypes>({
// Delete Orders using the digital product, to be able to delete the uploaded media file
for (const order of ordersWithDigitalProduct) {
const deleteOrderResponse = await AdminApiContext.delete(`./order/${order.id}`);
expect(deleteOrderResponse.ok()).toBeTruthy();
expect(deleteOrderResponse.status()).toBeLessThan(500);
}

// Unlink the media file from the product by deleting the product-download
Expand All @@ -121,9 +73,5 @@ export const DigitalProductData = base.extend<FixtureTypes>({
// Delete media after the test is done
const cleanupMediaResponse = await AdminApiContext.delete(`./media/${newMediaId}`);
expect(cleanupMediaResponse.ok()).toBeTruthy();

// Delete product after the test is done
const cleanupResponse = await AdminApiContext.delete(`./product/${productUuid}`);
expect(cleanupResponse.ok()).toBeTruthy();
},
});

0 comments on commit 4b53a77

Please sign in to comment.