Skip to content
This repository was archived by the owner on Jul 31, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/Client.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
});
10 changes: 6 additions & 4 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -199,9 +199,11 @@ export class Client extends EventEmitter implements IClient {
/**
* Retrieves and hydrates client side stores with state from the server
*/
public synchronizeState(): Promise<void> {
return Promise.all([this.synchronizeGroups(), this.synchronizeScenes()])
.then(() => {/** */});
public synchronizeState(): Promise<[IGroup[], IScene[]]> {
return Promise.all([
this.getGroups().then(res => this.state.synchronizeGroups(res)),
this.getScenes().then(res => this.state.synchronizeScenes(res)),
]);
}

/**
Expand Down