diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-10-20 16:38:46 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-10-20 16:38:46 -0400 |
| commit | d7e9ea57e410cf206f1e82a97e11e3cc793497bd (patch) | |
| tree | d4049b530c7dbbac9c0da86fc151ee14182ffce3 /test | |
| parent | 5fc529464393b5bd078e6a3987e6198503a433ef (diff) | |
test login api
Diffstat (limited to 'test')
| -rw-r--r-- | test/lib/promise.js | 16 | ||||
| -rw-r--r-- | test/lib/sdk.js | 1 | ||||
| l--------- | test/mocha | 1 | ||||
| -rw-r--r-- | test/test/01-product.js | 6 | ||||
| -rw-r--r-- | test/test/02-login.js | 48 |
5 files changed, 49 insertions, 23 deletions
diff --git a/test/lib/promise.js b/test/lib/promise.js index d2afe09c..ad895d90 100644 --- a/test/lib/promise.js +++ b/test/lib/promise.js @@ -1,5 +1,5 @@ module.exports = function(fn, data){ - var my_cb, my_res + var my_cb, my_res, error_cb, my_error data.success = function(res){ my_res = res if (my_cb) { @@ -7,14 +7,24 @@ module.exports = function(fn, data){ } } data.error = function(res){ - console.log('error!') - console.log(res) + my_error = res + if (error_cb) { + error_cb(res) + } + else { + console.log('error!') + console.log(res) + } } fn(data) var promise = { then: function(cb){ if (my_res) cb(my_res) else my_cb = cb + }, + error: function(cb){ + if (my_error) cb(my_error) + else error_cb = cb } } return promise diff --git a/test/lib/sdk.js b/test/lib/sdk.js index 1b922bd8..4ebffb8b 100644 --- a/test/lib/sdk.js +++ b/test/lib/sdk.js @@ -5,6 +5,7 @@ var path = require('path') najax.defaults({ rejectUnauthorized: false, contentType: 'application/json', + dataType: 'json', }) // hacky dummy jquery diff --git a/test/mocha b/test/mocha new file mode 120000 index 00000000..8c45d4ca --- /dev/null +++ b/test/mocha @@ -0,0 +1 @@ +./node_modules/.bin/mocha
\ No newline at end of file diff --git a/test/test/01-product.js b/test/test/01-product.js index 50fcc13f..2a3f1aa0 100644 --- a/test/test/01-product.js +++ b/test/test/01-product.js @@ -10,8 +10,7 @@ describe('product', function(){ describe('#collection()', function(){ it('returns a collection', function(done){ - promise(sdk.product.collection, { gallery_id: 31617 }).then(function(res){ - var data = JSON.parse(res) + promise(sdk.product.collection, { gallery_id: 31617 }).then(function(data){ assert(data.Header.StatusCode == 200) assert(data.SearchResponseFull.Results.Items.length > 0) test_item = data.SearchResponseFull.Results.Items[0] @@ -23,8 +22,7 @@ describe('product', function(){ describe('#item()', function(){ it('returns an item', function(done){ // console.log( test_item ) - promise(sdk.product.item, { code: test_item['Code8'] }).then(function(res){ - var data = JSON.parse(res) + promise(sdk.product.item, { code: test_item['Code8'] }).then(function(data){ assert(data.Header.StatusCode == 200) assert('Item' in data) done() diff --git a/test/test/02-login.js b/test/test/02-login.js index 359ae68b..c3d88346 100644 --- a/test/test/02-login.js +++ b/test/test/02-login.js @@ -12,17 +12,24 @@ describe('account', function(){ "Name": "TestName", "Password": "TestPassword", "Surname": "TestSurname", + "DataProfiling": true, + } + var login_user_data = { + "Email": new_user_data['Email'], + "Password": new_user_data['Password'], + } + var bad_user_data = { + "Email": new_user_data['Email'], + "Password": "BAD PASSWORD", } - var test_user describe('#signup()', function(){ it('makes a user and creates a token', function(done){ - promise(sdk.account.signup, { data: new_user_data }).then(function(res){ - var data = JSON.parse(res) - console.log(data) + promise(sdk.account.signup, { data: new_user_data }).then(function(data){ + // console.log(data) assert(data.Header.StatusCode == 201) - assert('UserId' in data) + assert('UserAccount' in data) test_user = data.UserAccount @@ -31,17 +38,26 @@ describe('account', function(){ }) }) -// describe('#login()', function(){ -// it('refreshes a token', function(done){ -// promise(sdk.account.login, { code: test_item['Code8'] }).then(function(res){ -// var data = JSON.parse(res) -// console.log(data) -// assert(data.Header.StatusCode == 200) -// assert('Item' in data) -// done() -// }) -// }) -// }) + describe('#login()', function(){ + it('refreshes the token', function(done){ + promise(sdk.account.login, { data: login_user_data }).then(function(data){ + // console.log(data) + assert(data.Header.StatusCode == 200) + assert('UserFull' in data) + done() + }) + }) + + it('throws an error if password is bad', function(done){ + promise(sdk.account.login, { data: bad_user_data }).error(function(data){ + // console.log(data) + // NB: we could JSON.parse(res.responseText) + assert(data.status == 404) + done() + }) + }) + + }) }) |
