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 mockSet = mock();
|
||||||
const mockWhere = mock();
|
const mockWhere = mock();
|
||||||
const mockOnConflictDoUpdate = mock();
|
const mockOnConflictDoUpdate = mock();
|
||||||
const mockRecordEvent = mock(() => Promise.resolve());
|
|
||||||
|
|
||||||
// Chain setup
|
// Chain setup
|
||||||
mockInsert.mockReturnValue({ values: mockValues });
|
mockInsert.mockReturnValue({ values: mockValues });
|
||||||
mockValues.mockReturnValue({
|
mockValues.mockReturnValue({
|
||||||
@@ -69,10 +67,17 @@ mock.module("@shared/lib/config", () => ({
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock Dashboard Service
|
// Mock Events (trivia service emits domain events instead of calling dashboardService directly)
|
||||||
mock.module("@shared/modules/dashboard/dashboard.service", () => ({
|
const mockEmit = mock(() => true);
|
||||||
dashboardService: {
|
mock.module("@shared/lib/events", () => ({
|
||||||
recordEvent: mockRecordEvent
|
systemEvents: {
|
||||||
|
emit: mockEmit,
|
||||||
|
},
|
||||||
|
EVENTS: {
|
||||||
|
DOMAIN: {
|
||||||
|
TRIVIA_STARTED: "domain:trivia_started",
|
||||||
|
TRIVIA_WON: "domain:trivia_won",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -109,7 +114,7 @@ describe("TriviaService", () => {
|
|||||||
mockSet.mockClear();
|
mockSet.mockClear();
|
||||||
mockWhere.mockClear();
|
mockWhere.mockClear();
|
||||||
mockOnConflictDoUpdate.mockClear();
|
mockOnConflictDoUpdate.mockClear();
|
||||||
mockRecordEvent.mockClear();
|
mockEmit.mockClear();
|
||||||
// Clear active sessions
|
// Clear active sessions
|
||||||
(triviaService as any).activeSessions.clear();
|
(triviaService as any).activeSessions.clear();
|
||||||
});
|
});
|
||||||
@@ -176,8 +181,8 @@ describe("TriviaService", () => {
|
|||||||
expect(mockInsert).toHaveBeenCalledWith(userTimers);
|
expect(mockInsert).toHaveBeenCalledWith(userTimers);
|
||||||
expect(mockOnConflictDoUpdate).toHaveBeenCalled();
|
expect(mockOnConflictDoUpdate).toHaveBeenCalled();
|
||||||
|
|
||||||
// Check dashboard event
|
// Check domain event emitted
|
||||||
expect(mockRecordEvent).toHaveBeenCalled();
|
expect(mockEmit).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw error if user has insufficient balance", async () => {
|
it("should throw error if user has insufficient balance", async () => {
|
||||||
@@ -219,7 +224,7 @@ describe("TriviaService", () => {
|
|||||||
// Verify balance update
|
// Verify balance update
|
||||||
expect(mockUpdate).toHaveBeenCalledWith(users);
|
expect(mockUpdate).toHaveBeenCalledWith(users);
|
||||||
expect(mockInsert).toHaveBeenCalledWith(transactions);
|
expect(mockInsert).toHaveBeenCalledWith(transactions);
|
||||||
expect(mockRecordEvent).toHaveBeenCalled();
|
expect(mockEmit).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not award prize for incorrect answer", async () => {
|
it("should not award prize for incorrect answer", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user