-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: omit cost center details REST calls for lists
* use the link list attributes to map the data for cost center lists
- Loading branch information
Showing
4 changed files
with
238 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
src/app/core/models/cost-center/cost-center.mapper.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,219 @@ | ||
import { Link } from 'ish-core/models/link/link.model'; | ||
|
||
import { CostCenterData } from './cost-center.interface'; | ||
import { CostCenterMapper } from './cost-center.mapper'; | ||
|
||
describe('Cost Center Mapper', () => { | ||
describe('fromListData', () => { | ||
it(`should return costCenters when getting CostCenterLinks`, () => { | ||
const costCenterListData = [ | ||
{ | ||
attributes: [ | ||
{ | ||
name: 'name', | ||
value: 'Oil Corp Headquarter', | ||
}, | ||
{ | ||
name: 'costCenterId', | ||
value: '100400', | ||
}, | ||
{ | ||
name: 'budgetPeriod', | ||
value: 'monthly', | ||
}, | ||
{ | ||
name: 'active', | ||
value: true, | ||
}, | ||
{ | ||
name: 'budget', | ||
value: { | ||
type: 'Money', | ||
value: 20000.0, | ||
currencyMnemonic: 'USD', | ||
currency: 'USD', | ||
}, | ||
}, | ||
{ | ||
name: 'pendingOrders', | ||
value: 0, | ||
}, | ||
{ | ||
name: 'approvedOrders', | ||
value: 0, | ||
}, | ||
{ | ||
name: 'costCenterOwner', | ||
value: { | ||
email: '[email protected]', | ||
firstName: 'Jack', | ||
lastName: 'Link', | ||
login: '[email protected]', | ||
}, | ||
}, | ||
{ | ||
name: 'spentBudget', | ||
value: { | ||
type: 'Money', | ||
value: 0.0, | ||
currencyMnemonic: 'USD', | ||
currency: 'USD', | ||
}, | ||
}, | ||
{ | ||
name: 'remainingBudget', | ||
value: { | ||
type: 'Money', | ||
value: 20000.0, | ||
currencyMnemonic: 'USD', | ||
currency: 'USD', | ||
}, | ||
}, | ||
], | ||
itemId: 'LmpA8AVnGzEAAAGRxuAADVoP', | ||
}, | ||
{ | ||
attributes: [ | ||
{ | ||
name: 'name', | ||
value: 'Oil Corp Subsidiary 1', | ||
}, | ||
{ | ||
name: 'costCenterId', | ||
value: '100401', | ||
}, | ||
{ | ||
name: 'budgetPeriod', | ||
value: 'monthly', | ||
}, | ||
{ | ||
name: 'active', | ||
value: true, | ||
}, | ||
{ | ||
name: 'budget', | ||
value: { | ||
type: 'Money', | ||
value: 5000.0, | ||
currencyMnemonic: 'USD', | ||
currency: 'USD', | ||
}, | ||
}, | ||
{ | ||
name: 'pendingOrders', | ||
value: 1, | ||
}, | ||
{ | ||
name: 'approvedOrders', | ||
value: 4, | ||
}, | ||
{ | ||
name: 'costCenterOwner', | ||
value: { | ||
email: '[email protected]', | ||
firstName: 'Bernhard', | ||
lastName: 'Boldner', | ||
login: '[email protected]', | ||
}, | ||
}, | ||
{ | ||
name: 'spentBudget', | ||
value: { | ||
type: 'Money', | ||
value: 156759.02, | ||
currencyMnemonic: 'USD', | ||
currency: 'USD', | ||
}, | ||
}, | ||
{ | ||
name: 'remainingBudget', | ||
value: { | ||
type: 'Money', | ||
value: -151759.02, | ||
currencyMnemonic: 'USD', | ||
currency: 'USD', | ||
}, | ||
}, | ||
], | ||
itemId: 'XopA8AVnEKUAAAGR0OAADVoP', | ||
}, | ||
] as Link[]; | ||
const costCenters = CostCenterMapper.fromListData(costCenterListData); | ||
|
||
expect(costCenters).toBeTruthy(); | ||
expect(costCenters).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"active": true, | ||
"approvedOrders": 0, | ||
"budget": { | ||
"currency": "USD", | ||
"currencyMnemonic": "USD", | ||
"type": "Money", | ||
"value": 20000, | ||
}, | ||
"budgetPeriod": "monthly", | ||
"costCenterId": "100400", | ||
"costCenterOwner": { | ||
"email": "[email protected]", | ||
"firstName": "Jack", | ||
"lastName": "Link", | ||
"login": "[email protected]", | ||
}, | ||
"id": "LmpA8AVnGzEAAAGRxuAADVoP", | ||
"name": "Oil Corp Headquarter", | ||
"pendingOrders": 0, | ||
"remainingBudget": { | ||
"currency": "USD", | ||
"currencyMnemonic": "USD", | ||
"type": "Money", | ||
"value": 20000, | ||
}, | ||
"spentBudget": { | ||
"currency": "USD", | ||
"currencyMnemonic": "USD", | ||
"type": "Money", | ||
"value": 0, | ||
}, | ||
}, | ||
{ | ||
"active": true, | ||
"approvedOrders": 4, | ||
"budget": { | ||
"currency": "USD", | ||
"currencyMnemonic": "USD", | ||
"type": "Money", | ||
"value": 5000, | ||
}, | ||
"budgetPeriod": "monthly", | ||
"costCenterId": "100401", | ||
"costCenterOwner": { | ||
"email": "[email protected]", | ||
"firstName": "Bernhard", | ||
"lastName": "Boldner", | ||
"login": "[email protected]", | ||
}, | ||
"id": "XopA8AVnEKUAAAGR0OAADVoP", | ||
"name": "Oil Corp Subsidiary 1", | ||
"pendingOrders": 1, | ||
"remainingBudget": { | ||
"currency": "USD", | ||
"currencyMnemonic": "USD", | ||
"type": "Money", | ||
"value": -151759.02, | ||
}, | ||
"spentBudget": { | ||
"currency": "USD", | ||
"currencyMnemonic": "USD", | ||
"type": "Money", | ||
"value": 156759.02, | ||
}, | ||
}, | ||
] | ||
`); | ||
}); | ||
}); | ||
|
||
describe('fromData', () => { | ||
it(`should return a CostCenter when getting CostCenterData`, () => { | ||
const costCenterData = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters