@@ -3,8 +3,9 @@ import { PATTERN_METADATA } from '../../constants';
33import {
44 MessagePattern ,
55 GrpcMethod ,
6- GrpcStreamMethod ,
6+ GrpcStreamMethod , GrpcMethodStreamingType ,
77} from '../../decorators/pattern.decorator' ;
8+ import { GrpcStreamCall } from '@nestjs/microservices' ;
89
910describe ( '@MessagePattern' , ( ) => {
1011 const pattern = { role : 'test' } ;
@@ -36,7 +37,7 @@ describe('@GrpcMethod', () => {
3637 expect ( metadata ) . to . be . eql ( {
3738 service : TestService . name ,
3839 rpc : 'Test' ,
39- streaming : false
40+ streaming : GrpcMethodStreamingType . NO_STREAMING
4041 } ) ;
4142 } ) ;
4243
@@ -46,7 +47,7 @@ describe('@GrpcMethod', () => {
4647 expect ( metadata ) . to . be . eql ( {
4748 service : 'TestService2' ,
4849 rpc : 'Test2' ,
49- streaming : false
50+ streaming : GrpcMethodStreamingType . NO_STREAMING
5051 } ) ;
5152 } ) ;
5253
@@ -56,7 +57,7 @@ describe('@GrpcMethod', () => {
5657 expect ( metadata ) . to . be . eql ( {
5758 service : 'TestService2' ,
5859 rpc : 'Test2' ,
59- streaming : false
60+ streaming : GrpcMethodStreamingType . NO_STREAMING
6061 } ) ;
6162 } ) ;
6263} ) ;
@@ -79,7 +80,7 @@ describe('@GrpcStreamMethod', () => {
7980 expect ( metadata ) . to . be . eql ( {
8081 service : TestService . name ,
8182 rpc : 'Test' ,
82- streaming : true
83+ streaming : GrpcMethodStreamingType . RX_STREAMING
8384 } ) ;
8485 } ) ;
8586
@@ -89,7 +90,7 @@ describe('@GrpcStreamMethod', () => {
8990 expect ( metadata ) . to . be . eql ( {
9091 service : 'TestService2' ,
9192 rpc : 'Test2' ,
92- streaming : true
93+ streaming : GrpcMethodStreamingType . RX_STREAMING
9394 } ) ;
9495 } ) ;
9596
@@ -99,7 +100,50 @@ describe('@GrpcStreamMethod', () => {
99100 expect ( metadata ) . to . be . eql ( {
100101 service : 'TestService2' ,
101102 rpc : 'Test2' ,
102- streaming : true
103+ streaming : GrpcMethodStreamingType . RX_STREAMING
104+ } ) ;
105+ } ) ;
106+ } ) ;
107+
108+ describe ( '@GrpcStreamCall' , ( ) => {
109+ class TestService {
110+ @GrpcStreamCall ( )
111+ public test ( ) { }
112+
113+ @GrpcStreamCall ( 'TestService2' )
114+ public test2 ( ) { }
115+
116+ @GrpcStreamCall ( 'TestService2' , 'Test2' )
117+ public test3 ( ) { }
118+ }
119+
120+ it ( 'should derive method and service name' , ( ) => {
121+ const svc = new TestService ( ) ;
122+ const metadata = Reflect . getMetadata ( PATTERN_METADATA , svc . test ) ;
123+ expect ( metadata ) . to . be . eql ( {
124+ service : TestService . name ,
125+ rpc : 'Test' ,
126+ streaming : GrpcMethodStreamingType . PT_STREAMING
127+ } ) ;
128+ } ) ;
129+
130+ it ( 'should derive method' , ( ) => {
131+ const svc = new TestService ( ) ;
132+ const metadata = Reflect . getMetadata ( PATTERN_METADATA , svc . test2 ) ;
133+ expect ( metadata ) . to . be . eql ( {
134+ service : 'TestService2' ,
135+ rpc : 'Test2' ,
136+ streaming : GrpcMethodStreamingType . PT_STREAMING
137+ } ) ;
138+ } ) ;
139+
140+ it ( 'should override both method and service' , ( ) => {
141+ const svc = new TestService ( ) ;
142+ const metadata = Reflect . getMetadata ( PATTERN_METADATA , svc . test3 ) ;
143+ expect ( metadata ) . to . be . eql ( {
144+ service : 'TestService2' ,
145+ rpc : 'Test2' ,
146+ streaming : GrpcMethodStreamingType . PT_STREAMING
103147 } ) ;
104148 } ) ;
105149} ) ;
0 commit comments