Skip to content

Commit

Permalink
v1.0.2 - fix test coverage and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCannon committed Nov 23, 2020
1 parent 399f82a commit f712fb6
Show file tree
Hide file tree
Showing 6 changed files with 1,124 additions and 241 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ module.exports = getUsers;

##### 1.0.1
- update README to reflect new error signature

##### 1.0.2
- fix test coverage and update dependencies
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
{
"name" : "alien-node-api-utils",
"version" : "1.0.1",
"description" : "Helper functions for API handling on NodeJS",
"main" : "lib/API.js",
"dependencies" : {
"aybabtu" : "*",
"ramda" : "^0.x.x",
"serialize-error" : "^4.1.0"
"name": "alien-node-api-utils",
"version": "1.0.2",
"description": "Helper functions for API handling on NodeJS",
"main": "lib/API.js",
"dependencies": {
"aybabtu": "*",
"ramda": "^0.x.x",
"serialize-error": "^4.1.0"
},
"devDependencies" : {
"coveralls" : "^2.11.2",
"istanbul" : "^0.3.13",
"jasmine" : "^2.3.1"
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.3.13",
"jasmine": "^2.3.1"
},
"scripts" : {
"test" : "./node_modules/.bin/istanbul cover ./node_modules/.bin/jasmine"
"scripts": {
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/jasmine"
},
"repository" : {
"type" : "git",
"url" : "https://github.com/aliencreations/alien-node-api-utils.git"
"repository": {
"type": "git",
"url": "https://github.com/aliencreations/alien-node-api-utils.git"
},
"keywords" : [
"keywords": [
"aliencreations",
"api",
"util",
"node",
"ramda"
],
"author" : "Sean Cannon",
"license" : "MIT",
"bugs" : {
"url" : "https://github.com/aliencreations/alien-node-api-utils/issues"
"author": "Sean Cannon",
"license": "MIT",
"bugs": {
"url": "https://github.com/aliencreations/alien-node-api-utils/issues"
},
"homepage" : "https://github.com/aliencreations/alien-node-api-utils"
"homepage": "https://github.com/aliencreations/alien-node-api-utils"
}
32 changes: 15 additions & 17 deletions spec/jsonResponseErrorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const mockRes = {
set : () => {
},
send : R.identity

};

const mockResHeadersSent = R.assoc('headersSent', true, mockRes);

const FAKE_HTTP_STATUS_CODE_ERROR = 1337;

const FAKE_ERROR_RESPONSE = {
Expand Down Expand Up @@ -60,48 +61,36 @@ const EXPECTED_RESPONSE_DATA_NO_SESSION = JSON.stringify({
const FAKE_NEXT = jasmine.createSpy('next');

describe('makeJsonResponseError without session', () => {

let response = {};

beforeEach(() => {
spyOn(mockRes, 'send');
response = jsonResponseError(mockReqNoSession, mockRes, FAKE_NEXT, FAKE_ERROR_RESPONSE);
jsonResponseError(mockReqNoSession, mockRes, FAKE_NEXT, FAKE_ERROR_RESPONSE);
});

it('executes the mock res.send function', () => {
expect(mockRes.send).toHaveBeenCalledWith(EXPECTED_RESPONSE_DATA_NO_SESSION);
});

});

describe('makeJsonResponseError without flash', () => {

let response = {};

beforeEach(() => {
spyOn(mockRes, 'send');
response = jsonResponseError(mockReqNoFlash, mockRes, FAKE_NEXT, FAKE_ERROR_RESPONSE);
jsonResponseError(mockReqNoFlash, mockRes, FAKE_NEXT, FAKE_ERROR_RESPONSE);
});

it('executes the mock res.send function', () => {
expect(mockRes.send).toHaveBeenCalledWith(EXPECTED_RESPONSE_DATA_NO_SESSION);
});

});

describe('makeJsonResponseError with session', () => {

let response = {};

beforeEach(() => {
spyOn(mockRes, 'send');
response = jsonResponseError(mockReqWithSession, mockRes, FAKE_NEXT, FAKE_ERROR_RESPONSE);
jsonResponseError(mockReqWithSession, mockRes, FAKE_NEXT, FAKE_ERROR_RESPONSE);
});

it('executes the mock res.send function', () => {
expect(mockRes.send).toHaveBeenCalledWith(EXPECTED_RESPONSE_DATA_WITH_SESSION);
});

});

describe('mockRes.send', () => {
Expand All @@ -110,8 +99,17 @@ describe('mockRes.send', () => {
});
});

describe('headers already sent', () => {
beforeAll(() => {
jsonResponseError(mockReqWithSession, mockResHeadersSent, FAKE_NEXT, FAKE_ERROR_RESPONSE);
});
it('sends an error if the headers have been sent', () => {
expect(FAKE_NEXT).toHaveBeenCalledWith(FAKE_ERROR_RESPONSE);
})
});

describe('mockReqWithSession.flash', () => {
it('returns the value given', () => {
it('is unaffected by the session', () => {
expect(mockReqWithSession.flash('foo')).toBe('foo');
});
});
18 changes: 3 additions & 15 deletions spec/jsonResponseSuccessSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,48 +50,36 @@ const FAKE_API_RESPONSE_NO_SESSION = JSON.stringify({
});

describe('makeJsonResponseSuccess without session', () => {

let response = {};

beforeEach(() => {
spyOn(mockRes, 'send');
response = jsonResponseSuccess(mockReqNoSession, mockRes, FAKE_DATABASE_RESPONSE);
jsonResponseSuccess(mockReqNoSession, mockRes, FAKE_DATABASE_RESPONSE);
});

it('executes the mock res.send function', () => {
expect(mockRes.send).toHaveBeenCalledWith(FAKE_API_RESPONSE_NO_SESSION);
});

});

describe('makeJsonResponseSuccess without flash', () => {

let response = {};

beforeEach(() => {
spyOn(mockRes, 'send');
response = jsonResponseSuccess(mockReqNoFlash, mockRes, FAKE_DATABASE_RESPONSE);
jsonResponseSuccess(mockReqNoFlash, mockRes, FAKE_DATABASE_RESPONSE);
});

it('executes the mock res.send function', () => {
expect(mockRes.send).toHaveBeenCalledWith(FAKE_API_RESPONSE_NO_SESSION);
});

});

describe('makeJsonResponseSuccess with session', () => {

let response = {};

beforeEach(() => {
spyOn(mockRes, 'send');
response = jsonResponseSuccess(mockReqWithSession, mockRes, FAKE_DATABASE_RESPONSE);
jsonResponseSuccess(mockReqWithSession, mockRes, FAKE_DATABASE_RESPONSE);
});

it('executes the mock res.send function', () => {
expect(mockRes.send).toHaveBeenCalledWith(FAKE_API_RESPONSE_WITH_SESSION);
});

});

describe('mockRes.send', () => {
Expand Down

0 comments on commit f712fb6

Please sign in to comment.