Skip to content

Commit

Permalink
feat: #1166 Cost Explorer (Usage and Cost) update (#1180)
Browse files Browse the repository at this point in the history
* feat: #1166 Cost Explorer (Usage and Cost) update

* chore: #1166 update actionType name

* chore: #1166 update follow PR comment

* chore: #1166 update file name
  • Loading branch information
Trường An authored May 11, 2020
1 parent 1568f52 commit c20bb78
Show file tree
Hide file tree
Showing 27 changed files with 613 additions and 351 deletions.
25 changes: 24 additions & 1 deletion packages/marketplace/src/actions/__tests__/developer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import {
fetchBilling,
fetchBillingSuccess,
fetchBillingFailure,
fetchMonthlyBilling,
fetchMonthlyBillingSuccess,
fetchMonthlyBillingFailure,
} from '../developer'
import ActionTypes from '../../constants/action-types'
import { appsDataStub } from '../../sagas/__stubs__/apps'
import { CreateDeveloperModel } from '@reapit/foundations-ts-definitions'
import { appPermissionStub } from '@/sagas/__stubs__/app-permission'
import { billing } from '@/sagas/__stubs__/billing'
import { monthlyBillingData } from '@/sagas/__stubs__/monthly-billing'

describe('developer actions', () => {
it('should create a developerLoading action', () => {
Expand Down Expand Up @@ -70,7 +74,26 @@ describe('developer actions', () => {
})

it('should create a fetchBillingFailure action', () => {
expect(fetchBillingFailure.type).toEqual(ActionTypes.DEVELOPER_FETCH_BILLING_FAILURE)
expect(fetchBillingFailure.type).toEqual(ActionTypes.DEVELOPER_FETCH_BILLING_FAILED)
expect(fetchBillingFailure('error').data).toEqual('error')
})

it('should create a fetchMonthlyBilling action', () => {
const params = {
applicationId: ['applicationId'],
month: 'month',
}
expect(fetchMonthlyBilling.type).toEqual(ActionTypes.DEVELOPER_FETCH_MONTHLY_BILLING)
expect(fetchMonthlyBilling(params).data).toEqual(params)
})

it('should create a fetchMonthlyBillingSuccess action', () => {
expect(fetchMonthlyBillingSuccess.type).toEqual(ActionTypes.DEVELOPER_FETCH_MONTHLY_BILLING_SUCCESS)
expect(fetchMonthlyBillingSuccess(monthlyBillingData).data).toEqual(monthlyBillingData)
})

it('should create a fetchMonthlyBillingFailure action', () => {
expect(fetchMonthlyBillingFailure.type).toEqual(ActionTypes.DEVELOPER_FETCH_MONTHLY_BILLING_FAILED)
expect(fetchMonthlyBillingFailure('error').data).toEqual('error')
})
})
10 changes: 8 additions & 2 deletions packages/marketplace/src/actions/developer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// TODO: WILL MOVE ALL DEVELOPER ACTIONS TO HERE
import { actionCreator } from '../utils/actions'
import ActionTypes from '../constants/action-types'
import { DeveloperItem, DeveloperRequestParams, Billing } from '../reducers/developer'
import { DeveloperItem, DeveloperRequestParams, Billing, MonthlyBilling } from '../reducers/developer'
import { CreateDeveloperModel, DeveloperModel } from '@reapit/foundations-ts-definitions'
import { FormState } from '@/types/core'
import { FetchBillingParams } from '@/sagas/api'
import { FetchMonthlyBillingParams } from '@/services/billings'

export const developerRequestData = actionCreator<DeveloperRequestParams>(ActionTypes.DEVELOPER_REQUEST_DATA)
export const developerRequestDataFailure = actionCreator<void>(ActionTypes.DEVELOPER_REQUEST_DATA_FAILURE)
Expand All @@ -17,4 +18,9 @@ export const fetchMyIdentity = actionCreator<void>(ActionTypes.DEVELOPER_FETCH_M
export const setMyIdentity = actionCreator<DeveloperModel>(ActionTypes.DEVELOPER_SET_MY_IDENTITY)
export const fetchBilling = actionCreator<FetchBillingParams>(ActionTypes.DEVELOPER_FETCH_BILLING)
export const fetchBillingSuccess = actionCreator<Billing>(ActionTypes.DEVELOPER_FETCH_BILLING_SUCCESS)
export const fetchBillingFailure = actionCreator<unknown>(ActionTypes.DEVELOPER_FETCH_BILLING_FAILURE)
export const fetchBillingFailure = actionCreator<unknown>(ActionTypes.DEVELOPER_FETCH_BILLING_FAILED)
export const fetchMonthlyBilling = actionCreator<FetchMonthlyBillingParams>(ActionTypes.DEVELOPER_FETCH_MONTHLY_BILLING)
export const fetchMonthlyBillingSuccess = actionCreator<MonthlyBilling>(
ActionTypes.DEVELOPER_FETCH_MONTHLY_BILLING_SUCCESS,
)
export const fetchMonthlyBillingFailure = actionCreator<unknown>(ActionTypes.DEVELOPER_FETCH_MONTHLY_BILLING_FAILED)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('DeveloperHome', () => {
requestsByPeriod: [],
},
isServiceChartLoading: false,
isMonthlyBillingLoading: false,
monthlyBilling: null,
loading: false,
isVisible: false,
developerData: {
Expand Down Expand Up @@ -61,6 +63,8 @@ describe('DeveloperHome', () => {
const mockProps: DeveloperProps = {
developerState: {
isServiceChartLoading: false,
isMonthlyBillingLoading: false,
monthlyBilling: null,
myIdentity: {},
error: null,
billing: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,152 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CostExplorerTable should match a snapshot 1`] = `
<Fragment>
<Component
bordered={true}
columns={
Array [
Object {
"Footer": "Total",
"Header": "Resource",
"accessor": "resource",
"columnProps": Object {
"className": "capitalize",
"width": 200,
},
},
Object {
"Footer": [Function],
"Header": "Endpoints",
"accessor": [Function],
},
Object {
"Footer": [Function],
"Header": "API Calls",
"accessor": [Function],
},
Object {
"Footer": [Function],
"Header": "Cost",
"accessor": [Function],
},
]
}
data={
Array [
Object {
"apiCalls": 1440,
"cost": 784,
"endpoints": 3,
"resource": "contacts",
"subRows": Array [
Object {
"apiCalls": 440,
"cost": 84,
"endpoints": 1,
"resource": "/contacts",
},
Object {
"apiCalls": 1200,
"cost": 500,
"endpoints": 1,
"resource": "/contacts/{ID}",
},
Object {
"apiCalls": 800,
"cost": 200,
"endpoints": 1,
"resource": "/contacts/{ID}",
},
],
},
Object {
"apiCalls": 4000,
"cost": 567,
"endpoints": 9,
"resource": "properties",
"subRows": Array [
Object {
"apiCalls": 1000,
"cost": 400,
"endpoints": 3,
"resource": "/properties",
},
Object {
"apiCalls": 1000,
"cost": 100,
"endpoints": 3,
"resource": "/properties/{ID}",
},
Object {
"apiCalls": 2000,
"cost": 67,
"endpoints": 3,
"resource": "/properties/{ID}",
},
],
},
Object {
"apiCalls": 6000,
"cost": 594,
"endpoints": 5,
"resource": "developers",
"subRows": Array [
Object {
"apiCalls": 2000,
"cost": 200,
"endpoints": 1,
"resource": "/developers",
},
Object {
"apiCalls": 3000,
"cost": 200,
"endpoints": 3,
"resource": "/developers/{ID}",
},
Object {
"apiCalls": 1000,
"cost": 194,
"endpoints": 2,
"resource": "/developers/{ID}",
},
],
},
Object {
"apiCalls": 1500,
"cost": 200,
"endpoints": 10,
"resource": "customers",
"subRows": Array [
Object {
"apiCalls": 500,
"cost": 50,
"endpoints": 5,
"resource": "/customers",
},
Object {
"apiCalls": 1000,
"cost": 50,
"endpoints": 1,
"resource": "/customers/{ID}",
},
Object {
"apiCalls": 500,
"cost": 100,
"endpoints": 4,
"resource": "/customers/{ID}",
},
],
},
]
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
expandable={true}
scrollable={true}
/>
<p
className="mt-5"
>
*All charges are subject to VAT. Your totals for each month will be sent to our Accounts Department and you will be automatically invoiced at the end of each billing period.
</p>
</Fragment>
}
>
<CostExplorerTable />
</ContextProvider>
`;
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CostCalculator should match a snapshot 1`] = `
<Fragment>
<Component>
Cost Explorer: Cost & Usage
</Component>
<Component>
<Component
className="is-half-desktop"
>
<Component>
<Component
className="is-one-quarter"
>
<Component>
Month
</Component>
</Component>
<Component>
<CostFilterForm
initialValues={
Object {
"createdMonth": "2019-10",
}
}
onSave={[Function]}
/>
</Component>
</Component>
</Component>
</Component>
<Component>
<Component>
<CostExplorerTable />
</Component>
</Component>
</Fragment>
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<CostExplorer />
</ContextProvider>
`;
Loading

0 comments on commit c20bb78

Please sign in to comment.