Skip to content

Commit

Permalink
refactor(): adjust coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Mar 9, 2019
1 parent 5f0829d commit 46d930f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions packages/common/test/utils/http-exception-body.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@ import { createHttpExceptionBody } from '../../utils/http-exception-body.util';

describe('createHttpExceptionBody', () => {
it('should return pre-defined body if message is string', () => {
expect(createHttpExceptionBody('message', 'error', 200)).to.eql({ message: 'message', error: 'error', statusCode: 200 });
expect(createHttpExceptionBody('message', 'error', 200)).to.eql({
message: 'message',
error: 'error',
statusCode: 200,
});
});

it('should override pre-defined body if message is object', () => {
expect(createHttpExceptionBody({ test: 'object' }, 'error', 200)).to.eql({ test: 'object' });
expect(createHttpExceptionBody({ test: 'object' }, 'error', 200)).to.eql({
test: 'object',
});
});

it('should not override pre-defined body if message is array', () => {
expect(createHttpExceptionBody(['a', 'random', 'array'], 'error', 200)).to.eql({ message: ['a', 'random', 'array'], error: 'error', statusCode: 200 });
expect(
createHttpExceptionBody(['a', 'random', 'array'], 'error', 200),
).to.eql({
message: ['a', 'random', 'array'],
error: 'error',
statusCode: 200,
});
});
});
4 changes: 3 additions & 1 deletion packages/common/utils/http-exception-body.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ export const createHttpExceptionBody = (
if (!message) {
return { statusCode, error };
}
return isObject(message) && !Array.isArray(message) ? message : { statusCode, error, message };
return isObject(message) && !Array.isArray(message)
? message
: { statusCode, error, message };
};

0 comments on commit 46d930f

Please sign in to comment.