Fix getChange ignoring optionsHex on project cache miss.
This is reland of I563322c36f4ea5a0ffec25fdf17c21777cce9104 with fixed
issue and test. The bug was that the query param ("q") was specified as
`params` field, but also as part of the url.
getChange uses different url, based on whether or not the UI knows which
project the change belongs to. Previously the branch of the code that
uses a search query url, wouldn't set the optionHex. This was not an
issue, because callsites that set options, would always have a previous
call that populated the cache (almost certainly). But this is a
suprising inconsistency in the API.
Bug: Google b/445644919
Release-Notes: skip
Change-Id: Iadca6e879dce158d291d005d625dc93424509de2
diff --git a/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts b/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts
index ada11f9..553000b 100644
--- a/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts
+++ b/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts
@@ -3541,10 +3541,15 @@
)
) as Promise<ChangeInfo | undefined>;
} else {
+ const params: FetchParams = {q: `change:${changeNum}`};
+ if (optionsHex) {
+ params['O'] = optionsHex;
+ }
return this._restApiHelper
.fetchJSON(
{
- url: `/changes/?q=change:${changeNum}`,
+ url: '/changes/',
+ params,
errFn,
anonymizedUrl: '/changes/?q=change:*',
},
diff --git a/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.ts b/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.ts
index 4e33381..78ac93f 100644
--- a/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.ts
+++ b/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.ts
@@ -1517,6 +1517,57 @@
});
});
+ suite('getChange', () => {
+ const changeNum = 555 as NumericChangeId;
+ const repo = 'test-repo' as RepoName;
+
+ test('getChange with known project', async () => {
+ element._projectLookup[changeNum] = Promise.resolve(repo);
+ const promise = mockPromise<ParsedJSON>();
+ const stub = sinon
+ .stub(element._restApiHelper, 'fetchJSON')
+ .returns(promise);
+
+ const change = element.getChange(
+ changeNum,
+ undefined,
+ listChangesOptionsToHex(ListChangesOption.DETAILED_ACCOUNTS)
+ );
+ promise.resolve({...createChange()} as unknown as ParsedJSON);
+
+ await change;
+
+ assert.isTrue(stub.called);
+ assert.equal(stub.args[0][0].url, '/changes/test-repo~555');
+ assert.deepEqual(stub.args[0][0].params, {
+ O: listChangesOptionsToHex(ListChangesOption.DETAILED_ACCOUNTS),
+ });
+ });
+
+ test('getChange with unknown projecgt', async () => {
+ const promise = mockPromise<ParsedJSON>();
+ const stub = sinon
+ .stub(element._restApiHelper, 'fetchJSON')
+ .returns(promise);
+
+ const change = element.getChange(
+ changeNum,
+ undefined,
+ listChangesOptionsToHex(ListChangesOption.DETAILED_ACCOUNTS)
+ );
+ promise.resolve({...createChange()} as unknown as ParsedJSON);
+
+ await change;
+
+ assert.isTrue(stub.called);
+ assert.equal(stub.args[0][0].url, '/changes/');
+ assert.deepEqual(stub.args[0][0].params, {
+ O: listChangesOptionsToHex(ListChangesOption.DETAILED_ACCOUNTS),
+ q: 'change:555',
+ });
+ });
+ });
+
suite('getChanges populates _projectLookup', () => {
test('multiple queries', async () => {
sinon.stub(element._restApiHelper, 'fetchJSON').resolves([