Skip to content

Commit

Permalink
fix: woof command exported properly
Browse files Browse the repository at this point in the history
  • Loading branch information
JackuB committed Oct 6, 2020
1 parent f77e7b0 commit 0b6593c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
33 changes: 6 additions & 27 deletions src/cli/commands/woof.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import { MethodArgs, ArgsOptions } from '../args';
import { MethodArgs } from '../args';
import getWoof from './woof/getWoof';

const woofs = {
en: 'Woof!',
he: ' !הב ',
ru: ' Гав!',
es: 'Guau!',
cs: ' Haf!',
};

export function getWoofLanguage(args: MethodArgs): string {
const options = args.pop() as ArgsOptions;
let lang = 'en';

if (
typeof options.language === 'string' &&
Object.keys(woofs).includes(options.language)
) {
lang = options.language;
}

return lang;
}

export default function woof(...args: MethodArgs) {
const lang = getWoofLanguage(args);
export = function woof(...args: MethodArgs) {
const woof = getWoof(args);
console.log(`
| |
/| |\\
Expand All @@ -37,7 +16,7 @@ export default function woof(...args: MethodArgs) {
| | | |
\\ ( ) /
\\_/ \\_/ /-----\\
\\U/ --( ${woofs[lang]} )
\\U/ --( ${woof} )
\\-----/
`);
}
};
23 changes: 23 additions & 0 deletions src/cli/commands/woof/getWoof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MethodArgs, ArgsOptions } from '../../args';

const woofs = {
en: 'Woof!',
he: ' !הב ',
ru: ' Гав!',
es: 'Guau!',
cs: ' Haf!',
};

export default function getWoof(args: MethodArgs): string {
const options = args.pop() as ArgsOptions;
let lang = 'en';

if (
typeof options.language === 'string' &&
Object.keys(woofs).includes(options.language)
) {
lang = options.language;
}

return woofs[lang];
}
12 changes: 6 additions & 6 deletions test/woof.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { getWoofLanguage } from '../src/cli/commands/woof';
import getWoof from '../src/cli/commands/woof/getWoof';

describe('Woof command - Language option', () => {
it('Default language is "en"', () => {
// $ snyk woof
expect(getWoofLanguage([{} as any])).toEqual('en');
expect(getWoof([{} as any])).toEqual('Woof!');
});

it('Returns selected language', () => {
expect(
getWoofLanguage([
getWoof([
{
language: 'he',
} as any,
]),
).toEqual('he');
).toEqual(' !הב ');
});

it('Returns default when selected language is invalid', () => {
expect(
getWoofLanguage([
getWoof([
{
language: 'toString',
} as any,
]),
).toEqual('en');
).toEqual('Woof!');
});
});

0 comments on commit 0b6593c

Please sign in to comment.