(fix) !spells and !chants returned null value (#40)

This commit is contained in:
2021-05-04 22:39:59 +02:00
committed by GitHub
parent 895f47847e
commit 4fa2dc7ab7
7 changed files with 56 additions and 7 deletions

View File

@ -1,5 +1,6 @@
require('module-alias/register'); require('module-alias/register');
const rewire = require('rewire'); const rewire = require('rewire');
const Attack = require('@Commands/Attack');
const rewireUtils = rewire('@Commands/Attack'); const rewireUtils = rewire('@Commands/Attack');
const getWeapon = rewireUtils.__get__('getWeapon'); const getWeapon = rewireUtils.__get__('getWeapon');
@ -13,6 +14,12 @@ const getCombatTechnique = rewireUtils.__get__('getCombatTechnique');
it('should be undefined without value', () => { it('should be undefined without value', () => {
expect(getCombatTechnique({})).toBeUndefined(); expect(getCombatTechnique({})).toBeUndefined();
}); });
it('should be undefined without value', () => {
expect(getCombatTechnique({ combattechnique: 'made-up' })).toBeUndefined();
});
it('should be null without any params.', () => {
expect(getCombatTechnique()).toBeNull();
});
it('should return defined object', () => { it('should return defined object', () => {
expect(getCombatTechnique({ combattechnique: 'dolche' })).toEqual( expect(getCombatTechnique({ combattechnique: 'dolche' })).toEqual(
expect.objectContaining({ expect.objectContaining({

View File

@ -1,13 +1,22 @@
require('module-alias/register'); require('module-alias/register');
// const { List } = require('@Commands/List'); const List = require('@Commands/List');
const rewire = require('rewire'); const rewire = require('rewire');
const reWireUtils = rewire('@Commands/List'); const reWireUtils = rewire('@Commands/List');
// const getStats = reWireUtils.__get__('getStats'); // const getStats = reWireUtils.__get__('getStats');
const getAttribute = reWireUtils.__get__('getAttribute'); const getAttribute = reWireUtils.__get__('getAttribute');
const printHeader = reWireUtils.__get__('printHeader');
const listStats = reWireUtils.__get__('listStats');
it('should return an attribute object', () => { it('should return an attribute object', () => {
expect(getAttribute({ id: 'mut', level: 9 })).toEqual( expect(getAttribute({ id: 'mut', level: 9 })).toEqual(
expect.objectContaining({
id: 'mut',
Name: 'Mut',
Level: 9,
})
);
expect(getAttribute()).toEqual(
expect.objectContaining({ expect.objectContaining({
id: expect.any(String), id: expect.any(String),
Name: expect.any(String), Name: expect.any(String),
@ -15,3 +24,16 @@ it('should return an attribute object', () => {
}) })
); );
}); });
it('should return null', () => {
expect(printHeader()).toBeNull();
});
it('should return a string', () => {
const attributes = [{ Short: 'AA' }, { Short: 'BB' }, { Short: 'CC' }];
expect(printHeader(attributes)).toMatch(/\s+AA\s+[|]\s+BB\s+[|]\s+CC\s+/g);
});
it('should return a string', () => {
expect(listStats([{ Level: 8 }, { Level: 9 }, { Level: 10 }])).toMatch(
/\s+8\s+[|]\s+9\s+[|]\s+10\s+/
);
});

View File

@ -6,3 +6,10 @@ describe('rolling dice', () => {
expect(roll(200, 6).dice).toContain(value); expect(roll(200, 6).dice).toContain(value);
}); });
}); });
describe('rolling dice', () => {
const expected = [1, 2, 3, 4, 5, 6];
test.each(expected)('contains only numbers from 1 to 6', value => {
expect(roll(200, 6, 'test').dice).toContain(value);
});
});

View File

@ -11,7 +11,8 @@ const createChantList = (Character = {}) => {
Character.chants.forEach(chant => Character.chants.forEach(chant =>
ChantList.push(getChant({ Character: Character, chant_name: chant.id })) ChantList.push(getChant({ Character: Character, chant_name: chant.id }))
); );
return ChantList.filter(value => value !== undefined); console.log(ChantList);
return ChantList.filter(value => value !== undefined && value !== null);
}; };
const ReplyChantList = (ChantList = []) => { const ReplyChantList = (ChantList = []) => {
@ -42,6 +43,7 @@ module.exports = {
if (isEmpty(doc)) { if (isEmpty(doc)) {
return message.reply(findMessage('NOENTRY')); return message.reply(findMessage('NOENTRY'));
} }
console.log(doc.character);
const Character = doc.character; const Character = doc.character;
if (!Character.hasOwnProperty('chants')) if (!Character.hasOwnProperty('chants'))
return message.reply(findMessage('NO_CHANTS')); return message.reply(findMessage('NO_CHANTS'));

View File

@ -5,9 +5,10 @@ const { db } = require('../globals');
const { Werte } = require('../globals'); const { Werte } = require('../globals');
function printHeader(attributes) { function printHeader(attributes) {
if (!attributes) return null;
return `${''.padStart(31)}${attributes return `${''.padStart(31)}${attributes
.map(a => `${a.Short}`.padEnd(4).padStart(6)) .map(a => `${a.Short}`.padEnd(4).padStart(6))
.join('|')}\n`; .join('|')}\n`.toString();
} }
function listStats(attributes) { function listStats(attributes) {
return `${attributes.map(a => `${a.Level}`.padEnd(4).padStart(6)).join('|')}\n`; return `${attributes.map(a => `${a.Level}`.padEnd(4).padStart(6)).join('|')}\n`;

View File

@ -22,7 +22,7 @@ const createSpellList = (Character = {}) => {
Character.spells.forEach(spell => Character.spells.forEach(spell =>
SpellList.push(getSpell({ Character: Character, spell_name: spell.id })) SpellList.push(getSpell({ Character: Character, spell_name: spell.id }))
); );
return SpellList.filter(value => value !== undefined); //?+ return SpellList.filter(value => value !== undefined && value !== null); //?+
}; };
module.exports = { module.exports = {

View File

@ -1,6 +1,6 @@
{ {
"name": "dsabot", "name": "dsabot",
"version": "1.6.1", "version": "1.6.2",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@ -39,7 +39,17 @@
"collectCoverageFrom": [ "collectCoverageFrom": [
"**/*.{js,jsx}", "**/*.{js,jsx}",
"!**/node_modules/**", "!**/node_modules/**",
"!**/vendor/**" "!**/vendor/**",
"!**/.github/**",
"!**/__tests__/**",
"!**/__mocks__/**"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"<rootDir>/__tests__/",
"<rootDir>/.github/",
"<rootDir>/coverage/",
"<rootDir>/__mocks__/"
], ],
"coverageDirectory": "coverage" "coverageDirectory": "coverage"
} }