Skip to content

Commit

Permalink
fix(taxes): side effect adds all taxes to first product
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Oct 8, 2024
1 parent e8698b4 commit 22550c9
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ import { Subject } from '@restorecommerce/rc-grpc-clients/dist/generated-server/
export type BigVAT = {
tax_id: string;
vat: BigNumber;
}
};

export type BigAmount = {
currency_id: string;
Expand Down Expand Up @@ -1439,7 +1439,7 @@ export class OrderingService
currency_id: item.amount.currency_id,
gross: new BigNumber(item.amount.gross!),
net: new BigNumber(item.amount.net!),
vats: item.amount.vats,
vats: [...item.amount.vats],
};
}
return amounts;
Expand All @@ -1463,7 +1463,7 @@ export class OrderingService
vats[vat.tax_id!].vat = vats[vat.tax_id!]?.vat.plus(vat.vat) ?? new BigNumber(vat.vat);
}
else {
vats[vat.tax_id!] = {
vats[vat.tax_id!] = {
tax_id: vat.tax_id,
vat: new BigNumber(vat.vat)
};
Expand Down
103 changes: 100 additions & 3 deletions test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const countries: CountryResponse[] = [{
countryCode: 'DE',
name: 'Deutschland',
geographicalName: 'Germany',
economicAreas: [],
economicAreas: ['EU'],
},
status: {
id: 'germany',
Expand All @@ -172,7 +172,7 @@ const taxes: TaxResponse[] = [
countryId: 'germany',
rate: 0.19,
typeId: 'taxType_1',
variant: 'MwSt.'
abbreviation: 'MwSt.',
},
status: {
id: 'tax_1',
Expand Down Expand Up @@ -265,6 +265,88 @@ const products: ProductResponse[] = [
message: 'OK',
}
},
{
payload: {
id: 'physicalProduct_2',
active: true,
shopId: 'shop_1',
tags: [],
associations: [],
product: {
name: 'Physical Product 2',
description: 'This is a physical product',
manufacturerId: 'manufacturer_1',
taxIds: [
taxes[0].payload?.id as string,
],
physical: {
variants: [
{
id: '1',
name: 'Physical Product 1 Blue',
description: 'This is a physical product in blue',
price: {
currencyId: 'currency_1',
regularPrice: 19.99,
salePrice: 18.99,
sale: false,
},
images: [],
files: [],
stockKeepingUnit: '123456789',
stockLevel: 300,
package: {
sizeInCm: {
height: 10,
length: 20,
width: 15,
},
weightInKg: 0.58,
rotatable: true,
},
properties: [
{
id: 'urn:product:property:color:main:name',
value: 'blue',
unitCode: 'text',
},
{
id: 'urn:product:property:color:main:value',
value: '#0000FF',
unitCode: '#RGB',
}
],
},
{
id: '2',
name: 'Physical Product 1 Red',
description: 'This is a physical product in red',
images: [],
files: [],
properties: [
{
id: 'urn:product:property:color:main:name',
value: 'red',
unitCode: 'text',
},
{
id: 'urn:product:property:color:main:value',
value: '#FF0000',
unitCode: '#RGB',
}
],
parentVariantId: '1',
}
]
}
},
},
status: {
id: 'physicalProduct_2',
code: 200,
message: 'OK',
}
},
];

const contactPoints = [
Expand Down Expand Up @@ -314,7 +396,7 @@ const shops = [
id: 'shop_1',
name: 'Shop1',
description: 'a mocked shop for unit tests',
domain: 'www.shop.com',
domains: ['www.shop.com'],
organizationId: organizations[0].payload?.id,
shopNumber: '0000000001',
},
Expand All @@ -336,6 +418,11 @@ const validOrders: { [key: string]: OrderList } = {
productId: products[0]?.payload?.id,
variantId: products[0]?.payload?.product?.physical?.variants?.[0]?.id,
quantity: 4,
},
{
productId: products[1]?.payload?.id,
variantId: products[1]?.payload?.product?.physical?.variants?.[0]?.id,
quantity: 2,
}
],
notificationEmail: '[email protected]',
Expand Down Expand Up @@ -366,6 +453,11 @@ const validOrders: { [key: string]: OrderList } = {
productId: products[0]?.payload?.id,
variantId: products[0]?.payload?.product?.physical?.variants?.[0]?.id,
quantity: 4,
},
{
productId: products[1]?.payload?.id,
variantId: products[1]?.payload?.product?.physical?.variants?.[0]?.id,
quantity: 2,
}
],
userId: 'user_1',
Expand Down Expand Up @@ -401,6 +493,11 @@ const invalidOrders: { [key: string]: OrderList } = {
productId: products[0]?.payload?.id,
variantId: products[0]?.payload?.product?.physical?.variants?.[0]?.id,
quantity: 4,
},
{
productId: products[1]?.payload?.id,
variantId: products[1]?.payload?.product?.physical?.variants?.[0]?.id,
quantity: 2,
}
],
userId: 'userId_1',
Expand Down

0 comments on commit 22550c9

Please sign in to comment.