fix(core): update

This commit is contained in:
Philipp Kunz 2019-04-22 23:11:51 +02:00
parent 241182ed2e
commit 30a02ae48b
4 changed files with 19 additions and 12 deletions

View File

@ -5,7 +5,7 @@ import * as smartuniverse from '../ts/index';
import { Observable } from 'rxjs';
let testUniverse: smartuniverse.Universe;
let testUniverseClient: smartuniverse.ClientUniverse;
let testClientUniverse: smartuniverse.ClientUniverse;
let testClientChannel: smartuniverse.ClientUniverseChannel;
const testChannelData = {
@ -25,10 +25,10 @@ tap.test('add a message to the SmartUniverse', async () => {
// testing message handling
tap.test('create smartuniverse client', async () => {
testUniverseClient = new smartuniverse.ClientUniverse({
testClientUniverse = new smartuniverse.ClientUniverse({
serverAddress: 'http://localhost:8765'
});
expect(testUniverseClient).to.be.instanceof(smartuniverse.ClientUniverse);
expect(testClientUniverse).to.be.instanceof(smartuniverse.ClientUniverse);
});
tap.test('should add a channel to the universe', async () => {
@ -36,12 +36,12 @@ tap.test('should add a channel to the universe', async () => {
});
tap.test('should get a observable correctly', async () => {
testClientChannel = await testUniverseClient.getChannel(testChannelData.channelName, testChannelData.channelPass);
testClientChannel = await testClientUniverse.getChannel(testChannelData.channelName);
expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel);
});
tap.test('should send a message correctly', async () => {
await testUniverseClient.sendMessage({
await testClientUniverse.sendMessage({
messageText: 'hello',
targetChannelName: 'channel1'
});
@ -50,7 +50,7 @@ tap.test('should send a message correctly', async () => {
tap.test('should receive a message correctly', async () => {});
tap.test('should disconnect the client correctly', async () => {
testUniverseClient.close();
testClientUniverse.close();
});
tap.test('should end the server correctly', async tools => {

View File

@ -42,12 +42,12 @@ export class ClientUniverse {
throw new Error('channel exists');
}
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
// lets create the channel
ClientUniverseChannel.createClientUniverseChannel(
this,
channelNameArg,
passphraseArg
);
this.channelCache.add(clientUniverseChannel);
}
/**

View File

@ -7,12 +7,19 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
// ======
// STATIC
// ======
/**
* creates a channel and adds it to the cache of clientUniverseArg
* @param clientUniverseArg
* @param channelNameArg
* @param passphraseArg
*/
public static async createClientUniverseChannel(
clientUniverseArg: ClientUniverse,
channelName: string,
channelNameArg: string,
passphraseArg: string
): Promise<ClientUniverseChannel> {
const clientChannel = new ClientUniverseChannel(clientUniverseArg, passphraseArg);
const clientChannel = new ClientUniverseChannel(clientUniverseArg, channelNameArg, passphraseArg);
clientUniverseArg.channelCache.add(clientChannel);
await clientChannel.subscribe();
return clientChannel;
}

View File

@ -83,8 +83,8 @@ export class UniverseChannel {
*/
public authenticate(universeMessageArg: UniverseMessage): boolean {
return (
this.name === universeMessageArg.requestedChannelName &&
this.passphrase === universeMessageArg.requestedChannelPassphrase
this.name === universeMessageArg.targetChannelName &&
this.passphrase === universeMessageArg.passphrase
);
}