1- import * as request from ' supertest' ;
1+ import * as request from " supertest" ;
22
33import { Test } from "@nestjs/testing" ;
44import { INestApplication , INestMicroservice } from "@nestjs/common" ;
@@ -15,7 +15,7 @@ describe("json-rpc-e2e", () => {
1515 let service : ITestClientService ;
1616 let unauthorizedService : ITestClientService ;
1717
18- describe ( ' standalone' , ( ) => {
18+ describe ( " standalone" , ( ) => {
1919 beforeAll ( async ( ) => {
2020 let moduleRef = await Test . createTestingModule ( {
2121 controllers : [ TestService ]
@@ -61,7 +61,10 @@ describe("json-rpc-e2e", () => {
6161 } ) ;
6262
6363 it ( `should fail to invoke unexposed methods` , async ( ) => {
64- const expectedCodedException = new CodedRpcException ( "Method not found: test.notExposed" , 404 ) ;
64+ const expectedCodedException = new CodedRpcException (
65+ "Method not found: test.notExposed" ,
66+ 404
67+ ) ;
6568 const resp = service . notExposed ( { test : "data" } ) ;
6669 await expect ( resp ) . rejects . toThrowError ( expectedCodedException ) ;
6770 } ) ;
@@ -83,17 +86,17 @@ describe("json-rpc-e2e", () => {
8386 } ) ;
8487 } ) ;
8588
86- describe ( ' hybrid' , ( ) => {
89+ describe ( " hybrid" , ( ) => {
8790 beforeAll ( async ( ) => {
8891 let moduleRef = await Test . createTestingModule ( {
8992 controllers : [ TestService ]
9093 } ) . compile ( ) ;
91-
94+
9295 app = moduleRef . createNestApplication ( ) ;
9396
9497 server = new JsonRpcServer ( {
95- path : ' /rpc' ,
96- adapter : app . getHttpAdapter ( ) ,
98+ path : " /rpc" ,
99+ adapter : app . getHttpAdapter ( )
97100 } ) ;
98101
99102 app . connectMicroservice ( { strategy : server } ) ;
@@ -102,46 +105,46 @@ describe("json-rpc-e2e", () => {
102105 await app . init ( ) ;
103106 } ) ;
104107
105- it ( ' should invoke RPC methods on incoming HTTP requests' , async ( ) => {
108+ it ( " should invoke RPC methods on incoming HTTP requests" , async ( ) => {
106109 await request ( app . getHttpServer ( ) )
107- . post ( ' /rpc' )
108- . set ( ' Authorization' , ' Bearer xyz' )
110+ . post ( " /rpc" )
111+ . set ( " Authorization" , " Bearer xyz" )
109112 . send ( {
110- jsonrpc : ' 2.0' ,
111- method : ' test.invokeClientService' ,
112- id : '1' ,
113+ jsonrpc : " 2.0" ,
114+ method : " test.invokeClientService" ,
115+ id : "1" ,
113116 params : {
114- test : 'hi' ,
115- } ,
117+ test : "hi"
118+ }
116119 } )
117120 . expect ( {
118- jsonrpc : ' 2.0' ,
119- id : '1' ,
120- result : { test : 'hi' }
121+ jsonrpc : " 2.0" ,
122+ id : "1" ,
123+ result : { test : "hi" }
121124 } ) ;
122125 } ) ;
123126
124- it ( ' should wrap json-rpc errors in http 200' , async ( ) => {
127+ it ( " should wrap json-rpc errors in http 200" , async ( ) => {
125128 await request ( app . getHttpServer ( ) )
126- . post ( ' /rpc' )
127- . set ( ' Authorization' , ' Bearer xyz' )
128- . send ( {
129- jsonrpc : ' 2.0' ,
130- method : ' test.notExposed' ,
131- id : '1' ,
132- params : {
133- test : 'hi' ,
134- } ,
135- } )
136- . expect ( {
137- jsonrpc : ' 2.0' ,
138- id : '1' ,
139- error : {
140- code : 404 ,
141- data : { } ,
142- message : ' Method not found: test.notExposed' ,
143- }
144- } ) ;
129+ . post ( " /rpc" )
130+ . set ( " Authorization" , " Bearer xyz" )
131+ . send ( {
132+ jsonrpc : " 2.0" ,
133+ method : " test.notExposed" ,
134+ id : "1" ,
135+ params : {
136+ test : "hi"
137+ }
138+ } )
139+ . expect ( {
140+ jsonrpc : " 2.0" ,
141+ id : "1" ,
142+ error : {
143+ code : 404 ,
144+ data : { } ,
145+ message : " Method not found: test.notExposed"
146+ }
147+ } ) ;
145148 } ) ;
146149 } ) ;
147150} ) ;
0 commit comments