This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from nordnet/unit-tests-refactoring
Unit tests refactoring and bug fixes
- Loading branch information
Showing
11 changed files
with
267 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; |
Oops, something went wrong.