Merge "Conditionally add PUSH_CERTIFICATES change option"

This commit is contained in:
Kasper Nilsson
2018-11-14 03:42:54 +00:00
committed by Gerrit Code Review
2 changed files with 64 additions and 25 deletions

View File

@@ -1297,21 +1297,27 @@
* @param {function()=} opt_cancelCondition * @param {function()=} opt_cancelCondition
*/ */
getChangeDetail(changeNum, opt_errFn, opt_cancelCondition) { getChangeDetail(changeNum, opt_errFn, opt_cancelCondition) {
const options = this.listChangesOptionsToHex( const options = [
this.ListChangesOption.ALL_COMMITS, this.ListChangesOption.ALL_COMMITS,
this.ListChangesOption.ALL_REVISIONS, this.ListChangesOption.ALL_REVISIONS,
this.ListChangesOption.CHANGE_ACTIONS, this.ListChangesOption.CHANGE_ACTIONS,
this.ListChangesOption.CURRENT_ACTIONS, this.ListChangesOption.CURRENT_ACTIONS,
this.ListChangesOption.DETAILED_LABELS, this.ListChangesOption.DETAILED_LABELS,
this.ListChangesOption.DOWNLOAD_COMMANDS, this.ListChangesOption.DOWNLOAD_COMMANDS,
this.ListChangesOption.MESSAGES, this.ListChangesOption.MESSAGES,
this.ListChangesOption.SUBMITTABLE, this.ListChangesOption.SUBMITTABLE,
this.ListChangesOption.WEB_LINKS, this.ListChangesOption.WEB_LINKS,
this.ListChangesOption.SKIP_MERGEABLE this.ListChangesOption.SKIP_MERGEABLE,
); ];
return this._getChangeDetail( return this.getConfig(false).then(config => {
changeNum, options, opt_errFn, opt_cancelCondition) if (config.receive && config.receive.enable_signed_push) {
.then(GrReviewerUpdatesParser.parse); options.push(this.ListChangesOption.PUSH_CERTIFICATES);
}
const optionsHex = this.listChangesOptionsToHex(...options);
return this._getChangeDetail(
changeNum, optionsHex, opt_errFn, opt_cancelCondition)
.then(GrReviewerUpdatesParser.parse);
});
}, },
/** /**

View File

@@ -722,15 +722,6 @@ limitations under the License.
assert.deepEqual(element._send.lastCall.args[0].body, {token: 'foo'}); assert.deepEqual(element._send.lastCall.args[0].body, {token: 'foo'});
}); });
test('GrReviewerUpdatesParser.parse is used', () => {
sandbox.stub(GrReviewerUpdatesParser, 'parse').returns(
Promise.resolve('foo'));
return element.getChangeDetail(42).then(result => {
assert.isTrue(GrReviewerUpdatesParser.parse.calledOnce);
assert.equal(result, 'foo');
});
});
test('setAccountStatus', () => { test('setAccountStatus', () => {
sandbox.stub(element, '_send').returns(Promise.resolve('OOO')); sandbox.stub(element, '_send').returns(Promise.resolve('OOO'));
element._cache.set('/accounts/self/detail', {}); element._cache.set('/accounts/self/detail', {});
@@ -1031,7 +1022,49 @@ limitations under the License.
}); });
}); });
suite('_getChangeDetail', () => { suite('getChangeDetail', () => {
suite('change detail options', () => {
let toHexStub;
setup(() => {
toHexStub = sandbox.stub(element, 'listChangesOptionsToHex',
options => 'deadbeef');
sandbox.stub(element, '_getChangeDetail',
async (changeNum, options) => ({changeNum, options}));
});
test('signed pushes disabled', async () => {
const {PUSH_CERTIFICATES} = element.ListChangesOption;
sandbox.stub(element, 'getConfig', async () => ({}));
const {changeNum, options} = await element.getChangeDetail(123);
assert.strictEqual(123, changeNum);
assert.strictEqual('deadbeef', options);
assert.isTrue(toHexStub.calledOnce);
assert.isFalse(toHexStub.lastCall.args.includes(PUSH_CERTIFICATES));
});
test('signed pushes enabled', async () => {
const {PUSH_CERTIFICATES} = element.ListChangesOption;
sandbox.stub(element, 'getConfig', async () => {
return {receive: {enable_signed_push: true}};
});
const {changeNum, options} = await element.getChangeDetail(123);
assert.strictEqual(123, changeNum);
assert.strictEqual('deadbeef', options);
assert.isTrue(toHexStub.calledOnce);
assert.isTrue(toHexStub.lastCall.args.includes(PUSH_CERTIFICATES));
});
});
test('GrReviewerUpdatesParser.parse is used', () => {
sandbox.stub(GrReviewerUpdatesParser, 'parse').returns(
Promise.resolve('foo'));
return element.getChangeDetail(42).then(result => {
assert.isTrue(GrReviewerUpdatesParser.parse.calledOnce);
assert.equal(result, 'foo');
});
});
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';