refactor: remove confusing abstraction
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
7c4e0ec41e
commit
24d9c94fe5
@ -1,30 +1,28 @@
|
||||
/* global expect beforeAll */
|
||||
/* global expect */
|
||||
const path = require('path');
|
||||
|
||||
const {
|
||||
createChallengeCreator,
|
||||
hasEnglishSourceCreator,
|
||||
createChallenge,
|
||||
hasEnglishSource,
|
||||
createCommentMap
|
||||
} = require('./getChallenges');
|
||||
|
||||
const EXISTING_CHALLENGE_PATH = 'challenge.md';
|
||||
const MISSING_CHALLENGE_PATH = 'no/challenge.md';
|
||||
|
||||
let hasEnglishSource;
|
||||
let createChallenge;
|
||||
const basePath = '__fixtures__';
|
||||
|
||||
describe('create non-English challenge', () => {
|
||||
describe('createChallenge', () => {
|
||||
it('throws if lang is an invalid language', async () => {
|
||||
createChallenge = createChallengeCreator(basePath, 'notlang');
|
||||
await expect(
|
||||
createChallenge(EXISTING_CHALLENGE_PATH, {})
|
||||
createChallenge(basePath, EXISTING_CHALLENGE_PATH, 'notlang', {})
|
||||
).rejects.toThrow('notlang is not a accepted language');
|
||||
});
|
||||
it('throws an error if the source challenge is missing', async () => {
|
||||
createChallenge = createChallengeCreator(basePath, 'chinese');
|
||||
await expect(createChallenge(MISSING_CHALLENGE_PATH, {})).rejects.toThrow(
|
||||
await expect(
|
||||
createChallenge(basePath, MISSING_CHALLENGE_PATH, 'chinese', {})
|
||||
).rejects.toThrow(
|
||||
`Missing English challenge for
|
||||
${MISSING_CHALLENGE_PATH}
|
||||
It should be in
|
||||
@ -33,19 +31,25 @@ It should be in
|
||||
});
|
||||
});
|
||||
describe('hasEnglishSource', () => {
|
||||
beforeAll(() => {
|
||||
hasEnglishSource = hasEnglishSourceCreator(basePath);
|
||||
});
|
||||
it('returns a boolean', async () => {
|
||||
const sourceExists = await hasEnglishSource(EXISTING_CHALLENGE_PATH);
|
||||
const sourceExists = await hasEnglishSource(
|
||||
basePath,
|
||||
EXISTING_CHALLENGE_PATH
|
||||
);
|
||||
expect(typeof sourceExists).toBe('boolean');
|
||||
});
|
||||
it('returns true if the English challenge exists', async () => {
|
||||
const sourceExists = await hasEnglishSource(EXISTING_CHALLENGE_PATH);
|
||||
const sourceExists = await hasEnglishSource(
|
||||
basePath,
|
||||
EXISTING_CHALLENGE_PATH
|
||||
);
|
||||
expect(sourceExists).toBe(true);
|
||||
});
|
||||
it('returns false if the English challenge is missing', async () => {
|
||||
const sourceExists = await hasEnglishSource(MISSING_CHALLENGE_PATH);
|
||||
const sourceExists = await hasEnglishSource(
|
||||
basePath,
|
||||
MISSING_CHALLENGE_PATH
|
||||
);
|
||||
expect(sourceExists).toBe(false);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user