From 78f251a51ad21d1fb7432dcbb03ad8c035d6a2d5 Mon Sep 17 00:00:00 2001 From: vanilla-wave Date: Fri, 4 Oct 2024 17:19:01 +0200 Subject: [PATCH] fix(promo-manager): get promo status for deleted promo --- src/promo-manager/core/controller.ts | 2 +- src/promo-manager/tests/controller.test.ts | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/promo-manager/core/controller.ts b/src/promo-manager/core/controller.ts index ac40ff5..ce100d4 100644 --- a/src/promo-manager/core/controller.ts +++ b/src/promo-manager/core/controller.ts @@ -552,7 +552,7 @@ export class Controller { }; private isPromoRepeatable = (slug: PromoSlug) => { - const isPromoRepeatable = this.helpers.promoBySlug[slug].repeatable; + const isPromoRepeatable = this.helpers.promoBySlug[slug]?.repeatable ?? false; const groupSlug = this.getGroupBySlug(slug); const group = this.options.config.promoGroups.find( diff --git a/src/promo-manager/tests/controller.test.ts b/src/promo-manager/tests/controller.test.ts index 1918ec0..b0b6b5b 100644 --- a/src/promo-manager/tests/controller.test.ts +++ b/src/promo-manager/tests/controller.test.ts @@ -132,6 +132,32 @@ describe('promo status', function () { expect(status).toBe('forbidden'); }); + it('undefined promo -> forbidden', async function () { + const controller = new Controller(testOptions); + + const status = controller.getPromoStatus('boardPollFake'); + + expect(status).toBe('forbidden'); + }); + + it('deleted promo with progress promo -> return false', async function () { + const controller = new Controller({ + ...testOptions, + progressState: { + finishedPromos: ['boardPollFake'], + progressInfoByPromo: { + boardPollFake: { + lastCallTime: Date.now(), + }, + }, + }, + }); + + const status = controller.getPromoStatus('boardPollFake'); + + expect(status).toBe('finished'); + }); + describe('repeatable promos', function () { it('repeatable finished promo -> canReRun', async function () { const controller = new Controller(testOptions);