fix issues
This commit is contained in:
@@ -7,6 +7,7 @@ import { UserRating } from '../../domain/value-objects/UserRating';
|
||||
import { RatingEventId } from '../../domain/value-objects/RatingEventId';
|
||||
import { RatingDimensionKey } from '../../domain/value-objects/RatingDimensionKey';
|
||||
import { RatingDelta } from '../../domain/value-objects/RatingDelta';
|
||||
import { RatingSnapshotCalculator } from '../../domain/services/RatingSnapshotCalculator';
|
||||
|
||||
// Mock Repository
|
||||
class MockAdminVoteSessionRepository {
|
||||
@@ -169,16 +170,8 @@ class MockAppendRatingEventsUseCase {
|
||||
// Recompute snapshot
|
||||
if (events.length > 0) {
|
||||
const allEvents = await this.ratingEventRepository.getAllByUserId(input.userId);
|
||||
// Simplified snapshot calculation
|
||||
const totalDelta = allEvents.reduce((sum, e) => sum + e.delta.value, 0);
|
||||
const snapshot = UserRating.create({
|
||||
userId: input.userId,
|
||||
driver: { value: Math.max(0, Math.min(100, 50 + totalDelta)) },
|
||||
adminTrust: { value: 50 },
|
||||
stewardTrust: { value: 50 },
|
||||
broadcasterTrust: { value: 50 },
|
||||
lastUpdated: new Date(),
|
||||
});
|
||||
// Use RatingSnapshotCalculator to create proper snapshot
|
||||
const snapshot = RatingSnapshotCalculator.calculate(input.userId, allEvents);
|
||||
await this.userRatingRepository.save(snapshot);
|
||||
}
|
||||
|
||||
@@ -199,10 +192,10 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
let castUseCase: CastAdminVoteUseCase;
|
||||
let closeUseCase: CloseAdminVoteSessionUseCase;
|
||||
|
||||
const now = new Date('2025-01-01T00:00:00Z');
|
||||
const tomorrow = new Date('2025-01-02T00:00:00Z');
|
||||
|
||||
let originalDateNow: () => number;
|
||||
// Use dates relative to current time so close() works
|
||||
const now = new Date(Date.now() - 86400000); // Yesterday
|
||||
const tomorrow = new Date(Date.now() + 86400000); // Tomorrow
|
||||
const dayAfter = new Date(Date.now() + 86400000 * 2); // Day after tomorrow
|
||||
|
||||
beforeEach(() => {
|
||||
mockSessionRepo = new MockAdminVoteSessionRepository();
|
||||
@@ -218,14 +211,6 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
mockRatingRepo,
|
||||
mockAppendUseCase
|
||||
);
|
||||
|
||||
// Mock Date.now to return our test time
|
||||
originalDateNow = Date.now;
|
||||
Date.now = (() => now.getTime()) as any;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
Date.now = originalDateNow;
|
||||
});
|
||||
|
||||
describe('OpenAdminVoteSessionUseCase', () => {
|
||||
@@ -279,13 +264,16 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
eligibleVoters: ['user-1'],
|
||||
});
|
||||
|
||||
// Try to create overlapping session
|
||||
// Try to create overlapping session (middle of first session)
|
||||
const overlapStart = new Date(now.getTime() + 12 * 3600000); // 12 hours after start
|
||||
const overlapEnd = new Date(tomorrow.getTime() + 12 * 3600000); // 12 hours after end
|
||||
|
||||
const result = await openUseCase.execute({
|
||||
voteSessionId: 'vote-456',
|
||||
leagueId: 'league-456',
|
||||
adminId: 'admin-789',
|
||||
startDate: new Date('2025-01-01T12:00:00Z').toISOString(),
|
||||
endDate: new Date('2025-01-02T12:00:00Z').toISOString(),
|
||||
startDate: overlapStart.toISOString(),
|
||||
endDate: overlapEnd.toISOString(),
|
||||
eligibleVoters: ['user-1'],
|
||||
});
|
||||
|
||||
@@ -385,7 +373,7 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.errors).toContain('Voter user-999 is not eligible for this session');
|
||||
expect(result.errors).toContain('Failed to cast vote: Voter user-999 is not eligible for this session');
|
||||
});
|
||||
|
||||
it('should prevent duplicate votes', async () => {
|
||||
@@ -402,7 +390,7 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.errors).toContain('Voter user-1 has already voted');
|
||||
expect(result.errors).toContain('Failed to cast vote: Voter user-1 has already voted');
|
||||
});
|
||||
|
||||
it('should reject votes after session closes', async () => {
|
||||
@@ -419,13 +407,13 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.errors).toContain('Session is closed');
|
||||
expect(result.errors).toContain('Vote session is not open for voting');
|
||||
});
|
||||
|
||||
it('should reject votes outside voting window', async () => {
|
||||
// Create session in future
|
||||
const futureStart = new Date('2025-02-01T00:00:00Z');
|
||||
const futureEnd = new Date('2025-02-02T00:00:00Z');
|
||||
// Create session in future (outside current window)
|
||||
const futureStart = new Date(Date.now() + 86400000 * 10); // 10 days from now
|
||||
const futureEnd = new Date(Date.now() + 86400000 * 11); // 11 days from now
|
||||
|
||||
await openUseCase.execute({
|
||||
voteSessionId: 'vote-future',
|
||||
@@ -595,9 +583,9 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
});
|
||||
|
||||
it('should reject closing outside voting window', async () => {
|
||||
// Create session in future
|
||||
const futureStart = new Date('2025-02-01T00:00:00Z');
|
||||
const futureEnd = new Date('2025-02-02T00:00:00Z');
|
||||
// Create session in future (outside current window)
|
||||
const futureStart = new Date(Date.now() + 86400000 * 10); // 10 days from now
|
||||
const futureEnd = new Date(Date.now() + 86400000 * 11); // 11 days from now
|
||||
|
||||
await openUseCase.execute({
|
||||
voteSessionId: 'vote-future',
|
||||
@@ -638,7 +626,7 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
// Check snapshot was updated
|
||||
const snapshot = await mockRatingRepo.findByUserId('admin-789');
|
||||
expect(snapshot).toBeDefined();
|
||||
expect(snapshot!.adminTrust.value).toBeGreaterThan(50); // Should have increased
|
||||
expect(snapshot!.admin.value).toBeGreaterThan(50); // Should have increased
|
||||
});
|
||||
});
|
||||
|
||||
@@ -704,7 +692,7 @@ describe('Admin Vote Session Use Cases', () => {
|
||||
// 5. Verify snapshot
|
||||
const snapshot = await mockRatingRepo.findByUserId('admin-full');
|
||||
expect(snapshot).toBeDefined();
|
||||
expect(snapshot!.adminTrust.value).toBeGreaterThan(50);
|
||||
expect(snapshot!.admin.value).toBeGreaterThan(50);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user