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),
})
);
});