Skip to content

Commit

Permalink
Merge branch 'release/v0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Jul 30, 2015
2 parents fa70c88 + ec2f0e9 commit 7cb8d2c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 138 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ node_js:
- '0.12'
- '0.11'
- '0.10'
- 'iojs-v1'
- 'iojs-v2'
- iojs-v1
- iojs-v2
script: npm test
before_script:
- npm install
after_success:
- ./node_modules/coveralls/bin/coveralls.js < ./lcov.info

- ./node_modules/coveralls/bin/coveralls.js < ./lcov.info
deploy:
provider: npm
email: fam-operations@freeallmedia.com
api_key:
secure: bDwKHmm7uqjI+jfHvBRn8hgDG6rW98yOILsYzZa2wdXaF8JQAMq/z/LiYE5hNd+p9pfqZvMf6VrJBjCFZDj1nFzOlNTtOSpIekHwzdCb/eHU4hmPb1th0/qC3rCLu52zXQbWFxfyrPW9fYUcQmo4JgEbiRAGBD2EQa10vKMjPYbYaj2+2bD9pNq4YZvhjIt7JgoH5PEKxbB7l2At/annV7wwWhgEFVOERqOp8jtkF5b99BB6pBdj5+FBc+g4fvRMMzG94T3AsADNs3InAKrhvNOdpc3NlXepmqYX/kl8U5urhmuzwSsmhM5hk+8lzua1aCIissW89WqPwGxvtqaenJ0+shvDedAiFGdUiegzFWs4QnBQp+jp5aejyy+tFK6HxbykoyF7TuTYfy9vTQ+dWz/PfazfYBm8mIRzKmS3s4nW8Pj0yAqXpVVrxFziND5tZcMQm+ZmfEW2P5z+dFbSp4MK1Vc5ZLhpdC6wG1/PmIp7rOyUU8Xz3WH4nvoQ5nYztyb+vzXzZ0QY/g9eGc1GswKHWQQYL1g/STPfhu7sCwtS+Z1IjJvehnJri0SsvzbuzIOzmy1kXDlHtAXqspRbzz8baCagq6LreNyvSmwICITcHRn2CslBPbbL2F/Jb550Tw0eEkWxYs6yi3mvbxnRQRcTqyLhkxnuT5Huf3kyvYI=
on:
branch: master
repo: FreeAllMedia/jsonapi-formatter
17 changes: 6 additions & 11 deletions es5/lib/jsonApiFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ Object.defineProperty(exports, "__esModule", {

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var _blunder = require("blunder");

var _blunder2 = _interopRequireDefault(_blunder);

var JsonApiFormatter = (function () {
function JsonApiFormatter() {
_classCallCheck(this, JsonApiFormatter);
Expand All @@ -29,17 +23,18 @@ var JsonApiFormatter = (function () {
}, {
key: "format",
value: function format(body) {
if (body instanceof _blunder2["default"]) {
if (body instanceof Error && typeof body.toJSON === "function") {
var _ret = (function () {
var errors = [];
body.errors.forEach(function (error) {
errors.push({
var errors = body.toJSON();
var result = [];
errors.forEach(function (error) {
result.push({
title: error.name,
details: error.message
});
});
return {
v: { errors: errors }
v: { errors: result }
};
})();

Expand Down
22 changes: 15 additions & 7 deletions es5/spec/jsonApiFormatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ var _libJsonApiFormatterJs = require("../lib/jsonApiFormatter.js");

var _libJsonApiFormatterJs2 = _interopRequireDefault(_libJsonApiFormatterJs);

var _blunder = require("blunder");

var _blunder2 = _interopRequireDefault(_blunder);

describe("JsonApiFormatter", function () {
var formatter = undefined,
data = undefined,
error = undefined;
error = undefined,
secondError = undefined,
multiError = undefined;

beforeEach(function () {
formatter = new _libJsonApiFormatterJs2["default"]();
data = { id: 2, name: "Bob Belcher Jr", age: 15 };
error = new Error("Bob Belcher does not have any kids.");
secondError = new Error("No, Bob does not have a wife neither.");
multiError = new Error();
multiError.toJSON = function () {
return [error, secondError];
};
});

describe(".format(body)", function () {
Expand All @@ -27,10 +30,15 @@ describe("JsonApiFormatter", function () {
});

it("add the .errors root element on the provided body if the (body instanceof MultiError === true)", function () {
formatter.format(new _blunder2["default"](error)).should.eql({ errors: [{
formatter.format(multiError).should.eql({
errors: [{
title: error.name,
details: error.message
}] });
}, {
title: secondError.name,
details: secondError.message
}]
});
});

it("add the .errors root element on the provided body if the (body instanceof Error === true)", function () {
Expand Down
13 changes: 6 additions & 7 deletions es6/lib/jsonApiFormatter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import MultiError from "blunder";

export default class JsonApiFormatter {
formatResponse(response) {
if(response && typeof response.set === "function") {
Expand All @@ -8,15 +6,16 @@ export default class JsonApiFormatter {
}

format(body) {
if(body instanceof MultiError) {
let errors = [];
body.errors.forEach((error) => {
errors.push({
if(body instanceof Error && (typeof body.toJSON === "function")) {
let errors = body.toJSON();
let result = [];
errors.forEach((error) => {
result.push({
title: error.name,
details: error.message
});
});
return {errors: errors};
return {errors: result};
} else if(body instanceof Error) {
return {
errors: [
Expand Down
28 changes: 22 additions & 6 deletions es6/spec/jsonApiFormatter.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import JsonApiFormatter from "../lib/jsonApiFormatter.js";
import MultiError from "blunder";

describe("JsonApiFormatter", () => {
let formatter,
data,
error;
error,
secondError,
multiError;

beforeEach(() => {
formatter = new JsonApiFormatter();
data = {id: 2, name: "Bob Belcher Jr", age: 15};
error = new Error("Bob Belcher does not have any kids.");
secondError = new Error("No, Bob does not have a wife neither.");
multiError = new Error();
multiError.toJSON = () => {
return [error, secondError];
};
});

describe(".format(body)", () => {
Expand All @@ -18,10 +24,20 @@ describe("JsonApiFormatter", () => {
});

it("add the .errors root element on the provided body if the (body instanceof MultiError === true)", () => {
formatter.format(new MultiError(error)).should.eql({errors: [{
title: error.name,
details: error.message
}]});
formatter.format(multiError).should.eql(
{
errors: [
{
title: error.name,
details: error.message
},
{
title: secondError.name,
details: secondError.message
}
]
}
);
});

it("add the .errors root element on the provided body if the (body instanceof Error === true)", () => {
Expand Down
98 changes: 0 additions & 98 deletions lcov.info

This file was deleted.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsonapi-formatter",
"version": "0.1.0",
"version": "0.1.1",
"description": "ES6 Component that works as an omnirouter middleware to provide jsonapi responses.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -33,23 +33,23 @@
"url": "https://github.com/FreeAllMedia/jsonapi-formatter/issues"
},
"homepage": "https://github.com/FreeAllMedia/jsonapi-formatter",
"dependencies": {
"blunder": "0.0.0"
},
"dependencies": {},
"devDependencies": {
"babel": "^5.5.6",
"babel-eslint": "^4.0.5",
"chai": "^3.0.0",
"coveralls": "^2.11.2",
"eslint": "^0.24.1",
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-istanbul": "^0.10.0",
"gulp-mocha": "^2.1.1",
"karma": "^0.12.36",
"karma-browserify": "^4.2.1",
"karma-chai": "^0.1.0",
"karma-detect-browsers": "^2.0.0",
"karma-mocha": "^0.1.10",
"karma-sauce-launcher": "^0.2.11",
"karma-detect-browsers": "^2.0.0",
"mocha": "^2.2.5"
}
}

0 comments on commit 7cb8d2c

Please sign in to comment.