some cleanup
This commit is contained in:
+61
-13
@@ -6,7 +6,7 @@ import * as uuidv4 from "uuid/v4"
|
||||
const add = (...args:number[]) => {return args.reduce((a,b)=>a+b, 0)}
|
||||
function makeServer(){
|
||||
let subcallback
|
||||
return new RPCServer<{ topic: string }>(20000, [{
|
||||
return new RPCServer<{ topic: string }>(21000, [{
|
||||
name: "test",
|
||||
exportRPCs: () => [
|
||||
{
|
||||
@@ -59,26 +59,26 @@ describe('RPCServer', () => {
|
||||
|
||||
const echo = (x) => x
|
||||
|
||||
const server = new RPCServer(20003, [{
|
||||
const server = new RPCServer(21003, [{
|
||||
name: 'HelloWorldRPCGroup',
|
||||
exportRPCs: () => [
|
||||
echo, //named function variable
|
||||
function echof(x){ return x }, //named function
|
||||
{
|
||||
name: 'echoExplicit', //describing object
|
||||
call: async (x) => x
|
||||
call: async (x,y,z) => [x,y,z]
|
||||
}
|
||||
]
|
||||
}])
|
||||
|
||||
const client = new RPCSocket(20003, 'localhost')
|
||||
const client = new RPCSocket(21003, 'localhost')
|
||||
|
||||
client.connect().then(async () => {
|
||||
const r0 = await client['HelloWorldRPCGroup'].echo('Hello')
|
||||
const r1 = await client['HelloWorldRPCGroup'].echof('World')
|
||||
const r2 = await client['HelloWorldRPCGroup'].echoExplicit('RPC!')
|
||||
const r2 = await client['HelloWorldRPCGroup'].echoExplicit('R','P','C!')
|
||||
|
||||
if(r0 === 'Hello' && r1 === 'World' && r2 ==='RPC!'){
|
||||
if(r0 === 'Hello' && r1 === 'World' && r2.join('') ==='RPC!'){
|
||||
client.destroy()
|
||||
server.destroy()
|
||||
done()
|
||||
@@ -108,7 +108,7 @@ describe('RPCSocket', () => {
|
||||
|
||||
before(async() => {
|
||||
server = makeServer()
|
||||
client = new RPCSocket(20000, "localhost")
|
||||
client = new RPCSocket(21000, "localhost")
|
||||
return await client.connect()
|
||||
})
|
||||
|
||||
@@ -177,7 +177,7 @@ describe('It should do unhook', () => {
|
||||
let server: RPCServer<{topic: string}>
|
||||
|
||||
before(async() => {
|
||||
server = new RPCServer<{ topic: string }>(20000, [{
|
||||
server = new RPCServer<{ topic: string }>(21000, [{
|
||||
name: "test",
|
||||
exportRPCs: () => [{
|
||||
name: 'subscribe',
|
||||
@@ -198,7 +198,7 @@ describe('It should do unhook', () => {
|
||||
closeHandler: (socket) => { console.log("closeHandler OK") },
|
||||
errorHandler: (socket, err) => { console.error("errorHandler OK SO YOU SHOULDN'T SEE THIS"); throw err }
|
||||
})
|
||||
client = new RPCSocket(20000, "localhost")
|
||||
client = new RPCSocket(21000, "localhost")
|
||||
return await client.connect()
|
||||
})
|
||||
|
||||
@@ -240,7 +240,7 @@ describe('Sesame should unlock the socket', () => {
|
||||
let cb = (...args) => {}
|
||||
|
||||
before(async() => {
|
||||
server = new RPCServer(20004, [{
|
||||
server = new RPCServer(21004, [{
|
||||
name: "test",
|
||||
exportRPCs: () => [
|
||||
{
|
||||
@@ -255,11 +255,12 @@ describe('Sesame should unlock the socket', () => {
|
||||
}
|
||||
},
|
||||
async function checkCandy():Promise<string> { cb(candy); cb=()=>{}; return candy },
|
||||
async function manyParams(a,b,c,d) {return [a,b,c,d]}
|
||||
]}
|
||||
],{
|
||||
sesame: (_sesame) => _sesame === 'sesame!'
|
||||
})
|
||||
const sock = new RPCSocket(20004, "localhost")
|
||||
const sock = new RPCSocket(21004, "localhost")
|
||||
client = await sock.connect<SesameTestIfc>('sesame!')
|
||||
})
|
||||
|
||||
@@ -272,8 +273,15 @@ describe('Sesame should unlock the socket', () => {
|
||||
client.test.checkCandy().then(c => done())
|
||||
})
|
||||
|
||||
it('should work with multiple params', (done) => {
|
||||
client.test['manyParams']('a','b','c','d').then(c => {
|
||||
if(c[0] == 'a' && c[1] === 'b' && c[2] === 'c' && c[3] === 'd')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not work without sesame', (done) => {
|
||||
const sock = new RPCSocket(20004, "localhost")
|
||||
const sock = new RPCSocket(21004, "localhost")
|
||||
sock.connect<SesameTestIfc>( /* no sesame */).then(async (c) => {
|
||||
c.test.checkCandy().then(d => {
|
||||
if(d === candy)
|
||||
@@ -299,7 +307,7 @@ describe('Sesame should unlock the socket', () => {
|
||||
})
|
||||
|
||||
it('callback should not work without sesame', (done) => {
|
||||
const sock = new RPCSocket(20004, "localhost")
|
||||
const sock = new RPCSocket(21004, "localhost")
|
||||
sock.connect<SesameTestIfc>( /* no sesame */).then(async (c) => {
|
||||
c.test.subscribe((c) => {
|
||||
console.log("CALLBACK TRIGGERED UNEXPECTED");
|
||||
@@ -317,3 +325,43 @@ describe('Sesame should unlock the socket', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
/*
|
||||
class myServer{
|
||||
server = new RPCServer(21004, [ {
|
||||
name: 'createUser' as 'createUser',
|
||||
exportRPCs: () => [{
|
||||
name: 'createUser' as 'createUser',
|
||||
call: this.createUser
|
||||
}]
|
||||
}
|
||||
])
|
||||
|
||||
createUser = async( user: {a:any,b:any}) => {
|
||||
console.log(user)
|
||||
return user
|
||||
}
|
||||
}
|
||||
|
||||
describe('Should pass the createUser edge case', ()=>{
|
||||
let server
|
||||
|
||||
before(()=>{
|
||||
server = new myServer()
|
||||
})
|
||||
|
||||
after(()=>{
|
||||
server.server.destroy()
|
||||
})
|
||||
|
||||
it("should work", async ()=>{
|
||||
let sock = new RPCSocket(21004, 'localhost')
|
||||
let client = await sock.connect()
|
||||
client["createUser"]["createUser"]({
|
||||
a:'a',
|
||||
b:'b'
|
||||
}).then(console.log)
|
||||
})
|
||||
|
||||
})
|
||||
*/
|
||||
Reference in New Issue
Block a user