Add(challenges): Add dev mode exception to next challenge logic
This commit is contained in:
@ -91,7 +91,14 @@ export function getFirstChallenge(
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNextChallenge(current, entities, skip = 0) {
|
export function getNextChallenge(
|
||||||
|
current,
|
||||||
|
entities,
|
||||||
|
{
|
||||||
|
isDev = false,
|
||||||
|
skip = 0
|
||||||
|
} = {}
|
||||||
|
) {
|
||||||
const { challenge: challengeMap, block: blockMap } = entities;
|
const { challenge: challengeMap, block: blockMap } = entities;
|
||||||
// find current challenge
|
// find current challenge
|
||||||
// find current block
|
// find current block
|
||||||
@ -108,15 +115,22 @@ export function getNextChallenge(current, entities, skip = 0) {
|
|||||||
// skip is used to skip isComingSoon challenges
|
// skip is used to skip isComingSoon challenges
|
||||||
block.challenges[ index + 1 + skip ]
|
block.challenges[ index + 1 + skip ]
|
||||||
];
|
];
|
||||||
if (nextChallenge && nextChallenge.isComingSoon) {
|
if (!isDev && nextChallenge && nextChallenge.isComingSoon) {
|
||||||
// if we find a next challenge and it is a coming soon
|
// if we find a next challenge and it is a coming soon
|
||||||
// recur with plus one to skip this challenge
|
// recur with plus one to skip this challenge
|
||||||
return getNextChallenge(current, entities, skip + 1);
|
return getNextChallenge(current, entities, { isDev, skip: skip + 1 });
|
||||||
}
|
}
|
||||||
return nextChallenge;
|
return nextChallenge;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFirstChallengeOfNextBlock(current, entities, skip = 0) {
|
export function getFirstChallengeOfNextBlock(
|
||||||
|
current,
|
||||||
|
entities,
|
||||||
|
{
|
||||||
|
isDev = false,
|
||||||
|
skip = 0
|
||||||
|
} = {}
|
||||||
|
) {
|
||||||
const {
|
const {
|
||||||
challenge: challengeMap,
|
challenge: challengeMap,
|
||||||
block: blockMap,
|
block: blockMap,
|
||||||
@ -147,28 +161,35 @@ export function getFirstChallengeOfNextBlock(current, entities, skip = 0) {
|
|||||||
}
|
}
|
||||||
// grab first challenge from next block
|
// grab first challenge from next block
|
||||||
const nextChallenge = challengeMap[newBlock.challenges[0]];
|
const nextChallenge = challengeMap[newBlock.challenges[0]];
|
||||||
if (nextChallenge && nextChallenge.isComingSoon) {
|
if (isDev || !nextChallenge || !nextChallenge.isComingSoon) {
|
||||||
|
return nextChallenge;
|
||||||
|
}
|
||||||
// if first challenge is coming soon, find next challenge here
|
// if first challenge is coming soon, find next challenge here
|
||||||
const nextChallenge2 = getNextChallenge(nextChallenge.dashedName, entities);
|
const nextChallenge2 = getNextChallenge(
|
||||||
if (!nextChallenge2) {
|
nextChallenge.dashedName,
|
||||||
|
entities,
|
||||||
|
{ isDev }
|
||||||
|
);
|
||||||
|
if (nextChallenge2) {
|
||||||
|
return nextChallenge2;
|
||||||
|
}
|
||||||
// whole block is coming soon
|
// whole block is coming soon
|
||||||
// skip this block
|
// skip this block
|
||||||
return getFirstChallengeOfNextBlock(
|
return getFirstChallengeOfNextBlock(
|
||||||
current,
|
current,
|
||||||
entities,
|
entities,
|
||||||
skip + 1
|
{ isDev, skip: skip + 1 }
|
||||||
);
|
);
|
||||||
}
|
|
||||||
return nextChallenge2;
|
|
||||||
}
|
|
||||||
return nextChallenge;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFirstChallengeOfNextSuperBlock(
|
export function getFirstChallengeOfNextSuperBlock(
|
||||||
current,
|
current,
|
||||||
entities,
|
entities,
|
||||||
superBlocks,
|
superBlocks,
|
||||||
|
{
|
||||||
|
isDev = false,
|
||||||
skip = 0
|
skip = 0
|
||||||
|
} = {}
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
challenge: challengeMap,
|
challenge: challengeMap,
|
||||||
@ -199,14 +220,15 @@ export function getFirstChallengeOfNextSuperBlock(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const nextChallenge = challengeMap[newBlock.challenges[0]];
|
const nextChallenge = challengeMap[newBlock.challenges[0]];
|
||||||
if (!nextChallenge || !nextChallenge.isComingSoon) {
|
if (isDev || !nextChallenge || !nextChallenge.isComingSoon) {
|
||||||
return nextChallenge;
|
return nextChallenge;
|
||||||
}
|
}
|
||||||
// coming soon challenge, grab next
|
// coming soon challenge, grab next
|
||||||
// non coming soon challenge in same block instead
|
// non coming soon challenge in same block instead
|
||||||
const nextChallengeInBlock = getNextChallenge(
|
const nextChallengeInBlock = getNextChallenge(
|
||||||
nextChallenge.dashedName,
|
nextChallenge.dashedName,
|
||||||
entities
|
entities,
|
||||||
|
{ isDev }
|
||||||
);
|
);
|
||||||
if (nextChallengeInBlock) {
|
if (nextChallengeInBlock) {
|
||||||
return nextChallengeInBlock;
|
return nextChallengeInBlock;
|
||||||
@ -215,7 +237,8 @@ export function getFirstChallengeOfNextSuperBlock(
|
|||||||
// grab first challenge in next block in newSuperBlock instead
|
// grab first challenge in next block in newSuperBlock instead
|
||||||
const challengeInNextBlock = getFirstChallengeOfNextBlock(
|
const challengeInNextBlock = getFirstChallengeOfNextBlock(
|
||||||
nextChallenge.dashedName,
|
nextChallenge.dashedName,
|
||||||
entities
|
entities,
|
||||||
|
{ isDev }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (challengeInNextBlock) {
|
if (challengeInNextBlock) {
|
||||||
@ -227,7 +250,7 @@ export function getFirstChallengeOfNextSuperBlock(
|
|||||||
current,
|
current,
|
||||||
entities,
|
entities,
|
||||||
superBlocks,
|
superBlocks,
|
||||||
skip + 1
|
{ isDev, skip: skip + 1 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
|
|
||||||
test('common/app/routes/challenges/utils', function(t) {
|
test('common/app/routes/challenges/utils', function(t) {
|
||||||
t.test('getNextChallenge', t => {
|
t.test('getNextChallenge', t => {
|
||||||
t.plan(4);
|
t.plan(5);
|
||||||
t.test('should return falsey when current challenge is not found', t => {
|
t.test('should return falsey when current challenge is not found', t => {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
const entities = {
|
const entities = {
|
||||||
@ -120,10 +120,46 @@ test('common/app/routes/challenges/utils', function(t) {
|
|||||||
);
|
);
|
||||||
t.isEqual(shouldBeNext, nextChallenge);
|
t.isEqual(shouldBeNext, nextChallenge);
|
||||||
});
|
});
|
||||||
|
t.test('should not skip isComingSoon challenge in dev', t => {
|
||||||
|
t.plan(1);
|
||||||
|
const currentChallenge = {
|
||||||
|
dashedName: 'current-challenge',
|
||||||
|
block: 'current-block'
|
||||||
|
};
|
||||||
|
const comingSoon = {
|
||||||
|
dashedName: 'coming-soon',
|
||||||
|
isComingSoon: true,
|
||||||
|
block: 'current-block'
|
||||||
|
};
|
||||||
|
const nextChallenge = {
|
||||||
|
dashedName: 'next-challenge',
|
||||||
|
block: 'current-block'
|
||||||
|
};
|
||||||
|
const entities = {
|
||||||
|
challenge: {
|
||||||
|
'current-challenge': currentChallenge,
|
||||||
|
'next-challenge': nextChallenge,
|
||||||
|
'coming-soon': comingSoon
|
||||||
|
},
|
||||||
|
block: {
|
||||||
|
'current-block': {
|
||||||
|
challenges: [
|
||||||
|
'current-challenge',
|
||||||
|
'coming-soon',
|
||||||
|
'next-challenge'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
t.isEqual(
|
||||||
|
getNextChallenge('current-challenge', entities, { isDev: true }),
|
||||||
|
comingSoon
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
t.test('getFirstChallengeOfNextBlock', t => {
|
t.test('getFirstChallengeOfNextBlock', t => {
|
||||||
t.plan(7);
|
t.plan(8);
|
||||||
t.test('should return falsey when current challenge is not found', t => {
|
t.test('should return falsey when current challenge is not found', t => {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
const entities = {
|
const entities = {
|
||||||
@ -302,6 +338,58 @@ test('common/app/routes/challenges/utils', function(t) {
|
|||||||
'getFirstChallengeOfNextBlock did not return the correct challenge'
|
'getFirstChallengeOfNextBlock did not return the correct challenge'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
t.test('should not skip coming soon in dev mode', t => {
|
||||||
|
t.plan(1);
|
||||||
|
const currentChallenge = {
|
||||||
|
dashedName: 'current-challenge',
|
||||||
|
block: 'current-block'
|
||||||
|
};
|
||||||
|
const firstChallenge = {
|
||||||
|
dashedName: 'first-challenge',
|
||||||
|
block: 'next-block'
|
||||||
|
};
|
||||||
|
const comingSoon = {
|
||||||
|
dashedName: 'coming-soon',
|
||||||
|
block: 'next-block',
|
||||||
|
isComingSoon: true
|
||||||
|
};
|
||||||
|
const entities = {
|
||||||
|
challenge: {
|
||||||
|
[currentChallenge.dashedName]: currentChallenge,
|
||||||
|
[firstChallenge.dashedName]: firstChallenge,
|
||||||
|
'coming-soon': comingSoon
|
||||||
|
},
|
||||||
|
block: {
|
||||||
|
'current-block': {
|
||||||
|
dashedName: 'current-block',
|
||||||
|
superBlock: 'current-super-block'
|
||||||
|
},
|
||||||
|
'next-block': {
|
||||||
|
dashedName: 'next-block',
|
||||||
|
superBlock: 'current-super-block',
|
||||||
|
challenges: [
|
||||||
|
'coming-soon',
|
||||||
|
'first-challenge'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
superBlock: {
|
||||||
|
'current-super-block': {
|
||||||
|
dashedName: 'current-super-block',
|
||||||
|
blocks: [ 'current-block', 'next-block' ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
t.equal(
|
||||||
|
getFirstChallengeOfNextBlock(
|
||||||
|
currentChallenge.dashedName,
|
||||||
|
entities,
|
||||||
|
{ isDev: true }
|
||||||
|
),
|
||||||
|
comingSoon,
|
||||||
|
'getFirstChallengeOfNextBlock returned isComingSoon challenge'
|
||||||
|
);
|
||||||
|
});
|
||||||
t.test('should skip block if all challenges are coming soon', t => {
|
t.test('should skip block if all challenges are coming soon', t => {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
const currentChallenge = {
|
const currentChallenge = {
|
||||||
@ -375,7 +463,7 @@ test('common/app/routes/challenges/utils', function(t) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
t.test('getFirstChallengeOfNextBlock', t => {
|
t.test('getFirstChallengeOfNextBlock', t => {
|
||||||
t.plan(9);
|
t.plan(10);
|
||||||
t.test('should return falsey if current challenge not found', t => {
|
t.test('should return falsey if current challenge not found', t => {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
const entities = {
|
const entities = {
|
||||||
@ -529,6 +617,53 @@ test('common/app/routes/challenges/utils', function(t) {
|
|||||||
firstChallenge
|
firstChallenge
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
t.test('should not skip coming soon in dev mode', t => {
|
||||||
|
t.plan(1);
|
||||||
|
const firstChallenge = {
|
||||||
|
dashedName: 'first-challenge',
|
||||||
|
block: 'next-block'
|
||||||
|
};
|
||||||
|
const comingSoon = {
|
||||||
|
dashedName: 'coming-soon',
|
||||||
|
block: 'next-block',
|
||||||
|
isComingSoon: true
|
||||||
|
};
|
||||||
|
const entities = {
|
||||||
|
challenge: {
|
||||||
|
'current-challenge': { block: 'current-block' },
|
||||||
|
[firstChallenge.dashedName]: firstChallenge,
|
||||||
|
'coming-soon': comingSoon
|
||||||
|
},
|
||||||
|
block: {
|
||||||
|
'current-block': { superBlock: 'current-super-block' },
|
||||||
|
'next-block': {
|
||||||
|
dashedName: 'next-block',
|
||||||
|
superBlock: 'next-super-block',
|
||||||
|
challenges: [ 'coming-soon', 'first-challenge' ]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
superBlock: {
|
||||||
|
'current-super-block': { dashedName: 'current-super-block' },
|
||||||
|
'next-super-block': {
|
||||||
|
dashedName: 'next-super-block',
|
||||||
|
blocks: [ 'next-block' ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const superBlocks = [
|
||||||
|
'current-super-block',
|
||||||
|
'next-super-block'
|
||||||
|
];
|
||||||
|
t.isEqual(
|
||||||
|
getFirstChallengeOfNextSuperBlock(
|
||||||
|
'current-challenge',
|
||||||
|
entities,
|
||||||
|
superBlocks,
|
||||||
|
{ isDev: true }
|
||||||
|
),
|
||||||
|
comingSoon
|
||||||
|
);
|
||||||
|
});
|
||||||
t.test('should skip coming soon block', t => {
|
t.test('should skip coming soon block', t => {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
const firstChallenge = {
|
const firstChallenge = {
|
||||||
|
Reference in New Issue
Block a user