@@ -7,13 +7,8 @@ import type { SinonStub } from 'sinon';
77import sinon from 'sinon' ;
88import { EXCEPTION_CODE } from '@constants/index' ;
99import MicroserviceResponse from '@core/microservice-response' ;
10- import {
11- IEndpointHandler ,
12- IEndpointOptions ,
13- MiddlewareHandler ,
14- MiddlewareType ,
15- } from '@interfaces/services/i-abstract-microservice' ;
16- import { AutoRegistrationAction , IExpressRequest } from '@interfaces/services/i-gateway' ;
10+ import { MiddlewareHandler , MiddlewareType } from '@interfaces/services/i-abstract-microservice' ;
11+ import { IExpressRequest } from '@interfaces/services/i-gateway' ;
1712import AbstractMicroservice from '@services/abstract-microservice' ;
1813import Gateway from '@services/gateway' ;
1914
@@ -49,10 +44,6 @@ describe('services/gateway', () => {
4944 const msName2 = 'ms2' ;
5045 const msHandler = ( ) => new MicroserviceResponse ( ) as unknown as Promise < MicroserviceResponse > ;
5146
52- // Only after start microservice
53- let autoRegistrationHandler : IEndpointHandler ;
54- const autoRegistrationSender = 'test' ;
55-
5647 before ( ( ) => {
5748 sinon . stub ( console , 'info' ) ;
5849 } ) ;
@@ -95,22 +86,6 @@ describe('services/gateway', () => {
9586 expect ( infoRoute ) . to . undefined ;
9687 } ) ;
9788
98- it ( 'should correct start microservice without auto registration endpoint' , async ( ) => {
99- const sandbox = sinon . createSandbox ( ) ;
100-
101- sandbox . stub ( ms . getExpress ( ) , 'listen' ) . returns ( { close : sinon . stub ( ) } as unknown as Server ) ;
102- sandbox . stub ( axios , 'request' ) . rejects ( new Error ( 'ECONNREFUSED' ) ) ;
103- sandbox . stub ( Gateway , 'instance' as any ) . value ( undefined ) ;
104-
105- const localMs = Gateway . create ( { hasAutoRegistrationEndpoint : false } ) ;
106-
107- await localMs . start ( ) ;
108-
109- sandbox . restore ( ) ;
110-
111- expect ( localMs ) . to . property ( 'endpoints' ) . have . not . property ( 'register-microservice' ) ;
112- } ) ;
113-
11489 it ( 'should correct register microservice handler' , ( ) => {
11590 ms . addMicroservice ( msName , msHandler ) ;
11691 ms . addMicroservice ( msName2 ) ;
@@ -166,51 +141,13 @@ describe('services/gateway', () => {
166141 stubbed . restore ( ) ;
167142 stubbedAxios . restore ( ) ;
168143
169- const { handler } = ms [ 'endpoints' ] [ ms [ 'autoRegistrationEndpoint' ] ] ;
170-
171- autoRegistrationHandler = handler ;
172-
173144 const [ port , host , funcLog ] = stubbed . firstCall . args as unknown as [ string , string , ( ) => void ] ;
174145
175146 expect ( port ) . to . equal ( 3000 ) ;
176147 expect ( host ) . to . equal ( '0.0.0.0' ) ;
177148 expect ( ( ) => funcLog ( ) ) . to . not . throw ( ) ;
178149 } ) ;
179150
180- it ( 'should correct add auto registration endpoint' , ( ) => {
181- expect ( ms ) . to . property ( 'endpoints' ) . have . property ( 'register-microservice' ) ;
182- } ) ;
183-
184- it ( 'should correct auto register microservice' , async ( ) => {
185- await autoRegistrationHandler ( { action : AutoRegistrationAction . ADD } , {
186- sender : autoRegistrationSender ,
187- } as IEndpointOptions ) ;
188-
189- expect ( ms ) . to . property ( 'microservices' ) . have . property ( autoRegistrationSender ) ;
190- } ) ;
191-
192- it ( 'should throw errors if incorrect try auto register microservice' , ( ) => {
193- expect ( ( ) =>
194- autoRegistrationHandler ( { action : 'unknown' } , {
195- sender : autoRegistrationSender ,
196- } as IEndpointOptions ) ,
197- ) . to . throw ( ) ;
198- expect ( ( ) =>
199- autoRegistrationHandler ( { action : AutoRegistrationAction . REMOVE } , {
200- sender : '' ,
201- } as IEndpointOptions ) ,
202- ) . to . throw ( ) ;
203- } ) ;
204-
205- it ( 'should correct auto cancel microservice registration' , async ( ) => {
206- await autoRegistrationHandler ( { action : AutoRegistrationAction . REMOVE } , {
207- sender : autoRegistrationSender ,
208- } as IEndpointOptions ) ;
209-
210- expect ( ms ) . to . property ( 'microservices' ) . not . have . property ( autoRegistrationSender ) ;
211- } ) ;
212- // end
213-
214151 it ( 'should correct response info route' , ( ) => {
215152 const infoRoute = _ . findLast ( ms . getExpress ( ) . _router . stack , {
216153 route : { path : '/' , methods : { get : true } } ,
0 commit comments