diff --git a/.gitignore b/.gitignore index ae73ac5..154b6ce 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ Thumbs.db !/data/*.js !/data/*.json /private - +coverage diff --git a/__tests__/functions/CalculateQuality.js b/__tests__/functions/CalculateQuality.js index faaeeaa..de42cdd 100644 --- a/__tests__/functions/CalculateQuality.js +++ b/__tests__/functions/CalculateQuality.js @@ -1,12 +1,24 @@ -const {CalculateQuality} = require('@dsabot/CalculateQuality'); +require('module-alias/register'); +const { CalculateQuality } = require('@dsabot/CalculateQuality'); const TestValues = [ - [1,1], [2,1], [3,1], - [4,2], [5,2], [6,2], - [7,3], [8,3], [9,3], - [10,4],[11,4],[12,4], - [13,5],[14,5],[15,5] + [1, 1], + [2, 1], + [3, 1], + [4, 2], + [5, 2], + [6, 2], + [7, 3], + [8, 3], + [9, 3], + [10, 4], + [11, 4], + [12, 4], + [13, 5], + [14, 5], + [15, 5], ]; + test.each(TestValues)('Retrieving Quality for %s', (input, output) => { expect(CalculateQuality(input)).toBe(output); - }); \ No newline at end of file +}); diff --git a/__tests__/functions/Capitalize.js b/__tests__/functions/Capitalize.js new file mode 100644 index 0000000..a559ae9 --- /dev/null +++ b/__tests__/functions/Capitalize.js @@ -0,0 +1,6 @@ +require('module-alias/register'); +const { Capitalize } = require('@dsabot/Capitalize'); + +it('should capitalize the first letter.', () => { + expect(Capitalize('mother')).toBe('Mother'); +}); diff --git a/__tests__/functions/CompareResults.js b/__tests__/functions/CompareResults.js new file mode 100644 index 0000000..8dc7a81 --- /dev/null +++ b/__tests__/functions/CompareResults.js @@ -0,0 +1,60 @@ +require('module-alias/register'); + +const { CompareResults } = require('@dsabot/CompareResults'); + +it('should return an object', () => { + let Obj = { + Passed: 0, + CriticalHit: 0, + Fumbles: 0, + PointsUsed: [], + PointsRemaining: 0, + }; + expect(CompareResults).toBeInstanceOf(Object); + expect(CompareResults()).toMatchObject(Obj); +}); + +it('should match No. of Fumbles', () => { + let Obj = { + Passed: 0, + CriticalHit: 0, + Fumbles: 2, + PointsUsed: [0, 0, 0], + PointsRemaining: 0, + }; + expect(CompareResults([9, 20, 20])).toMatchObject(Obj); +}); + +it('should match No. of Passed', () => { + let Obj = { + Passed: 3, + CriticalHit: 0, + Fumbles: 0, + PointsUsed: [0, 0, 0], + PointsRemaining: 0, + }; + expect(CompareResults([7, 7, 7])).toMatchObject(Obj); +}); + +it('should match No. of Critical Hits', () => { + let Obj = { + Passed: 3, + CriticalHit: 2, + Fumbles: 0, + PointsUsed: [0, 0, 0], + PointsRemaining: 0, + }; + expect(CompareResults([8, 1, 1])).toMatchObject(Obj); +}); + +it('should decrease Points remaining', () => { + let Obj = { + Passed: 3, + CriticalHit: 0, + Fumbles: 0, + PointsUsed: [0, 0, 3], + PointsRemaining: 3, + }; + + expect(CompareResults([11, 9, 15], [12, 12, 12], 0, 6)).toMatchObject(Obj); +}); diff --git a/__tests__/functions/CountOccurences.js b/__tests__/functions/CountOccurences.js index d5cefb2..ef52b2c 100644 --- a/__tests__/functions/CountOccurences.js +++ b/__tests__/functions/CountOccurences.js @@ -1,6 +1,4 @@ -const { - CountOccurences -} = require('../../functions/CountOccurences'); +const { CountOccurences } = require('../../functions/CountOccurences'); test('Counting Occurences', () => { - expect(CountOccurences([1, 2, 3, 4, 1], 1)).toBe(2); -}); \ No newline at end of file + expect(CountOccurences([1, 2, 3, 4, 1], 1)).toBe(2); +}); diff --git a/__tests__/functions/CreateResultTable.js b/__tests__/functions/CreateResultTable.js new file mode 100644 index 0000000..59b26a2 --- /dev/null +++ b/__tests__/functions/CreateResultTable.js @@ -0,0 +1,9 @@ +require('module-alias/register'); + +const { CreateResultTable, f } = require('@dsabot/CreateResultTable'); + +it('turn any number into a string', () => { + expect(f(2)).toBe('+2'); + expect(f(0)).toBe('0'); + expect(f(-1)).toBe('-1'); +}); diff --git a/__tests__/functions/Random.js b/__tests__/functions/Random.js new file mode 100644 index 0000000..80510ad --- /dev/null +++ b/__tests__/functions/Random.js @@ -0,0 +1,19 @@ +require('module-alias/register'); + +const { Random } = require('@dsabot/Random'); + +it('should return with no min or max value', () => { + expect(Random.int()).toBeUndefined(); +}); +it('call for use should return true', () => { + expect(Random.use(null)).toBeTruthy(); +}); +it('should return between 1 and 2', () => { + expect(Random.int(1, 2)).toBeGreaterThanOrEqual(1); +}); +it('should return between 1 and 2', () => { + expect(Random.int(1, 2)).toBeLessThanOrEqual(2); +}); +it('should return exactly 1', () => { + expect(Random.int(1, 1)).toBe(1); +}); diff --git a/__tests__/functions/Roll.js b/__tests__/functions/Roll.js index 12d183f..2c07a1d 100644 --- a/__tests__/functions/Roll.js +++ b/__tests__/functions/Roll.js @@ -1,8 +1,8 @@ const { roll } = require('@dsabot/Roll'); 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).dice).toContain(value); - }); -}); \ No newline at end of file + const expected = [1, 2, 3, 4, 5, 6]; + test.each(expected)('contains only numbers from 1 to 6', value => { + expect(roll(200, 6).dice).toContain(value); + }); +}); diff --git a/__tests__/functions/getAttributeLevels.js b/__tests__/functions/getAttributeLevels.js new file mode 100644 index 0000000..644f3d7 --- /dev/null +++ b/__tests__/functions/getAttributeLevels.js @@ -0,0 +1,23 @@ +require('module-alias/register'); +const { getAttributeLevels } = require('@dsabot/getAttributeLevels'); + +const Character = { + attributes: [ + { id: 'mut', level: 10 }, + { id: 'klugheit', level: 11 }, + { id: 'intuition', level: 12 }, + { id: 'charisma', level: 13 }, + { id: 'fingerfertigkeit', level: 14 }, + { id: 'gewandtheit', level: 15 }, + { id: 'konstitution', level: 16 }, + { id: 'koerperkraft', level: 17 }, + ], +}; + +it('should return an array', () => { + expect(getAttributeLevels(['MU', 'IN', 'KO'], Character)).toBeInstanceOf(Array); +}); + +it('should have 3 items in it.', () => { + expect(getAttributeLevels(['MU', 'IN', 'KO'], Character)).toHaveLength(3); +}); diff --git a/functions/Random.js b/functions/Random.js index 932fdd5..8d7644a 100644 --- a/functions/Random.js +++ b/functions/Random.js @@ -1,13 +1,14 @@ -const Random = {int, use}; +const Random = { int, use }; -function int (min, max) { - if (!min || !max) { return; } - //return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min))) + min; - return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + min; +function int(min, max) { + if (!min || !max) { + return; } + return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + min; +} -function use (str) { +function use(str) { return true; } -module.exports = { Random }; \ No newline at end of file +module.exports = { Random }; diff --git a/functions/getAttributeLevels.js b/functions/getAttributeLevels.js index 555a15e..9cecc01 100644 --- a/functions/getAttributeLevels.js +++ b/functions/getAttributeLevels.js @@ -1,14 +1,14 @@ const globals = require('../globals'); const getAttributeLevels = (Attributes = [], Character = {}) => { - let AttributeId; - let AttributeLevel; - let AttributeList = []; - for (let Attribute of Attributes) { - AttributeId = globals.Werte.find((attribute) => attribute.kuerzel === Attribute).id; - AttributeLevel = Character.attributes.find((att) => att.id === AttributeId).level; - AttributeList.push({ Name: Attribute, Level: AttributeLevel }); - } - return AttributeList; + let AttributeId; + let AttributeLevel; + let AttributeList = []; + for (let Attribute of Attributes) { + AttributeId = globals.Werte.find(att => att.kuerzel === Attribute).id; + AttributeLevel = Character.attributes.find(att => att.id === AttributeId).level; + AttributeList.push({ Name: Attribute, Level: AttributeLevel }); + } + return AttributeList; }; -module.exports = { getAttributeLevels}; +module.exports = { getAttributeLevels }; diff --git a/jest.config.js b/jest.config.js index c23092f..3202d00 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,6 +5,6 @@ module.exports = { '@Commands/(.*)': '/commands/$1', '@Root/(.*)': '/$1', '@data/(.*)': '/data/$i', - '@lib/(.*)': '/lib/$i', + '@Lib/(.*)': '/lib/$i', }, }; diff --git a/package-lock.json b/package-lock.json index 0679166..b9c2b79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "dsabot", - "version": "1.1.0", + "version": "1.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.1.0", + "version": "1.5.0", "license": "ISC", "dependencies": { "discord.js": "^12.5.3", @@ -16,6 +16,7 @@ "random": "^3.0.6" }, "devDependencies": { + "@types/jest": "^26.0.23", "jest": "^26.6.3" } }, @@ -673,6 +674,7 @@ "jest-resolve": "^26.6.2", "jest-util": "^26.6.2", "jest-worker": "^26.6.2", + "node-notifier": "^8.0.0", "slash": "^3.0.0", "source-map": "^0.6.0", "string-length": "^4.0.1", @@ -865,6 +867,16 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/jest": { + "version": "26.0.23", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.23.tgz", + "integrity": "sha512-ZHLmWMJ9jJ9PTiT58juykZpL7KjwJywFN3Rr2pTSkyQfydf/rk22yS7W8p5DaVUMQ2BQC7oYiU3FjbTM/mYrOA==", + "dev": true, + "dependencies": { + "jest-diff": "^26.0.0", + "pretty-format": "^26.0.0" + } + }, "node_modules/@types/node": { "version": "14.14.25", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.25.tgz", @@ -1889,7 +1901,8 @@ "esprima": "^4.0.1", "estraverse": "^4.2.0", "esutils": "^2.0.2", - "optionator": "^0.8.1" + "optionator": "^0.8.1", + "source-map": "~0.6.1" }, "bin": { "escodegen": "bin/escodegen.js", @@ -3137,6 +3150,7 @@ "@types/node": "*", "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", + "fsevents": "^2.1.2", "graceful-fs": "^4.2.4", "jest-regex-util": "^26.0.0", "jest-serializer": "^26.6.2", @@ -6996,6 +7010,16 @@ "@types/istanbul-lib-report": "*" } }, + "@types/jest": { + "version": "26.0.23", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.23.tgz", + "integrity": "sha512-ZHLmWMJ9jJ9PTiT58juykZpL7KjwJywFN3Rr2pTSkyQfydf/rk22yS7W8p5DaVUMQ2BQC7oYiU3FjbTM/mYrOA==", + "dev": true, + "requires": { + "jest-diff": "^26.0.0", + "pretty-format": "^26.0.0" + } + }, "@types/node": { "version": "14.14.25", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.25.tgz", diff --git a/package.json b/package.json index b373c33..f13aef6 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,11 @@ "random": "^3.0.6" }, "devDependencies": { + "@types/jest": "^26.0.23", "jest": "^26.6.3" + }, + "jest": { + "collectCoverage": true, + "collectCoverageFrom": ["**/*.{js,jsx}", "!**/node_modules/**", "!**/vendor/**"] } }