Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from nordnet/unit-tests-refactoring
Browse files Browse the repository at this point in the history
Unit tests refactoring and bug fixes
  • Loading branch information
dimchez committed Feb 16, 2016
2 parents e68b1fd + d3a3ba2 commit bfe215d
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 237 deletions.
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"build": "babel src --out-dir lib",
"build:umd": "webpack --config ./webpack/webpack.config src/index.js dist/nordnet-next-api.js && NODE_ENV=production webpack --config ./webpack/webpack.config src/index.js dist/nordnet-next-api.min.js",
"eslint": "eslint --ext=.jsx --ext=.js -c .eslintrc src || echo \"Linting failed...\"",
"jscs": "jscs -c .jscsrc src",
"lint": "npm run jscs && npm run eslint",
"lint": "npm run eslint",
"pretest": "rimraf reports/test-results.xml reports/coverage",
"test": "karma start ./test/karma.conf.js --reporters mocha,junit,coverage --source-map",
"test:debug": "karma start ./test/karma.conf.js --no-single-run --reporters mocha --browsers Chrome --source-map",
Expand All @@ -34,7 +33,6 @@
"babel": "^5.5.8",
"babel-core": "^5.6.18",
"babel-eslint": "^3.1.23",
"babel-jscs": "^2.0.3",
"babel-loader": "^5.1.4",
"chai": "^3.0.0",
"chai-as-promised": "^5.1.0",
Expand All @@ -44,8 +42,6 @@
"husky": "^0.8.1",
"isparta": "^3.0.3",
"isparta-loader": "^0.2.0",
"jscs": "jscs-dev/node-jscs#c5adeba",
"jscs-jsdoc": "^1.1.0",
"karma": "0.12.31",
"karma-chai": "0.1.0",
"karma-chai-plugins": "0.6.0",
Expand All @@ -71,8 +67,8 @@
"webpack-dev-server": "^1.8.2"
},
"dependencies": {
"es6-promise": "^2.3.0",
"isomorphic-fetch": "^2.1.1",
"lodash": "^3.10.0"
"es6-promise": "2.3.0",
"isomorphic-fetch": "2.1.1",
"lodash": "3.10.0"
}
}
24 changes: 24 additions & 0 deletions src/__tests__/expectations/get-accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import api from '../../index';

export default {
conditions: {
request: [
api.get,
['/api/2/accounts'],
],
response: [
'GET',
'/api/2/accounts',
[401, { 'Content-Type': 'application/json; charset=UTF-8' }, JSON.stringify({ code: 'NEXT_INVALID_SESSION' })],
],
},
expected: {
url: '/api/2/accounts',
headers: { 'Accept': 'application/json' },
method: 'get',
credentials: true,
body: undefined,
status: 401,
data: { code: 'NEXT_INVALID_SESSION' },
},
};
27 changes: 27 additions & 0 deletions src/__tests__/expectations/get-instrument.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import api from '../../index';

const params = { instrument_id: 123, positions: [456, 789], accno: 987 };
const headers = { 'Accept-Language': 'sv' };

export default {
conditions: {
request: [
api.get,
['/api/2/instruments/{instrument_id}?positions={positions}', params, headers],
],
response: [
'GET',
'/api/2/instruments/123?positions=456%2C789&accno=987',
[200, { 'Content-Type': 'application/json; charset=UTF-8' }, JSON.stringify({ instrument_id: 123 })],
],
},
expected: {
url: `/api/2/instruments/123?positions=${encodeURIComponent('456,789')}&accno=987`,
headers: { 'Accept-Language': 'sv', 'Accept': 'application/json' },
method: 'get',
credentials: true,
body: undefined,
status: 200,
data: { instrument_id: 123 },
},
};
13 changes: 13 additions & 0 deletions src/__tests__/expectations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import getInstrument from './get-instrument';
import getAccounts from './get-accounts';
import postUserSettings from './post-user-settings';
import postUserLists from './post-user-lists';
import ping from './ping';

export default {
getInstrument,
getAccounts,
postUserSettings,
postUserLists,
ping,
};
20 changes: 20 additions & 0 deletions src/__tests__/expectations/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import api from '../../index';

export default {
conditions: {
request: [
api.get,
['/api/2/ping'],
],
response: [
'GET',
'/api/2/ping',
[200, {}, 'pong'],
],
},
expected: {
url: '/api/2/ping',
status: 200,
data: 'pong',
},
};
28 changes: 28 additions & 0 deletions src/__tests__/expectations/post-user-lists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import api from '../../index';

const name = 'abc';
const params = { name };
const response = { id: 1, name }

export default {
conditions: {
request: [
api.post,
['/api/2/user/lists', params],
],
response: [
'POST',
'/api/2/user/lists',
[201, { 'Content-type': 'application/json; charset=UTF-8' }, JSON.stringify(response)],
],
},
expected: {
url: '/api/2/user/lists',
headers: { 'Content-type': 'application/x-www-form-urlencoded', Accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' },
method: 'post',
credentials: true,
body: `name=${name}`,
status: 201,
data: response,
},
};
27 changes: 27 additions & 0 deletions src/__tests__/expectations/post-user-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import api from '../../index';

const params = { key: 1, settings: { widgets: [{ id: 1, name: 'winners/losers' }] }};
const headers = { 'Content-type': 'application/json' };

export default {
conditions: {
request: [
api.post,
['/api/2/user/settings/{key}', params, headers],
],
response: [
'POST',
'/api/2/user/settings/1',
[201, { 'Content-type': 'application/json; charset=UTF-8' }, JSON.stringify(params)],
],
},
expected: {
url: '/api/2/user/settings/1',
headers: { 'Content-type': 'application/json', Accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' },
method: 'post',
credentials: true,
body: JSON.stringify({ settings: params.settings }),
status: 201,
data: params,
},
};
Loading

0 comments on commit bfe215d

Please sign in to comment.