test(bot): implement tests on the regex filter using jest
This commit is contained in:
parent
f294a751dc
commit
cda89f824e
11
jest.config.js
Normal file
11
jest.config.js
Normal file
@ -0,0 +1,11 @@
|
||||
/** @type {import('ts-jest').JestConfigWithTsJest} **/
|
||||
module.exports = {
|
||||
testEnvironment: "node",
|
||||
transform: {
|
||||
"^.+\.tsx?$": ["ts-jest",{}],
|
||||
},
|
||||
testPathIgnorePatterns: [
|
||||
"node_modules/",
|
||||
"generated/"
|
||||
]
|
||||
};
|
@ -3,6 +3,7 @@
|
||||
"version": "0.1.5",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"start": "node ./dist/app.js",
|
||||
"dryrun": "npx ts-node -r tsconfig-paths/register ./src/app.ts",
|
||||
"dev": "npm run build:client && npm run dryrun",
|
||||
@ -30,6 +31,7 @@
|
||||
"@types/dropzone": "^5.7.9",
|
||||
"@types/ejs": "^3.1.5",
|
||||
"@types/express": "^5.0.1",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/jquery": "^3.5.32",
|
||||
"@types/lodash": "^4.17.16",
|
||||
"@types/node": "^22.14.1",
|
||||
@ -37,6 +39,7 @@
|
||||
"autoprefixer": "^10.4.21",
|
||||
"esbuild": "^0.25.2",
|
||||
"fast-glob": "^3.3.3",
|
||||
"jest": "^29.7.0",
|
||||
"nodemon": "^3.1.9",
|
||||
"postcss": "^8.5.3",
|
||||
"postcss-cli": "^11.0.1",
|
||||
@ -44,6 +47,7 @@
|
||||
"prisma": "^6.6.0",
|
||||
"standard-version": "^9.5.0",
|
||||
"tailwindcss": "^4.1.4",
|
||||
"ts-jest": "^29.3.2",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsc-alias": "^1.8.15",
|
||||
"typescript": "^5.8.3"
|
||||
|
70
src/bot/__tests__/filters.test.ts
Normal file
70
src/bot/__tests__/filters.test.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import * as filters from "../filter";
|
||||
import prisma, { MatchingAlgorithms } from "../../../generated/prisma";
|
||||
|
||||
const templateFilter: prisma.Filter = {
|
||||
id: 0,
|
||||
guild_id: "",
|
||||
name: "",
|
||||
value: "",
|
||||
matching_algorithm: MatchingAlgorithms.ALL,
|
||||
is_insensitive: false,
|
||||
is_whitelist: false,
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
|
||||
};
|
||||
|
||||
describe("Regex Matching Test", () => {
|
||||
const filter: prisma.Filter = {
|
||||
...templateFilter,
|
||||
name: "Block American Politics",
|
||||
value: String.raw`\b(trump|biden|democrat|republican|gop|dnc|kamala|harris)\b`,
|
||||
is_insensitive: true
|
||||
}
|
||||
|
||||
const testCases: { input: string, expected: boolean }[] = [
|
||||
{
|
||||
input: "Republicans float new tax breaks for tips, local taxes in Trump budget package",
|
||||
expected: true // Contains 'republican' and 'trump'.
|
||||
},
|
||||
{
|
||||
input: "Biden’s Approval Rating Dips Amid Economic Concerns",
|
||||
expected: true // Contains 'biden'.
|
||||
},
|
||||
{
|
||||
input: "GOP Governors Call for Tougher Border Security Measures",
|
||||
expected: true // Contains 'gop'.
|
||||
},
|
||||
{
|
||||
input: "Biden Announces New Initiative to Tackle Climate Change",
|
||||
expected: true // Contains 'biden'.
|
||||
},
|
||||
{
|
||||
input: "Biden Announces New Initiative to Tackle Climate Change",
|
||||
expected: true // Contains 'biden'.
|
||||
},
|
||||
{
|
||||
input: "Joe Biden gives thoughts on Donald Trump, Vladimir Putin, Ukraine, and Kamala Harris in first interview since leaving office",
|
||||
expected: true // Contains 'biden', 'trump', 'kamala' and 'harris'.
|
||||
},
|
||||
{
|
||||
input: "UK Prime Minister Keir Starmer hails limited US-UK trade deal, but 10% duties remain",
|
||||
expected: false
|
||||
},
|
||||
{
|
||||
input: "Scientists discover new species of fish in Pacific Ocean",
|
||||
expected: false
|
||||
},
|
||||
{
|
||||
input: "Federal Reserve signals cautious approach to interest rate cuts in 2025",
|
||||
expected: false
|
||||
}
|
||||
];
|
||||
|
||||
for (const { input, expected } of testCases) {
|
||||
test(`Test input: ${input}`, () => {
|
||||
const result = filters.regex(filter, input);
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
}
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user