fix bug in subscribe with param

This commit is contained in:
2020-02-09 01:01:36 +01:00
parent a2268526af
commit 96976974c7
4 changed files with 71 additions and 23 deletions
+55 -15
View File
@@ -175,6 +175,7 @@ describe('RPCSocket', () => {
describe('It should do unhook', () => {
let candy = "OK"
let cb: Function
let cb2: Function
let client: RPCSocket
let server: RPCServer<{topic: string}>
@@ -192,6 +193,26 @@ describe('It should do unhook', () => {
}
}
},
{
name: 'subscribeWithParam',
hook: async(param, callback):Promise<SubscriptionResponse<{topic:string}>> => {
if(param != "OK"){
console.log("param was"+ param);
return {
result: "Success",
uuid: "no",
topic: "test"
}
}
cb2 = <Function> callback
return {
result: "Success",
uuid: "OK",
topic: "test"
}
}
},
function checkCandy():string { cb(candy); return candy },
function stealCandy():string { candy = "_OK"; cb(candy); cb = () => {}; return candy }
]
@@ -209,6 +230,15 @@ describe('It should do unhook', () => {
server.destroy()
})
it('Subscribe with param', (done) => {
client['test'].subscribeWithParam("OK", c => {}).then( async (res: SubscriptionResponse) => {
if(res.uuid === "OK"){
done()
}else
done(new Error("Results did not match "+res.uuid))
})
})
it('Unhook+unsubscribe should stop callbacks', (done) => {
client['test'].subscribe(c => {}).then( async (res: SubscriptionResponse) => {
const r1 = await client['test'].checkCandy()
@@ -502,32 +532,42 @@ describe("Errorhandler functionality", ()=>{
})
})
type myExporterIfc = {
MyExporter: {
myRPC: ()=>Promise<string>
}
}
describe("Class binding", ()=>{
class MyExporter implements RPCExporter{
name = "MyExporter";
class MyExporter implements RPCExporter<myExporterIfc>{
name = "MyExporter" as "MyExporter";
exportRPCs = () => [
this.myRPC
]
myRPC = () => "Hello World"
myRPC = async () => "Hello World"
}
let serv: RPCServer,
sock: RPCSocket,
exporter: MyExporter
before((done)=>{
exporter = new MyExporter()
serv = new RPCServer(21004, [exporter])
sock = new RPCSocket(21004, 'localhost')
sock.connect<myExporterIfc>().then(_ => done())
})
after(() => {
sock.destroy()
serv.destroy()
})
it("binds correctly", (done)=>{
const exporter = new MyExporter()
const serv = new RPCServer(21004, [exporter])
const sock = new RPCSocket(21004, 'localhost')
sock.connect().then(sock => {
if(sock.MyExporter && sock.MyExporter.myRPC){
done()
}
})
.catch(done)
.finally(() => {
sock.destroy()
serv.destroy()
sock['MyExporter'].myRPC().then(() => {
done()
})
})
})