@@ -119,6 +119,81 @@ describe('Test rabbit class', function() {
119119 stub . calledWith ( handler ) . should . be . true ( ) ;
120120 } ) ;
121121
122+ it ( 'should create queue with max priority when priority is specified' , async function ( ) {
123+ const subscription = sandbox . stub ( Queue . prototype , 'subscribe' ) ;
124+ rabbit = new Rabbit ( this . url ) ;
125+ await rabbit . connected ;
126+ const stub = sandbox . stub ( rabbit . consumeChannel , 'assertQueue' )
127+ . resolves ( { queue : this . name , messageCount : 0 , consumerCount : 0 } ) ;
128+ const priority = 23 ;
129+ const handler = ( ) => { } ;
130+ await rabbit . createQueue ( this . name , { priority : priority } , handler ) ;
131+ subscription . calledWith ( handler ) . should . be . true ( ) ;
132+ const [ name , options ] = stub . firstCall . args ;
133+ name . should . equal ( this . name ) ;
134+ options ! . arguments [ 'x-max-priority' ] . should . equals ( priority ) ;
135+ } ) ;
136+
137+ it ( 'should apply queue type when defaultQueueType is provided' , async function ( ) {
138+ const subscription = sandbox . stub ( Queue . prototype , 'subscribe' ) ;
139+ const queueType = 'classic' ;
140+ rabbit = new Rabbit ( this . url , { defaultQueueType : queueType } ) ;
141+ await rabbit . connected ;
142+ const stub = sandbox . stub ( rabbit . consumeChannel , 'assertQueue' )
143+ . resolves ( { queue : this . name , messageCount : 0 , consumerCount : 0 } ) ;
144+ const handler = ( ) => { } ;
145+ await rabbit . createQueue ( this . name , { } , handler ) ;
146+ subscription . calledWith ( handler ) . should . be . true ( ) ;
147+ const [ name , options ] = stub . firstCall . args ;
148+ name . should . equal ( this . name ) ;
149+ options ! . arguments [ 'x-queue-type' ] . should . equals ( queueType ) ;
150+ } ) ;
151+
152+ it ( 'should not set x-queue-type when neither default nor explicit queue type is provided' , async function ( ) {
153+ const subscription = sandbox . stub ( Queue . prototype , 'subscribe' ) ;
154+ rabbit = new Rabbit ( this . url ) ;
155+ await rabbit . connected ;
156+ const stub = sandbox . stub ( rabbit . consumeChannel , 'assertQueue' )
157+ . resolves ( { queue : this . name , messageCount : 0 , consumerCount : 0 } ) ;
158+ const handler = ( ) => { } ;
159+ await rabbit . createQueue ( this . name , { } , handler ) ;
160+ subscription . calledWith ( handler ) . should . be . true ( ) ;
161+ stub . calledOnce . should . be . true ( ) ;
162+ const [ name , options ] = stub . firstCall . args ;
163+ name . should . equal ( this . name ) ;
164+ options ! . arguments . should . not . have . property ( 'x-queue-type' ) ;
165+ } ) ;
166+
167+ it ( 'should use the provided queue type instead of the default' , async function ( ) {
168+ const subscription = sandbox . stub ( Queue . prototype , 'subscribe' ) ;
169+ rabbit = new Rabbit ( this . url , { defaultQueueType : 'classic' } ) ;
170+ await rabbit . connected ;
171+ const stub = sandbox . stub ( rabbit . consumeChannel , 'assertQueue' )
172+ . resolves ( { queue : this . name , messageCount : 0 , consumerCount : 0 } ) ;
173+ const handler = ( ) => { } ;
174+ const queueType = 'quorum' ;
175+ await rabbit . createQueue ( this . name , { arguments : { 'x-queue-type' : queueType } } , handler ) ;
176+ subscription . calledWith ( handler ) . should . be . true ( ) ;
177+ const [ name , options ] = stub . firstCall . args ;
178+ name . should . equal ( this . name ) ;
179+ options ! . arguments [ 'x-queue-type' ] . should . equals ( queueType ) ;
180+ } ) ;
181+
182+ it ( 'should ignore priority when creating a quorum queue' , async function ( ) {
183+ const subscription = sandbox . stub ( Queue . prototype , 'subscribe' ) ;
184+ rabbit = new Rabbit ( this . url , { defaultQueueType : 'quorum' } ) ;
185+ await rabbit . connected ;
186+ const stub = sandbox . stub ( rabbit . consumeChannel , 'assertQueue' )
187+ . resolves ( { queue : this . name , messageCount : 0 , consumerCount : 0 } ) ;
188+ const handler = ( ) => { } ;
189+ await rabbit . createQueue ( this . name , { priority : 23 } , handler ) ;
190+ subscription . calledWith ( handler ) . should . be . true ( ) ;
191+ stub . calledOnce . should . be . true ( ) ;
192+ const [ name , options ] = stub . firstCall . args ;
193+ name . should . equal ( this . name ) ;
194+ options ! . arguments . should . not . have . property ( 'x-max-priority' ) ;
195+ } ) ;
196+
122197 it ( 'should unsubscribe' , async function ( ) {
123198 const stub = sandbox . stub ( Queue . prototype , 'unsubscribe' ) ;
124199 rabbit = new Rabbit ( this . url ) ;
0 commit comments