Skip to content

Commit

Permalink
Merge pull request #30 from andrefgneves/patch-1
Browse files Browse the repository at this point in the history
Don't prepend success/error suffixes with "_"
  • Loading branch information
svrcekmichal authored Sep 8, 2016
2 parents ac43ce0 + bb27764 commit 733eb7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/getActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const SUCCESS_SUFFIX = 'SUCCESS';
export const ERROR_SUFFIX = 'FAIL';
export const SUCCESS_SUFFIX = '_SUCCESS';
export const ERROR_SUFFIX = '_FAIL';

export const getActionTypes = (action, {
errorSuffix = ERROR_SUFFIX,
Expand All @@ -8,7 +8,7 @@ export const getActionTypes = (action, {
let types;
if (typeof action.type !== 'undefined') {
const { type } = action;
types = [type, `${type}_${successSuffix}`, `${type}_${errorSuffix}`];
types = [type, `${type}${successSuffix}`, `${type}${errorSuffix}`];
} else if (typeof action.types !== 'undefined') {
types = action.types;
} else {
Expand Down
20 changes: 8 additions & 12 deletions test/getActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ describe('getActionTypes', () => {
const types = getActionTypes(action);
expect(types).to.be.array;
expect(types[0]).to.equal(action.type);
expect(types[1]).to.equal(`${action.type}_${SUCCESS_SUFFIX}`);
expect(types[2]).to.equal(`${action.type}_${ERROR_SUFFIX}`);
expect(types[1]).to.equal(`${action.type}${SUCCESS_SUFFIX}`);
expect(types[2]).to.equal(`${action.type}${ERROR_SUFFIX}`);
});

it('should return custom types with `types` key', () => {
Expand All @@ -35,27 +35,27 @@ describe('getActionTypes', () => {

it('should use custom success sufix if defined', () => {
const action = {type:'TYPE'};
const types = getActionTypes(action, {successSuffix:'AWESOME'});
const types = getActionTypes(action, {successSuffix:'_AWESOME'});
expect(types).to.be.array;
expect(types[0]).to.equal(action.type);
expect(types[1]).to.equal(`${action.type}_AWESOME`);
expect(types[2]).to.equal(`${action.type}_${ERROR_SUFFIX}`);
expect(types[2]).to.equal(`${action.type}${ERROR_SUFFIX}`);
});

it('should use custom error sufix if defined', () => {
const action = {type:'TYPE'};
const types = getActionTypes(action, {errorSuffix:'OH_NO'});
const types = getActionTypes(action, {errorSuffix:'_OH_NO'});
expect(types).to.be.array;
expect(types[0]).to.equal(action.type);
expect(types[1]).to.equal(`${action.type}_${SUCCESS_SUFFIX}`);
expect(types[1]).to.equal(`${action.type}${SUCCESS_SUFFIX}`);
expect(types[2]).to.equal(`${action.type}_OH_NO`);
});

it('should use custom success and error sufix if defined', () => {
const action = {type:'TYPE'};
const types = getActionTypes(action,{
successSuffix:'AWESOME',
errorSuffix:'OH_NO'
successSuffix:'_AWESOME',
errorSuffix:'_OH_NO'
});
expect(types).to.be.array;
expect(types[0]).to.equal(action.type);
Expand All @@ -64,7 +64,3 @@ describe('getActionTypes', () => {
});

});




0 comments on commit 733eb7f

Please sign in to comment.