fix: update trivia test to mock events instead of dashboardService
All checks were successful
Deploy to Production / test (push) Successful in 38s
All checks were successful
Deploy to Production / test (push) Successful in 38s
The trivia service now emits domain events via systemEvents instead of directly calling dashboardService.recordEvent. Updated the test mock and assertions to match. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,8 +14,6 @@ const mockReturning = mock();
|
||||
const mockSet = mock();
|
||||
const mockWhere = mock();
|
||||
const mockOnConflictDoUpdate = mock();
|
||||
const mockRecordEvent = mock(() => Promise.resolve());
|
||||
|
||||
// Chain setup
|
||||
mockInsert.mockReturnValue({ values: mockValues });
|
||||
mockValues.mockReturnValue({
|
||||
@@ -69,10 +67,17 @@ mock.module("@shared/lib/config", () => ({
|
||||
}
|
||||
}));
|
||||
|
||||
// Mock Dashboard Service
|
||||
mock.module("@shared/modules/dashboard/dashboard.service", () => ({
|
||||
dashboardService: {
|
||||
recordEvent: mockRecordEvent
|
||||
// Mock Events (trivia service emits domain events instead of calling dashboardService directly)
|
||||
const mockEmit = mock(() => true);
|
||||
mock.module("@shared/lib/events", () => ({
|
||||
systemEvents: {
|
||||
emit: mockEmit,
|
||||
},
|
||||
EVENTS: {
|
||||
DOMAIN: {
|
||||
TRIVIA_STARTED: "domain:trivia_started",
|
||||
TRIVIA_WON: "domain:trivia_won",
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -109,7 +114,7 @@ describe("TriviaService", () => {
|
||||
mockSet.mockClear();
|
||||
mockWhere.mockClear();
|
||||
mockOnConflictDoUpdate.mockClear();
|
||||
mockRecordEvent.mockClear();
|
||||
mockEmit.mockClear();
|
||||
// Clear active sessions
|
||||
(triviaService as any).activeSessions.clear();
|
||||
});
|
||||
@@ -176,8 +181,8 @@ describe("TriviaService", () => {
|
||||
expect(mockInsert).toHaveBeenCalledWith(userTimers);
|
||||
expect(mockOnConflictDoUpdate).toHaveBeenCalled();
|
||||
|
||||
// Check dashboard event
|
||||
expect(mockRecordEvent).toHaveBeenCalled();
|
||||
// Check domain event emitted
|
||||
expect(mockEmit).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throw error if user has insufficient balance", async () => {
|
||||
@@ -219,7 +224,7 @@ describe("TriviaService", () => {
|
||||
// Verify balance update
|
||||
expect(mockUpdate).toHaveBeenCalledWith(users);
|
||||
expect(mockInsert).toHaveBeenCalledWith(transactions);
|
||||
expect(mockRecordEvent).toHaveBeenCalled();
|
||||
expect(mockEmit).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not award prize for incorrect answer", async () => {
|
||||
|
||||
Reference in New Issue
Block a user