fix the failing tests below. i also added the files FAIL…
- User
fix the failing tests below. i also added the files
FAIL functions/src/submitPlayerName.test.ts > submitPlayerName Function > submits a valid player name Unknown Error: Internal Server Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/3]⎯
FAIL functions/src/submitPlayerName.test.ts > submitPlayerName Function > rejects duplicate player name AssertionError: expected [Function] to throw error including 'Name already taken in this game.' but got 'Internal Server Error'
Expected: "Name already taken in this game." Received: "Internal Server Error"
❯ functions/src/submitPlayerName.test.ts:131:5 129| 130| // Invoke the function and expect it to throw an error 131| await expect(wrapped(data, context)).rejects.toThrow('Name already … | ^ 132| 133| // Ensure Firestore methods were called correctly
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/3]⎯
FAIL functions/src/submitPlayerName.test.ts > submitPlayerName Function > handles internal server errors gracefully AssertionError: expected "spy" to be called at least once ❯ functions/src/submitPlayerName.test.ts:212:27 210| 211| // Ensure Firestore methods were called correctly up to the point o… 212| expect(firestoreMock).toHaveBeenCalled(); | ^ 213| expect(admin.firestore).toHaveBeenCalled(); 214| expect(collectionMock).toHaveBeenCalledWith('players');
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/3]⎯
Test Files 1 failed (1)
// submitPlayerName.test.ts import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import firebaseFunctionsTest from 'firebase-functions-test';
// Declare mock functions using 'let' to allow reassignment let setMock: ReturnType; let getMock: ReturnType; let docMock: ReturnType; let whereMock: ReturnType; let collectionMock: ReturnType; let firestoreMock: ReturnType;
// Initialize mock functions before each test beforeEach(() => { setMock = vi.fn().mockResolvedValue(undefined); getMock = vi.fn(); docMock = vi.fn(() => ({ id: 'newPlayerId', set: setMock, })); // Mock 'where' to return the same mock to allow chaining whereMock = vi.fn().mockReturnThis(); collectionMock = vi.fn(() => ({ where: whereMock, doc: docMock, })); // Mock Firestore including FieldValue firestoreMock = vi.fn(() => ({ collection: collectionMock, FieldValue: { serverTimestamp: vi.fn(() => new Date()), }, })); });
describe('submitPlayerName Function', () => { let testEnv: any;
beforeEach(() => { // Reset all mocks before each test to ensure isolation vi.resetAllMocks();
// Mock 'firebase-admin' module using vi.doMock inside beforeEach vi.doMock('firebase-admin', () => ({ initializeApp: vi.fn(), firestore: firestoreMock, })); // Initialize firebase-functions-test testEnv = firebaseFunctionsTest(); - Assistant