Adding scrape files for testing

This commit is contained in:
Max committed 2026-11-03 11:20:03 -07:00
1 parent 7d255fe687
commit 8d60aae65c
40 files changed
+4423

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
//
// Socket.IO emit wrapper.
//
// Replaces the `if(typeof SocketIo != 'undefined')` guards that were scattered
// through the models. Those guards did not just avoid a crash - they silently
// disabled ALL scraping under Jest, which is why none of this code was ever
// testable. Here the no-socket case is a no-op rather than a skipped branch, so
// the surrounding logic runs identically in tests and in production.
//
let Realtime = module.exports = {}
let warned = false
const server = () => (typeof global.SocketIo !== 'undefined' && global.SocketIo) ? global.SocketIo : null
Realtime.isEnabled = () => server() !== null
const emit = (room, event, payload) => {
const io = server()
if (!io) {
if (!warned) {
warned = true
console.log('[realtime] no socket server bound; emits are no-ops')
}
return false
}
try {
if (payload === undefined) { io.to(room).emit(event) }
else { io.to(room).emit(event, payload) }
return true
} catch (error) {
console.log('[realtime] emit failed', event, error.message)
return false
}
}
Realtime.emitToUser = (userId, event, payload) => emit(`user:${userId}`, event, payload)
Realtime.emitToNote = (noteRawTextId, event, payload) => emit(`note:${noteRawTextId}`, event, payload)
Realtime.__resetWarning = () => { warned = false }