11import $ from 'jquery' ;
2- import { Client , Request } from 'app/api' ;
3- import GroupActions from 'app/actions/groupActions' ;
2+ import { Client , Request , paramsToQueryArgs } from 'app/api' ;
43
54describe ( 'api' , function ( ) {
65 beforeEach ( function ( ) {
@@ -9,6 +8,30 @@ describe('api', function () {
98 this . api = new Client ( ) ;
109 } ) ;
1110
11+
12+ describe ( 'paramsToQueryArgs()' , function ( ) {
13+ it ( 'should convert itemIds properties to id array' , function ( ) {
14+ expect ( paramsToQueryArgs ( {
15+ itemIds : [ 1 , 2 , 3 ] ,
16+ query : 'is:unresolved' // itemIds takes precedence
17+ } ) ) . to . eql ( { id : [ 1 , 2 , 3 ] } ) ;
18+ } ) ;
19+
20+ it ( 'should extract query property if no itemIds' , function ( ) {
21+ expect ( paramsToQueryArgs ( {
22+ query : 'is:unresolved' ,
23+ foo : 'bar'
24+ } ) ) . to . eql ( { query : 'is:unresolved' } ) ;
25+ } ) ;
26+
27+ it ( 'should convert params w/o itemIds or query to undefined' , function ( ) {
28+ expect ( paramsToQueryArgs ( {
29+ foo : 'bar' ,
30+ bar : 'baz' // paramsToQueryArgs ignores these
31+ } ) ) . to . be . undefined ;
32+ } ) ;
33+ } ) ;
34+
1235 describe ( 'Client' , function ( ) {
1336 beforeEach ( function ( ) {
1437 this . sandbox . stub ( $ , 'ajax' ) ;
@@ -56,8 +79,6 @@ describe('api', function () {
5679 } ) ;
5780
5881 it ( 'should use query as query if itemIds are absent' , function ( ) {
59- this . sandbox . stub ( GroupActions , 'update' ) ;
60-
6182 this . api . bulkUpdate ( {
6283 orgId : '1337' ,
6384 projectId : '1337' ,
@@ -71,4 +92,40 @@ describe('api', function () {
7192 expect ( requestArgs . query ) . to . eql ( { query : 'is:resolved' } ) ;
7293 } ) ;
7394 } ) ;
95+
96+ describe ( 'merge()' , function ( ) {
97+ // TODO: this is totally copypasta from the test above. We need to refactor
98+ // these API methods/tests.
99+ beforeEach ( function ( ) {
100+ this . sandbox . stub ( this . api , '_wrapRequest' ) ;
101+ } ) ;
102+
103+ it ( 'should use itemIds as query if provided' , function ( ) {
104+ this . api . merge ( {
105+ orgId : '1337' ,
106+ projectId : '1337' ,
107+ itemIds : [ 1 , 2 , 3 ] ,
108+ data : { status : 'unresolved' } ,
109+ query : 'is:resolved'
110+ } ) ;
111+
112+ expect ( this . api . _wrapRequest . calledOnce ) . to . be . ok ;
113+ let requestArgs = this . api . _wrapRequest . getCall ( 0 ) . args [ 1 ] ;
114+ expect ( requestArgs . query ) . to . eql ( { id : [ 1 , 2 , 3 ] } ) ;
115+ } ) ;
116+
117+ it ( 'should use query as query if itemIds are absent' , function ( ) {
118+ this . api . merge ( {
119+ orgId : '1337' ,
120+ projectId : '1337' ,
121+ itemIds : null ,
122+ data : { status : 'unresolved' } ,
123+ query : 'is:resolved'
124+ } ) ;
125+
126+ expect ( this . api . _wrapRequest . calledOnce ) . to . be . ok ;
127+ let requestArgs = this . api . _wrapRequest . getCall ( 0 ) . args [ 1 ] ;
128+ expect ( requestArgs . query ) . to . eql ( { query : 'is:resolved' } ) ;
129+ } ) ;
130+ } ) ;
74131} ) ;
0 commit comments