Initial Upload
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
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
This commit is contained in:
48
apps/server/src/jobs/poller/__tests__/violations.test.ts
Normal file
48
apps/server/src/jobs/poller/__tests__/violations.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user