Skip to content

Commit

Permalink
refactor(promo-manager): promoType -> promoGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilla-wave committed Sep 5, 2024
1 parent 36b829f commit 2d547a7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/promo-manager/core/condition/condition-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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);
});
});
});
Expand Down Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/promo-manager/core/condition/condition-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/promo-manager/core/condition/condition-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/promo-manager/core/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -339,7 +339,7 @@ export class Controller {
const resultForPromo = checkCondition(
this.state,
{
promoType: type,
promoGroup: group,
promoSlug: slug,
currentDate: this.dateNow(),
helpers: this.conditionHelpers,
Expand Down
2 changes: 1 addition & 1 deletion src/promo-manager/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type PromoOptions = {
};

export type ConditionContext = {
promoType?: PromoGroupSlug;
promoGroup?: PromoGroupSlug;
promoSlug?: PromoSlug;
currentDate: number;
helpers?: Record<string, ConditionHelper>;
Expand Down

0 comments on commit 2d547a7

Please sign in to comment.