feat(db): add pure isBanActive predicate matching Laravel ban filtering
This commit is contained in:
1 parent
5369f99b07
commit
3e3776b477
2 files changed
+27
No files matched your search
@@ -0,0 +1,22 @@
|
|||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { isBanActive } from "./is-ban-active.js";
|
||||||
|
|
||||||
|
describe("isBanActive", () => {
|
||||||
|
const now = 1_700_000_000; // fixed unix seconds
|
||||||
|
|
||||||
|
it("is active when ban_expire is in the future", () => {
|
||||||
|
expect(isBanActive({ banExpire: now + 100 }, now)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is inactive when ban_expire is in the past", () => {
|
||||||
|
expect(isBanActive({ banExpire: now - 100 }, now)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is inactive when ban_expire equals now (Laravel uses strict >)", () => {
|
||||||
|
expect(isBanActive({ banExpire: now }, now)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is inactive for the default 0 expiry", () => {
|
||||||
|
expect(isBanActive({ banExpire: 0 }, now)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// Mirrors Laravel's active-ban query: where('ban_expire', '>', time()).
|
||||||
|
// ban_expire and now are both unix timestamps in seconds.
|
||||||
|
export function isBanActive(ban: { banExpire: number }, nowUnixSeconds: number): boolean {
|
||||||
|
return ban.banExpire > nowUnixSeconds;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user