fix: handle video challenges
This commit is contained in:
parent
a66455b983
commit
1ec6cf1efd
@ -93,14 +93,17 @@ async function buildCurriculum(file, curriculum) {
|
||||
async function parseTranslation(engPath, transPath, dict) {
|
||||
const engChal = await parseMarkdown(engPath);
|
||||
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(
|
||||
engChal,
|
||||
getChallengeLang(transPath),
|
||||
dict,
|
||||
codeLang
|
||||
);
|
||||
const engWithTranslatedComments = codeLang
|
||||
? translateCommentsInChallenge(
|
||||
engChal,
|
||||
getChallengeLang(transPath),
|
||||
dict,
|
||||
codeLang
|
||||
)
|
||||
: engChal;
|
||||
return mergeChallenges(engWithTranslatedComments, translatedChal);
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,17 @@ const ENGLISH_CHALLENGE_NO_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 = {
|
||||
id: '561add10cb82ac38a17513bc',
|
||||
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 = {
|
||||
id: 'id',
|
||||
title: 'Title',
|
||||
@ -202,6 +224,8 @@ exports.ENGLISH_CERTIFICATE = ENGLISH_CERTIFICATE;
|
||||
exports.ENGLISH_CHALLENGE = ENGLISH_CHALLENGE;
|
||||
exports.ENGLISH_CHALLENGE_TWO_SOLUTIONS = ENGLISH_CHALLENGE_TWO_SOLUTIONS;
|
||||
exports.ENGLISH_CHALLENGE_NO_FILES = ENGLISH_CHALLENGE_NO_FILES;
|
||||
exports.ENGLISH_VIDEO_CHALLENGE = ENGLISH_VIDEO_CHALLENGE;
|
||||
exports.TRANSLATED_CERTIFICATE = TRANSLATED_CERTIFICATE;
|
||||
exports.TRANSLATED_CHALLENGE = TRANSLATED_CHALLENGE;
|
||||
exports.TRANSLATED_VIDEO_CHALLENGE = TRANSLATED_VIDEO_CHALLENGE;
|
||||
exports.WRONG_NUM_TESTS_CHALLENGE = WRONG_NUM_TESTS_CHALLENGE;
|
||||
|
@ -31,31 +31,55 @@ exports.translateCommentsInChallenge = (challenge, lang, dict, codeLang) => {
|
||||
};
|
||||
|
||||
exports.mergeChallenges = (engChal, transChal) => {
|
||||
if (!transChal.tests || transChal.tests.length !== engChal.tests.length)
|
||||
throw Error(
|
||||
`Challenges in both languages must have the same number of tests.
|
||||
title: ${engChal.title}
|
||||
localeTitle: ${transChal.localeTitle}`
|
||||
);
|
||||
|
||||
const translatedTests =
|
||||
engChal.challengeType === 7
|
||||
? transChal.tests.map(({ title }, i) => ({
|
||||
title,
|
||||
id: engChal.tests[i].id
|
||||
}))
|
||||
: transChal.tests.map(({ text }, i) => ({
|
||||
text,
|
||||
testString: engChal.tests[i].testString
|
||||
}));
|
||||
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,
|
||||
tests: translatedTests
|
||||
forumTopicId: transChal.forumTopicId
|
||||
};
|
||||
if (!hasTests)
|
||||
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.
|
||||
title: ${engChal.title}
|
||||
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 =
|
||||
engChal.challengeType === 7
|
||||
? transChal.tests.map(({ title }, i) => ({
|
||||
title,
|
||||
id: engChal.tests[i].id
|
||||
}))
|
||||
: transChal.tests.map(({ text }, i) => ({
|
||||
text,
|
||||
testString: engChal.tests[i].testString
|
||||
}));
|
||||
challenge.tests = translatedTests;
|
||||
} else {
|
||||
challenge.question = transChal.question;
|
||||
}
|
||||
|
||||
// certificates do not have forumTopicIds
|
||||
if (challenge.challengeType === 7) delete challenge.forumTopicId;
|
||||
return challenge;
|
||||
|
@ -9,9 +9,11 @@ const {
|
||||
ENGLISH_CHALLENGE,
|
||||
ENGLISH_CHALLENGE_NO_FILES,
|
||||
ENGLISH_CHALLENGE_TWO_SOLUTIONS,
|
||||
ENGLISH_VIDEO_CHALLENGE,
|
||||
TRANSLATED_CERTIFICATE,
|
||||
TRANSLATED_CHALLENGE,
|
||||
WRONG_NUM_TESTS_CHALLENGE
|
||||
TRANSLATED_VIDEO_CHALLENGE
|
||||
// WRONG_NUM_TESTS_CHALLENGE
|
||||
} = require('./__fixtures__/challenge-objects');
|
||||
const { SIMPLE_TRANSLATION } = require('./__mocks__/mock-comments');
|
||||
|
||||
@ -30,6 +32,11 @@ const COMBINED_CERTIFICATE = mergeChallenges(
|
||||
TRANSLATED_CERTIFICATE
|
||||
);
|
||||
|
||||
const COMBINED_VIDEO_CHALLENGE = mergeChallenges(
|
||||
ENGLISH_VIDEO_CHALLENGE,
|
||||
TRANSLATED_VIDEO_CHALLENGE
|
||||
);
|
||||
|
||||
let logSpy;
|
||||
|
||||
describe('translation parser', () => {
|
||||
@ -98,11 +105,12 @@ describe('translation parser', () => {
|
||||
TRANSLATED_CHALLENGE.localeTitle
|
||||
);
|
||||
});
|
||||
it('throws an error if the numbers of tests do not match', () => {
|
||||
expect(() =>
|
||||
mergeChallenges(ENGLISH_CHALLENGE, WRONG_NUM_TESTS_CHALLENGE)
|
||||
).toThrow();
|
||||
});
|
||||
// TODO: reinstate this after alpha testing.
|
||||
// it('throws an error if the numbers of tests do not match', () => {
|
||||
// expect(() =>
|
||||
// mergeChallenges(ENGLISH_CHALLENGE, WRONG_NUM_TESTS_CHALLENGE)
|
||||
// ).toThrow();
|
||||
// });
|
||||
it('takes the forum id from the second challenge', () => {
|
||||
expect(COMBINED_CHALLENGE.forumTopicId).toBe(
|
||||
TRANSLATED_CHALLENGE.forumTopicId
|
||||
@ -130,6 +138,11 @@ describe('translation parser', () => {
|
||||
false
|
||||
);
|
||||
});
|
||||
it('takes the question from the second challenge', () => {
|
||||
expect(COMBINED_VIDEO_CHALLENGE.question).toBe(
|
||||
TRANSLATED_VIDEO_CHALLENGE.question
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('translateCommentsInChallenge', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user