Skip to content

Commit 00e09b4

Browse files
benvinegarmattrobenolt
authored andcommitted
Merge pull request #2607 from getsentry/fix-merge-again
Fix bulk merge (#2585)
1 parent 2cc0045 commit 00e09b4

File tree

3 files changed

+77
-15
lines changed

3 files changed

+77
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"eslint-plugin-react": "3.11.2",
6262
"gettext-parser": "1.1.1",
6363
"js-cookie": "2.0.4",
64-
"karma": "0.13.15",
64+
"karma": "0.13.19",
6565
"karma-chai": "0.1.0",
6666
"karma-mocha": "0.1.10",
6767
"karma-phantomjs-launcher": "0.1.4",

src/sentry/static/sentry/app/api.jsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ export class Request {
1414
}
1515
}
1616

17+
/**
18+
* Converts input parameters to API-compatible query arguments
19+
* @param params
20+
*/
21+
export function paramsToQueryArgs(params) {
22+
return params.itemIds
23+
? {id: params.itemIds} // items matching array of itemids
24+
: params.query
25+
? {query: params.query} // items matching search query
26+
: undefined; // all items
27+
}
28+
1729
export class Client {
1830
constructor(options) {
1931
if (typeof options === 'undefined') {
@@ -119,7 +131,7 @@ export class Client {
119131

120132
bulkDelete(params, options) {
121133
let path = '/projects/' + params.orgId + '/' + params.projectId + '/issues/';
122-
let query = (params.itemIds ? {id: params.itemIds} : undefined);
134+
let query = paramsToQueryArgs(params);
123135
let id = this.uniqueId();
124136

125137
GroupActions.delete(id, params.itemIds);
@@ -138,14 +150,7 @@ export class Client {
138150

139151
bulkUpdate(params, options) {
140152
let path = '/projects/' + params.orgId + '/' + params.projectId + '/issues/';
141-
142-
let query =
143-
params.itemIds
144-
? {id: params.itemIds}
145-
: params.query
146-
? {query: params.query}
147-
: undefined;
148-
153+
let query = paramsToQueryArgs(params);
149154
let id = this.uniqueId();
150155

151156
GroupActions.update(id, params.itemIds, params.data);
@@ -165,7 +170,7 @@ export class Client {
165170

166171
merge(params, options) {
167172
let path = '/projects/' + params.orgId + '/' + params.projectId + '/issues/';
168-
let query = (params.itemIds ? {id: params.itemIds} : undefined);
173+
let query = paramsToQueryArgs(params);
169174
let id = this.uniqueId();
170175

171176
GroupActions.merge(id, params.itemIds);

tests/js/spec/api.spec.jsx

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import $ 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

54
describe('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

Comments
 (0)