2018-03-13 05:15:40 +00:00
|
|
|
// tslint:disable-next-line:no-implicit-dependencies
|
2018-03-07 21:22:15 +00:00
|
|
|
import { expect, tap } from 'tapbundle';
|
|
|
|
import * as smartuniverse from '../ts/index';
|
|
|
|
|
2018-03-20 07:16:54 +00:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
2018-03-13 05:15:40 +00:00
|
|
|
let testUniverse: smartuniverse.Universe;
|
2018-05-28 10:07:25 +00:00
|
|
|
let testUniverseClient: smartuniverse.ClientUniverse;
|
|
|
|
let testClientChannel: smartuniverse.ClientUniverseChannel;
|
2018-03-08 22:42:46 +00:00
|
|
|
|
2018-03-07 21:22:15 +00:00
|
|
|
tap.test('first test', async () => {
|
2018-03-13 05:15:40 +00:00
|
|
|
testUniverse = new smartuniverse.Universe({
|
2018-03-20 07:16:54 +00:00
|
|
|
messageExpiryInMilliseconds: 1000
|
2018-03-13 05:15:40 +00:00
|
|
|
});
|
2018-03-07 21:22:15 +00:00
|
|
|
});
|
|
|
|
|
2018-03-13 05:15:40 +00:00
|
|
|
tap.test('add a message to the SmartUniverse', async () => {
|
|
|
|
await testUniverse.initServer(8765);
|
2018-03-20 07:16:54 +00:00
|
|
|
});
|
2018-03-13 05:15:40 +00:00
|
|
|
|
|
|
|
// testing message handling
|
|
|
|
tap.test('create smartuniverse client', async () => {
|
2018-05-28 10:07:25 +00:00
|
|
|
testUniverseClient = new smartuniverse.ClientUniverse({
|
2018-03-15 00:16:16 +00:00
|
|
|
serverAddress: 'http://localhost:8765'
|
2018-03-15 00:05:13 +00:00
|
|
|
});
|
2018-05-28 10:07:25 +00:00
|
|
|
expect(testUniverseClient).to.be.instanceof(smartuniverse.ClientUniverse);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should add a channel to the universe', async () => {
|
|
|
|
await testUniverse.addChannel('testChannel', 'testPassword');
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should get a observable correctly', async () => {
|
|
|
|
testClientChannel = await testUniverseClient.getChannel('testChannel');
|
|
|
|
expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel);
|
2018-03-20 07:16:54 +00:00
|
|
|
});
|
2018-03-13 05:15:40 +00:00
|
|
|
|
2018-03-15 00:16:16 +00:00
|
|
|
tap.test('should send a message correctly', async () => {
|
|
|
|
await testUniverseClient.sendMessage('greeting', {
|
|
|
|
anyBool: true
|
2018-03-20 07:16:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-13 13:45:48 +00:00
|
|
|
tap.test('should receive a message correctly', async () => {});
|
2018-03-15 00:16:16 +00:00
|
|
|
|
2018-03-27 22:38:32 +00:00
|
|
|
tap.test('should disconnect the client correctly', async () => {
|
|
|
|
testUniverseClient.close();
|
2018-04-13 13:45:48 +00:00
|
|
|
});
|
2018-03-27 22:38:32 +00:00
|
|
|
|
2018-04-13 13:45:48 +00:00
|
|
|
tap.test('should end the server correctly', async tools => {
|
2018-03-13 05:15:40 +00:00
|
|
|
await testUniverse.stopServer();
|
2018-03-20 07:16:54 +00:00
|
|
|
});
|
2018-03-13 05:15:40 +00:00
|
|
|
|
2018-03-07 21:22:15 +00:00
|
|
|
tap.start();
|