From 2d547a7730237c6fe424c3adfd19f81fb1b09a0a Mon Sep 17 00:00:00 2001 From: vanilla-wave Date: Thu, 5 Sep 2024 19:05:50 +0200 Subject: [PATCH] refactor(promo-manager): promoType -> promoGroup --- .../core/condition/condition-helpers.test.ts | 6 +++--- src/promo-manager/core/condition/condition-helpers.ts | 2 +- src/promo-manager/core/condition/condition-utils.ts | 2 +- src/promo-manager/core/controller.ts | 10 +++++----- src/promo-manager/core/types.ts | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/promo-manager/core/condition/condition-helpers.test.ts b/src/promo-manager/core/condition/condition-helpers.test.ts index 8a2b944..5c3896f 100644 --- a/src/promo-manager/core/condition/condition-helpers.test.ts +++ b/src/promo-manager/core/condition/condition-helpers.test.ts @@ -96,7 +96,7 @@ describe('ShowOnceForPeriod', function () { }, }; - expect(helper(state, {currentDate, promoType: 'promoGroup1', config})).toBe(false); + expect(helper(state, {currentDate, promoGroup: 'promoGroup1', config})).toBe(false); }); it('enough time has passed to start -> true', function () { @@ -117,7 +117,7 @@ describe('ShowOnceForPeriod', function () { }, }; - expect(helper(state, {currentDate, promoType: 'promoGroup1', config})).toBe(true); + expect(helper(state, {currentDate, promoGroup: 'promoGroup1', config})).toBe(true); }); }); }); @@ -180,7 +180,7 @@ describe('ShowOnceForSession', function () { const helper = ShowOnceForSession(); - expect(helper(state, {currentDate, promoType: 'promoGroup1', config})).toBe(false); + expect(helper(state, {currentDate, promoGroup: 'promoGroup1', config})).toBe(false); }); describe('with slugs param', function () { diff --git a/src/promo-manager/core/condition/condition-helpers.ts b/src/promo-manager/core/condition/condition-helpers.ts index 575a7da..d99fd00 100644 --- a/src/promo-manager/core/condition/condition-helpers.ts +++ b/src/promo-manager/core/condition/condition-helpers.ts @@ -26,7 +26,7 @@ export const ShowOnceForSession = ({slugs: slugsFromParams}: SlugsParam = {}) => return (state: PromoState, ctx: ConditionContext) => { const targetInterval = dayjs.duration(performance.now()); - const slugFromContext = ctx.promoType || ctx.promoSlug; + const slugFromContext = ctx.promoGroup || ctx.promoSlug; const slugs = slugsFromParams ?? [slugFromContext]; for (const slug of slugs) { diff --git a/src/promo-manager/core/condition/condition-utils.ts b/src/promo-manager/core/condition/condition-utils.ts index 2cfac69..66c8027 100644 --- a/src/promo-manager/core/condition/condition-utils.ts +++ b/src/promo-manager/core/condition/condition-utils.ts @@ -16,7 +16,7 @@ export const getLastTimeCall = (state: PromoState, ctx: ConditionContext, slug?: export const getTimeFromLastCallInMs = (state: PromoState, ctx: ConditionContext) => { const nowDate = dayjs(ctx.currentDate); - const lastTimeCall = getLastTimeCall(state, ctx, ctx.promoSlug || ctx.promoType); + const lastTimeCall = getLastTimeCall(state, ctx, ctx.promoSlug || ctx.promoGroup); if (!lastTimeCall) { return Infinity; diff --git a/src/promo-manager/core/controller.ts b/src/promo-manager/core/controller.ts index 669f22b..9725e3d 100644 --- a/src/promo-manager/core/controller.ts +++ b/src/promo-manager/core/controller.ts @@ -315,19 +315,19 @@ export class Controller { return false; } - const type = this.getGroupBySlug(slug); + const group = this.getGroupBySlug(slug); - if (!type) { + if (!group) { return false; } - const conditionsForType = this.conditions.typeConditions[type] ?? []; + const conditionsForType = this.conditions.typeConditions[group] ?? []; const conditionsForSlug = this.conditions.promoConditions[slug] ?? []; const resultForGroup = checkCondition( this.state, { - promoType: type, + promoGroup: group, currentDate: this.dateNow(), config: this.options.config, }, @@ -339,7 +339,7 @@ export class Controller { const resultForPromo = checkCondition( this.state, { - promoType: type, + promoGroup: group, promoSlug: slug, currentDate: this.dateNow(), helpers: this.conditionHelpers, diff --git a/src/promo-manager/core/types.ts b/src/promo-manager/core/types.ts index 55dd10b..2a8985c 100644 --- a/src/promo-manager/core/types.ts +++ b/src/promo-manager/core/types.ts @@ -61,7 +61,7 @@ export type PromoOptions = { }; export type ConditionContext = { - promoType?: PromoGroupSlug; + promoGroup?: PromoGroupSlug; promoSlug?: PromoSlug; currentDate: number; helpers?: Record;