test: aggiunge copertura completa per le nuove funzionalità

- Nuovo db.test.js: 11 test per salvaPartita, getPartite, getPartita
  (isolamento con DB in memoria via vi.stubEnv + vi.resetModules)
- gameState.test.js: test per confermaSet, formInizioSet, partitaFinita,
  checkVittoriaPartita e guardie setFinito/partitaFinita; fix di 6 test
  pre-esistenti non allineati con la logica striscia aggiornata
- websocket.test.js: mock di db.js e 4 test per il salvataggio automatico
  su DB al termine della partita
- server-utils.test.js: 2 test aggiuntivi per storicoPort
- ControllerPage.test.js: 4 test per l'overlay di fine set (setFinito)
- DisplayPage.test.js: 4 test per l'overlay di fine partita (partitaFinita)
This commit is contained in:
2026-02-21 18:59:50 +01:00
parent 1df239ed3d
commit b3faf06477
6 changed files with 590 additions and 11 deletions

View File

@@ -109,6 +109,7 @@ describe('Server Utils', () => {
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
expect(allLogs).toContain('5173')
expect(allLogs).toContain('3001')
expect(allLogs).toContain('3002')
consoleSpy.mockRestore()
})
@@ -122,17 +123,27 @@ describe('Server Utils', () => {
consoleSpy.mockRestore()
})
it('dovrebbe mostrare gli URL remoti se ci sono IP di rete', () => {
it('dovrebbe stampare storicoPort personalizzato', () => {
os.networkInterfaces.mockReturnValue({})
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
printServerInfo(3000, 3001, 5000)
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
expect(allLogs).toContain('5000')
consoleSpy.mockRestore()
})
it('dovrebbe mostrare gli URL remoti per controller e storico', () => {
os.networkInterfaces.mockReturnValue({
eth0: [
{ family: 'IPv4', internal: false, address: '192.168.1.50' }
]
})
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
printServerInfo(3000, 3001)
printServerInfo(3000, 3001, 3002)
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
expect(allLogs).toContain('192.168.1.50')
expect(allLogs).toContain('remoti')
expect(allLogs).toContain('3001')
expect(allLogs).toContain('3002')
consoleSpy.mockRestore()
})