Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add more subscription duration conditions tests

Steven Teydeb1b9118cad
diff --git a/apps/web/tests/rewards/reward-conditions.test.ts b/apps/web/tests/rewards/reward-conditions.test.ts
index cc28f4c154..34c9beccc8 100644
--- a/apps/web/tests/rewards/reward-conditions.test.ts
+++ b/apps/web/tests/rewards/reward-conditions.test.ts
@@ -1662,68 +1662,96 @@ describe("evaluateRewardConditions", () => {
});
describe("subscription duration conditions", () => {
- describe("customer.subscriptionDurationMonths", () => {
- test("should match when subscription duration meets greater_than_or_equal condition", () => {
- const conditions = [
+ const lessThanOrEqualCondition = [
+ {
+ operator: "AND" as const,
+ type: "flat" as const,
+ amountInCents: 5000,
+ conditions: [
{
- operator: "AND" as const,
- type: "flat" as const,
- amountInCents: 5000,
- conditions: [
- {
- entity: "customer" as const,
- attribute: "subscriptionDurationMonths" as const,
- operator: "greater_than_or_equal" as const,
- value: 12,
- },
- ],
+ entity: "customer" as const,
+ attribute: "subscriptionDurationMonths" as const,
+ operator: "less_than_or_equal" as const,
+ value: 12,
},
- ];
-
- const context: RewardContext = {
- customer: {
- subscriptionDurationMonths: 12,
+ ],
+ },
+ ];
+
+ const greaterThanCondition = [
+ {
+ operator: "AND" as const,
+ type: "flat" as const,
+ amountInCents: 5000,
+ conditions: [
+ {
+ entity: "customer" as const,
+ attribute: "subscriptionDurationMonths" as const,
+ operator: "greater_than" as const,
+ value: 12,
},
- };
+ ],
+ },
+ ];
- const result = evaluateRewardConditions({
- conditions,
- context,
- });
+ test("should match when subscription duration meets less_than_or_equal condition", () => {
+ const context: RewardContext = {
+ customer: {
+ subscriptionDurationMonths: 12,
+ },
+ };
- expect(result).toEqual(conditions[0]);
+ const result = evaluateRewardConditions({
+ conditions: lessThanOrEqualCondition,
+ context,
});
- test("should not match when subscription duration is less than condition value", () => {
- const conditions = [
- {
- operator: "AND" as const,
- type: "flat" as const,
- amountInCents: 5000,
- conditions: [
- {
- entity: "customer" as const,
- attribute: "subscriptionDurationMonths" as const,
- operator: "greater_than_or_equal" as const,
- value: 12,
- },
- ],
- },
- ];
+ expect(result).toEqual(lessThanOrEqualCondition[0]);
+ });
- const context: RewardContext = {
- customer: {
- subscriptionDurationMonths: 6,
- },
- };
+ test("should not match when subscription duration is more than less_than_or_equal condition value", () => {
+ const context: RewardContext = {
+ customer: {
+ subscriptionDurationMonths: 16,
+ },
+ };
- const result = evaluateRewardConditions({
- conditions,
- context,
- });
+ const result = evaluateRewardConditions({
+ conditions: lessThanOrEqualCondition,
+ context,
+ });
- expect(result).toBe(null);
+ expect(result).toBe(null);
+ });
+
+ test("should match when subscription duration meets greater_than condition", () => {
+ const context: RewardContext = {
+ customer: {
+ subscriptionDurationMonths: 16,
+ },
+ };
+
+ const result = evaluateRewardConditions({
+ conditions: greaterThanCondition,
+ context,
});
+
+ expect(result).toEqual(greaterThanCondition[0]);
+ });
+
+ test("should not match when subscription duration is less than greater_than condition value", () => {
+ const context: RewardContext = {
+ customer: {
+ subscriptionDurationMonths: 6,
+ },
+ };
+
+ const result = evaluateRewardConditions({
+ conditions: greaterThanCondition,
+ context,
+ });
+
+ expect(result).toBe(null);
});
});
});