@@ -1662,68 +1662,96 @@ describe("evaluateRewardConditions", () => {
16621662 } ) ;
16631663
16641664 describe ( "subscription duration conditions" , ( ) => {
1665- describe ( "customer.subscriptionDurationMonths" , ( ) => {
1666- test ( "should match when subscription duration meets greater_than_or_equal condition" , ( ) => {
1667- const conditions = [
1665+ const lessThanOrEqualCondition = [
1666+ {
1667+ operator : "AND" as const ,
1668+ type : "flat" as const ,
1669+ amountInCents : 5000 ,
1670+ conditions : [
16681671 {
1669- operator : "AND" as const ,
1670- type : "flat" as const ,
1671- amountInCents : 5000 ,
1672- conditions : [
1673- {
1674- entity : "customer" as const ,
1675- attribute : "subscriptionDurationMonths" as const ,
1676- operator : "greater_than_or_equal" as const ,
1677- value : 12 ,
1678- } ,
1679- ] ,
1672+ entity : "customer" as const ,
1673+ attribute : "subscriptionDurationMonths" as const ,
1674+ operator : "less_than_or_equal" as const ,
1675+ value : 12 ,
16801676 } ,
1681- ] ;
1682-
1683- const context : RewardContext = {
1684- customer : {
1685- subscriptionDurationMonths : 12 ,
1677+ ] ,
1678+ } ,
1679+ ] ;
1680+
1681+ const greaterThanCondition = [
1682+ {
1683+ operator : "AND" as const ,
1684+ type : "flat" as const ,
1685+ amountInCents : 5000 ,
1686+ conditions : [
1687+ {
1688+ entity : "customer" as const ,
1689+ attribute : "subscriptionDurationMonths" as const ,
1690+ operator : "greater_than" as const ,
1691+ value : 12 ,
16861692 } ,
1687- } ;
1693+ ] ,
1694+ } ,
1695+ ] ;
16881696
1689- const result = evaluateRewardConditions ( {
1690- conditions,
1691- context,
1692- } ) ;
1697+ test ( "should match when subscription duration meets less_than_or_equal condition" , ( ) => {
1698+ const context : RewardContext = {
1699+ customer : {
1700+ subscriptionDurationMonths : 12 ,
1701+ } ,
1702+ } ;
16931703
1694- expect ( result ) . toEqual ( conditions [ 0 ] ) ;
1704+ const result = evaluateRewardConditions ( {
1705+ conditions : lessThanOrEqualCondition ,
1706+ context,
16951707 } ) ;
16961708
1697- test ( "should not match when subscription duration is less than condition value" , ( ) => {
1698- const conditions = [
1699- {
1700- operator : "AND" as const ,
1701- type : "flat" as const ,
1702- amountInCents : 5000 ,
1703- conditions : [
1704- {
1705- entity : "customer" as const ,
1706- attribute : "subscriptionDurationMonths" as const ,
1707- operator : "greater_than_or_equal" as const ,
1708- value : 12 ,
1709- } ,
1710- ] ,
1711- } ,
1712- ] ;
1709+ expect ( result ) . toEqual ( lessThanOrEqualCondition [ 0 ] ) ;
1710+ } ) ;
17131711
1714- const context : RewardContext = {
1715- customer : {
1716- subscriptionDurationMonths : 6 ,
1717- } ,
1718- } ;
1712+ test ( "should not match when subscription duration is more than less_than_or_equal condition value" , ( ) => {
1713+ const context : RewardContext = {
1714+ customer : {
1715+ subscriptionDurationMonths : 16 ,
1716+ } ,
1717+ } ;
17191718
1720- const result = evaluateRewardConditions ( {
1721- conditions,
1722- context,
1723- } ) ;
1719+ const result = evaluateRewardConditions ( {
1720+ conditions : lessThanOrEqualCondition ,
1721+ context,
1722+ } ) ;
17241723
1725- expect ( result ) . toBe ( null ) ;
1724+ expect ( result ) . toBe ( null ) ;
1725+ } ) ;
1726+
1727+ test ( "should match when subscription duration meets greater_than condition" , ( ) => {
1728+ const context : RewardContext = {
1729+ customer : {
1730+ subscriptionDurationMonths : 16 ,
1731+ } ,
1732+ } ;
1733+
1734+ const result = evaluateRewardConditions ( {
1735+ conditions : greaterThanCondition ,
1736+ context,
17261737 } ) ;
1738+
1739+ expect ( result ) . toEqual ( greaterThanCondition [ 0 ] ) ;
1740+ } ) ;
1741+
1742+ test ( "should not match when subscription duration is less than greater_than condition value" , ( ) => {
1743+ const context : RewardContext = {
1744+ customer : {
1745+ subscriptionDurationMonths : 6 ,
1746+ } ,
1747+ } ;
1748+
1749+ const result = evaluateRewardConditions ( {
1750+ conditions : greaterThanCondition ,
1751+ context,
1752+ } ) ;
1753+
1754+ expect ( result ) . toBe ( null ) ;
17271755 } ) ;
17281756 } ) ;
17291757} ) ;
0 commit comments