|
@@ -175,6 +175,7 @@ describe('RPCSocket', () => {
|
175
|
175
|
describe('It should do unhook', () => {
|
176
|
176
|
let candy = "OK"
|
177
|
177
|
let cb: Function
|
|
178
|
+ let cb2: Function
|
178
|
179
|
let client: RPCSocket
|
179
|
180
|
let server: RPCServer<{topic: string}>
|
180
|
181
|
|
|
@@ -192,6 +193,26 @@ describe('It should do unhook', () => {
|
192
|
193
|
}
|
193
|
194
|
}
|
194
|
195
|
},
|
|
196
|
+ {
|
|
197
|
+ name: 'subscribeWithParam',
|
|
198
|
+ hook: async(param, callback):Promise<SubscriptionResponse<{topic:string}>> => {
|
|
199
|
+
|
|
200
|
+ if(param != "OK"){
|
|
201
|
+ console.log("param was"+ param);
|
|
202
|
+ return {
|
|
203
|
+ result: "Success",
|
|
204
|
+ uuid: "no",
|
|
205
|
+ topic: "test"
|
|
206
|
+ }
|
|
207
|
+ }
|
|
208
|
+ cb2 = <Function> callback
|
|
209
|
+ return {
|
|
210
|
+ result: "Success",
|
|
211
|
+ uuid: "OK",
|
|
212
|
+ topic: "test"
|
|
213
|
+ }
|
|
214
|
+ }
|
|
215
|
+ },
|
195
|
216
|
function checkCandy():string { cb(candy); return candy },
|
196
|
217
|
function stealCandy():string { candy = "_OK"; cb(candy); cb = () => {}; return candy }
|
197
|
218
|
]
|
|
@@ -209,6 +230,15 @@ describe('It should do unhook', () => {
|
209
|
230
|
server.destroy()
|
210
|
231
|
})
|
211
|
232
|
|
|
233
|
+ it('Subscribe with param', (done) => {
|
|
234
|
+ client['test'].subscribeWithParam("OK", c => {}).then( async (res: SubscriptionResponse) => {
|
|
235
|
+ if(res.uuid === "OK"){
|
|
236
|
+ done()
|
|
237
|
+ }else
|
|
238
|
+ done(new Error("Results did not match "+res.uuid))
|
|
239
|
+ })
|
|
240
|
+ })
|
|
241
|
+
|
212
|
242
|
it('Unhook+unsubscribe should stop callbacks', (done) => {
|
213
|
243
|
client['test'].subscribe(c => {}).then( async (res: SubscriptionResponse) => {
|
214
|
244
|
const r1 = await client['test'].checkCandy()
|
|
@@ -502,32 +532,42 @@ describe("Errorhandler functionality", ()=>{
|
502
|
532
|
})
|
503
|
533
|
})
|
504
|
534
|
|
|
535
|
+type myExporterIfc = {
|
|
536
|
+ MyExporter: {
|
|
537
|
+ myRPC: ()=>Promise<string>
|
|
538
|
+ }
|
|
539
|
+}
|
|
540
|
+
|
505
|
541
|
|
506
|
542
|
describe("Class binding", ()=>{
|
507
|
543
|
|
508
|
|
- class MyExporter implements RPCExporter{
|
509
|
|
- name = "MyExporter";
|
|
544
|
+ class MyExporter implements RPCExporter<myExporterIfc>{
|
|
545
|
+ name = "MyExporter" as "MyExporter";
|
510
|
546
|
exportRPCs = () => [
|
511
|
547
|
this.myRPC
|
512
|
548
|
]
|
513
|
549
|
|
514
|
|
- myRPC = () => "Hello World"
|
|
550
|
+ myRPC = async () => "Hello World"
|
515
|
551
|
|
516
|
552
|
}
|
|
553
|
+ let serv: RPCServer,
|
|
554
|
+ sock: RPCSocket,
|
|
555
|
+ exporter: MyExporter
|
|
556
|
+
|
|
557
|
+ before((done)=>{
|
|
558
|
+ exporter = new MyExporter()
|
|
559
|
+ serv = new RPCServer(21004, [exporter])
|
|
560
|
+ sock = new RPCSocket(21004, 'localhost')
|
|
561
|
+ sock.connect<myExporterIfc>().then(_ => done())
|
|
562
|
+ })
|
|
563
|
+ after(() => {
|
|
564
|
+ sock.destroy()
|
|
565
|
+ serv.destroy()
|
|
566
|
+ })
|
517
|
567
|
|
518
|
568
|
it("binds correctly", (done)=>{
|
519
|
|
- const exporter = new MyExporter()
|
520
|
|
- const serv = new RPCServer(21004, [exporter])
|
521
|
|
- const sock = new RPCSocket(21004, 'localhost')
|
522
|
|
- sock.connect().then(sock => {
|
523
|
|
- if(sock.MyExporter && sock.MyExporter.myRPC){
|
524
|
|
- done()
|
525
|
|
- }
|
526
|
|
- })
|
527
|
|
- .catch(done)
|
528
|
|
- .finally(() => {
|
529
|
|
- sock.destroy()
|
530
|
|
- serv.destroy()
|
|
569
|
+ sock['MyExporter'].myRPC().then(() => {
|
|
570
|
+ done()
|
531
|
571
|
})
|
532
|
572
|
})
|
533
|
573
|
})
|