85 lines
2.6 KiB
TypeScript
Raw Normal View History

2018-03-13 06:15:40 +01:00
// tslint:disable-next-line:no-implicit-dependencies
2019-01-31 02:52:18 +01:00
import { expect, tap } from '@pushrocks/tapbundle';
2018-03-07 22:22:15 +01:00
import * as smartuniverse from '../ts/index';
2018-03-20 08:16:54 +01:00
import { Observable } from 'rxjs';
2018-03-13 06:15:40 +01:00
let testUniverse: smartuniverse.Universe;
2019-04-22 23:11:51 +02:00
let testClientUniverse: smartuniverse.ClientUniverse;
2019-04-28 12:42:08 +02:00
let testClientUniverse2: smartuniverse.ClientUniverse;
let testClientChannel: smartuniverse.ClientUniverseChannel;
2018-03-08 23:42:46 +01:00
2019-04-28 12:42:08 +02:00
const testServerData = {
serverAddress: 'http://localhost:8765'
};
2019-04-11 18:50:43 +02:00
const testChannelData = {
channelName: 'awesomeTestChannel',
2019-08-13 15:48:20 +02:00
channelPass: 'awesomeChannelPass'
2019-04-22 13:06:01 +02:00
};
2019-04-11 18:50:43 +02:00
2018-03-07 22:22:15 +01:00
tap.test('first test', async () => {
2018-03-13 06:15:40 +01:00
testUniverse = new smartuniverse.Universe({
2018-03-20 08:16:54 +01:00
messageExpiryInMilliseconds: 1000
2018-03-13 06:15:40 +01:00
});
2018-03-07 22:22:15 +01:00
});
2018-03-13 06:15:40 +01:00
tap.test('add a message to the SmartUniverse', async () => {
2019-04-11 18:50:43 +02:00
await testUniverse.start(8765);
2018-03-20 08:16:54 +01:00
});
2018-03-13 06:15:40 +01:00
// testing message handling
tap.test('create smartuniverse client', async () => {
2019-04-22 23:11:51 +02:00
testClientUniverse = new smartuniverse.ClientUniverse({
2019-04-28 12:42:08 +02:00
serverAddress: testServerData.serverAddress
2018-03-15 01:05:13 +01:00
});
2019-04-22 23:11:51 +02:00
expect(testClientUniverse).to.be.instanceof(smartuniverse.ClientUniverse);
});
tap.test('should add a channel to the universe', async () => {
2019-09-01 17:04:25 +02:00
testUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
2019-04-22 23:23:36 +02:00
});
tap.test('should add the same channel to the client universe in the same way', async () => {
2019-08-13 18:43:33 +02:00
testClientUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
});
2019-08-13 15:48:20 +02:00
tap.test('should start the ClientUniverse', async () => {
await testClientUniverse.start();
2019-09-01 17:04:25 +02:00
});
2019-08-13 15:48:20 +02:00
tap.test('should get a observable correctly', async () => {
2019-08-13 18:41:27 +02:00
testClientChannel = testClientUniverse.getChannel(testChannelData.channelName);
expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel);
2018-03-20 08:16:54 +01:00
});
2018-03-13 06:15:40 +01:00
2018-03-15 01:16:16 +01:00
tap.test('should send a message correctly', async () => {
2019-09-01 17:04:25 +02:00
await testClientUniverse.getChannel(testChannelData.channelName).sendMessage({
2019-08-12 17:23:10 +02:00
messageText: 'hello'
2018-03-20 08:16:54 +01:00
});
});
2019-04-24 18:20:31 +02:00
tap.test('universe should contain the sent message', async () => {
expect(testUniverse.universeCache.messageMap.getArray()[0].messageText).to.equal('hello');
});
2019-04-28 12:42:08 +02:00
tap.test('a second client should be able to subscibe', async () => {
testClientUniverse2 = new smartuniverse.ClientUniverse({
serverAddress: testServerData.serverAddress
});
testClientUniverse2.addChannel(testChannelData.channelName, testChannelData.channelPass);
});
2018-04-13 15:45:48 +02:00
tap.test('should receive a message correctly', async () => {});
2018-03-15 01:16:16 +01:00
tap.test('should disconnect the client correctly', async () => {
2019-09-10 00:39:18 +02:00
await testClientUniverse.stop();
2018-04-13 15:45:48 +02:00
});
2018-04-13 15:45:48 +02:00
tap.test('should end the server correctly', async tools => {
2018-03-13 06:15:40 +01:00
await testUniverse.stopServer();
2018-03-20 08:16:54 +01:00
});
2018-03-13 06:15:40 +01:00
2018-03-07 22:22:15 +01:00
tap.start();