summaryrefslogtreecommitdiffstats
path: root/test/app/inventory/InventoryActions.test.js
diff options
context:
space:
mode:
authorJames Forsyth <jf2512@att.com>2019-03-12 02:57:39 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-12 02:57:39 +0000
commitb2c7546f9027099161aeaf5791f1d0f3a52b92d2 (patch)
tree32be51dc53e9cca8a2573b29183e6404ec9629c1 /test/app/inventory/InventoryActions.test.js
parent85fa41b6a03a3914788e825cb28db84b33772489 (diff)
parenteec9820acfb269178e8f8c8bdc2ecfb2d13ad5f4 (diff)
Merge "Add tests to Inventory module"
Diffstat (limited to 'test/app/inventory/InventoryActions.test.js')
-rw-r--r--test/app/inventory/InventoryActions.test.js219
1 files changed, 219 insertions, 0 deletions
diff --git a/test/app/inventory/InventoryActions.test.js b/test/app/inventory/InventoryActions.test.js
new file mode 100644
index 0000000..9efe54d
--- /dev/null
+++ b/test/app/inventory/InventoryActions.test.js
@@ -0,0 +1,219 @@
+import configureMockStore from 'redux-mock-store';
+import thunk from 'redux-thunk';
+import fetchMock from 'fetch-mock';
+import expect from 'expect';
+
+import {onLoadTotalCountByDate, onCountByTypeLoad, onTopographicMapMounted} from 'app/inventory/InventoryActions';
+import {InventoryActionTypes} from 'app/inventory/InventoryConstants';
+
+
+const middlewares = [thunk];
+const mockStore = configureMockStore(middlewares);
+
+
+function mockRequestToEntityCountHistoryEndpoint(postfix, response) {
+ fetchMock.getOnce(
+ `http://localhost:/rest/visualization${postfix}`,
+ response
+ );
+}
+
+describe('InventoryActions', () => {
+
+ afterEach(() => {
+ fetchMock.restore()
+ });
+
+ describe('verify onLoadTotalCountByDate', () => {
+ it('creates COUNT_BY_DATE_SUCCESS response when there is no error', async () => {
+
+ // given
+ mockRequestToEntityCountHistoryEndpoint("/entityCountHistory?type=graph",{
+ status: 200,
+ body: {
+ "result": {
+ "keyA": "valueA",
+ "keyB": "valueB"
+ }
+ }
+ });
+
+ const expectedActions = [
+ {
+ type: InventoryActionTypes.COUNT_BY_DATE_SUCCESS,
+ data: {
+ countByDate: {
+ "keyA": "valueA",
+ "keyB": "valueB"
+ }
+ }
+ }];
+
+ const store = mockStore();
+
+ // when
+ await store.dispatch(onLoadTotalCountByDate());
+
+ // then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+
+
+ it('creates COUNT_BY_DATE_FAILED response when there is a problem with remote service', async () => {
+
+ // given
+ mockRequestToEntityCountHistoryEndpoint("/entityCountHistory?type=graph",{
+ status: 500
+ });
+
+ const expectedActions = [
+ {
+ type: InventoryActionTypes.COUNT_BY_DATE_FAILED,
+ data: {
+ message: 'Error fetching data from server',
+ severity: 'danger'
+ }
+ }];
+
+ const store = mockStore();
+
+ // when
+ await store.dispatch(onLoadTotalCountByDate());
+
+ // then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
+
+
+
+ describe('verify onCountByTypeLoad', () => {
+ it('creates COUNT_BY_ENTITY_SUCCESS response when there is no error', async () => {
+
+ // given
+ mockRequestToEntityCountHistoryEndpoint("/entityCountHistory?type=table",{
+ status: 200,
+ body: {
+ "result": {
+ "keyA": "valueA",
+ "keyB": "valueB"
+ }
+ }
+ });
+
+ const expectedActions = [
+ {
+ type: InventoryActionTypes.COUNT_BY_ENTITY_SUCCESS,
+ data: {
+ countByType: {
+ "keyA": "valueA",
+ "keyB": "valueB"
+ }
+ }
+ }];
+
+ const store = mockStore();
+
+ // when
+ await store.dispatch(onCountByTypeLoad());
+
+ // then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+
+
+ it('creates COUNT_BY_ENTITY_FAILED response when there is a problem with remote service', async () => {
+
+ // given
+ mockRequestToEntityCountHistoryEndpoint("/entityCountHistory?type=table",{
+ status: 500
+ });
+
+ const expectedActions = [
+ {
+ type: InventoryActionTypes.COUNT_BY_ENTITY_FAILED,
+ data: {
+ message: 'Error fetching data from server',
+ severity: 'danger'
+ }
+ }];
+
+ const store = mockStore();
+
+ // when
+ await store.dispatch(onCountByTypeLoad());
+
+ // then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
+
+
+
+ describe('verify onTopographicMapMounted', () => {
+ it('creates TOPOGRAPHIC_QUERY_SUCCESS response when there is no error', async () => {
+
+ // given
+ const requestObject = {
+ entityType: "entityType"
+ };
+ mockRequestToEntityCountHistoryEndpoint("/geovisualization/?entity=entityType",{
+ status: 200,
+ body: {
+ "plotPoints": {
+ "keyA": "valueA",
+ "keyB": "valueB"
+ }
+ }
+ });
+
+ const expectedActions = [
+ {
+ type: InventoryActionTypes.TOPOGRAPHIC_QUERY_SUCCESS,
+ data: {
+ plotPoints: {
+ "keyA": "valueA",
+ "keyB": "valueB"
+ }
+ }
+ }];
+
+ const store = mockStore();
+
+ // when
+ await store.dispatch(onTopographicMapMounted(requestObject));
+
+ // then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+
+
+ it('creates TOPOGRAPHIC_QUERY_FAILED response when there is a problem with remote service', async () => {
+
+ // given
+ const requestObject = {
+ entityType: "entityType"
+ };
+ mockRequestToEntityCountHistoryEndpoint("/geovisualization/?entity=entityType",{
+ status: 500
+ });
+
+ const expectedActions = [
+ {
+ type: InventoryActionTypes.TOPOGRAPHIC_QUERY_FAILED,
+ data: {
+ message: 'Error fetching data from server',
+ severity: 'danger'
+ }
+ }];
+
+ const store = mockStore();
+
+ // when
+ await store.dispatch(onTopographicMapMounted(requestObject));
+
+ // then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
+});