Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
feat: added integration stub for profile 0
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Feb 25, 2018
1 parent 93f2f60 commit df8af47
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 61 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"changelog": "standard-version",
"release": "yarn reset && yarn test && yarn docs:publish && yarn changelog",
"reset": "git clean -dfx && git reset --hard && yarn",
"ci": "yarn test"
"ci": "yarn test",
"start": "node dist/index.js"
},
"scripts-info": {
"info": "Display information about the scripts",
Expand Down Expand Up @@ -74,6 +75,7 @@
"gh-pages": "^1.0.0",
"jest": "^22.4.2",
"mkdirp": "^0.5.1",
"mongodb-memory-server": "^1.7.0",
"npm-scripts-info": "^0.3.6",
"nyc": "^11.0.3",
"opn-cli": "^3.1.0",
Expand Down Expand Up @@ -105,6 +107,7 @@
"ddp-ejson": "~0.8.1-3",
"ddp-random": "~0.8.1-1",
"mos-connection": "git+https://Mfn2bXzQtEFXHKpo12x2y78QJMR7gUZz:x-oauth-basic@bitbucket.org/superflytv/mos-connection.git",
"tslib": "^1.6.0"
"tslib": "^1.6.0",
"underscore": "^1.8.3"
}
}
71 changes: 71 additions & 0 deletions src/connectors/__mocks__/ddp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

// mock the ddp connector:

import {DDPClient} from "../ddpConnector"
import * as _ from "underscore"



const ddp:any = jest.genMockFromModule('ddp');


let connectionPossible = true;

ddp.prototype.__setConnectionPossible = function(possible:boolean) {
connectionPossible = possible;
}

ddp.prototype.connect = function(cb:any) {



if (connectionPossible) {
// return true
this.emit('connected');
_.defer(() => {
this.connected = true;
cb();
})



} else {
_.defer(() => {

this.socket.emit('socket-close', 'mock: timeout');
});

}
}



module.exports = ddp;


/*
// This is a custom function that our tests can use during setup to specify
// what the files on the "mock" filesystem should look like when any of the
// `fs` APIs are used.
let mockFiles = Object.create(null);
function __setMockFiles(newMockFiles) {
mockFiles = Object.create(null);
for (const file in newMockFiles) {
const dir = path.dirname(file);
if (!mockFiles[dir]) {
mockFiles[dir] = [];
}
mockFiles[dir].push(path.basename(file));
}
}
// A custom version of `readdirSync` that reads from the special mocked out
// file list set via __setMockFiles
function readdirSync(directoryPath) {
return mockFiles[directoryPath] || [];
}
fs.__setMockFiles = __setMockFiles;
fs.readdirSync = readdirSync;
module.exports = fs;
*/
35 changes: 35 additions & 0 deletions src/connectors/__tests__/ddpConnector.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@



import {DDPConnector} from "../ddpConnector"

jest.mock('ddp');


beforeEach(() => {
// Set up some mocked out file info before each test
//require('ddp').__setMockFiles(MOCK_FILE_INFO);
});


test('Test DDPConnector', async () => {

var ddpConnector = new DDPConnector({
host: '127.0.0.1',
port: 3000
});


expect(ddpConnector).toBeInstanceOf(DDPConnector);



await ddpConnector.connect();



expect(ddpConnector.connected).toBe(true);

return 1;
})

17 changes: 7 additions & 10 deletions src/connectors/ddpConnector.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
let ddp: any = require("ddp");
let DDP = require("ddp");

import {EventEmitter} from 'events';




export interface DDPConnectorOptions {
host: string;
port: number;
Expand Down Expand Up @@ -46,10 +44,7 @@ export interface DDPClient {
autoReconnect: boolean;
autoReconnectTimer: number;
ddpVersion: any;
}



}

export class DDPConnector extends EventEmitter {
private _options:DDPConnectorOptions;
Expand Down Expand Up @@ -83,7 +78,9 @@ export class DDPConnector extends EventEmitter {
};
if (!this.ddpClient) {

this.ddpClient = new ddp(o);


this.ddpClient = new DDP(o);
this.ddpClient.on("socket-close", () => {

this._onclientConnectionChange(false)
Expand Down Expand Up @@ -128,18 +125,18 @@ export class DDPConnector extends EventEmitter {
if (!this.ddpClient) {
this.createClient();
}

if (this.ddpClient && !this._connecting) {

this._connecting = true;

this.ddpClient.connect((error: Object, isReconnecting: boolean) => {
this.ddpClient.connect((error: Object/*, isReconnecting: boolean*/) => {
this._connecting = false;


if (error) {
reject(error);
} else {
this._connected = true;
resolve();
}
});
Expand Down
38 changes: 0 additions & 38 deletions src/ddp.d.ts

This file was deleted.

44 changes: 40 additions & 4 deletions src/mosHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import {MosConnection} from "mos-connection"
import {
MosConnection,
IMosconnection,
IMOSDevice,
IMOSDeviceP0,
IMOSDeviceP1,
IMOSDeviceP2,
IMOSDeviceP3,
IMOSDeviceP4,
IMOSDeviceP5,
IMOSDeviceP6
} from "mos-connection"

import {CoreHandler} from "./coreHandler"

interface IMyMOSDevice extends IMOSDeviceP1, IMOSDeviceP0 {}

export class MosHandler {

public mos:MosConnection;

init() {
private mosDevices:{[id:string]:IMOSDevice}

init(coreHandler:CoreHandler) {

this.mos = new MosConnection({
acceptConnections: true, // default:true
Expand All @@ -22,17 +39,36 @@ export class MosHandler {
}
});

this.mos.onConnection(() => {
this.mos.onConnection((mosDevice:IMyMOSDevice) => {
// a new connection has been made

this.mosDevices[mosDevice.id] = mosDevice;


// Setup messages [ MOSDevice >>>> Core ] -----------------------
/*mosDevice.onMessage((message:string) => {-
});
*/
mosDevice.onConnectionChange((connectionStatus:IMOSConnectionStatus) => {
coreHandler.connected = connected;
});


let coreMosHandler = coreHandler.registerMosDevice(mosDevice)

// Setup messages [ MOSDevice <<<< Core ] -----------------------
coreMosHandler.onGetMachineInfo(() => {
return mosDevice.getMachineInfo();
});


});

// Connect to ENPS:
return this.mos.connect({
ncs: {
ncsID: "WINSERVERSOMETHINGENPS",
id: "WINSERVERSOMETHINGENPS",
host: "192.168.0.1"
},
/*ncsBuddy?: {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./config/tsconfig.base",
"exclude": [
"node_modules/**",
"src/**/*spec.ts"
"src/**/*spec.ts",
"src/**/__mocks__/*"
]
}
Loading

0 comments on commit df8af47

Please sign in to comment.