import { describe, it, expect, vi, afterEach } from 'vitest'
import { setWsSend, wsSend } from '@/composables/wsBridge.js'
afterEach(() => {
setWsSend(null)
})
describe('wsBridge', () => {
it('refuses when no socket has registered', () => {
expect(wsSend({ type: 'ping' })).toBe(false)
})
it('passes the payload to the registered send', () => {
const send = vi.fn()
setWsSend(send)
expect(wsSend({ type: 'ping' })).toBe(true)
expect(send).toHaveBeenCalledWith({ type: 'ping' })
})
it('refuses again once the socket is gone', () => {
setWsSend(vi.fn())
setWsSend(null)
expect(wsSend({ type: 'ping' })).toBe(false)
})
})