diff options
| -rw-r--r-- | StoneIsland/www/js/lib/products/CollectionView.js | 4 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/_sdk.js | 9 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/address.js | 2 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/product.js | 4 | ||||
| -rw-r--r-- | test/Makefile | 9 | ||||
| -rw-r--r-- | test/lib/promise.js | 21 | ||||
| -rw-r--r-- | test/lib/sdk.js | 9 | ||||
| -rw-r--r-- | test/package.json | 1 | ||||
| -rw-r--r-- | test/test/00-setup.js | 1 | ||||
| -rw-r--r-- | test/test/01-product.js | 36 | ||||
| -rw-r--r-- | test/test/02-login.js | 47 | ||||
| -rw-r--r-- | test/test/TESTS.txt | 21 |
12 files changed, 156 insertions, 8 deletions
diff --git a/StoneIsland/www/js/lib/products/CollectionView.js b/StoneIsland/www/js/lib/products/CollectionView.js index 71d07723..987804fc 100644 --- a/StoneIsland/www/js/lib/products/CollectionView.js +++ b/StoneIsland/www/js/lib/products/CollectionView.js @@ -26,8 +26,8 @@ var CollectionView = View.extend({ fetch: function(){ this.$loader.show() - sdk.product.fetch_collection({ - gallery_id: 31483, // FOCUS ON CAMO + sdk.product.collection({ + gallery_id: 31617, success: this.populate.bind(this) }) }, diff --git a/StoneIsland/www/js/sdk/_sdk.js b/StoneIsland/www/js/sdk/_sdk.js index ce68da62..a7ecf6d3 100644 --- a/StoneIsland/www/js/sdk/_sdk.js +++ b/StoneIsland/www/js/sdk/_sdk.js @@ -1,9 +1,14 @@ var sdk = (function(){ var sdk = {} - // var endpoint = "https://secure.api.yoox.biz/" var endpoint = "https://sandbox.api.yoox.biz/" - + + sdk.init = function(opt){ + if (opt && opt.production) { + endpoint = "https://secure.api.yoox.biz/" + } + } + sdk.path = function(api, path){ return endpoint + api + "/STONEISLAND_US/" + path } diff --git a/StoneIsland/www/js/sdk/address.js b/StoneIsland/www/js/sdk/address.js index 16fc2dc4..2b1bfae0 100644 --- a/StoneIsland/www/js/sdk/address.js +++ b/StoneIsland/www/js/sdk/address.js @@ -34,5 +34,7 @@ sdk.address = (function(){ error: opt.error, }) } + + return address })()
\ No newline at end of file diff --git a/StoneIsland/www/js/sdk/product.js b/StoneIsland/www/js/sdk/product.js index c904eb32..a2ba30a1 100644 --- a/StoneIsland/www/js/sdk/product.js +++ b/StoneIsland/www/js/sdk/product.js @@ -1,7 +1,7 @@ sdk.product = (function(){ var product = {} - product.fetch_collection = function(opt){ + product.collection = function(opt){ $.ajax({ method: "GET", url: sdk.path("Search.API/1.2", "search.json"), @@ -15,7 +15,7 @@ sdk.product = (function(){ product.item = function(opt){ $.ajax({ method: "GET", - url: sdk.path("Item.API/1.0", "item/" + data.code + ".json"), + url: sdk.path("Item.API/1.0", "item/" + opt.code + ".json"), success: opt.success, error: opt.error, }) diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 00000000..877cd699 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,9 @@ + +test: + ./node_modules/.bin/mocha -R nyan + +spec: + ./node_modules/.bin/mocha -R spec + +.PHONY: test + diff --git a/test/lib/promise.js b/test/lib/promise.js new file mode 100644 index 00000000..d2afe09c --- /dev/null +++ b/test/lib/promise.js @@ -0,0 +1,21 @@ +module.exports = function(fn, data){ + var my_cb, my_res + data.success = function(res){ + my_res = res + if (my_cb) { + my_cb(res) + } + } + data.error = function(res){ + console.log('error!') + console.log(res) + } + fn(data) + var promise = { + then: function(cb){ + if (my_res) cb(my_res) + else my_cb = cb + } + } + return promise +}
\ No newline at end of file diff --git a/test/lib/sdk.js b/test/lib/sdk.js index f1ae8f4c..1b922bd8 100644 --- a/test/lib/sdk.js +++ b/test/lib/sdk.js @@ -2,6 +2,11 @@ var najax = require('najax') var fs = require('fs') var path = require('path') +najax.defaults({ + rejectUnauthorized: false, + contentType: 'application/json', +}) + // hacky dummy jquery var $ = { ajax: najax, @@ -14,9 +19,9 @@ var files = "_sdk.js auth.js account.js address.js cart.js payment.js product.js for (var i = 0; i < files.length; i++) { var fn = path.join(__dirname, "../../StoneIsland/www/js/sdk/", files[i]) - console.log(fn) eval( fs.readFileSync(fn) + '' ) } -module.exports = sdk +sdk.init({ production: true }) +module.exports = sdk diff --git a/test/package.json b/test/package.json index 6d6df943..dd095e58 100644 --- a/test/package.json +++ b/test/package.json @@ -10,6 +10,7 @@ "license": "LNT", "dependencies": { "jquery": "^2.1.4", + "mocha": "^2.3.3", "najax": "^0.2.1" } } diff --git a/test/test/00-setup.js b/test/test/00-setup.js new file mode 100644 index 00000000..e95c4eac --- /dev/null +++ b/test/test/00-setup.js @@ -0,0 +1 @@ +Error.stackTraceLimit = 1 diff --git a/test/test/01-product.js b/test/test/01-product.js new file mode 100644 index 00000000..50fcc13f --- /dev/null +++ b/test/test/01-product.js @@ -0,0 +1,36 @@ +var sdk = require('../lib/sdk') +var promise = require('../lib/promise') +var assert = require("assert") + +// sdk.product.fetch_collection +// sdk.product.item + +describe('product', function(){ + var test_item + + describe('#collection()', function(){ + it('returns a collection', function(done){ + promise(sdk.product.collection, { gallery_id: 31617 }).then(function(res){ + var data = JSON.parse(res) + assert(data.Header.StatusCode == 200) + assert(data.SearchResponseFull.Results.Items.length > 0) + test_item = data.SearchResponseFull.Results.Items[0] + done() + }) + }) + }) + + 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) + assert(data.Header.StatusCode == 200) + assert('Item' in data) + done() + }) + }) + }) + +}) + diff --git a/test/test/02-login.js b/test/test/02-login.js new file mode 100644 index 00000000..359ae68b --- /dev/null +++ b/test/test/02-login.js @@ -0,0 +1,47 @@ +var sdk = require('../lib/sdk') +var promise = require('../lib/promise') +var assert = require("assert") + +// sdk.account.signup +// sdk.account.login + +describe('account', function(){ + var new_user_data = { + "Email": "testit.account" + Math.floor(Math.random() * 10000000) + "@yoox.com", + "Gender": "M", + "Name": "TestName", + "Password": "TestPassword", + "Surname": "TestSurname", + } + + 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) + assert(data.Header.StatusCode == 201) + assert('UserId' in data) + + test_user = data.UserAccount + + done() + }) + }) + }) + +// 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() +// }) +// }) +// }) + +}) + diff --git a/test/test/TESTS.txt b/test/test/TESTS.txt new file mode 100644 index 00000000..94e1ab80 --- /dev/null +++ b/test/test/TESTS.txt @@ -0,0 +1,21 @@ +// sdk.address.add +// sdk.address.list +// sdk.cart.initialize +// sdk.cart.set_user +// sdk.cart.add_item +// sdk.cart.delete_item +// sdk.cart.get_status +// sdk.cart.set_shipping_address +// sdk.shipping.get_box_types +// sdk.shipping.set_box_type +// sdk.shipping.get_delivery_types +// sdk.shipping.set_delivery_type +// sdk.cart.set_payment_type +// sdk.cart.set_credit_card +// sdk.payment.list_credit_cards +// sdk.payment.add_credit_card +// sdk.payment.delete_credit_card +// sdk.payment.get_payment_types +// sdk.cart.use_stored_credit_card +// sdk.cart.finalize +// |
