11// deno-lint-ignore-file no-explicit-any
22import { assertEquals , assertObjectMatch } from 'https://deno.land/[email protected] /assert/mod.ts' ; 33import { beforeEach , describe , it } from 'https://deno.land/[email protected] /testing/bdd.ts' ; 4- import { spy } from " https://deno.land/[email protected] /testing/mock.ts" ; 4+ import { spy } from ' https://deno.land/[email protected] /testing/mock.ts' ; 55
66import { AppObjectRegistry } from '../../AppObjectRegistry.ts' ;
77import videoconfHandler from '../videoconference-handler.ts' ;
8- import { assertInstanceOf } from " https://deno.land/[email protected] /assert/assert_instance_of.ts" ; 9- import { JsonRpcError } from " jsonrpc-lite" ;
8+ import { assertInstanceOf } from ' https://deno.land/[email protected] /assert/assert_instance_of.ts' ; 9+ import { JsonRpcError } from ' jsonrpc-lite' ;
1010
1111describe ( 'handlers > videoconference' , ( ) => {
1212 // deno-lint-ignore no-unused-vars
@@ -16,15 +16,18 @@ describe('handlers > videoconference', () => {
1616 // deno-lint-ignore no-unused-vars
1717 const mockMethodWithTwoParam = ( call : any , user : any , read : any , modify : any , http : any , persis : any ) : Promise < string > => Promise . resolve ( 'ok two' ) ;
1818 // deno-lint-ignore no-unused-vars
19- const mockMethodWithThreeParam = ( call : any , user : any , options : any , read : any , modify : any , http : any , persis : any ) : Promise < string > => Promise . resolve ( 'ok three' ) ;
19+ const mockMethodWithThreeParam = ( call : any , user : any , options : any , read : any , modify : any , http : any , persis : any ) : Promise < string > =>
20+ Promise . resolve ( 'ok three' ) ;
2021 const mockProvider = {
2122 empty : mockMethodWithoutParam ,
2223 one : mockMethodWithOneParam ,
2324 two : mockMethodWithTwoParam ,
2425 three : mockMethodWithThreeParam ,
2526 notAFunction : true ,
26- error : ( ) => { throw new Error ( 'Method execution error example' ) }
27- }
27+ error : ( ) => {
28+ throw new Error ( 'Method execution error example' ) ;
29+ } ,
30+ } ;
2831
2932 beforeEach ( ( ) => {
3033 AppObjectRegistry . clear ( ) ;
@@ -36,9 +39,9 @@ describe('handlers > videoconference', () => {
3639
3740 const result = await videoconfHandler ( 'videoconference:test-provider:empty' , [ ] ) ;
3841
39- assertEquals ( result , 'ok none' )
42+ assertEquals ( result , 'ok none' ) ;
4043 assertEquals ( _spy . calls [ 0 ] . args . length , 4 ) ;
41-
44+
4245 _spy . restore ( ) ;
4346 } ) ;
4447
@@ -47,7 +50,7 @@ describe('handlers > videoconference', () => {
4750
4851 const result = await videoconfHandler ( 'videoconference:test-provider:one' , [ 'call' ] ) ;
4952
50- assertEquals ( result , 'ok one' )
53+ assertEquals ( result , 'ok one' ) ;
5154 assertEquals ( _spy . calls [ 0 ] . args . length , 5 ) ;
5255 assertEquals ( _spy . calls [ 0 ] . args [ 0 ] , 'call' ) ;
5356
@@ -59,7 +62,7 @@ describe('handlers > videoconference', () => {
5962
6063 const result = await videoconfHandler ( 'videoconference:test-provider:two' , [ 'call' , 'user' ] ) ;
6164
62- assertEquals ( result , 'ok two' )
65+ assertEquals ( result , 'ok two' ) ;
6366 assertEquals ( _spy . calls [ 0 ] . args . length , 6 ) ;
6467 assertEquals ( _spy . calls [ 0 ] . args [ 0 ] , 'call' ) ;
6568 assertEquals ( _spy . calls [ 0 ] . args [ 1 ] , 'user' ) ;
@@ -72,7 +75,7 @@ describe('handlers > videoconference', () => {
7275
7376 const result = await videoconfHandler ( 'videoconference:test-provider:three' , [ 'call' , 'user' , 'options' ] ) ;
7477
75- assertEquals ( result , 'ok three' )
78+ assertEquals ( result , 'ok three' ) ;
7679 assertEquals ( _spy . calls [ 0 ] . args . length , 7 ) ;
7780 assertEquals ( _spy . calls [ 0 ] . args [ 0 ] , 'call' ) ;
7881 assertEquals ( _spy . calls [ 0 ] . args [ 1 ] , 'user' ) ;
@@ -84,34 +87,36 @@ describe('handlers > videoconference', () => {
8487 it ( 'correctly handles an error on execution of a videoconf method' , async ( ) => {
8588 const result = await videoconfHandler ( 'videoconference:test-provider:error' , [ ] ) ;
8689
87- assertInstanceOf ( result , JsonRpcError )
90+ assertInstanceOf ( result , JsonRpcError ) ;
8891 assertObjectMatch ( result , {
8992 message : 'Method execution error example' ,
90- code : - 32000
91- } )
92- } )
93+ code : - 32000 ,
94+ } ) ;
95+ } ) ;
9396
9497 it ( 'correctly handles an error when provider is not found' , async ( ) => {
95- const providerName = 'error-provider'
98+ const providerName = 'error-provider' ;
9699 const result = await videoconfHandler ( `videoconference:${ providerName } :method` , [ ] ) ;
97100
98- assertInstanceOf ( result , JsonRpcError )
101+ assertInstanceOf ( result , JsonRpcError ) ;
99102 assertObjectMatch ( result , {
100103 message : `Provider ${ providerName } not found` ,
101- code : - 32000
102- } )
103- } )
104+ code : - 32000 ,
105+ } ) ;
106+ } ) ;
104107
105108 it ( 'correctly handles an error if method is not a function of provider' , async ( ) => {
106- const methodName = 'notAFunction'
107- const providerName = 'test-provider'
109+ const methodName = 'notAFunction' ;
110+ const providerName = 'test-provider' ;
108111 const result = await videoconfHandler ( `videoconference:${ providerName } :${ methodName } ` , [ ] ) ;
109112
110- assertInstanceOf ( result , JsonRpcError )
113+ assertInstanceOf ( result , JsonRpcError ) ;
111114 assertObjectMatch ( result , {
112- message : `Method ${ methodName } not found on provider ${ providerName } ` ,
113- code : - 32000
114- } )
115- } )
116-
115+ message : 'Method not found' ,
116+ code : - 32601 ,
117+ data : {
118+ message : `Method ${ methodName } not found on provider ${ providerName } ` ,
119+ } ,
120+ } ) ;
121+ } ) ;
117122} ) ;
0 commit comments