Skip to content

Commit 2b2e570

Browse files
committed
billing history tests
2 parents 6a5466e + e125dff commit 2b2e570

File tree

7 files changed

+64
-17
lines changed

7 files changed

+64
-17
lines changed

src/api/account.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { actions } from './configs/account';
44

55
export function transferPool() {
66
return async (dispatch) => {
7-
const _transferpool = await dispatch(
8-
thunkFetch.get('/account/transfer')
9-
);
10-
dispatch(actions.one({ _transferpool }, 0));
7+
const _transferpool = await dispatch(thunkFetch.get('/account/transfer'));
8+
dispatch(actions.one({ _transferpool }));
119
};
1210
}

src/api/apiResultActionReducerGenerator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function generateDefaultStateOne(config, one) {
118118
export class ReducerGenerator {
119119
static one(config, oldStateMany, action) {
120120
if (config.singular) {
121-
return action.resource;
121+
return { ...oldStateMany, ...action.resource };
122122
}
123123

124124
const nonNanActionIds = (action.ids || []).filter(i => !_.isNaN(i));

src/billing/layouts/DashboardPage.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ import { Table } from 'linode-components/tables';
1010
import { LinkCell } from 'linode-components/tables/cells';
1111

1212
import { setSource } from '~/actions/source';
13-
import { account, invoices } from '~/api';
1413

1514

1615
export class DashboardPage extends Component {
17-
static async preload({ dispatch }) {
18-
await dispatch(account.one());
19-
await dispatch(invoices.all());
20-
}
21-
2216
componentDidMount() {
2317
const { dispatch } = this.props;
2418
dispatch(setSource(__filename));

src/billing/layouts/HistoryPage.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ import { setSource } from '~/actions/source';
1313

1414

1515
export class HistoryPage extends Component {
16-
static async preload({ dispatch }) {
17-
await dispatch(account.one());
18-
await dispatch(invoices.all());
19-
}
20-
2116
componentDidMount() {
2217
const { dispatch } = this.props;
2318
dispatch(setSource(__filename));

src/billing/layouts/IndexPage.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import { push } from 'react-router-redux';
55
import { Tabs } from 'linode-components/tabs';
66

77
import { setAnalytics, setTitle } from '~/actions';
8+
import { account, invoices } from '~/api';
89

910

1011
export class IndexPage extends Component {
12+
static async preload({ dispatch }) {
13+
await Promise.all([account.one(), invoices.all()].map(r => dispatch(r)));
14+
}
15+
1116
componentDidMount() {
1217
const { dispatch } = this.props;
1318
dispatch(setTitle('Billing'));

src/billing/layouts/InvoicePage.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { setSource } from '~/actions/source';
1616

1717
export class InvoicePage extends Component {
1818
static async preload({ dispatch, getState }, { invoiceId }) {
19-
await dispatch(invoices.one([invoiceId]));
2019
await dispatch(invoices.items.one([invoiceId]));
2120
}
2221

@@ -41,6 +40,9 @@ export class InvoicePage extends Component {
4140
label: 'From',
4241
headerClassName: 'DateColumn',
4342
formatFn: (from) => {
43+
if(!from) {
44+
return;
45+
}
4446
const time = moment.utc(from, moment.iso_8601).tz(timezone);
4547
return time.format('MMM D YYYY h:mm A z');
4648
},
@@ -50,6 +52,9 @@ export class InvoicePage extends Component {
5052
label: 'To',
5153
headerClassName: 'DateColumn',
5254
formatFn: (to) => {
55+
if(!to) {
56+
return;
57+
}
5358
const time = moment.utc(to, moment.iso_8601).tz(timezone);
5459
return time.format('MMM D YYYY h:mm A z');
5560
},
@@ -66,6 +71,9 @@ export class InvoicePage extends Component {
6671
headerClassName: 'IntegerColumn text-right',
6772
className: 'text-right',
6873
formatFn: (unitPrice) => {
74+
if(!unitPrice) {
75+
return;
76+
}
6977
return `$${parseFloat(unitPrice).toFixed(4)}`;
7078
},
7179
},
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import sinon from 'sinon';
3+
import { mount } from 'enzyme';
4+
import { expect } from 'chai';
5+
import moment from 'moment-timezone';
6+
7+
import { HistoryPage } from '~/billing/layouts/HistoryPage';
8+
import { api } from '@/data';
9+
import { account } from '@/data/account';
10+
11+
12+
const { invoices } = api;
13+
14+
describe('billing/layouts/HistoryPage', () => {
15+
const sandbox = sinon.sandbox.create();
16+
17+
afterEach(() => {
18+
sandbox.restore();
19+
});
20+
21+
const dispatch = sandbox.spy();
22+
23+
it('renders a list of invoices', () => {
24+
const page = mount(
25+
<HistoryPage
26+
dispatch={dispatch}
27+
account={account}
28+
invoices={invoices.invoices}
29+
/>
30+
);
31+
32+
const rowCount = Object.keys(invoices.invoices).length;
33+
expect(page.find('.TableRow').length).to.equal(rowCount);
34+
});
35+
36+
it('renders account balance', () => {
37+
const page = mount(
38+
<HistoryPage
39+
dispatch={dispatch}
40+
account={account}
41+
invoices={invoices.invoices}
42+
/>
43+
);
44+
45+
expect(page.find('strong').text()).to.equal(`Current Balance: $${account.balance}`);
46+
});
47+
});

0 commit comments

Comments
 (0)