Skip to content

Commit

Permalink
test(promo-manager): add promo status tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilla-wave committed Sep 29, 2024
1 parent 843e309 commit b172c38
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/promo-manager/tests/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,81 @@ describe('active promo', () => {
});
});

describe('promo status', function () {
it('no progress -> forbidden', function () {
const controller = new Controller({...testOptions, progressState: undefined});

const status = controller.getPromoStatus('boardPoll');

expect(status).toBe('forbidden');
});

it('active promo -> active', async function () {
const controller = new Controller(testOptions);
await controller.requestStart('boardPoll');

const status = controller.getPromoStatus('boardPoll');

expect(status).toBe('active');
});

it('common finished promo -> finished', async function () {
const controller = new Controller(testOptions);
await controller.requestStart('boardPoll');
await controller.finishPromo('boardPoll');

const status = controller.getPromoStatus('boardPoll');

expect(status).toBe('finished');
});

it('promo in queue -> pending', async function () {
const controller = new Controller(testOptions);
await controller.requestStart('ganttPoll');
await controller.requestStart('boardPoll');

const status = controller.getPromoStatus('boardPoll');

expect(status).toBe('pending');
});

it('pass conditions -> canRun', async function () {
const controller = new Controller(testOptions);

const status = controller.getPromoStatus('boardPoll');

expect(status).toBe('canRun');
});

it('not pass conditions -> forbidden', async function () {
const controller = new Controller(testOptions);

const status = controller.getPromoStatus('pastDayPoll');

expect(status).toBe('forbidden');
});

it('repeatable finished promo -> canReRun', async function () {
const controller = new Controller(testOptions);
await controller.requestStart('boardPoll');
await controller.finishPromo('boardPoll');

const status = controller.getPromoStatus('boardPoll');

expect(status).toBe('finished');
});

it('repeatable promo not pass conditions -> canReRun', async function () {
const controller = new Controller(testOptions);
await controller.requestStart('forbiddenRepeatablePoll');
await controller.finishPromo('forbiddenRepeatablePoll');

const status = controller.getPromoStatus('forbiddenRepeatablePoll');

expect(status).toBe('forbidden');
});
});

describe('repeatred runs', function () {
it('common promo -> cannot run', async function () {
const controller = new Controller(testOptions);
Expand Down
5 changes: 5 additions & 0 deletions src/promo-manager/tests/promoGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export const repeatedPoll: PromoGroup = {
repeatable: true,
conditions: [],
},
{
slug: 'forbiddenRepeatablePoll',
repeatable: true,
conditions: [() => false],
},
],
};

Expand Down

0 comments on commit b172c38

Please sign in to comment.