diff options
author | Yash Chaturvedi <yash.chaturvedi@linaro.org> | 2023-10-10 16:39:17 +0530 |
---|---|---|
committer | Yash Chaturvedi <yash.chaturvedi@linaro.org> | 2023-10-11 14:21:26 +0530 |
commit | e56d2c66234225094a2b322b8e6b606ad42598b8 (patch) | |
tree | 5d0a63a4dc765a22121a8ec2718325f6ae17e05e | |
parent | d8584015caac5a4ed7086386b3658abad3a8b287 (diff) |
Fix bug where changing preferred email results in duplicate emails
While changing preferred email, the client-side cache is incorrectly
updated, resulting in duplicate emails in the cache. Fix the issue by
updating the relevant logic.
Bug: Issue 304335624
Release-Notes: Changing preferred email does not result in duplicate emails
Change-Id: Ifea0d2a91426acc27b8b89720b39c858f859f31e
-rw-r--r-- | polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts | 4 | ||||
-rw-r--r-- | polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts index d468cf9674..8c4ac6d53e 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts @@ -818,9 +818,9 @@ export class GrRestApiInterface if (cachedEmails) { const emails = cachedEmails.map(entry => { if (entry.email === email) { - return {email, preferred: true}; + return {email: entry.email, preferred: true}; } else { - return {email}; + return {email: entry.email, preferred: false}; } }); this._cache.set('/accounts/self/emails', emails); diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js index df37502f9c..9c096bf554 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js @@ -458,6 +458,31 @@ suite('gr-rest-api-interface tests', () => { assert.deepEqual(sendStub.lastCall.args[0].body, {token: 'foo'}); }); + test('setPreferredAccountEmail', () => { + const email1 = 'email1@example.com'; + const email2 = 'email2@example.com'; + const encodedEmail = encodeURIComponent(email2); + const sendStub = sinon.stub(element._restApiHelper, 'send').resolves(); + element._cache.set('/accounts/self/emails', [ + {email: email1, preferred: true}, + {email: email2, preferred: false}, + ]); + + return element.setPreferredAccountEmail(email2).then(() => { + assert.isTrue(sendStub.calledOnce); + assert.equal(sendStub.lastCall.args[0].method, 'PUT'); + assert.equal(sendStub.lastCall.args[0].url, + `/accounts/self/emails/${encodedEmail}/preferred` + ); + assert.deepEqual( + element._restApiHelper._cache.get('/accounts/self/emails'), [ + {email: email1, preferred: false}, + {email: email2, preferred: true}, + ] + ); + }); + }); + test('setAccountStatus', () => { const sendStub = sinon.stub(element._restApiHelper, 'send') .returns(Promise.resolve('OOO')); |