Compare commits

...

5 commits

Author SHA1 Message Date
425266eed9 Fix lint
All checks were successful
Test / build (push) Successful in 11s
2024-07-26 18:30:21 +01:00
a718011640 Add tests to check if all events are registered 2024-07-26 18:30:21 +01:00
a7b9a3a463 Create unit test plan 2024-07-26 18:30:21 +01:00
097b7284e6 Fix list not being sorted (#320)
All checks were successful
Deploy To Stage / build (push) Successful in 9s
Deploy To Stage / deploy (push) Successful in 17s
- Fix list on `/allbalance` command not being sorted by currency

#260

Reviewed-on: #320
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-07-26 18:29:57 +01:00
fef80709ee Resolve ws to ^8.17.1 (#319)
All checks were successful
Deploy To Stage / build (push) Successful in 10s
Deploy To Stage / deploy (push) Successful in 17s
- Upgrade ws to ^8.17.1 to fix vulnerability

#269

Reviewed-on: #319
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-07-26 18:28:32 +01:00
4 changed files with 77 additions and 10 deletions

View file

@ -7,7 +7,7 @@
"clean": "rm -rf node_modules/ dist/", "clean": "rm -rf node_modules/ dist/",
"build": "tsc", "build": "tsc",
"start": "node ./dist/bot.js", "start": "node ./dist/bot.js",
"test": "jest --passWithNoTests", "test": "jest",
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix", "lint:fix": "eslint . --fix",
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js", "db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
@ -15,11 +15,11 @@
"db:create": "typeorm migration:create ./src/database/migrations/app/new", "db:create": "typeorm migration:create ./src/database/migrations/app/new",
"release": "np --no-publish" "release": "np --no-publish"
}, },
"repository": "https://gitea.vylpes.xyz/External/card-drop.git", "repository": "https://git.vylpes.xyz/External/card-drop.git",
"author": "Ethan Lane <ethan@vylpes.com>", "author": "Ethan Lane <ethan@vylpes.com>",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https//gitea.vylpes.xyz/External/card-drop/issues", "url": "https//git.vylpes.xyz/External/card-drop/issues",
"email": "helpdesk@vylpes.com" "email": "helpdesk@vylpes.com"
}, },
"homepage": "https://gitea.vylpes.xyz/External/card-drop", "homepage": "https://gitea.vylpes.xyz/External/card-drop",
@ -49,8 +49,8 @@
"winston-daily-rotate-file": "^5.0.0", "winston-daily-rotate-file": "^5.0.0",
"winston-discord-transport": "^1.3.0" "winston-discord-transport": "^1.3.0"
}, },
"overrides": { "resolutions": {
"undici": "^5.28.3" "**/ws": "^8.17.1"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20.0.0", "@types/node": "^20.0.0",

View file

@ -16,7 +16,8 @@ export default class AllBalance extends Command {
public override async execute(interaction: CommandInteraction) { public override async execute(interaction: CommandInteraction) {
const users = await User.FetchAll(User); const users = await User.FetchAll(User);
const filteredUsers = users.filter(x => x.Currency > 0); const filteredUsers = users.filter(x => x.Currency > 0)
.sort((a, b) => b.Currency - a.Currency);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)

66
tests/registry.test.ts Normal file
View file

@ -0,0 +1,66 @@
import {CoreClient} from "../src/client/client";
import Registry from "../src/registry";
import fs from "fs";
import path from "path";
describe("RegisterCommands", () => {
test("EXPECT every command in the commands folder to be registered", () => {
const registeredCommands: string[] = [];
CoreClient.RegisterCommand = jest.fn().mockImplementation((name: string) => {
registeredCommands.push(name);
});
Registry.RegisterCommands();
const commandFiles = getFilesInDirectory(path.join(process.cwd(), "src", "commands"))
.filter(x => x.endsWith(".ts"));
for (const file of commandFiles) {
expect(registeredCommands).toContain(file.split("/").pop()!.split(".")[0]);
}
expect(commandFiles.length).toBe(registeredCommands.length);
});
});
describe("RegisterButtonEvents", () => {
test("EXEPCT every button event in the button events folder to be registered", () => {
const registeredButtonEvents: string[] = [];
CoreClient.RegisterButtonEvent = jest.fn().mockImplementation((name: string) => {
registeredButtonEvents.push(name);
});
Registry.RegisterButtonEvents();
const eventFiles = getFilesInDirectory(path.join(process.cwd(), "src", "buttonEvents"))
.filter(x => x.endsWith(".ts"));
for (const file of eventFiles) {
expect(registeredButtonEvents).toContain(file.split("/").pop()!.split(".")[0].toLowerCase());
}
expect(eventFiles.length).toBe(registeredButtonEvents.length);
});
});
function getFilesInDirectory(dir: string): string[] {
let results: string[] = [];
const list = fs.readdirSync(dir);
list.forEach(file => {
file = path.join(dir, file);
const stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
/* recurse into a subdirectory */
results = results.concat(getFilesInDirectory(file));
} else {
/* is a file */
results.push(file);
}
});
return results;
}

View file

@ -6838,10 +6838,10 @@ write-file-atomic@^4.0.2:
imurmurhash "^0.1.4" imurmurhash "^0.1.4"
signal-exit "^3.0.7" signal-exit "^3.0.7"
ws@^8.16.0: ws@^8.16.0, ws@^8.17.1:
version "8.17.0" version "8.18.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.0.tgz#d145d18eca2ed25aaf791a183903f7be5e295fea" resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc"
integrity sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow== integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==
xdg-basedir@^5.0.1, xdg-basedir@^5.1.0: xdg-basedir@^5.0.1, xdg-basedir@^5.1.0:
version "5.1.0" version "5.1.0"