const WebSocket = require('ws')

const WS_URL = 'ws://localhost:8080/api/ws/notify'
const token = 'mock-token-mp-21'

const ws = new WebSocket(`${WS_URL}?token=${encodeURIComponent(token)}`)

ws.on('open', () => {
  console.log('Connected')
  ws.send(JSON.stringify({ type: 'ping' }))
})

ws.on('message', (data) => {
  console.log('Received:', data.toString())
})

ws.on('error', (err) => {
  console.error('Error:', err.message)
})

ws.on('close', () => {
  console.log('Closed')
})

setTimeout(() => {
  ws.close()
  process.exit(0)
}, 5000)
