Skip to content

Commit c2eead1

Browse files
committed
Set sse event name to micro-analytics-ping
1 parent cd5656a commit c2eead1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/sse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const db = require('./db')
22

33
module.exports = function handleSseConnection(connection) {
44
const subscription = db.subscribe((event) => {
5-
connection.send({ event: 'new-event', data: JSON.stringify(event) })
5+
connection.send({ event: 'micro-analytics-ping', data: JSON.stringify(event) })
66
})
77

88
connection.on('close', function () {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
exports[`sse should publish events with correct structure 1`] = `
2+
Array [
3+
Array [
4+
Object {
5+
"data": "{\"key\":\"superview\",\"value\":{\"views\":[{\"time\":1490432584312}]}}",
6+
"event": "micro-analytics-ping",
7+
},
8+
],
9+
]
10+
`;

tests/sse.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ describe('sse', () => {
2020

2121
expect(sendMock).toHaveBeenCalled()
2222
})
23+
24+
it("should publish events with correct structure", () => {
25+
const sendMock = jest.fn()
26+
const eventListenerMock = jest.fn()
27+
sseHandler({send: sendMock, on: eventListenerMock})
28+
29+
db.put('superview', { views: [{ time: 1490432584312 }] })
30+
31+
expect(sendMock.mock.calls).toMatchSnapshot()
32+
})
2333
})

0 commit comments

Comments
 (0)