Compare commits

...

3 commits

Author SHA1 Message Date
4ca13712ed
Add test for calculateReloaded
All checks were successful
discord bot tests / discord bot tests (push) Successful in 10s
2024-10-22 11:52:29 +02:00
000f7e969c
Add @types/jest as a devDependency
All checks were successful
discord bot tests / discord bot tests (push) Successful in 10s
2024-10-22 11:51:12 +02:00
10934bb04f
Tests: Start implementing tests
All checks were successful
discord bot tests / discord bot tests (push) Successful in 10s
Only convertDateToISOString for now
2024-10-22 11:49:17 +02:00
5 changed files with 3710 additions and 124 deletions

18
.github/workflows/run_node_tests.yml vendored Normal file
View file

@ -0,0 +1,18 @@
name: discord bot tests
on: [push]
jobs:
discord_bot_tests:
runs-on: node
name: discord bot tests
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 'latest'
- name: install dependencies
run: npm install
- name: run tests
run: npm test

3770
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -15,12 +15,16 @@
"valid-url": "^1.0.9" "valid-url": "^1.0.9"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "jest"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/SileNce5k/discord_bot.git" "url": "git+https://github.com/SileNce5k/discord_bot.git"
}, },
"author": "SileNce5k", "author": "SileNce5k",
"license": "UNLICENSE" "license": "UNLICENSE",
"devDependencies": {
"@types/jest": "^29.5.13",
"jest": "^29.7.0"
}
} }

View file

@ -0,0 +1,26 @@
const calculateReloaded = require('../util/calculateReloaded')
let client = {commands: new Map()};
for(let i = 0; i < 10; i++){
client.commands.set(i, i * 420);
}
let beforeSizes = [0, 12, 10, 9, 11, 6, 104];
let expectedResults = [
`10 modules were added, and a total of 10 were reloaded.`,
`10 modules were reloaded after 2 were disabled.`,
`10 modules were reloaded.`,
`1 module was added, and a total of 10 were reloaded.`,
`10 modules were reloaded after 1 module was deleted.`,
`4 modules were added, and a total of 10 were reloaded.`,
`10 modules were reloaded after 94 were disabled.`
]
if(beforeSizes.length != expectedResults.length) throw "Error: beforeSizes and expectedResults are unequal length"
for(let i = 0; i < beforeSizes.length; i++){
test('calculateReloaded test', () => {
expect(calculateReloaded(beforeSizes[i], client)).toBe(expectedResults[i])
});
}

View file

@ -0,0 +1,12 @@
const convertDateToISOString = require('../util/convertDateToISOString');
let dates = [new Date("2020-01-01"), new Date(0), new Date(5600000), new Date(1000200000000)]
let expectedDateStrings = ["2020-01-01 00:00:00", "1970-01-01 00:00:00", "1970-01-01 01:33:20", "2001-09-11 09:20:00"]
for (let i = 0; i < dates.length; i++) {
test('Converts to human readable date string', () => {
expect(convertDateToISOString(dates[i])).toBe(expectedDateStrings[i]);
});
}