merge dev branch (more tests) (#47)

* more tests and bugfixes on spells

* linting
This commit is contained in:
2021-05-06 21:35:58 +02:00
committed by GitHub
parent 25ad8ad160
commit ba63be64dd
12 changed files with 219 additions and 45 deletions

View File

@ -4,9 +4,11 @@ require('babel-plugin-rewire');
const command = require('@Commands/Roll');
//const exec = command.__get__('exec');
describe('roll command', () => {
const message = { reply: str => str };
const reply = jest.fn(str => str);
const message = { author: { tag: 'test' }, reply: reply };
it('should not return anything without correct arguments', () => {
const args = ['1'];
const args = ['1w6'];
expect(command.exec(message, args)).resolves.toBeUndefined();
expect(reply).toHaveBeenCalled();
});
});

View File

@ -0,0 +1,76 @@
require('module-alias/register');
require('babel-plugin-rewire');
const Spells = require('@Commands/Spells');
const createSpellList = Spells.__get__('createSpellList');
const TestValue = {
Name: 'Test',
Level: 10,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
};
describe('createSpellList', () => {
it('should return an array with expected object(s)', () => {
const Test = { spells: [{ id: 'test', level: 10 }] };
const expected = {
Name: 'Test',
Level: 10,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
};
Spells.__Rewire__('getSpell', () => expected);
expect(createSpellList(Test)).toEqual(expect.arrayContaining([expected]));
Spells.__ResetDependency__('getSpell');
});
it('should abort if character has no chants', () => {
expect(createSpellList({ attributes: [] })).toBeNull();
expect(createSpellList()).toBeNull();
expect(createSpellList({})).toBeNull();
});
});
describe('ReplySpell', () => {
const ReplySpell = Spells.__get__('ReplySpell');
it('should return null if no param given.', () => {
expect(ReplySpell()).toBeNull();
});
it('should return a string', () => {
// toBeInstanceOf(String) is not working :(
expect(
ReplySpell({
Name: 'Test',
Level: 9,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
})
).toMatch(/.*Test.*(9)?.*/);
});
Spells.__ResetDependency__('ReplySpell');
});
describe('ReplySpellList', () => {
const ReplySpellList = Spells.__get__('ReplySpellList');
it('should return null if params are empty', () => {
expect(ReplySpellList('')).toBe('Du kennst keine Zaubersprüche.');
expect(ReplySpellList([])).toBe('Du kennst keine Zaubersprüche.');
expect(ReplySpellList()).toBe('Du kennst keine Zaubersprüche.');
});
it('should return Name and Level', () => {
const input = [TestValue];
expect(ReplySpellList(input)).toMatch('Test (10)');
});
});

View File

@ -0,0 +1,109 @@
require('module-alias/register');
require('babel-plugin-rewire');
const command = require('@dsabot/getSpell');
describe('getSpell integration test', () => {
it('should not find an entry for a spell', () => {
const getSpell = command.__get__('getSpell');
expect(getSpell({ Character: { name: '' }, spell_name: 'test' })).toBeNull();
});
it('should return null if char has no spells.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
};
command.__set__('Spells', [
{ id: 'test', name: 'Test', attributes: ['MU', 'KL', 'CH'], modified_by: ['SK'] },
]);
const getSpell = command.__get__('getSpell');
expect(getSpell({ Character: Character, spell_name: 'test' })).toBeNull();
});
it('should return a correct spell result.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
spells: [{ id: 'test', level: 7 }, { id: 'no-level' }],
};
const Spells = [
{
id: 'test',
name: 'Testspell',
attributes: ['MU', 'KL', 'CH'],
modified_by: ['SK'],
},
{ id: 'no-level', name: 'No Level', attributes: ['MU', 'KL', 'CH'], modified_by: [] },
];
command.__set__('Spells', Spells);
const getSpell = command.__get__('getSpell');
expect(getSpell({ Character: Character, spell_name: 'test' })).toEqual(
expect.objectContaining({
Name: 'Testspell',
Level: 7,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
ModifiedBy: ['SK'],
})
);
expect(getSpell({ Character: Character, spell_name: 'Testspell' })).toEqual(
expect.objectContaining({
Name: 'Testspell',
Level: 7,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
ModifiedBy: ['SK'],
})
);
expect(getSpell({ Character: Character, spell_name: 'no-level' })).toEqual(
expect.objectContaining({
Name: 'No Level',
Level: 0,
Attributes: [
{ Level: 10, Name: 'MU' },
{ Level: 11, Name: 'KL' },
{ Level: 12, Name: 'CH' },
],
ModifiedBy: [],
})
);
});
it('should not find the spell.', () => {
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'charisma', level: 12 },
],
spells: [{ id: 'test', level: 7 }],
};
const Spells = [{ id: 'test', name: 'Testspell', attributes: ['MU', 'KL', 'CH'] }];
command.__set__('Spells', Spells);
const getSpell = command.__get__('getSpell');
expect(getSpell({ Character: Character, spell_name: 'well-hidden' })).toBeNull();
});
});