beerbay-math
Advanced tools
Comparing version 1.1.9 to 1.1.10
@@ -37,7 +37,11 @@ "use strict"; | ||
var active = isCouponActive(coupon); | ||
var max_uses = coupon.userMaxUses ? parseInt(coupon.userMaxUses) : Infinity; | ||
var uses = coupon.uses ? coupon.uses.filter(function (uses) { | ||
var maxUses = coupon.maxUses ? parseInt(coupon.maxUses) : Infinity; | ||
var couponUses = coupon.uses ? coupon.uses.length : 0; | ||
var couponHasUses = couponUses < maxUses; | ||
var userMaxUses = coupon.userMaxUses ? parseInt(coupon.userMaxUses) : Infinity; | ||
var userUser = coupon.uses ? coupon.uses.filter(function (uses) { | ||
return uses.user_email === user.email; | ||
}).length : 0; | ||
return active && uses < max_uses; | ||
var userCanUse = userUser < userMaxUses; | ||
return active && couponHasUses && userCanUse; | ||
} | ||
@@ -44,0 +48,0 @@ |
@@ -31,2 +31,8 @@ "use strict"; | ||
}); | ||
test("Underused Coupon is usable another time", function () { | ||
expect((0, _coupon.isCouponUsable)(_coupon2.UNDERUSED_COUPON_10_USD, _coupon2.MOCK_USER)).toBe(true); | ||
}); | ||
test("Used Coupon is not usable anymore", function () { | ||
expect((0, _coupon.isCouponUsable)(_coupon2.USED_COUPON_10_USD, _coupon2.MOCK_USER)).toBe(false); | ||
}); | ||
}); | ||
@@ -33,0 +39,0 @@ describe("isFreeShipping", function () { |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.ALREADY_USED_BY_USER_COUPON = exports.USD_10_COUPON = exports.PERCENTAGE_20_COUPON = exports.FREE_SHIPPING_SPAIN_COUPON = exports.INACTIVE_COUPON = exports.MOCK_USER = void 0; | ||
exports.USED_COUPON_10_USD = exports.UNDERUSED_COUPON_10_USD = exports.ALREADY_USED_BY_USER_COUPON = exports.USD_10_COUPON = exports.PERCENTAGE_20_COUPON = exports.FREE_SHIPPING_SPAIN_COUPON = exports.INACTIVE_COUPON = exports.MOCK_USER = void 0; | ||
var MOCK_USER = { | ||
@@ -24,2 +24,4 @@ id: 1, | ||
//12 usd value | ||
maxUses: 25, | ||
//25 global uses | ||
uses: [{ | ||
@@ -63,3 +65,21 @@ user_email: "v@g.com" | ||
}] | ||
}; //Used 2 times, can be used 3 times | ||
exports.ALREADY_USED_BY_USER_COUPON = ALREADY_USED_BY_USER_COUPON; | ||
var UNDERUSED_COUPON_10_USD = { | ||
active: true, | ||
type: "flat", | ||
value: 10.0, | ||
maxUses: 3, | ||
uses: [{}, {}] | ||
}; //Used 3 times, can be used 3 times = done | ||
exports.UNDERUSED_COUPON_10_USD = UNDERUSED_COUPON_10_USD; | ||
var USED_COUPON_10_USD = { | ||
active: true, | ||
type: "flat", | ||
value: 10.0, | ||
maxUses: 3, | ||
uses: [{}, {}, {}] | ||
}; | ||
exports.ALREADY_USED_BY_USER_COUPON = ALREADY_USED_BY_USER_COUPON; | ||
exports.USED_COUPON_10_USD = USED_COUPON_10_USD; |
{ | ||
"name": "beerbay-math", | ||
"version": "1.1.9", | ||
"version": "1.1.10", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36054
1113