Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #139 from msecret/refactor-shared_assertions
Browse files Browse the repository at this point in the history
Remove duplication in action tests
  • Loading branch information
Marco Segreto committed Nov 13, 2015
2 parents f7669c1 + 7565737 commit de0cf2a
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 113 deletions.
7 changes: 7 additions & 0 deletions static_src/actions/service_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import AppDispatcher from '../dispatcher.js';
import { serviceActionTypes } from '../constants';

export default {
fetchAllServices(orgGuid) {
AppDispatcher.handleViewAction({
type: serviceActionTypes.SERVICES_FETCH,
orgGuid: orgGuid
});
},

fetchAllInstances(spaceGuid) {
AppDispatcher.handleViewAction({
type: serviceActionTypes.SERVICE_INSTANCES_FETCH,
Expand Down
29 changes: 17 additions & 12 deletions static_src/test/unit/actions/app_actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import '../../global_setup.js';

import AppDispatcher from '../../../dispatcher.js';
import { assertAction, setupViewSpy, setupServerSpy } from '../helpers.js';
import cfApi from '../../../util/cf_api.js';
import appActions from '../../../actions/app_actions.js';
import { appActionTypes } from '../../../constants.js';
Expand All @@ -19,30 +20,34 @@ describe('appActions', function() {

describe('fetch()', function() {
it('should dispatch a view event of type app fetch', function() {
var spy = sandbox.spy(AppDispatcher, 'handleViewAction'),
expectedAppGuid = 'asdflkjz';
var expectedAppGuid = 'asdflkjz',
expectedParams = {
appGuid: expectedAppGuid
};

let spy = setupViewSpy(sandbox)

appActions.fetch(expectedAppGuid);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(appActionTypes.APP_FETCH);
expect(arg.appGuid).toEqual(expectedAppGuid);
assertAction(spy, appActionTypes.APP_FETCH,
expectedParams)
});
});

describe('receivedApp()', function() {
it('should dispatch a server event of type app resv with app data',
function() {
var spy = sandbox.spy(AppDispatcher, 'handleServerAction'),
expected = { guid: 'asdfa', service: [] };
var expected = { guid: 'asdfa', service: [] },
expectedParams = {
app: expected
};

let spy = setupServerSpy(sandbox)

appActions.receivedApp(expected);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(appActionTypes.APP_RECEIVED);
expect(arg.app).toEqual(expected);
assertAction(spy, appActionTypes.APP_RECEIVED,
expectedParams)
});
});
});
41 changes: 23 additions & 18 deletions static_src/test/unit/actions/org_actions.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../../global_setup.js';

import AppDispatcher from '../../../dispatcher.js';
import { assertAction, setupViewSpy, setupServerSpy } from '../helpers.js';
import cfApi from '../../../util/cf_api.js';
import orgActions from '../../../actions/org_actions.js';
import { orgActionTypes } from '../../../constants.js';
Expand All @@ -18,20 +19,22 @@ describe('orgActions', () => {

describe('fetch()', () => {
it('should dispatch a view event of type org fetch', () => {
var spy = sandbox.spy(AppDispatcher, 'handleViewAction'),
expected = 'adsfa';
var expected = 'adsfa',
expectedParams = {
orgGuid: expected
};

let spy = setupViewSpy(sandbox)

orgActions.fetch(expected);

let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(orgActionTypes.ORG_FETCH);
expect(arg.orgGuid).toEqual(expected);
assertAction(spy, orgActionTypes.ORG_FETCH, expectedParams);
});
});

describe('fetchAll()', () => {
it('should dispatch a view event of type orgs fetch', (done) => {
var spy = sandbox.spy(AppDispatcher, 'handleViewAction');
var spy = setupViewSpy(sandbox)

orgActions.fetchAll();

Expand All @@ -45,29 +48,31 @@ describe('orgActions', () => {

describe('receivedOrg()', function() {
it('should dispatch a server event for org fetch with the org', function() {
var expected: { guid: 'asdf', name: 'adsfa' },
spy = sandbox.spy(AppDispatcher, 'handleServerAction');
var expected = { guid: 'asdf', name: 'adsfa' },
expectedParams = {
org: expected
};

let spy = setupServerSpy(sandbox)

orgActions.receivedOrg(expected);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(orgActionTypes.ORG_RECEIVED);
expect(arg.org).toEqual(expected);
assertAction(spy, orgActionTypes.ORG_RECEIVED, expectedParams);
});
});

describe('changeCurrentOrg()', function() {
it('should send an org change current event action with new org', function() {
var spy = sandbox.spy(AppDispatcher, 'handleViewAction'),
expected = 'asdlfka';
var expected = 'asdlfka',
expectedParams = {
orgGuid: expected
};

let spy = setupViewSpy(sandbox)

orgActions.changeCurrentOrg(expected);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(orgActionTypes.ORG_CHANGE_CURRENT);
expect(arg.orgGuid).toEqual(expected);
assertAction(spy, orgActionTypes.ORG_CHANGE_CURRENT, expectedParams);
});
});
});
76 changes: 48 additions & 28 deletions static_src/test/unit/actions/service_actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import '../../global_setup.js';

import AppDispatcher from '../../../dispatcher.js';
import { assertAction, setupViewSpy, setupServerSpy } from '../helpers.js';
import cfApi from '../../../util/cf_api.js';
import serviceActions from '../../../actions/service_actions.js';
import { serviceActionTypes } from '../../../constants.js';
Expand All @@ -17,72 +18,91 @@ describe('serviceActions', function() {
sandbox.restore();
});

describe('fetchAllServices()', function() {
it('should dispatch a view event of type service fetch', function() {
let expectedParams = {
orgGuid: 'adsfa'
}
let spy = setupViewSpy(sandbox)

serviceActions.fetchAllServices(expectedParams.orgGuid);

assertAction(spy, serviceActionTypes.SERVICES_FETCH, expectedParams);
});
});

describe('fetchInstance()', function() {
it('should dispatch a view event of type service instance fetch', function() {
var spy = sandbox.spy(AppDispatcher, 'handleViewAction'),
expectedSpaceGuid = 'aksfdsaaa8899';
var expectedSpaceGuid = 'aksfdsaaa8899';

let expectedParams = {
spaceGuid: expectedSpaceGuid
}

let spy = setupViewSpy(sandbox)

serviceActions.fetchAllInstances(expectedSpaceGuid);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(serviceActionTypes.SERVICE_INSTANCES_FETCH);
expect(arg.spaceGuid).toEqual(expectedSpaceGuid);
assertAction(spy, serviceActionTypes.SERVICE_INSTANCES_FETCH,
expectedParams)
});
});

describe('receivedInstance()', function() {
it('should dispatch a server event of type service instance resv with ' +
'the service instances', function() {
var expected,
expectedGuid,
spy = sandbox.spy(AppDispatcher, 'handleServerAction');

expected = [
var expected = [
{ metadata: {
guid: expectedGuid
guid: 'afds'
},
entity: {
type: 'someasdf'
}
}
];

let expectedParams = {
serviceInstances: expected
}

let spy = setupServerSpy(sandbox)

serviceActions.receivedInstances(expected);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(serviceActionTypes.SERVICE_INSTANCES_RECEIVED);
expect(arg.serviceInstances).toEqual(expected);
assertAction(spy, serviceActionTypes.SERVICE_INSTANCES_RECEIVED,
expectedParams);
});
});

describe('deleteInstance()', function() {
it('should dispatch a instance delete view event with instance guid', () => {
var spy = sandbox.spy(AppDispatcher, 'handleViewAction'),
expectedInstanceGuid = '0sd9fajdmz';
var expectedInstanceGuid = 'asdfasdf';
var expectedParams = {
serviceInstanceGuid: expectedInstanceGuid
}

let spy = setupViewSpy(sandbox)
serviceActions.deleteInstance(expectedInstanceGuid);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(serviceActionTypes.SERVICE_INSTANCE_DELETE);
expect(arg.serviceInstanceGuid).toEqual(expectedInstanceGuid);
assertAction(spy, serviceActionTypes.SERVICE_INSTANCE_DELETE,
expectedParams);
});
});

describe('deletedInstance()', function() {
// TODO create test case to simulate failed delete attempt.
it('should dispatch a instance deleted server event with guid', function() {
var spy = sandbox.spy(AppDispatcher, 'handleServerAction'),
expectedGuid = 'admxzcg';
var expectedGuid = 'admxzcg',
expectedParams = {
serviceInstanceGuid: expectedGuid
};

let spy = setupServerSpy(sandbox)

serviceActions.deletedInstance(expectedGuid);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(serviceActionTypes.SERVICE_INSTANCE_DELETED);
expect(arg.serviceInstanceGuid).toEqual(expectedGuid);
assertAction(spy, serviceActionTypes.SERVICE_INSTANCE_DELETED,
expectedParams);
});
});
});
15 changes: 8 additions & 7 deletions static_src/test/unit/actions/space_actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import '../../global_setup.js';

import AppDispatcher from '../../../dispatcher.js';
import { assertAction, setupViewSpy, setupServerSpy } from '../helpers.js';
import cfApi from '../../../util/cf_api.js';
import spaceActions from '../../../actions/space_actions.js';
import { spaceActionTypes } from '../../../constants.js';
Expand Down Expand Up @@ -29,7 +30,7 @@ describe('spaceActions', () => {
});

it('should dispatch a view event of type space fetch', () => {
var spy = sandbox.spy(AppDispatcher, 'handleViewAction');
let spy = setupViewSpy(sandbox);

spaceActions.fetch();

Expand All @@ -40,15 +41,15 @@ describe('spaceActions', () => {

describe('receivedSpace()', () => {
it('should dispatch server event of type space received', () => {
var spy = sandbox.spy(AppDispatcher, 'handleServerAction'),
expected = { guid: 'asdf' };
var expected = { guid: 'asdf' },
spy = setupServerSpy(sandbox),
expectedParams = {
space: expected
};

spaceActions.receivedSpace(expected);

expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
expect(arg.type).toEqual(spaceActionTypes.SPACE_RECEIVED);
expect(arg.space).toEqual(expected);
assertAction(spy, spaceActionTypes.SPACE_RECEIVED, expectedParams);
});
});
});
Loading

0 comments on commit de0cf2a

Please sign in to comment.