Files
Tracearr/apps/server/src/jobs/poller/__tests__/violations.test.ts
Rephl3x 3015f48118
Some checks failed
CI / Lint & Typecheck (push) Has been cancelled
CI / Test (routes) (push) Has been cancelled
CI / Test (security) (push) Has been cancelled
CI / Test (services) (push) Has been cancelled
CI / Test (unit) (push) Has been cancelled
CI / Test (integration) (push) Has been cancelled
CI / Test Coverage (push) Has been cancelled
CI / Build (push) Has been cancelled
Initial Upload
2025-12-17 12:32:50 +13:00

49 lines
1.6 KiB
TypeScript

/**
* Violations Module Tests
*
* Tests rule/violation functions from poller/violations.ts:
* - getTrustScorePenalty: Map violation severity to trust score penalty
* - doesRuleApplyToUser: Check if a rule applies to a specific user
*/
import { describe, it, expect } from 'vitest';
import { randomUUID } from 'node:crypto';
import { getTrustScorePenalty, doesRuleApplyToUser } from '../violations.js';
describe('getTrustScorePenalty', () => {
describe('severity mapping', () => {
it('should return 20 for HIGH severity', () => {
expect(getTrustScorePenalty('high')).toBe(20);
});
it('should return 10 for WARNING severity', () => {
expect(getTrustScorePenalty('warning')).toBe(10);
});
it('should return 5 for LOW severity', () => {
expect(getTrustScorePenalty('low')).toBe(5);
});
});
});
describe('doesRuleApplyToUser', () => {
describe('global rules', () => {
it('should apply global rules (serverUserId=null) to any user', () => {
const globalRule = { serverUserId: null };
expect(doesRuleApplyToUser(globalRule, randomUUID())).toBe(true);
expect(doesRuleApplyToUser(globalRule, randomUUID())).toBe(true);
});
});
describe('user-specific rules', () => {
it('should apply user-specific rule only to that user', () => {
const targetServerUserId = randomUUID();
const otherServerUserId = randomUUID();
const userRule = { serverUserId: targetServerUserId };
expect(doesRuleApplyToUser(userRule, targetServerUserId)).toBe(true);
expect(doesRuleApplyToUser(userRule, otherServerUserId)).toBe(false);
});
});
});