fix: handle video challenges
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
a66455b983
commit
1ec6cf1efd
@ -93,14 +93,17 @@ async function buildCurriculum(file, curriculum) {
|
|||||||
async function parseTranslation(engPath, transPath, dict) {
|
async function parseTranslation(engPath, transPath, dict) {
|
||||||
const engChal = await parseMarkdown(engPath);
|
const engChal = await parseMarkdown(engPath);
|
||||||
const translatedChal = await parseMarkdown(transPath);
|
const translatedChal = await parseMarkdown(transPath);
|
||||||
const codeLang = engChal.files[0] ? engChal.files[0].ext : null;
|
const codeLang =
|
||||||
|
engChal.files && engChal.files[0] ? engChal.files[0].ext : null;
|
||||||
|
|
||||||
const engWithTranslatedComments = translateCommentsInChallenge(
|
const engWithTranslatedComments = codeLang
|
||||||
|
? translateCommentsInChallenge(
|
||||||
engChal,
|
engChal,
|
||||||
getChallengeLang(transPath),
|
getChallengeLang(transPath),
|
||||||
dict,
|
dict,
|
||||||
codeLang
|
codeLang
|
||||||
);
|
)
|
||||||
|
: engChal;
|
||||||
return mergeChallenges(engWithTranslatedComments, translatedChal);
|
return mergeChallenges(engWithTranslatedComments, translatedChal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +109,17 @@ const ENGLISH_CHALLENGE_NO_FILES = {
|
|||||||
files: []
|
files: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ENGLISH_VIDEO_CHALLENGE = {
|
||||||
|
id: 'id',
|
||||||
|
title: 'Title',
|
||||||
|
challengeType: 0,
|
||||||
|
videoId: 'abc123',
|
||||||
|
forumTopicId: 12345,
|
||||||
|
question: 'english question',
|
||||||
|
description: 'description html string',
|
||||||
|
instructions: 'instructions html string'
|
||||||
|
};
|
||||||
|
|
||||||
const TRANSLATED_CERTIFICATE = {
|
const TRANSLATED_CERTIFICATE = {
|
||||||
id: '561add10cb82ac38a17513bc',
|
id: '561add10cb82ac38a17513bc',
|
||||||
title: 'Responsive Web Design Certificate',
|
title: 'Responsive Web Design Certificate',
|
||||||
@ -170,6 +181,17 @@ const TRANSLATED_CHALLENGE = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TRANSLATED_VIDEO_CHALLENGE = {
|
||||||
|
id: 'id',
|
||||||
|
title: 'Title',
|
||||||
|
challengeType: 0,
|
||||||
|
videoId: 'abc123',
|
||||||
|
forumTopicId: 12345,
|
||||||
|
question: 'translated question',
|
||||||
|
description: 'translated description html string',
|
||||||
|
instructions: 'translated instructions html string'
|
||||||
|
};
|
||||||
|
|
||||||
const WRONG_NUM_TESTS_CHALLENGE = {
|
const WRONG_NUM_TESTS_CHALLENGE = {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
title: 'Title',
|
title: 'Title',
|
||||||
@ -202,6 +224,8 @@ exports.ENGLISH_CERTIFICATE = ENGLISH_CERTIFICATE;
|
|||||||
exports.ENGLISH_CHALLENGE = ENGLISH_CHALLENGE;
|
exports.ENGLISH_CHALLENGE = ENGLISH_CHALLENGE;
|
||||||
exports.ENGLISH_CHALLENGE_TWO_SOLUTIONS = ENGLISH_CHALLENGE_TWO_SOLUTIONS;
|
exports.ENGLISH_CHALLENGE_TWO_SOLUTIONS = ENGLISH_CHALLENGE_TWO_SOLUTIONS;
|
||||||
exports.ENGLISH_CHALLENGE_NO_FILES = ENGLISH_CHALLENGE_NO_FILES;
|
exports.ENGLISH_CHALLENGE_NO_FILES = ENGLISH_CHALLENGE_NO_FILES;
|
||||||
|
exports.ENGLISH_VIDEO_CHALLENGE = ENGLISH_VIDEO_CHALLENGE;
|
||||||
exports.TRANSLATED_CERTIFICATE = TRANSLATED_CERTIFICATE;
|
exports.TRANSLATED_CERTIFICATE = TRANSLATED_CERTIFICATE;
|
||||||
exports.TRANSLATED_CHALLENGE = TRANSLATED_CHALLENGE;
|
exports.TRANSLATED_CHALLENGE = TRANSLATED_CHALLENGE;
|
||||||
|
exports.TRANSLATED_VIDEO_CHALLENGE = TRANSLATED_VIDEO_CHALLENGE;
|
||||||
exports.WRONG_NUM_TESTS_CHALLENGE = WRONG_NUM_TESTS_CHALLENGE;
|
exports.WRONG_NUM_TESTS_CHALLENGE = WRONG_NUM_TESTS_CHALLENGE;
|
||||||
|
@ -31,13 +31,40 @@ exports.translateCommentsInChallenge = (challenge, lang, dict, codeLang) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.mergeChallenges = (engChal, transChal) => {
|
exports.mergeChallenges = (engChal, transChal) => {
|
||||||
if (!transChal.tests || transChal.tests.length !== engChal.tests.length)
|
const hasTests =
|
||||||
|
(engChal.tests && transChal.tests) ||
|
||||||
|
(engChal.question && transChal.question);
|
||||||
|
const challenge = {
|
||||||
|
...engChal,
|
||||||
|
description: transChal.description,
|
||||||
|
instructions: transChal.instructions,
|
||||||
|
localeTitle: transChal.localeTitle,
|
||||||
|
forumTopicId: transChal.forumTopicId
|
||||||
|
};
|
||||||
|
if (!hasTests)
|
||||||
throw Error(
|
throw Error(
|
||||||
|
`Both challenges must have tests or questions.
|
||||||
|
title: ${engChal.title}
|
||||||
|
localeTitle: ${transChal.localeTitle}`
|
||||||
|
);
|
||||||
|
// TODO: this should break the build when we go to production, but
|
||||||
|
// not for testing.
|
||||||
|
if (transChal.tests && transChal.tests.length !== engChal.tests.length) {
|
||||||
|
console.error(
|
||||||
`Challenges in both languages must have the same number of tests.
|
`Challenges in both languages must have the same number of tests.
|
||||||
title: ${engChal.title}
|
title: ${engChal.title}
|
||||||
localeTitle: ${transChal.localeTitle}`
|
localeTitle: ${transChal.localeTitle}`
|
||||||
);
|
);
|
||||||
|
return challenge;
|
||||||
|
}
|
||||||
|
|
||||||
|
// throw Error(
|
||||||
|
// `Challenges in both languages must have the same number of tests.
|
||||||
|
// title: ${engChal.title}
|
||||||
|
// localeTitle: ${transChal.localeTitle}`
|
||||||
|
// );
|
||||||
|
|
||||||
|
if (transChal.tests) {
|
||||||
const translatedTests =
|
const translatedTests =
|
||||||
engChal.challengeType === 7
|
engChal.challengeType === 7
|
||||||
? transChal.tests.map(({ title }, i) => ({
|
? transChal.tests.map(({ title }, i) => ({
|
||||||
@ -48,14 +75,11 @@ exports.mergeChallenges = (engChal, transChal) => {
|
|||||||
text,
|
text,
|
||||||
testString: engChal.tests[i].testString
|
testString: engChal.tests[i].testString
|
||||||
}));
|
}));
|
||||||
const challenge = {
|
challenge.tests = translatedTests;
|
||||||
...engChal,
|
} else {
|
||||||
description: transChal.description,
|
challenge.question = transChal.question;
|
||||||
instructions: transChal.instructions,
|
}
|
||||||
localeTitle: transChal.localeTitle,
|
|
||||||
forumTopicId: transChal.forumTopicId,
|
|
||||||
tests: translatedTests
|
|
||||||
};
|
|
||||||
// certificates do not have forumTopicIds
|
// certificates do not have forumTopicIds
|
||||||
if (challenge.challengeType === 7) delete challenge.forumTopicId;
|
if (challenge.challengeType === 7) delete challenge.forumTopicId;
|
||||||
return challenge;
|
return challenge;
|
||||||
|
@ -9,9 +9,11 @@ const {
|
|||||||
ENGLISH_CHALLENGE,
|
ENGLISH_CHALLENGE,
|
||||||
ENGLISH_CHALLENGE_NO_FILES,
|
ENGLISH_CHALLENGE_NO_FILES,
|
||||||
ENGLISH_CHALLENGE_TWO_SOLUTIONS,
|
ENGLISH_CHALLENGE_TWO_SOLUTIONS,
|
||||||
|
ENGLISH_VIDEO_CHALLENGE,
|
||||||
TRANSLATED_CERTIFICATE,
|
TRANSLATED_CERTIFICATE,
|
||||||
TRANSLATED_CHALLENGE,
|
TRANSLATED_CHALLENGE,
|
||||||
WRONG_NUM_TESTS_CHALLENGE
|
TRANSLATED_VIDEO_CHALLENGE
|
||||||
|
// WRONG_NUM_TESTS_CHALLENGE
|
||||||
} = require('./__fixtures__/challenge-objects');
|
} = require('./__fixtures__/challenge-objects');
|
||||||
const { SIMPLE_TRANSLATION } = require('./__mocks__/mock-comments');
|
const { SIMPLE_TRANSLATION } = require('./__mocks__/mock-comments');
|
||||||
|
|
||||||
@ -30,6 +32,11 @@ const COMBINED_CERTIFICATE = mergeChallenges(
|
|||||||
TRANSLATED_CERTIFICATE
|
TRANSLATED_CERTIFICATE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const COMBINED_VIDEO_CHALLENGE = mergeChallenges(
|
||||||
|
ENGLISH_VIDEO_CHALLENGE,
|
||||||
|
TRANSLATED_VIDEO_CHALLENGE
|
||||||
|
);
|
||||||
|
|
||||||
let logSpy;
|
let logSpy;
|
||||||
|
|
||||||
describe('translation parser', () => {
|
describe('translation parser', () => {
|
||||||
@ -98,11 +105,12 @@ describe('translation parser', () => {
|
|||||||
TRANSLATED_CHALLENGE.localeTitle
|
TRANSLATED_CHALLENGE.localeTitle
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('throws an error if the numbers of tests do not match', () => {
|
// TODO: reinstate this after alpha testing.
|
||||||
expect(() =>
|
// it('throws an error if the numbers of tests do not match', () => {
|
||||||
mergeChallenges(ENGLISH_CHALLENGE, WRONG_NUM_TESTS_CHALLENGE)
|
// expect(() =>
|
||||||
).toThrow();
|
// mergeChallenges(ENGLISH_CHALLENGE, WRONG_NUM_TESTS_CHALLENGE)
|
||||||
});
|
// ).toThrow();
|
||||||
|
// });
|
||||||
it('takes the forum id from the second challenge', () => {
|
it('takes the forum id from the second challenge', () => {
|
||||||
expect(COMBINED_CHALLENGE.forumTopicId).toBe(
|
expect(COMBINED_CHALLENGE.forumTopicId).toBe(
|
||||||
TRANSLATED_CHALLENGE.forumTopicId
|
TRANSLATED_CHALLENGE.forumTopicId
|
||||||
@ -130,6 +138,11 @@ describe('translation parser', () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('takes the question from the second challenge', () => {
|
||||||
|
expect(COMBINED_VIDEO_CHALLENGE.question).toBe(
|
||||||
|
TRANSLATED_VIDEO_CHALLENGE.question
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('translateCommentsInChallenge', () => {
|
describe('translateCommentsInChallenge', () => {
|
||||||
|
Reference in New Issue
Block a user