@@ -1687,6 +1687,174 @@ medusaIntegrationTestRunner({
16871687 } )
16881688 )
16891689 } )
1690+
1691+ it ( "should add tax inclusive promotion to cart successfully with percentage discount" , async ( ) => {
1692+ const publishableKey = await generatePublishableKey ( appContainer )
1693+ const storeHeaders = generateStoreHeaders ( { publishableKey } )
1694+
1695+ const salesChannel = (
1696+ await api . post (
1697+ "/admin/sales-channels" ,
1698+ { name : "Webshop" , description : "channel" } ,
1699+ adminHeaders
1700+ )
1701+ ) . data . sales_channel
1702+
1703+ await api . post (
1704+ "/admin/price-preferences" ,
1705+ {
1706+ attribute : "currency_code" ,
1707+ value : "dkk" ,
1708+ is_tax_inclusive : true ,
1709+ } ,
1710+ adminHeaders
1711+ )
1712+
1713+ const region = (
1714+ await api . post (
1715+ "/admin/regions" ,
1716+ {
1717+ name : "DK" ,
1718+ currency_code : "dkk" ,
1719+ countries : [ "dk" ] ,
1720+ } ,
1721+ adminHeaders
1722+ )
1723+ ) . data . region
1724+
1725+ const product = (
1726+ await api . post (
1727+ "/admin/products" ,
1728+ {
1729+ ...medusaTshirtProduct ,
1730+ shipping_profile_id : shippingProfile . id ,
1731+ } ,
1732+ adminHeaders
1733+ )
1734+ ) . data . product
1735+
1736+ const response = await api . post (
1737+ `/admin/promotions` ,
1738+ {
1739+ code : "PERCENTAGE_10" ,
1740+ type : PromotionType . STANDARD ,
1741+ status : PromotionStatus . ACTIVE ,
1742+ is_tax_inclusive : true ,
1743+ is_automatic : true ,
1744+ application_method : {
1745+ target_type : "items" ,
1746+ type : "percentage" ,
1747+ allocation : "across" ,
1748+ currency_code : "DKK" ,
1749+ value : 10 ,
1750+ } ,
1751+ } ,
1752+ adminHeaders
1753+ )
1754+
1755+ expect ( response . status ) . toEqual ( 200 )
1756+ expect ( response . data . promotion ) . toEqual (
1757+ expect . objectContaining ( {
1758+ id : expect . any ( String ) ,
1759+ code : "PERCENTAGE_10" ,
1760+ type : "standard" ,
1761+ is_tax_inclusive : true ,
1762+ is_automatic : true ,
1763+ application_method : expect . objectContaining ( {
1764+ value : 10 ,
1765+ type : "percentage" ,
1766+ target_type : "items" ,
1767+ allocation : "across" ,
1768+ } ) ,
1769+ } )
1770+ )
1771+
1772+ const cart = (
1773+ await api . post (
1774+ `/store/carts?fields=*items,*items.adjustments` ,
1775+ {
1776+ currency_code : "dkk" ,
1777+ sales_channel_id : salesChannel . id ,
1778+ region_id : region . id ,
1779+ items : [
1780+ {
1781+ variant_id : product . variants [ 0 ] . id ,
1782+ quantity : 2 ,
1783+ } ,
1784+ ] ,
1785+ promo_codes : [ response . data . promotion . code ] ,
1786+ } ,
1787+ storeHeaders
1788+ )
1789+ ) . data . cart
1790+
1791+ console . log ( JSON . stringify ( cart , null , 2 ) )
1792+
1793+ /**
1794+ * Orignal total -> 2600 DKK (tax incl.)
1795+ * Tax rate -> 25%
1796+ * Promotion -> PERCENTAGE 10 (tax incl.)
1797+ *
1798+ * We want total to be 2600 DKK - 260 DKK = 2340 DKK
1799+ */
1800+ expect ( cart ) . toEqual (
1801+ expect . objectContaining ( {
1802+ currency_code : "dkk" ,
1803+
1804+ subtotal : 2080 , // taxable_base = subtotal - discount_subtotal = 2080 - 208 = 1872
1805+ total : 2340 , // total = taxable_base * (1 + tax rate) = 1872 * (1 + 0.25) = 2340
1806+ tax_total : 468 ,
1807+
1808+ original_total : 2600 ,
1809+ original_tax_total : 520 ,
1810+
1811+ discount_total : 260 ,
1812+ discount_subtotal : 208 ,
1813+ discount_tax_total : 52 ,
1814+
1815+ item_total : 2340 ,
1816+ item_subtotal : 2080 ,
1817+ item_tax_total : 468 ,
1818+
1819+ original_item_total : 2600 ,
1820+ original_item_subtotal : 2080 ,
1821+ original_item_tax_total : 520 ,
1822+
1823+ shipping_total : 0 ,
1824+ shipping_subtotal : 0 ,
1825+ shipping_tax_total : 0 ,
1826+
1827+ original_shipping_tax_total : 0 ,
1828+ original_shipping_subtotal : 0 ,
1829+ original_shipping_total : 0 ,
1830+
1831+ // items: expect.arrayContaining([
1832+ // expect.objectContaining({
1833+ // quantity: 1,
1834+ // unit_price: 1300,
1835+
1836+ // subtotal: 1040,
1837+ // tax_total: 240,
1838+ // total: 1200,
1839+
1840+ // original_total: 1300,
1841+ // original_tax_total: 260,
1842+
1843+ // discount_total: 100,
1844+ // discount_subtotal: 80,
1845+ // discount_tax_total: 20,
1846+
1847+ // adjustments: expect.arrayContaining([
1848+ // expect.objectContaining({
1849+ // amount: 100,
1850+ // is_tax_inclusive: true,
1851+ // }),
1852+ // ]),
1853+ // }),
1854+ // ]),
1855+ } )
1856+ )
1857+ } )
16901858 } )
16911859
16921860 describe ( "DELETE /admin/promotions/:id" , ( ) => {
0 commit comments