summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-03-04 22:37:20 +0100
committerJules Laplace <jules@okfoc.us>2016-03-04 22:37:20 +0100
commit08c203b4dc4b9fdacd9aa0f2f2074dbd7d431a80 (patch)
tree40719f082ec67774654d10f50a332ea06ba23bb8
parent3a7ab01806ec52c048284029613b9bdaa0f6ec25 (diff)
checkin stuff
-rwxr-xr-xStoneIsland/platforms/ios/www/index.html2
-rwxr-xr-xStoneIsland/platforms/ios/www/js/lib/account/AccountView.js50
-rwxr-xr-xStoneIsland/platforms/ios/www/js/lib/auth/LoginView.js2
-rwxr-xr-xStoneIsland/platforms/ios/www/js/lib/cart/CartView.js2
-rwxr-xr-xStoneIsland/platforms/ios/www/js/lib/etc/push.js1
-rwxr-xr-xStoneIsland/platforms/ios/www/js/lib/products/CollectionView.js23
-rwxr-xr-xStoneIsland/platforms/ios/www/js/lib/products/ProductView.js57
-rwxr-xr-xStoneIsland/platforms/ios/www/js/sdk/auth.js43
-rwxr-xr-xStoneIsland/www/index.html2
-rwxr-xr-xStoneIsland/www/js/lib/account/AccountView.js50
-rwxr-xr-xStoneIsland/www/js/lib/auth/LoginView.js2
-rwxr-xr-xStoneIsland/www/js/lib/cart/CartView.js2
-rwxr-xr-xStoneIsland/www/js/lib/etc/push.js1
-rwxr-xr-xStoneIsland/www/js/lib/products/CollectionView.js23
-rwxr-xr-xStoneIsland/www/js/lib/products/ProductView.js57
-rwxr-xr-xStoneIsland/www/js/sdk/auth.js43
-rwxr-xr-xtest/test/02-login.js8
-rw-r--r--test/test/06-more-cart-flows.js112
18 files changed, 392 insertions, 88 deletions
diff --git a/StoneIsland/platforms/ios/www/index.html b/StoneIsland/platforms/ios/www/index.html
index 886afe3b..a7f12b98 100755
--- a/StoneIsland/platforms/ios/www/index.html
+++ b/StoneIsland/platforms/ios/www/index.html
@@ -229,7 +229,7 @@
<div id="collection">
<div class="scroll">
- <h1>COLLECTION NAME</h1>
+ <h1>LOADING...</h1>
<div class="loader"></div>
<div class="content">
<script type="text/html" class="template">
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
index 7d3b719a..0d015ab3 100755
--- a/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
@@ -98,25 +98,45 @@ var AccountView = View.extend({
}
if ( ! auth.has_cart() ) {
app.curtain.show("loading")
- auth.create_cart(function(){
- if (auth.deferred_product) {
- auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
- setTimeout(function(){
- app.curtain.hide("loading")
- }, 500)
- })
- }
- else {
- app.router.go("account/profile")
- app.curtain.hide("loading")
- }
+ auth.create_cart({
+ success: function(){
+ if (auth.deferred_product) {
+ auth.add_deferred_product_to_cart({
+ success: function(){
+ app.router.go("cart")
+ setTimeout(function(){
+ app.curtain.hide("loading")
+ }, 500)
+ },
+ error: function(){
+ // TODO: should not be called because cart was just created
+ console.log("ERROR ADDING PRODUCT TO NEW CART")
+ },
+ })
+ }
+ else {
+ app.router.go("account/profile")
+ app.curtain.hide("loading")
+ }
+ },
+ error: function(){
+ // error CREATING cart...
+ console.log("ERROR CREATING CART")
+ auth.log_out()
+ app.account.logged_out()
+ },
})
}
else {
if (auth.deferred_product) {
- auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
+ auth.add_deferred_product_to_cart({
+ success: function(){
+ app.router.go("cart")
+ },
+ error: function(){
+ // TODO: cart might be invalid..
+ console.log("CALLED LOGGED_IN, HAD DEFERRED PRODUCT")
+ },
})
}
else {
diff --git a/StoneIsland/platforms/ios/www/js/lib/auth/LoginView.js b/StoneIsland/platforms/ios/www/js/lib/auth/LoginView.js
index 88a15f7e..d7968c22 100755
--- a/StoneIsland/platforms/ios/www/js/lib/auth/LoginView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/auth/LoginView.js
@@ -33,7 +33,7 @@ var LoginView = FormView.extend({
},
forgot_password: function(){
- window.open("http://www.stoneisland.com//r/passwordrecovery/recoveryrequest", '_system')
+ window.open("http://www.stoneisland.com/", '_system')
},
validate_presence: {
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js
index a10efb46..6ed8238f 100755
--- a/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js
@@ -30,7 +30,7 @@ var CartView = View.extend({
}.bind(this),
error: function(data){
console.log(data)
-
+ auth.clear_cart()
},
})
},
diff --git a/StoneIsland/platforms/ios/www/js/lib/etc/push.js b/StoneIsland/platforms/ios/www/js/lib/etc/push.js
index 5585ba71..634ffe6d 100755
--- a/StoneIsland/platforms/ios/www/js/lib/etc/push.js
+++ b/StoneIsland/platforms/ios/www/js/lib/etc/push.js
@@ -55,6 +55,7 @@ var push = (function(){
app.intro.$alert.show().html("[ HUB UPDATED ]")
}
else {
+ auth.clear_cart()
app.intro.$alert.show().html("[ STORE UPDATED ]")
}
}
diff --git a/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js b/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js
index 1c50c80d..3fd4a757 100755
--- a/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js
@@ -80,8 +80,10 @@ var CollectionView = ScrollableView.extend({
else {
console.log("populate 2")
this.data = data
+ this.loaded = false
console.log(data)
}
+ console.log(">>>>>>>> YES ")
if (! this.loaded) {
console.log("populate 3")
this.loaded = true
@@ -89,7 +91,16 @@ var CollectionView = ScrollableView.extend({
this.$content.empty()
// DefaultCode10
// data.SearchResponseFull.Results.Items.length = 1
- this.$content.toggleClass("single", (data.SearchResponseFull.Results.Items.length == 1))
+ var is_single_product = (data.SearchResponseFull.Results.Items.length == 1)
+ this.$content.toggleClass("single", is_single_product)
+
+ if (is_single_product) {
+ console.log("IS SINGLE PRODUCT")
+ var item = data.SearchResponseFull.Results.Items[0]
+ var url = sdk.image(item['DefaultCode10'], '13_f')
+ var img = new Image ()
+ img.src = url
+ }
// if (data.SearchResponseFull.Results.Items.length == 1) {
// app.footer.hide()
@@ -98,16 +109,20 @@ var CollectionView = ScrollableView.extend({
// app.footer.show("FILTER")
// }
- data.SearchResponseFull.Results.Items.forEach(this.append.bind(this))
+ console.log( data.SearchResponseFull.Results.Items.length )
+ data.SearchResponseFull.Results.Items.forEach(function(item){
+ console.log(">>> ITEM")
+ this.append(item, is_single_product)
+ }.bind(this))
this.deferScrollToTop()
}
this.afterFetchCallback && this.afterFetchCallback()
app.collection.deferRefresh()
},
- append: function(item){
+ append: function(item, is_single_product){
this.items[ item['Code8'] ] = item
- var t = this.template.replace(/{{image}}/, sdk.image(item['DefaultCode10'], '11_f'))
+ var t = this.template.replace(/{{image}}/, sdk.image(item['DefaultCode10'], is_single_product ? '13_f' : '11_f'))
.replace(/{{code8}}/, item['Code8'])
this.$content.append(t)
},
diff --git a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js
index 9ce4a1f3..72ff9da3 100755
--- a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js
@@ -224,6 +224,7 @@ var ProductView = ScrollableView.extend({
sizes[ size['SizeId'] ] = {
id: label,
label: label.toUpperCase(),
+ value: size['SizeId'],
colors: {},
}
})
@@ -246,6 +247,7 @@ var ProductView = ScrollableView.extend({
}.bind(this))
app.selector.select("style", sizes, function(size){
+ console.log(size)
this.size = size.value
this.$size.html(size.label)
}.bind(this))
@@ -277,27 +279,62 @@ var ProductView = ScrollableView.extend({
},
add_to_cart: function(opt){
- auth.deferred_product = { Size: this.size, Code10: this.code }
+ var deferred_product = auth.deferred_product = { Size: this.size, Code10: this.code }
+ console.log("ADDING " + this.size + " " + this.code )
+ // if we are not logged in...
if ( ! auth.logged_in() ) {
app.router.go("account/login")
app.last_view = app.cart
}
+ // if we don't have a cart setup...
else if ( ! auth.has_cart() ) {
app.curtain.show("loading")
- auth.create_cart(function(){
- auth.add_deferred_product_to_cart(function(){
+ auth.create_cart({
+ success: function(){
+ auth.add_deferred_product_to_cart({
+ success: function(){
+ app.curtain.hide("loading")
+ app.router.go("cart")
+ },
+ error: function(){
+ // SHOULD NOT BE A PROBLEM
+ console.log("ERROR ADDING PRODUCT TO NEW CART SIMPLE ADD TO CART")
+ app.curtain.hide("loading")
+ app.router.go("account/login")
+ auth.deferred_product = deferred_product
+ app.last_view = app.cart
+ },
+ })
+ },
+ error: function(){
+ // ERROR CREATING CART?
+ console.log("ERROR CREATING CART")
+ auth.log_out()
+ app.account.logged_out()
app.curtain.hide("loading")
- app.router.go("cart")
- })
+ app.router.go("account/login")
+ auth.deferred_product = deferred_product
+ app.last_view = app.cart
+ },
})
}
else {
app.curtain.show("loading")
- auth.add_deferred_product_to_cart(function(){
- app.curtain.hide("loading")
- if (opt.route) {
- app.router.go("cart")
- }
+ auth.add_deferred_product_to_cart({
+ success: function(){
+ app.curtain.hide("loading")
+ if (opt.route) {
+ app.router.go("cart")
+ }
+ },
+ error: function(){
+ console.log("CART MIGHT BE OLD")
+ // TODO - CART MIGHT BE OLD
+ app.curtain.hide("loading")
+ app.router.go("account/login")
+ auth.deferred_product = deferred_product
+ app.last_view = app.cart
+ },
})
}
},
diff --git a/StoneIsland/platforms/ios/www/js/sdk/auth.js b/StoneIsland/platforms/ios/www/js/sdk/auth.js
index 87ce60ea..fa8dd71c 100755
--- a/StoneIsland/platforms/ios/www/js/sdk/auth.js
+++ b/StoneIsland/platforms/ios/www/js/sdk/auth.js
@@ -30,7 +30,12 @@ var auth = sdk.auth = (function(){
sdk.account.checkin({
success: function(data){
fn && fn( auth.logged_in() )
- }
+ },
+ error: function(){
+ auth.log_out()
+ fn && fn( false )
+ //
+ },
})
auth.get_cart()
}
@@ -78,40 +83,54 @@ var auth = sdk.auth = (function(){
localStorage.removeItem("yoox.cart_id")
cb && cb()
}
- auth.create_cart = function(cb){
- if (auth.has_cart()) { return cb() }
+ auth.create_cart = function(opt){
+ opt = opt || {}
+ if (auth.has_cart()) {
+ opt.success && opt.success()
+ return
+ }
sdk.cart.initialize({
success: function(data){
sdk.cart.set_user({
success: function(){
auth.set_cart(sdk.cart.id, sdk.cart.token, function(){
- cb && cb()
+ opt.success && opt.success()
})
- }
+ },
+ error: function(){
+ opt.clear_cart()
+ opt.error && opt.error()
+ },
})
+ },
+ error: function(){
+ opt.clear_cart()
+ opt.error && opt.error()
}
})
}
- auth.add_deferred_product_to_cart = function(cb){
+
+ auth.add_deferred_product_to_cart = function(opt){
+ opt = opt || {}
// auth.deferred_product
if (! auth.deferred_product) {
- console.log("VV NO DEF PROD")
- cb && cb()
+ console.log("VV NO DEFERRED PROD")
+ opt.success && opt.success()
return
}
sdk.cart.add_item({
data: auth.deferred_product,
success: function(){
console.log("ADDED ITEM")
- cb && cb()
+ app.header.increment_cart_count()
+ opt.success && opt.success()
},
error: function(data){
- console.log("ERROR ADDING ITEM", data)
- cb && cb()
+ console.log("ERROR ADDING ITEM")
+ opt.error && opt.error()
},
})
auth.deferred_product = null
- app.header.increment_cart_count()
}
auth.log_out = function(){
diff --git a/StoneIsland/www/index.html b/StoneIsland/www/index.html
index 886afe3b..a7f12b98 100755
--- a/StoneIsland/www/index.html
+++ b/StoneIsland/www/index.html
@@ -229,7 +229,7 @@
<div id="collection">
<div class="scroll">
- <h1>COLLECTION NAME</h1>
+ <h1>LOADING...</h1>
<div class="loader"></div>
<div class="content">
<script type="text/html" class="template">
diff --git a/StoneIsland/www/js/lib/account/AccountView.js b/StoneIsland/www/js/lib/account/AccountView.js
index 7d3b719a..0d015ab3 100755
--- a/StoneIsland/www/js/lib/account/AccountView.js
+++ b/StoneIsland/www/js/lib/account/AccountView.js
@@ -98,25 +98,45 @@ var AccountView = View.extend({
}
if ( ! auth.has_cart() ) {
app.curtain.show("loading")
- auth.create_cart(function(){
- if (auth.deferred_product) {
- auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
- setTimeout(function(){
- app.curtain.hide("loading")
- }, 500)
- })
- }
- else {
- app.router.go("account/profile")
- app.curtain.hide("loading")
- }
+ auth.create_cart({
+ success: function(){
+ if (auth.deferred_product) {
+ auth.add_deferred_product_to_cart({
+ success: function(){
+ app.router.go("cart")
+ setTimeout(function(){
+ app.curtain.hide("loading")
+ }, 500)
+ },
+ error: function(){
+ // TODO: should not be called because cart was just created
+ console.log("ERROR ADDING PRODUCT TO NEW CART")
+ },
+ })
+ }
+ else {
+ app.router.go("account/profile")
+ app.curtain.hide("loading")
+ }
+ },
+ error: function(){
+ // error CREATING cart...
+ console.log("ERROR CREATING CART")
+ auth.log_out()
+ app.account.logged_out()
+ },
})
}
else {
if (auth.deferred_product) {
- auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
+ auth.add_deferred_product_to_cart({
+ success: function(){
+ app.router.go("cart")
+ },
+ error: function(){
+ // TODO: cart might be invalid..
+ console.log("CALLED LOGGED_IN, HAD DEFERRED PRODUCT")
+ },
})
}
else {
diff --git a/StoneIsland/www/js/lib/auth/LoginView.js b/StoneIsland/www/js/lib/auth/LoginView.js
index 88a15f7e..d7968c22 100755
--- a/StoneIsland/www/js/lib/auth/LoginView.js
+++ b/StoneIsland/www/js/lib/auth/LoginView.js
@@ -33,7 +33,7 @@ var LoginView = FormView.extend({
},
forgot_password: function(){
- window.open("http://www.stoneisland.com//r/passwordrecovery/recoveryrequest", '_system')
+ window.open("http://www.stoneisland.com/", '_system')
},
validate_presence: {
diff --git a/StoneIsland/www/js/lib/cart/CartView.js b/StoneIsland/www/js/lib/cart/CartView.js
index a10efb46..6ed8238f 100755
--- a/StoneIsland/www/js/lib/cart/CartView.js
+++ b/StoneIsland/www/js/lib/cart/CartView.js
@@ -30,7 +30,7 @@ var CartView = View.extend({
}.bind(this),
error: function(data){
console.log(data)
-
+ auth.clear_cart()
},
})
},
diff --git a/StoneIsland/www/js/lib/etc/push.js b/StoneIsland/www/js/lib/etc/push.js
index 5585ba71..634ffe6d 100755
--- a/StoneIsland/www/js/lib/etc/push.js
+++ b/StoneIsland/www/js/lib/etc/push.js
@@ -55,6 +55,7 @@ var push = (function(){
app.intro.$alert.show().html("[ HUB UPDATED ]")
}
else {
+ auth.clear_cart()
app.intro.$alert.show().html("[ STORE UPDATED ]")
}
}
diff --git a/StoneIsland/www/js/lib/products/CollectionView.js b/StoneIsland/www/js/lib/products/CollectionView.js
index 1c50c80d..3fd4a757 100755
--- a/StoneIsland/www/js/lib/products/CollectionView.js
+++ b/StoneIsland/www/js/lib/products/CollectionView.js
@@ -80,8 +80,10 @@ var CollectionView = ScrollableView.extend({
else {
console.log("populate 2")
this.data = data
+ this.loaded = false
console.log(data)
}
+ console.log(">>>>>>>> YES ")
if (! this.loaded) {
console.log("populate 3")
this.loaded = true
@@ -89,7 +91,16 @@ var CollectionView = ScrollableView.extend({
this.$content.empty()
// DefaultCode10
// data.SearchResponseFull.Results.Items.length = 1
- this.$content.toggleClass("single", (data.SearchResponseFull.Results.Items.length == 1))
+ var is_single_product = (data.SearchResponseFull.Results.Items.length == 1)
+ this.$content.toggleClass("single", is_single_product)
+
+ if (is_single_product) {
+ console.log("IS SINGLE PRODUCT")
+ var item = data.SearchResponseFull.Results.Items[0]
+ var url = sdk.image(item['DefaultCode10'], '13_f')
+ var img = new Image ()
+ img.src = url
+ }
// if (data.SearchResponseFull.Results.Items.length == 1) {
// app.footer.hide()
@@ -98,16 +109,20 @@ var CollectionView = ScrollableView.extend({
// app.footer.show("FILTER")
// }
- data.SearchResponseFull.Results.Items.forEach(this.append.bind(this))
+ console.log( data.SearchResponseFull.Results.Items.length )
+ data.SearchResponseFull.Results.Items.forEach(function(item){
+ console.log(">>> ITEM")
+ this.append(item, is_single_product)
+ }.bind(this))
this.deferScrollToTop()
}
this.afterFetchCallback && this.afterFetchCallback()
app.collection.deferRefresh()
},
- append: function(item){
+ append: function(item, is_single_product){
this.items[ item['Code8'] ] = item
- var t = this.template.replace(/{{image}}/, sdk.image(item['DefaultCode10'], '11_f'))
+ var t = this.template.replace(/{{image}}/, sdk.image(item['DefaultCode10'], is_single_product ? '13_f' : '11_f'))
.replace(/{{code8}}/, item['Code8'])
this.$content.append(t)
},
diff --git a/StoneIsland/www/js/lib/products/ProductView.js b/StoneIsland/www/js/lib/products/ProductView.js
index 9ce4a1f3..72ff9da3 100755
--- a/StoneIsland/www/js/lib/products/ProductView.js
+++ b/StoneIsland/www/js/lib/products/ProductView.js
@@ -224,6 +224,7 @@ var ProductView = ScrollableView.extend({
sizes[ size['SizeId'] ] = {
id: label,
label: label.toUpperCase(),
+ value: size['SizeId'],
colors: {},
}
})
@@ -246,6 +247,7 @@ var ProductView = ScrollableView.extend({
}.bind(this))
app.selector.select("style", sizes, function(size){
+ console.log(size)
this.size = size.value
this.$size.html(size.label)
}.bind(this))
@@ -277,27 +279,62 @@ var ProductView = ScrollableView.extend({
},
add_to_cart: function(opt){
- auth.deferred_product = { Size: this.size, Code10: this.code }
+ var deferred_product = auth.deferred_product = { Size: this.size, Code10: this.code }
+ console.log("ADDING " + this.size + " " + this.code )
+ // if we are not logged in...
if ( ! auth.logged_in() ) {
app.router.go("account/login")
app.last_view = app.cart
}
+ // if we don't have a cart setup...
else if ( ! auth.has_cart() ) {
app.curtain.show("loading")
- auth.create_cart(function(){
- auth.add_deferred_product_to_cart(function(){
+ auth.create_cart({
+ success: function(){
+ auth.add_deferred_product_to_cart({
+ success: function(){
+ app.curtain.hide("loading")
+ app.router.go("cart")
+ },
+ error: function(){
+ // SHOULD NOT BE A PROBLEM
+ console.log("ERROR ADDING PRODUCT TO NEW CART SIMPLE ADD TO CART")
+ app.curtain.hide("loading")
+ app.router.go("account/login")
+ auth.deferred_product = deferred_product
+ app.last_view = app.cart
+ },
+ })
+ },
+ error: function(){
+ // ERROR CREATING CART?
+ console.log("ERROR CREATING CART")
+ auth.log_out()
+ app.account.logged_out()
app.curtain.hide("loading")
- app.router.go("cart")
- })
+ app.router.go("account/login")
+ auth.deferred_product = deferred_product
+ app.last_view = app.cart
+ },
})
}
else {
app.curtain.show("loading")
- auth.add_deferred_product_to_cart(function(){
- app.curtain.hide("loading")
- if (opt.route) {
- app.router.go("cart")
- }
+ auth.add_deferred_product_to_cart({
+ success: function(){
+ app.curtain.hide("loading")
+ if (opt.route) {
+ app.router.go("cart")
+ }
+ },
+ error: function(){
+ console.log("CART MIGHT BE OLD")
+ // TODO - CART MIGHT BE OLD
+ app.curtain.hide("loading")
+ app.router.go("account/login")
+ auth.deferred_product = deferred_product
+ app.last_view = app.cart
+ },
})
}
},
diff --git a/StoneIsland/www/js/sdk/auth.js b/StoneIsland/www/js/sdk/auth.js
index 87ce60ea..fa8dd71c 100755
--- a/StoneIsland/www/js/sdk/auth.js
+++ b/StoneIsland/www/js/sdk/auth.js
@@ -30,7 +30,12 @@ var auth = sdk.auth = (function(){
sdk.account.checkin({
success: function(data){
fn && fn( auth.logged_in() )
- }
+ },
+ error: function(){
+ auth.log_out()
+ fn && fn( false )
+ //
+ },
})
auth.get_cart()
}
@@ -78,40 +83,54 @@ var auth = sdk.auth = (function(){
localStorage.removeItem("yoox.cart_id")
cb && cb()
}
- auth.create_cart = function(cb){
- if (auth.has_cart()) { return cb() }
+ auth.create_cart = function(opt){
+ opt = opt || {}
+ if (auth.has_cart()) {
+ opt.success && opt.success()
+ return
+ }
sdk.cart.initialize({
success: function(data){
sdk.cart.set_user({
success: function(){
auth.set_cart(sdk.cart.id, sdk.cart.token, function(){
- cb && cb()
+ opt.success && opt.success()
})
- }
+ },
+ error: function(){
+ opt.clear_cart()
+ opt.error && opt.error()
+ },
})
+ },
+ error: function(){
+ opt.clear_cart()
+ opt.error && opt.error()
}
})
}
- auth.add_deferred_product_to_cart = function(cb){
+
+ auth.add_deferred_product_to_cart = function(opt){
+ opt = opt || {}
// auth.deferred_product
if (! auth.deferred_product) {
- console.log("VV NO DEF PROD")
- cb && cb()
+ console.log("VV NO DEFERRED PROD")
+ opt.success && opt.success()
return
}
sdk.cart.add_item({
data: auth.deferred_product,
success: function(){
console.log("ADDED ITEM")
- cb && cb()
+ app.header.increment_cart_count()
+ opt.success && opt.success()
},
error: function(data){
- console.log("ERROR ADDING ITEM", data)
- cb && cb()
+ console.log("ERROR ADDING ITEM")
+ opt.error && opt.error()
},
})
auth.deferred_product = null
- app.header.increment_cart_count()
}
auth.log_out = function(){
diff --git a/test/test/02-login.js b/test/test/02-login.js
index e0484dbb..cd5869d7 100755
--- a/test/test/02-login.js
+++ b/test/test/02-login.js
@@ -75,6 +75,14 @@ describe('account', function(){
})
})
+ it('does not fetch anything if the tokens are invalid', function(done){
+ promise(sdk.account.checkin, {}).then(function(data){
+ console.log("SHOULD NOT WORK BUT IT DID??", data)
+ }).error(function(data){
+ done()
+ })
+ })
+
it('works if no token is set on auth', function(done){
sdk.auth.access_token = ""
sdk.auth.user_id = -1
diff --git a/test/test/06-more-cart-flows.js b/test/test/06-more-cart-flows.js
new file mode 100644
index 00000000..892c9e47
--- /dev/null
+++ b/test/test/06-more-cart-flows.js
@@ -0,0 +1,112 @@
+var sdk = require('../lib/sdk')
+var promise = require('../lib/promise')
+var assert = require("assert")
+
+// sdk.cart.initialize
+// sdk.cart.set_user
+// sdk.cart.add_item
+// sdk.cart.delete_item
+// sdk.cart.get_status
+
+describe('buggy_cart', function(){
+ var new_user_data = {
+ "Email": "blahtest+" + Math.floor(Math.random() * 10000000) + "@blahtest.com",
+ "Password": "TestPasswordYOOX",
+ "Gender": "U",
+ "Name": "test",
+ "Surname": "test",
+ "DataProfiling": true,
+ }
+ var test_product = {
+ "Code10": "37725683OV",
+ "Size": 4,
+ }
+
+ this.timeout(30000)
+
+ var test_item
+
+ describe('#signup()', function(){
+ it('makes a user and creates a token', function(done){
+ promise(sdk.account.signup, { data: new_user_data }).then(function(data){
+ // console.log(data)
+ assert(data.Header.StatusCode == 201)
+ assert('UserAccount' in data)
+
+ // console.log(data)
+
+ done()
+ })
+ })
+ })
+
+ describe('#initialize()', function(){
+ it('initializes the cart', function(done){
+ promise(sdk.cart.initialize, { data: {} }).then(function(data){
+ assert(data.Header.StatusCode == 200)
+ assert(sdk.cart.id !== "")
+ assert(sdk.cart.token !== "")
+ done()
+ })
+ })
+ })
+
+ describe('#set_user()', function(){
+ it('sets user to cart', function(done){
+ var user_creds = {
+ "UserId": sdk.auth.user_id,
+ "UserToken": sdk.auth.access_token,
+ }
+ promise(sdk.cart.set_user, { data: user_creds }).then(function(data){
+ assert(data.Header.StatusCode == 200)
+ done()
+ })
+ })
+ })
+
+ describe('#collection()', function(){
+ it('returns a collection', function(done){
+ promise(sdk.product.collection).then(function(data){
+ assert(data.Header.StatusCode == 200)
+ assert(data.SearchResponseFull.Results.Items.length > 0)
+ test_item = data.SearchResponseFull.Results.Items[0]
+ done()
+ }).error(function(error){
+ done()
+ })
+ })
+ })
+
+ describe('#add_item()', function(){
+ it('adds item to cart', function(done){
+ var product_item = {
+ Code10: test_item.DefaultCode10,
+ Size: test_item.Sizes[0].Id,
+ }
+ promise(sdk.cart.add_item, { data: product_item }).then(function(data){
+ assert(data.Header.StatusCode == 201)
+ done()
+ }).error(function(){
+ console.log("ERROR ADDING TO CART")
+ done()
+ })
+ })
+
+ it('does not add item if cart is messed up', function(done){
+ var product_item = {
+ Code10: test_item.DefaultCode10,
+ Size: test_item.Sizes[0].Id,
+ }
+ sdk.cart.id = "BROKEN"
+ sdk.cart.token = "BROKEN"
+ promise(sdk.cart.add_item, { data: product_item }).then(function(data){
+ assert(data.Header.StatusCode !== 201)
+ }).error(function(data){
+ assert(data.status !== 201)
+ done()
+ })
+ })
+
+ })
+
+})