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

Remove duplication in action tests #139

Merged
merged 7 commits into from
Nov 13, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 36 additions & 6 deletions static_src/test/unit/actions/service_actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import cfApi from '../../../util/cf_api.js';
import serviceActions from '../../../actions/service_actions.js';
import { serviceActionTypes } from '../../../constants.js';

function assertAction(spy, type, params) {
expect(spy).toHaveBeenCalledOnce();
let arg = spy.getCall(0).args[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change arg to actualOrgGuidArg or something that lets the reader know that the arg being assigned should the org.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only worry is the indices used for getCall and args i really doubt the order of the call or args will ever matter (since we are only expecting one call and the call will have just one arg for now for these org calls). but i'm just thinking how this will be used in case some other developer comes along trying to add tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with that said. i'm fine with it (the index hard coding) for now, and we can worry about it later when that time comes.

expect(arg.type).toEqual(type);
for (let param in params) {
expect(arg[param]).toEqual(params[param]);
}
}

describe('serviceActions', function() {
var sandbox;

Expand All @@ -17,17 +26,38 @@ describe('serviceActions', function() {
sandbox.restore();
});

function setupViewSpy() {
var spy = sandbox.spy(AppDispatcher, 'handleViewAction');
return spy;
}

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

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()

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)
});
});

Expand Down