From 5b79810440721b86b43af8ba6856a0be7d3c6c21 Mon Sep 17 00:00:00 2001 From: kateract Date: Thu, 1 Jun 2017 17:27:11 -0500 Subject: [PATCH 1/4] add syncScenes --- src/Client.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Client.ts b/src/Client.ts index ef28f37..1ccfbf2 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -133,7 +133,7 @@ export class Client extends EventEmitter implements IClient { this.createSocket(options); this.socket.connect(); return resolveOn(this, 'open') - .then(() => this); + .then(() => this); } /** @@ -196,6 +196,13 @@ export class Client extends EventEmitter implements IClient { .then(res => this.state.synchronizeGroups(res)); } + public synchronizeState(): Promise<[IGroup[], IScene[]]> { + return Promise.all([ + this.getGroups().then(res => this.state.synchronizeGroups(res)), + this.getScenes().then(res => this.state.synchronizeScenes(res)) + ]); + } + /** * Retrieves and hydrates client side stores with state from the server */ From 10fd04b4bf09a6ff29e3daea86c4832acda9b781 Mon Sep 17 00:00:00 2001 From: kateract Date: Thu, 1 Jun 2017 17:27:20 -0500 Subject: [PATCH 2/4] attempt to add tests --- src/Client.spec.ts | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Client.spec.ts b/src/Client.spec.ts index 2b37a44..439b75e 100644 --- a/src/Client.spec.ts +++ b/src/Client.spec.ts @@ -1,8 +1,10 @@ +import { expect } from 'chai'; +import * as sinon from 'sinon'; import * as WebSocket from 'ws'; import { setWebSocket } from './'; -import { Method } from './wire/packets'; - import { Client, ClientType } from './Client'; +import { IClient } from './IClient'; +import { Method } from './wire/packets'; setWebSocket(WebSocket); const port = process.env.SERVER_PORT || 1339; @@ -61,5 +63,37 @@ describe('client', () => { }); }); + describe('state synchronization', () => { + let mockClient: IClient; + beforeEach(() => { + client = createClient(); + client.execute = sinon.stub().returns(new Promise(resolve => { resolve(); })); + //client.open(socketOptions); + }); + it('synchronizes scenes', () => { + const scenes = client.getScenes(); + mockClient = client; + //const stub = sinon.stub(mockClient, 'execute'); + client.synchronizeScenes(); + expect(client.execute).to.be.calledWith(new Promise(resolve => {resolve(scenes); })); + }); + it('synchronizes groups', () => { + const groups = client.getGroups(); + mockClient = client; + //const stub = sinon.stub(mockClient, 'execute'); + client.synchronizeGroups(); + expect(client.execute).to.be.calledWith(groups); + }); + it('synchronizes state', () => { + const scenes = client.getScenes(); + const groups = client.getGroups(); + mockClient = client; + //const stub = sinon.stub(mockClient, 'execute'); + client.synchronizeState(); + expect(client.execute).to.be.calledWith(scenes); + expect(client.execute).to.be.calledWith(groups); + }); + }); + afterEach(done => tearDown(done)); }); From 9ddf9dacf99b54a67b5f20cb84819f76e7995ed0 Mon Sep 17 00:00:00 2001 From: kateract Date: Fri, 2 Jun 2017 15:53:43 -0500 Subject: [PATCH 3/4] merge changes --- src/Client.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index 1ccfbf2..a058337 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -196,6 +196,9 @@ export class Client extends EventEmitter implements IClient { .then(res => this.state.synchronizeGroups(res)); } + /** + * Retrieves and hydrates client side stores with state from the server + */ public synchronizeState(): Promise<[IGroup[], IScene[]]> { return Promise.all([ this.getGroups().then(res => this.state.synchronizeGroups(res)), @@ -203,14 +206,6 @@ export class Client extends EventEmitter implements IClient { ]); } - /** - * Retrieves and hydrates client side stores with state from the server - */ - public synchronizeState(): Promise { - return Promise.all([this.synchronizeGroups(), this.synchronizeScenes()]) - .then(() => {/** */}); - } - /** * Gets the time from the server as a unix timestamp in UTC. */ From 7b0155d22f1ab0d58a2681171779b84f5267dab4 Mon Sep 17 00:00:00 2001 From: kateract Date: Fri, 2 Jun 2017 16:03:01 -0500 Subject: [PATCH 4/4] added trailing comma for linting --- src/Client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.ts b/src/Client.ts index a058337..deaf3ba 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -202,7 +202,7 @@ export class Client extends EventEmitter implements IClient { public synchronizeState(): Promise<[IGroup[], IScene[]]> { return Promise.all([ this.getGroups().then(res => this.state.synchronizeGroups(res)), - this.getScenes().then(res => this.state.synchronizeScenes(res)) + this.getScenes().then(res => this.state.synchronizeScenes(res)), ]); }