diff options
Diffstat (limited to 'polygerrit-ui/app/models/accounts-model/accounts-model_test.ts')
-rw-r--r-- | polygerrit-ui/app/models/accounts-model/accounts-model_test.ts | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/polygerrit-ui/app/models/accounts-model/accounts-model_test.ts b/polygerrit-ui/app/models/accounts-model/accounts-model_test.ts index 53c90a67ea..e84723c6b2 100644 --- a/polygerrit-ui/app/models/accounts-model/accounts-model_test.ts +++ b/polygerrit-ui/app/models/accounts-model/accounts-model_test.ts @@ -5,12 +5,23 @@ */ import '../../test/common-test-setup'; -import {EmailAddress} from '../../api/rest-api'; +import { + AccountDetailInfo, + AccountId, + EmailAddress, + Timestamp, +} from '../../api/rest-api'; import {getAppContext} from '../../services/app-context'; import {stubRestApi} from '../../test/test-utils'; import {AccountsModel} from './accounts-model'; import {assert} from '@open-wc/testing'; +const KERMIT: AccountDetailInfo = { + _account_id: 1 as AccountId, + name: 'Kermit', + registered_on: '2015-03-12 18:32:08.000000000' as Timestamp, +}; + suite('accounts-model tests', () => { let model: AccountsModel; @@ -22,6 +33,24 @@ suite('accounts-model tests', () => { model.finalize(); }); + test('basic lookup', async () => { + const stub = stubRestApi('getAccountDetails').returns( + Promise.resolve(KERMIT) + ); + + let filled = await model.fillDetails({_account_id: 1 as AccountId}); + assert.equal(filled.name, 'Kermit'); + assert.equal(filled, KERMIT); + assert.equal(stub.callCount, 1); + + filled = await model.fillDetails({_account_id: 1 as AccountId}); + assert.equal(filled.name, 'Kermit'); + // Cache objects are cloned on lookup, so this is a different object. + assert.notEqual(filled, KERMIT); + // Did not have to call the REST API again. + assert.equal(stub.callCount, 1); + }); + test('invalid account makes only one request', () => { const response = {...new Response(), status: 404}; const getAccountDetails = stubRestApi('getAccountDetails').callsFake( |