switched nedb to nedb-promises (#37)

* breaking change: switched to nedb-promises
* Linting
* some dev dependencies
* more tests
* updated package version
* bug fixing
* changed isNaN to isString
* (fix) args[0]
This commit is contained in:
2021-05-03 18:39:33 +02:00
committed by GitHub
parent dc746276ab
commit c6cacdae5e
41 changed files with 16168 additions and 13670 deletions

View File

@ -1,7 +1,7 @@
require('module-alias/register');
const rewire = require('rewire');
const rewireUtils = rewire('@Commands/Attack');
const rewireUtils = rewire('@Commands/Attack');
const getWeapon = rewireUtils.__get__('getWeapon');
const getAttributeLevel = rewireUtils.__get__('getAttributeLevel');
const getCombatTechniqueLevel = rewireUtils.__get__('getCombatTechniqueLevel');
@ -139,7 +139,7 @@ it('should abort with a message: no entry found', () => {
};
const handleAttack = rewireUtils.__get__('handleAttack');
//expect(handleAttack(err)).toThrowError();
expect(handleAttack([], { message: message })).toEqual(
expect(handleAttack({}, { message: message })).toEqual(
'Sorry, für dich habe ich leider keinen Eintrag 😥'
);
});
@ -178,7 +178,7 @@ it('complete run with melee weapon', () => {
};
const handleAttack = rewireUtils.__get__('handleAttack');
const args = ['messer'];
expect(handleAttack([{ character: character }], { message: message, args: args })).toEqual(
expect(handleAttack({ character: character }, { message: message, args: args })).toEqual(
expect.any(String)
);
});
@ -204,7 +204,7 @@ it('complete run with ranged weapon', () => {
};
const handleAttack = rewireUtils.__get__('handleAttack');
const args = ['langbogen'];
expect(handleAttack([{ character: character }], { message: message, args: args })).toEqual(
expect(handleAttack({ character: character }, { message: message, args: args })).toEqual(
expect.any(String)
);
});

View File

@ -1,7 +1,8 @@
require('module-alias/register');
const rewire = require('rewire');
const rewireUtils = rewire('@Commands/Attribute');
const Attribute = require('@Commands/Attribute');
const rewireUtils = rewire('@Commands/Attribute');
const HandleNamedAttributes = rewireUtils.__get__('HandleNamedAttributes');
const getAttributeLevel = rewireUtils.__get__('getAttributeLevel');
const getAttribute = rewireUtils.__get__('getAttribute');
@ -44,9 +45,9 @@ it('should return with no errors', () => {
tag: 'test',
},
};
const docs = [{ character: { attributes: [{ id: 'mut', level: 8 }] } }];
const doc = { character: { attributes: [{ id: 'mut', level: 8 }] } };
const args = ['mut'];
expect(handleAttributeCheck(docs, { message, args })).toEqual(expect.any(String));
expect(handleAttributeCheck(doc, { message, args })).toEqual(expect.any(String));
});
it('should return with no errors', () => {
const reply = jest.fn(str => str);
@ -56,7 +57,7 @@ it('should return with no errors', () => {
tag: 'test',
},
};
const docs = [{ character: { attributes: [{ id: 'mut', level: 8 }] } }];
const docs = { character: { attributes: [{ id: 'mut', level: 8 }] } };
const args = ['MU'];
expect(handleAttributeCheck(docs, { message, args })).toEqual(expect.any(String));
});
@ -70,7 +71,7 @@ it('should return with no errors', () => {
};
const docs = [{ character: { attributes: [{ id: 'mut', level: 8 }] } }];
const args = [8];
for (let i = 0; i < 30; i++) {
for (let i = 0; i < 30; i += 1) {
expect(handleAttributeCheck(docs, { message, args })).toEqual(expect.any(String));
}
});
@ -84,15 +85,18 @@ it('should return with no errors', () => {
};
const docs = [{ character: { attributes: [{ id: 'mut', level: 8 }] } }];
const args = [8, '+2'];
for (let i = 0; i < 30; i++) {
for (let i = 0; i < 30; i += 1) {
expect(handleAttributeCheck(docs, { message, args })).toEqual(expect.any(String));
}
});
it('should return empty', () => {
const message = { author: { tag: 'test' } };
const message = { author: { tag: 'test' }, reply: jest.fn(str => str) };
const args = ['MU'];
expect(Attribute.exec(message, args)).toEqual(expect.objectContaining({}));
expect(Attribute.exec(message, args)).toBeInstanceOf(Promise);
//expect(Attribute.exec(message, args)).resolves.toBeUndefined();
});
/*
const reply = jest.fn(str => str);

View File

@ -0,0 +1,17 @@
require('module-alias/register');
// const { List } = require('@Commands/List');
const rewire = require('rewire');
const reWireUtils = rewire('@Commands/List');
// const getStats = reWireUtils.__get__('getStats');
const getAttribute = reWireUtils.__get__('getAttribute');
it('should return an attribute object', () => {
expect(getAttribute({ id: 'mut', level: 9 })).toEqual(
expect.objectContaining({
id: expect.any(String),
Name: expect.any(String),
Level: expect.any(Number),
})
);
});

View File

@ -3,7 +3,7 @@ require('module-alias/register');
const { CompareResults } = require('@dsabot/CompareResults');
it('should return an object', () => {
let Obj = {
const Obj = {
Passed: 0,
CriticalHit: 0,
Fumbles: 0,
@ -15,7 +15,7 @@ it('should return an object', () => {
});
it('should match No. of Fumbles', () => {
let Obj = {
const Obj = {
Passed: 0,
CriticalHit: 0,
Fumbles: 2,
@ -26,7 +26,7 @@ it('should match No. of Fumbles', () => {
});
it('should match No. of Passed', () => {
let Obj = {
const Obj = {
Passed: 3,
CriticalHit: 0,
Fumbles: 0,
@ -37,7 +37,7 @@ it('should match No. of Passed', () => {
});
it('should match No. of Critical Hits', () => {
let Obj = {
const Obj = {
Passed: 3,
CriticalHit: 2,
Fumbles: 0,
@ -48,7 +48,7 @@ it('should match No. of Critical Hits', () => {
});
it('should decrease Points remaining', () => {
let Obj = {
const Obj = {
Passed: 3,
CriticalHit: 0,
Fumbles: 0,

View File

@ -0,0 +1,6 @@
require('module-alias/register');
const { findMessage } = require('@dsabot/findMessage');
it('should capitalize the first letter.', () => {
expect(findMessage('ERROR')).toBe('Irgendwas ist schief gelaufen. 🤔');
});

View File

@ -0,0 +1,12 @@
require('module-alias/register');
const { isEmpty } = require('@dsabot/isEmpty');
it('should return true statements', () => {
expect(isEmpty({})).toBeTruthy();
expect(isEmpty()).toBeTruthy();
expect(isEmpty('')).toBeTruthy();
expect(isEmpty([])).toBeTruthy();
expect(isEmpty({ key: 'value' })).toBeFalsy();
expect(isEmpty([null])).toBeFalsy();
expect(isEmpty([''])).toBeFalsy();
});