-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…s not open bug (#936) * Fix #932 : fix start scene button in scene list * Fix #931 : WebSocket is not open bug * Add tests on Websocket manager
- Loading branch information
1 parent
15c063a
commit cedf198
Showing
3 changed files
with
103 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const EventEmitter = require('events'); | ||
const WebSocket = require('ws'); | ||
const { assert, fake } = require('sinon'); | ||
const WebsocketManager = require('../../api/websockets'); | ||
|
||
describe('Websockets', () => { | ||
it('should send message to all users', () => { | ||
const wss = new EventEmitter(); | ||
const gladys = { | ||
event: new EventEmitter(), | ||
}; | ||
const websocketManager = new WebsocketManager(wss, gladys); | ||
const client = { | ||
readyState: WebSocket.OPEN, | ||
send: fake.returns(0), | ||
}; | ||
const message = { | ||
type: 'test', | ||
payload: 'test', | ||
}; | ||
websocketManager.userConnected({ id: 'aa0eaee9-5b90-4287-841a-0237f9d75832' }, client); | ||
websocketManager.sendMessageAllUsers(message); | ||
assert.calledWith(client.send, JSON.stringify(message)); | ||
}); | ||
it('should not send message to all users', () => { | ||
const wss = new EventEmitter(); | ||
const gladys = { | ||
event: new EventEmitter(), | ||
}; | ||
const websocketManager = new WebsocketManager(wss, gladys); | ||
const client = { | ||
readyState: WebSocket.CLOSED, | ||
send: fake.returns(0), | ||
}; | ||
const message = { | ||
type: 'test', | ||
payload: 'test', | ||
}; | ||
websocketManager.userConnected({ id: 'aa0eaee9-5b90-4287-841a-0237f9d75832' }, client); | ||
websocketManager.sendMessageAllUsers(message); | ||
assert.notCalled(client.send); | ||
}); | ||
it('should send message to one users', () => { | ||
const wss = new EventEmitter(); | ||
const gladys = { | ||
event: new EventEmitter(), | ||
}; | ||
const websocketManager = new WebsocketManager(wss, gladys); | ||
const client = { | ||
readyState: WebSocket.OPEN, | ||
send: fake.returns(0), | ||
}; | ||
const message = { | ||
type: 'test', | ||
payload: 'test', | ||
}; | ||
websocketManager.userConnected({ id: 'aa0eaee9-5b90-4287-841a-0237f9d75832' }, client); | ||
websocketManager.sendMessageUser({ ...message, userId: 'aa0eaee9-5b90-4287-841a-0237f9d75832' }); | ||
assert.calledWith(client.send, JSON.stringify(message)); | ||
}); | ||
}); |