Merge "Rename params variable to optionsHex"

This commit is contained in:
Thomas Shafer 2019-03-13 21:36:02 +00:00 committed by Gerrit Code Review
commit 2fc37eb9e8
2 changed files with 15 additions and 13 deletions

View File

@ -353,7 +353,7 @@
/** /**
* @param {string} url * @param {string} url
* @param {?Object=} opt_params URL params, key-value hash. * @param {?Object|string=} opt_params URL params, key-value hash.
* @return {string} * @return {string}
*/ */
_urlWithParams(url, opt_params) { _urlWithParams(url, opt_params) {
@ -1352,30 +1352,32 @@
* @param {function()=} opt_cancelCondition * @param {function()=} opt_cancelCondition
*/ */
getDiffChangeDetail(changeNum, opt_errFn, opt_cancelCondition) { getDiffChangeDetail(changeNum, opt_errFn, opt_cancelCondition) {
const params = this.listChangesOptionsToHex( const optionsHex = this.listChangesOptionsToHex(
this.ListChangesOption.ALL_COMMITS, this.ListChangesOption.ALL_COMMITS,
this.ListChangesOption.ALL_REVISIONS, this.ListChangesOption.ALL_REVISIONS,
this.ListChangesOption.SKIP_MERGEABLE this.ListChangesOption.SKIP_MERGEABLE
); );
return this._getChangeDetail(changeNum, params, opt_errFn, return this._getChangeDetail(changeNum, optionsHex, opt_errFn,
opt_cancelCondition); opt_cancelCondition);
}, },
/** /**
* @param {number|string} changeNum * @param {number|string} changeNum
* @param {string|undefined} optionsHex list changes options in hex
* @param {function(?Response, string=)=} opt_errFn * @param {function(?Response, string=)=} opt_errFn
* @param {function()=} opt_cancelCondition * @param {function()=} opt_cancelCondition
*/ */
_getChangeDetail(changeNum, params, opt_errFn, opt_cancelCondition) { _getChangeDetail(changeNum, optionsHex, opt_errFn, opt_cancelCondition) {
return this.getChangeActionURL(changeNum, null, '/detail').then(url => { return this.getChangeActionURL(changeNum, null, '/detail').then(url => {
const urlWithParams = this._urlWithParams(url, params); const urlWithParams = this._urlWithParams(url, optionsHex);
const params = {O: optionsHex};
const req = { const req = {
url, url,
errFn: opt_errFn, errFn: opt_errFn,
cancelCondition: opt_cancelCondition, cancelCondition: opt_cancelCondition,
params: {O: params}, params,
fetchOptions: this._etags.getOptions(urlWithParams), fetchOptions: this._etags.getOptions(urlWithParams),
anonymizedUrl: '/changes/*~*/detail?O=' + params, anonymizedUrl: '/changes/*~*/detail?O=' + optionsHex,
}; };
return this._fetchRawJSON(req).then(response => { return this._fetchRawJSON(req).then(response => {
if (response && response.status === 304) { if (response && response.status === 304) {

View File

@ -1151,12 +1151,12 @@ limitations under the License.
test('_getChangeDetail passes params to ETags decorator', () => { test('_getChangeDetail passes params to ETags decorator', () => {
const changeNum = 4321; const changeNum = 4321;
element._projectLookup[changeNum] = 'test'; element._projectLookup[changeNum] = 'test';
const params = {foo: 'bar'};
const expectedUrl = const expectedUrl =
window.CANONICAL_PATH + '/changes/test~4321/detail?foo=bar'; window.CANONICAL_PATH + '/changes/test~4321/detail?'+
'0=5&1=1&2=6&3=7&4=1&5=4';
sandbox.stub(element._etags, 'getOptions'); sandbox.stub(element._etags, 'getOptions');
sandbox.stub(element._etags, 'collect'); sandbox.stub(element._etags, 'collect');
return element._getChangeDetail(changeNum, params).then(() => { return element._getChangeDetail(changeNum, '516714').then(() => {
assert.isTrue(element._etags.getOptions.calledWithExactly( assert.isTrue(element._etags.getOptions.calledWithExactly(
expectedUrl)); expectedUrl));
assert.equal(element._etags.collect.lastCall.args[0], expectedUrl); assert.equal(element._etags.collect.lastCall.args[0], expectedUrl);
@ -1169,7 +1169,7 @@ limitations under the License.
.returns(Promise.resolve('')); .returns(Promise.resolve(''));
sandbox.stub(element, '_fetchRawJSON') sandbox.stub(element, '_fetchRawJSON')
.returns(Promise.resolve({ok: false, status: 500})); .returns(Promise.resolve({ok: false, status: 500}));
return element._getChangeDetail(123, {}, errFn).then(() => { return element._getChangeDetail(123, '516714', errFn).then(() => {
assert.isTrue(errFn.called); assert.isTrue(errFn.called);
}); });
}); });
@ -1185,7 +1185,7 @@ limitations under the License.
parsed: mockResponse, parsed: mockResponse,
raw: JSON.stringify(mockResponse), raw: JSON.stringify(mockResponse),
})); }));
return element._getChangeDetail(1).then(() => { return element._getChangeDetail(1, '516714').then(() => {
assert.equal(Object.keys(element._projectLookup).length, 1); assert.equal(Object.keys(element._projectLookup).length, 1);
assert.equal(element._projectLookup[1], 'test'); assert.equal(element._projectLookup[1], 'test');
}); });
@ -1216,7 +1216,7 @@ limitations under the License.
ok: true, ok: true,
})); }));
return element._getChangeDetail(123, {}).then(detail => { return element._getChangeDetail(123, '516714').then(detail => {
assert.isFalse(getPayloadSpy.called); assert.isFalse(getPayloadSpy.called);
assert.isTrue(collectSpy.calledOnce); assert.isTrue(collectSpy.calledOnce);
const cachedResponse = element._etags.getCachedPayload(requestUrl); const cachedResponse = element._etags.getCachedPayload(requestUrl);