Skip to content

Commit

Permalink
feat(Realtime): Use object on constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
kosssi committed May 7, 2019
1 parent 47c582a commit 4744a23
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/cozy-realtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ or
```js
import CozyRealtime, { EVENT_CREATED, EVENT_UPDATED } from 'cozy-realtime'

const realtime = new CozyRealtime(cozyClient)
const realtime = new CozyRealtime({ cozyClient })
const type = 'io.cozy.accounts'
const id = 'document_id'
const handlerCreate = accounts => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cozy-realtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CozyRealtime {
* @constructor
* @param {CozyClient} cozyClient A cozy client
*/
constructor(cozyClient) {
constructor({ cozyClient }) {
this._cozyClient = cozyClient

this._updateAuthentication = this._updateAuthentication.bind(this)
Expand Down
12 changes: 6 additions & 6 deletions packages/cozy-realtime/src/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Realtime, {
import CozyRealtime, {
generateKey,
getWebSocketUrl,
getWebSocketToken,
Expand All @@ -19,14 +19,14 @@ class CozyClient {
}
}
MicroEE.mixin(CozyClient)
const COZY_CLIENT = new CozyClient()
const cozyClient = new CozyClient()
const pause = time => new Promise(resolve => setTimeout(resolve, time))

describe('Realtime', () => {
describe('CozyRealtime', () => {
let realtime, cozyStack

beforeEach(() => {
realtime = new Realtime(COZY_CLIENT)
realtime = new CozyRealtime({ cozyClient })
cozyStack = new Server(WS_URL)
cozyStack.emitMessage = (type, doc, event, id) => {
cozyStack.emit(
Expand Down Expand Up @@ -179,13 +179,13 @@ describe('Realtime', () => {
describe('authentication', () => {
it('should update socket authentication when client login', async () => {
realtime._socket.updateAuthentication = jest.fn()
COZY_CLIENT.emit('login')
cozyClient.emit('login')
expect(realtime._socket.updateAuthentication.mock.calls.length).toBe(1)
})

it('should update socket authentication when client token refreshed ', async () => {
realtime._socket.updateAuthentication = jest.fn()
COZY_CLIENT.emit('login')
cozyClient.emit('login')
expect(realtime._socket.updateAuthentication.mock.calls.length).toBe(1)
})
})
Expand Down

0 comments on commit 4744a23

Please sign in to comment.