Fix isBeta challenges displaying without title when they should be hidden

pull/12989/merge
systimotic 2017-01-30 21:45:51 +01:00 committed by Berkeley Martinez
parent e3eb02e9b1
commit 01291162ef
2 changed files with 80 additions and 2 deletions

View File

@ -10,12 +10,30 @@ export function filterComingSoonBetaChallenge(
}
export function filterComingSoonBetaFromEntities(
{ challenge: challengeMap, ...rest },
{ challenge: challengeMap, block: blockMap, ...rest },
isDev = false
) {
const filter = filterComingSoonBetaChallenge.bind(null, isDev);
return {
...rest,
block: Object.keys(blockMap)
.map(dashedName => {
const block = blockMap[dashedName];
const filteredChallenges = block.challenges
.map(dashedName => challengeMap[dashedName])
.filter(filter)
.map(challenge => challenge.dashedName);
return {
...block,
challenges: [ ...filteredChallenges ]
};
})
.reduce((blockMap, block) => {
blockMap[block.dashedName] = block;
return blockMap;
}, {}),
challenge: Object.keys(challengeMap)
.map(dashedName => challengeMap[dashedName])
.filter(filter)

View File

@ -37,7 +37,7 @@ test.test('filterComingSoonBetaChallenge', t => {
test.test('filterComingSoonBetaFromEntities', t => {
t.plan(2);
t.test('should filter isBeta|coming-soon by default', t => {
t.plan(2);
t.plan(4);
const normalChallenge = { dashedName: 'normal-challenge' };
const entities = {
challenge: {
@ -48,8 +48,23 @@ test.test('filterComingSoonBetaFromEntities', t => {
isBeta: true
},
[normalChallenge.dashedName]: normalChallenge
},
block: {
'coming-soon': {
dashedName: 'coming-soon',
challenges: ['coming-soon']
},
'is-beta': {
dashedName: 'is-beta',
challenges: ['is-beta']
},
normal: {
dashedName: 'normal',
challenges: [normalChallenge.dashedName]
}
}
};
const actual = filterComingSoonBetaFromEntities(entities);
t.isEqual(
Object.keys(actual.challenge).length,
@ -61,6 +76,23 @@ test.test('filterComingSoonBetaFromEntities', t => {
normalChallenge,
'did not return the correct challenge'
);
const challengesFromBlocks = [];
Object.keys(actual.block)
.forEach(block => {
const challenges = actual.block[block].challenges;
challenges.forEach(challenge => challengesFromBlocks.push(challenge));
});
t.isEqual(
challengesFromBlocks.length,
1,
'did not filter the correct amount of challenges from blocks'
);
t.isEqual(
challengesFromBlocks[0],
normalChallenge.dashedName,
'did not return the correct challenge from blocks'
);
});
t.test('should not filter isBeta|coming-soon when isDev', t => {
t.plan(1);
@ -80,6 +112,24 @@ test.test('filterComingSoonBetaFromEntities', t => {
isBeta: true
},
[normalChallenge.dashedName]: normalChallenge
},
block: {
'coming-soon': {
dashedName: 'coming-soon',
challenges: ['coming-soon']
},
'is-beta': {
dashedName: 'is-beta',
challenges: ['is-beta']
},
'is-both': {
dashedName: 'is-both',
challenges: ['is-both']
},
normal: {
dashedName: 'normal',
challenges: [normalChallenge.dashedName]
}
}
};
const actual = filterComingSoonBetaFromEntities(entities, true);
@ -88,5 +138,15 @@ test.test('filterComingSoonBetaFromEntities', t => {
4,
'filtered challenges'
);
let challengesFromBlocksCount = 0;
Object.keys(actual.block)
.forEach(block => {
challengesFromBlocksCount += actual.block[block].challenges.length;
});
t.isEqual(
challengesFromBlocksCount,
4,
'filtered challenges from blocks'
);
});
});