Skip to content

Commit aedce04

Browse files
authored
test: add justask regex unit tests (#49)
* πŸ€– ci: add REGULAR_ROLE_ID to env.test * πŸ› fix: update regex for subject patterns and export isAskingToAsk function * 🚨 test: add unit tests for just ask regex detection * 🚨 test: refractor justask test to use multiple `it` for each testcase
1 parent ba98b1b commit aedce04

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

β€Ž.env.testβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ REPEL_LOG_CHANNEL_ID=your-repel-log-channel-id
2020
# Role IDs (from your dev server)
2121
REPEL_ROLE_ID=your-repel-role-id
2222
MODERATORS_ROLE_IDS=your-moderator-role-id
23+
REGULAR_ROLE_ID=your-regular-role-id
2324

2425
# Other
2526
GUIDES_TRACKER_PATH=guides-tracker.json

β€Žsrc/events/just-ask.test.tsβ€Ž

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import assert from 'node:assert';
2+
import { describe, it } from 'node:test';
3+
import { isAskingToAsk } from './just-ask.js';
4+
5+
describe('justAsk Regex', () => {
6+
const testCases = [
7+
{ input: 'Anyone knows js?', expected: true },
8+
{ input: 'Somebody can help with Python?', expected: true },
9+
{ input: 'No one has experience with js?', expected: true },
10+
{ input: 'Everybody tried React?', expected: true },
11+
{ input: 'People familiar with Kubernetes?', expected: true },
12+
13+
{ input: 'I know js well.', expected: false },
14+
{ input: 'This is a question without the pattern.', expected: false },
15+
];
16+
testCases.forEach(({ input, expected }) => {
17+
it(`should return ${expected} for input: "${input}"`, () => {
18+
const result = isAskingToAsk(input);
19+
assert.strictEqual(result, expected);
20+
});
21+
});
22+
});

β€Žsrc/events/just-ask.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { loadMarkdownOptions } from '../util/markdown.js';
66
import { rateLimit } from '../util/rate-limit.js';
77

88
// Subject patterns (who)
9-
const reSubject = `(?:(?:any|some|no|every)(?:one|body)|people|folks|peeps|who)`;
9+
const reSubject = `(?:(?:any|some|no|every)(?: ?(?:one|body))|people|folks|peeps|who)`;
1010

1111
// Verb patterns (has/knows/can help/etc)
1212
const reVerb = `(?:ha[sv]e?|got|knows?|can(?: help)?|tried|used|worked(?: with)?|familiar(?: with)?|experience[ds]?(?: with)?|heard(?: of)?|seen)`;
@@ -25,7 +25,7 @@ const askToAskPattern = new RegExp(
2525
'i'
2626
);
2727

28-
const isAskingToAsk = (text: string) => askToAskPattern.test(text);
28+
export const isAskingToAsk = (text: string) => askToAskPattern.test(text);
2929

3030
const [response] = await loadMarkdownOptions<{ name: string }>(
3131
new URL('../commands/tips/subjects/', import.meta.url),

0 commit comments

Comments
Β (0)