Compare commits

...

3 commits

Author SHA1 Message Date
2a1e691d62
fix time splitter when multiples options occurs
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 11s
2024-09-27 14:36:17 +02:00
884b53b8b2
fix test 2024-09-27 14:36:05 +02:00
99b3722ed3
ci 2024-09-27 14:34:30 +02:00
3 changed files with 18 additions and 8 deletions

View file

@ -23,4 +23,4 @@ jobs:
run: npm run format-check run: npm run format-check
- name: Run tests - name: Run tests
run: npm run test run: npm run test -- --ci --onlyChanged

View file

@ -46,13 +46,23 @@ export type dbReminder = {
* @returns An object with the time and the option * @returns An object with the time and the option
*/ */
export const splitTime = (time: string) => { export const splitTime = (time: string) => {
if (time?.endsWith("@")) { const mapping = {
return { time: time.slice(0, -1), option: OptionReminder.Mention }; [OptionReminder.DirectMessage]: "p",
} else if (time?.toLowerCase().endsWith("p")) { [OptionReminder.Mention]: "@",
return { time: time.slice(0, -1), option: OptionReminder.DirectMessage }; };
}
const lowered = time.toLowerCase();
const trimmed = lowered.replaceAll(new RegExp(Object.values(mapping).join("|"), "g"), "");
// Depending of the last character of the string
switch (lowered.slice(-1)) {
case mapping[OptionReminder.Mention]:
return { time: trimmed, option: OptionReminder.Mention };
case mapping[OptionReminder.DirectMessage]:
return { time: trimmed, option: OptionReminder.DirectMessage };
default:
return { time: time, option: OptionReminder.Nothing }; return { time: time, option: OptionReminder.Nothing };
}
}; };
/** /**

View file

@ -10,7 +10,7 @@ describe("Time splitter", () => {
{ {
const name = "2m@p"; const name = "2m@p";
test(name, () => { test(name, () => {
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.Mention, time: "2m" }); expect(splitTime(name)).toStrictEqual({ option: OptionReminder.DirectMessage, time: "2m" });
}); });
} }
{ {