Adds SFRA 6.0
This commit is contained in:
@@ -0,0 +1,379 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
var chai = require('chai');
|
||||
var chaiSubset = require('chai-subset');
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe('Cart: Selecting Shipping Methods', function () {
|
||||
this.timeout(5000);
|
||||
|
||||
var variantPid1 = '740357440196M';
|
||||
var qty1 = '1';
|
||||
var variantPid2 = '013742335538M';
|
||||
var qty2 = '1';
|
||||
|
||||
var cookieJar = request.jar();
|
||||
var myRequest = {
|
||||
url: '',
|
||||
method: 'POST',
|
||||
form: {},
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
var cookieString;
|
||||
|
||||
var expectedResponseCommon = {
|
||||
'action': 'Cart-SelectShippingMethod',
|
||||
'numOfShipments': 1,
|
||||
'shipments': [
|
||||
{
|
||||
'shippingMethods': [
|
||||
{
|
||||
'description': 'Order received within 7-10 business days',
|
||||
'displayName': 'Ground',
|
||||
'ID': '001',
|
||||
'shippingCost': '$7.99',
|
||||
'estimatedArrivalTime': '7-10 Business Days'
|
||||
},
|
||||
{
|
||||
'description': 'Order received in 2 business days',
|
||||
'displayName': '2-Day Express',
|
||||
'ID': '002',
|
||||
'shippingCost': '$11.99',
|
||||
'estimatedArrivalTime': '2 Business Days'
|
||||
},
|
||||
{
|
||||
'description': 'Order received the next business day',
|
||||
'displayName': 'Overnight',
|
||||
'ID': '003',
|
||||
'shippingCost': '$19.99',
|
||||
'estimatedArrivalTime': 'Next Day'
|
||||
},
|
||||
{
|
||||
'description': 'Orders shipped outside continental US received in 2-3 business days',
|
||||
'displayName': 'Express',
|
||||
'ID': '012',
|
||||
'shippingCost': '$22.99',
|
||||
'estimatedArrivalTime': '2-3 Business Days'
|
||||
},
|
||||
{
|
||||
'description': 'Order shipped by USPS received within 7-10 business days',
|
||||
'displayName': 'USPS',
|
||||
'ID': '021',
|
||||
'shippingCost': '$7.99',
|
||||
'estimatedArrivalTime': '7-10 Business Days'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
before(function () {
|
||||
// ----- adding product #1:
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid1,
|
||||
childProducts: [],
|
||||
quantity: qty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function () {
|
||||
cookieString = cookieJar.getCookieString(myRequest.url);
|
||||
})
|
||||
|
||||
// ----- adding product #2, a different variant of same product 1:
|
||||
.then(function () {
|
||||
myRequest.form = {
|
||||
pid: variantPid2,
|
||||
childProducts: [],
|
||||
quantity: qty2
|
||||
};
|
||||
|
||||
var cookie = request.cookie(cookieString);
|
||||
cookieJar.setCookie(cookie, myRequest.url);
|
||||
|
||||
return request(myRequest);
|
||||
});
|
||||
});
|
||||
|
||||
it(' 1>. should set the shipping method to Overnight', function () {
|
||||
var expectTotals = {
|
||||
'subTotal': '$139.00',
|
||||
'grandTotal': '$166.94',
|
||||
'totalTax': '$7.95',
|
||||
'totalShippingCost': '$19.99',
|
||||
'orderLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
};
|
||||
|
||||
var shipMethodId = '003'; // 003 = Overnight
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
assert.containSubset(bodyAsJson, expectedResponseCommon, 'Actual response not as expected.');
|
||||
assert.containSubset(bodyAsJson.totals, expectTotals);
|
||||
assert.equal(bodyAsJson.shipments[0].selectedShippingMethod, shipMethodId);
|
||||
});
|
||||
});
|
||||
|
||||
it(' 2>. should set the shipping method to Ground', function () {
|
||||
var expectTotals = {
|
||||
'subTotal': '$139.00',
|
||||
'grandTotal': '$164.84',
|
||||
'totalTax': '$7.85',
|
||||
'totalShippingCost': '$17.99',
|
||||
'orderLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
};
|
||||
|
||||
var shipMethodId = '001'; // 001 = Ground
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
assert.containSubset(bodyAsJson.totals, expectTotals);
|
||||
assert.equal(bodyAsJson.shipments[0].selectedShippingMethod, shipMethodId);
|
||||
});
|
||||
});
|
||||
|
||||
it(' 3>. should set the shipping method to 2-Day Express', function () {
|
||||
var expectTotals = {
|
||||
'subTotal': '$139.00',
|
||||
'grandTotal': '$158.54',
|
||||
'totalTax': '$7.55',
|
||||
'totalShippingCost': '$11.99',
|
||||
'orderLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
};
|
||||
|
||||
var shipMethodId = '002'; // 002 = 2-Day Express
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.totals, expectTotals, 'Actual response not as expected.');
|
||||
assert.equal(bodyAsJson.shipments[0].selectedShippingMethod, shipMethodId);
|
||||
});
|
||||
});
|
||||
|
||||
it(' 4>. should set to default method Ground when shipping method is set to Store Pickup', function () {
|
||||
var expectTotals = {
|
||||
'subTotal': '$139.00',
|
||||
'grandTotal': '$145.95',
|
||||
'totalTax': '$6.95',
|
||||
'totalShippingCost': '$0.00',
|
||||
'orderLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
};
|
||||
|
||||
var shipMethodId = '005'; // 005 = Store Pickup
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.totals, expectTotals);
|
||||
assert.equal(bodyAsJson.shipments[0].selectedShippingMethod, shipMethodId);
|
||||
});
|
||||
});
|
||||
|
||||
it(' 5>. should set the shipping method to Express', function () {
|
||||
var expectTotals = {
|
||||
'subTotal': '$139.00',
|
||||
'grandTotal': '$170.09',
|
||||
'totalTax': '$8.10',
|
||||
'totalShippingCost': '$22.99',
|
||||
'orderLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
};
|
||||
|
||||
var shipMethodId = '012'; // 012 = Express
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.totals, expectTotals);
|
||||
assert.equal(bodyAsJson.shipments[0].selectedShippingMethod, shipMethodId);
|
||||
});
|
||||
});
|
||||
|
||||
it(' 6>. should set the shipping method to USPS', function () {
|
||||
var expectTotals = {
|
||||
'subTotal': '$139.00',
|
||||
'grandTotal': '$154.34',
|
||||
'totalTax': '$7.35',
|
||||
'totalShippingCost': '$7.99',
|
||||
'orderLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
};
|
||||
|
||||
var shipMethodId = '021'; // 021 = USPS
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.totals, expectTotals);
|
||||
assert.equal(bodyAsJson.shipments[0].selectedShippingMethod, shipMethodId);
|
||||
});
|
||||
});
|
||||
|
||||
it(' 7>. should default to default shipping method for method with excluded Products', function () {
|
||||
var expectTotals = {
|
||||
'subTotal': '$139.00',
|
||||
'grandTotal': '$164.84',
|
||||
'totalTax': '$7.85',
|
||||
'totalShippingCost': '$17.99',
|
||||
'orderLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
};
|
||||
|
||||
var shipMethodId = '004'; // 004 = Super Saver, has excluded Products
|
||||
var groundShipMethodId = '001';
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.totals, expectTotals);
|
||||
assert.equal(bodyAsJson.shipments[0].selectedShippingMethod, groundShipMethodId);
|
||||
});
|
||||
});
|
||||
|
||||
it(' 8>. should default to default shipping method for non-exist method', function () {
|
||||
var expectTotals = {
|
||||
'subTotal': '$139.00',
|
||||
'grandTotal': '$164.84',
|
||||
'totalTax': '$7.85',
|
||||
'totalShippingCost': '$17.99',
|
||||
'orderLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'formatted': '$0.00',
|
||||
'value': 0
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
};
|
||||
|
||||
var shipMethodId = '9999';
|
||||
var groundShipMethodId = '001';
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.totals, expectTotals);
|
||||
assert.equal(bodyAsJson.shipments[0].selectedShippingMethod, groundShipMethodId);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,451 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
var chai = require('chai');
|
||||
var chaiSubset = require('chai-subset');
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe('Add Product Set to cart', function () {
|
||||
this.timeout(5000);
|
||||
|
||||
it('should add all products in a product set', function () {
|
||||
var cookieJar = request.jar();
|
||||
|
||||
var pidsObj = [
|
||||
{
|
||||
'pid': '726819487824M',
|
||||
'qty': '1',
|
||||
options: ''
|
||||
},
|
||||
{
|
||||
'pid': '69309284M-2',
|
||||
'qty': '1',
|
||||
options: ''
|
||||
},
|
||||
{
|
||||
'pid': '799927335059M',
|
||||
'qty': '1',
|
||||
options: ''
|
||||
}
|
||||
];
|
||||
|
||||
var pidsObjString = JSON.stringify(pidsObj);
|
||||
|
||||
var myRequest = {
|
||||
url: config.baseUrl + '/Cart-AddProduct',
|
||||
method: 'POST',
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
form: {
|
||||
pidsObj: pidsObjString
|
||||
},
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200);
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
var expectedResponse = {
|
||||
'action': 'Cart-AddProduct',
|
||||
'queryString': '',
|
||||
'locale': 'en_US',
|
||||
'quantityTotal': 3,
|
||||
'message': 'Product added to cart',
|
||||
'cart': {
|
||||
'actionUrls': {
|
||||
'removeProductLineItemUrl': '/on/demandware.store/Sites-RefArch-Site/en_US/Cart-RemoveProductLineItem',
|
||||
'updateQuantityUrl': '/on/demandware.store/Sites-RefArch-Site/en_US/Cart-UpdateQuantity',
|
||||
'selectShippingUrl': '/on/demandware.store/Sites-RefArch-Site/en_US/Cart-SelectShippingMethod',
|
||||
'submitCouponCodeUrl': '/on/demandware.store/Sites-RefArch-Site/en_US/Cart-AddCoupon',
|
||||
'removeCouponLineItem': '/on/demandware.store/Sites-RefArch-Site/en_US/Cart-RemoveCouponLineItem'
|
||||
},
|
||||
'numOfShipments': 1,
|
||||
'totals': {
|
||||
'subTotal': '$268.00',
|
||||
'totalShippingCost': '$9.99',
|
||||
'grandTotal': '$291.89',
|
||||
'totalTax': '$13.90',
|
||||
'orderLevelDiscountTotal': {
|
||||
'value': 0,
|
||||
'formatted': '$0.00'
|
||||
},
|
||||
'shippingLevelDiscountTotal': {
|
||||
'value': 0,
|
||||
'formatted': '$0.00'
|
||||
},
|
||||
'discounts': [],
|
||||
'discountsHtml': '\n'
|
||||
},
|
||||
'shipments': [
|
||||
{
|
||||
'shippingMethods': [
|
||||
{
|
||||
'ID': '001',
|
||||
'displayName': 'Ground',
|
||||
'description': 'Order received within 7-10 business days',
|
||||
'estimatedArrivalTime': '7-10 Business Days',
|
||||
'default': true,
|
||||
'shippingCost': '$9.99',
|
||||
'selected': true
|
||||
},
|
||||
{
|
||||
'ID': '002',
|
||||
'displayName': '2-Day Express',
|
||||
'description': 'Order received in 2 business days',
|
||||
'estimatedArrivalTime': '2 Business Days',
|
||||
'default': false,
|
||||
'shippingCost': '$15.99',
|
||||
'selected': false
|
||||
},
|
||||
{
|
||||
'ID': '003',
|
||||
'displayName': 'Overnight',
|
||||
'description': 'Order received the next business day',
|
||||
'estimatedArrivalTime': 'Next Day',
|
||||
'default': false,
|
||||
'shippingCost': '$21.99',
|
||||
'selected': false
|
||||
},
|
||||
{
|
||||
'ID': '012',
|
||||
'displayName': 'Express',
|
||||
'description': 'Orders shipped outside continental US received in 2-3 business days',
|
||||
'estimatedArrivalTime': '2-3 Business Days',
|
||||
'default': false,
|
||||
'shippingCost': '$28.99',
|
||||
'selected': false
|
||||
},
|
||||
{
|
||||
'ID': '021',
|
||||
'displayName': 'USPS',
|
||||
'description': 'Order shipped by USPS received within 7-10 business days',
|
||||
'estimatedArrivalTime': '7-10 Business Days',
|
||||
'default': false,
|
||||
'shippingCost': '$9.99',
|
||||
'selected': false
|
||||
}
|
||||
],
|
||||
'selectedShippingMethod': '001'
|
||||
}
|
||||
],
|
||||
'approachingDiscounts': [],
|
||||
'items': [
|
||||
{
|
||||
'id': '726819487824M',
|
||||
'productName': 'Platinum V Neck Suit Dress',
|
||||
'price': {
|
||||
'sales': {
|
||||
'value': 99,
|
||||
'currency': 'USD',
|
||||
'formatted': '$99.00'
|
||||
},
|
||||
'list': null
|
||||
},
|
||||
'productType': 'variant',
|
||||
'images': {
|
||||
'small': [
|
||||
{
|
||||
'alt': 'Platinum V Neck Suit Dress, Black, small',
|
||||
'url': '/on/demandware.static/-/Sites-apparel-catalog/default/dw98d73d67/images/small/PG.821301999.JJDH0XX.PZ.jpg',
|
||||
'title': 'Platinum V Neck Suit Dress, Black'
|
||||
}
|
||||
]
|
||||
},
|
||||
'rating': 2,
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Black',
|
||||
'attributeId': 'color',
|
||||
'id': 'color'
|
||||
},
|
||||
{
|
||||
'displayName': 'Size',
|
||||
'displayValue': '6',
|
||||
'attributeId': 'size',
|
||||
'id': 'size'
|
||||
}
|
||||
],
|
||||
'quantityOptions': {
|
||||
'minOrderQuantity': 1,
|
||||
'maxOrderQuantity': 10
|
||||
},
|
||||
'priceTotal': {
|
||||
'price': '$99.00',
|
||||
'renderedPrice': '\n\n\n<div class="strike-through\nnon-adjusted-price"\n>\n null\n</div>\n<div class="pricing line-item-total-price-amount item-total-null">$99.00</div>\n\n'
|
||||
},
|
||||
'isBonusProductLineItem': false,
|
||||
'isGift': false,
|
||||
'UUID': '609a030b33812caaf9654ddc1e',
|
||||
'quantity': 1,
|
||||
'isOrderable': true,
|
||||
'promotions': null,
|
||||
'renderedPromotions': '',
|
||||
'attributes': null,
|
||||
'availability': {
|
||||
'messages': [
|
||||
'In Stock'
|
||||
],
|
||||
'inStockDate': null
|
||||
},
|
||||
'isAvailableForInStorePickup': false
|
||||
},
|
||||
{
|
||||
'id': '69309284M-2',
|
||||
'productName': 'Modern Striped Dress Shirt',
|
||||
'price': {
|
||||
'sales': {
|
||||
'value': 135,
|
||||
'currency': 'USD',
|
||||
'formatted': '$135.00'
|
||||
},
|
||||
'list': null
|
||||
},
|
||||
'productType': 'variant',
|
||||
'images': {
|
||||
'small': [
|
||||
{
|
||||
'alt': 'Modern Striped Dress Shirt, Blue, small',
|
||||
'url': '/on/demandware.static/-/Sites-apparel-catalog/default/dw30e81930/images/small/B0174514_GY9_0.jpg',
|
||||
'title': 'Modern Striped Dress Shirt, Blue'
|
||||
}
|
||||
]
|
||||
},
|
||||
'rating': 0,
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'color',
|
||||
'displayValue': 'Blue',
|
||||
'attributeId': 'color',
|
||||
'id': 'color'
|
||||
},
|
||||
{
|
||||
'displayName': 'size',
|
||||
'displayValue': '15L',
|
||||
'attributeId': 'size',
|
||||
'id': 'size'
|
||||
}
|
||||
],
|
||||
'quantityOptions': {
|
||||
'minOrderQuantity': 1,
|
||||
'maxOrderQuantity': 10
|
||||
},
|
||||
'priceTotal': {
|
||||
'price': '$135.00',
|
||||
'renderedPrice': '\n\n\n<div class="strike-through\nnon-adjusted-price"\n>\n null\n</div>\n<div class="pricing line-item-total-price-amount item-total-null">$135.00</div>\n\n'
|
||||
},
|
||||
'isBonusProductLineItem': false,
|
||||
'isGift': false,
|
||||
'UUID': '5f7095b9af2af2ba8a062a2586',
|
||||
'quantity': 1,
|
||||
'isOrderable': true,
|
||||
'promotions': null,
|
||||
'renderedPromotions': '',
|
||||
'attributes': null,
|
||||
'availability': {
|
||||
'messages': [
|
||||
'In Stock'
|
||||
],
|
||||
'inStockDate': null
|
||||
},
|
||||
'isAvailableForInStorePickup': false
|
||||
},
|
||||
{
|
||||
'id': '799927335059M',
|
||||
'productName': 'Classic Wrap',
|
||||
'price': {
|
||||
'sales': {
|
||||
'value': 34,
|
||||
'currency': 'USD',
|
||||
'formatted': '$34.00'
|
||||
},
|
||||
'list': null
|
||||
},
|
||||
'productType': 'variant',
|
||||
'images': {
|
||||
'small': [
|
||||
{
|
||||
'alt': 'Classic Wrap, Ivory, small',
|
||||
'url': '/on/demandware.static/-/Sites-apparel-catalog/default/dwd7013224/images/small/PG.W20766.IVORYXX.PZ.jpg',
|
||||
'title': 'Classic Wrap, Ivory'
|
||||
}
|
||||
]
|
||||
},
|
||||
'rating': 4,
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Ivory',
|
||||
'attributeId': 'color',
|
||||
'id': 'color'
|
||||
}
|
||||
],
|
||||
'quantityOptions': {
|
||||
'minOrderQuantity': 1,
|
||||
'maxOrderQuantity': 10
|
||||
},
|
||||
'priceTotal': {
|
||||
'price': '$34.00',
|
||||
'renderedPrice': '\n\n\n<div class="strike-through\nnon-adjusted-price"\n>\n null\n</div>\n<div class="pricing line-item-total-price-amount item-total-null">$34.00</div>\n\n'
|
||||
},
|
||||
'isBonusProductLineItem': false,
|
||||
'isGift': false,
|
||||
'UUID': 'fdb8c0e48d32acecfa239fb2df',
|
||||
'quantity': 1,
|
||||
'isOrderable': true,
|
||||
'promotions': null,
|
||||
'renderedPromotions': '',
|
||||
'attributes': null,
|
||||
'availability': {
|
||||
'messages': [
|
||||
'In Stock'
|
||||
],
|
||||
'inStockDate': null
|
||||
},
|
||||
'isAvailableForInStorePickup': false
|
||||
}
|
||||
],
|
||||
'numItems': 3,
|
||||
'resources': {
|
||||
'numberOfItems': '3 Items',
|
||||
'emptyCartMsg': 'Your Shopping Cart is Empty'
|
||||
}
|
||||
},
|
||||
'error': false
|
||||
};
|
||||
|
||||
function verifyShippingMethods(shipMethod, ExpectedShipMethod) {
|
||||
assert.equal(shipMethod.description, ExpectedShipMethod.description);
|
||||
assert.equal(shipMethod.displayName, ExpectedShipMethod.displayName);
|
||||
assert.equal(shipMethod.ID, ExpectedShipMethod.ID);
|
||||
assert.equal(shipMethod.estimatedArrivalTime, ExpectedShipMethod.estimatedArrivalTime);
|
||||
assert.equal(shipMethod.isDefault, ExpectedShipMethod.isDefault);
|
||||
assert.equal(shipMethod.isSelected, ExpectedShipMethod.isSelected);
|
||||
assert.equal(shipMethod.shippingCost, ExpectedShipMethod.shippingCost);
|
||||
}
|
||||
|
||||
// ----- Verify quantityTotal, message, action, queryString
|
||||
assert.equal(bodyAsJson.quantityTotal, expectedResponse.quantityTotal);
|
||||
assert.equal(bodyAsJson.message, expectedResponse.message);
|
||||
assert.equal(bodyAsJson.action, expectedResponse.action);
|
||||
|
||||
// ----- Verify actionUrls
|
||||
var actionUrls = bodyAsJson.cart.actionUrls;
|
||||
var expectedActionUrls = expectedResponse.cart.actionUrls;
|
||||
assert.equal(actionUrls.removeProductLineItemUrl, expectedActionUrls.removeProductLineItemUrl);
|
||||
assert.equal(actionUrls.updateQuantityUrl, expectedActionUrls.updateQuantityUrl);
|
||||
assert.equal(actionUrls.selectShippingUrl, expectedActionUrls.selectShippingUrl);
|
||||
assert.equal(actionUrls.submitCouponCodeUrl, expectedActionUrls.submitCouponCodeUrl);
|
||||
assert.equal(actionUrls.removeCouponLineItem, expectedActionUrls.removeCouponLineItem);
|
||||
|
||||
// ----- Verify approaching discounts
|
||||
assert.lengthOf(bodyAsJson.cart.approachingDiscounts, 0);
|
||||
|
||||
// ----- Verify numOfShipments
|
||||
assert.equal(bodyAsJson.cart.numOfShipments, expectedResponse.cart.numOfShipments);
|
||||
|
||||
// ----- Verify totals
|
||||
var totals = bodyAsJson.cart.totals;
|
||||
var expectedTotals = expectedResponse.cart.totals;
|
||||
assert.equal(totals.subTotal, expectedTotals.subTotal);
|
||||
assert.equal(totals.grandTotal, expectedTotals.grandTotal);
|
||||
assert.equal(totals.totalTax, expectedTotals.totalTax);
|
||||
assert.equal(totals.totalShippingCost, expectedTotals.totalShippingCost);
|
||||
assert.equal(totals.orderLevelDiscountTotal.value, expectedTotals.orderLevelDiscountTotal.value);
|
||||
assert.equal(totals.orderLevelDiscountTotal.formatted, expectedTotals.orderLevelDiscountTotal.formatted);
|
||||
assert.equal(totals.shippingLevelDiscountTotal.value, expectedTotals.shippingLevelDiscountTotal.value);
|
||||
assert.equal(totals.shippingLevelDiscountTotal.formatted, expectedTotals.shippingLevelDiscountTotal.formatted);
|
||||
assert.lengthOf(totals.discounts, 0);
|
||||
|
||||
// ----- Verify Shipments
|
||||
var shipMethods = bodyAsJson.cart.shipments[0].shippingMethods;
|
||||
var ExpectedShipMethods = expectedResponse.cart.shipments[0].shippingMethods;
|
||||
for (var i = 0; i < ExpectedShipMethods.length; i++) {
|
||||
verifyShippingMethods(shipMethods[i], ExpectedShipMethods[i]);
|
||||
}
|
||||
|
||||
assert.equal(bodyAsJson.cart.shipments[0].selectedShippingMethod, expectedResponse.cart.shipments[0].selectedShippingMethod);
|
||||
|
||||
// ----- Verify product line items in cart
|
||||
assert.lengthOf(bodyAsJson.cart.items, 3);
|
||||
|
||||
// Verify items in cart - item 1
|
||||
var expectedItem0 = {
|
||||
id: '726819487824M',
|
||||
productName: 'Platinum V Neck Suit Dress',
|
||||
price:
|
||||
{
|
||||
sales: {
|
||||
value: 99,
|
||||
currency: 'USD',
|
||||
formatted: '$99.00'
|
||||
}
|
||||
},
|
||||
variationAttributes:
|
||||
[{ displayName: 'Color',
|
||||
displayValue: 'Black'
|
||||
},
|
||||
{ displayName: 'Size',
|
||||
displayValue: '6'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
assert.containSubset(bodyAsJson.cart.items[0], expectedItem0);
|
||||
|
||||
// Verify items in cart - item 2
|
||||
var expectedItem1 = {
|
||||
id: '69309284M-2',
|
||||
productName: 'Modern Striped Dress Shirt',
|
||||
price: {
|
||||
sales: {
|
||||
value: 135,
|
||||
currency: 'USD'
|
||||
}
|
||||
},
|
||||
variationAttributes:
|
||||
[{
|
||||
displayName: 'color',
|
||||
displayValue: 'Blue'
|
||||
},
|
||||
{ displayName: 'size',
|
||||
displayValue: '15L'
|
||||
}
|
||||
]
|
||||
};
|
||||
assert.containSubset(bodyAsJson.cart.items[1], expectedItem1);
|
||||
|
||||
// Verify items in cart - item 3
|
||||
var expectedItem2 = {
|
||||
id: '799927335059M',
|
||||
productName: 'Classic Wrap',
|
||||
price: {
|
||||
sales: {
|
||||
value: 34,
|
||||
currency: 'USD'
|
||||
}
|
||||
},
|
||||
variationAttributes:
|
||||
[{ displayName: 'Color',
|
||||
displayValue: 'Ivory'
|
||||
}
|
||||
],
|
||||
quantity: 1
|
||||
};
|
||||
assert.containSubset(bodyAsJson.cart.items[2], expectedItem2);
|
||||
|
||||
// ----- Verify number of items
|
||||
assert.equal(bodyAsJson.cart.numItems, expectedResponse.cart.numItems);
|
||||
|
||||
// ----- Verify resource
|
||||
assert.equal(bodyAsJson.cart.resources.numberOfItems, expectedResponse.cart.resources.numberOfItems);
|
||||
assert.equal(bodyAsJson.cart.resources.emptyCartMsg, expectedResponse.cart.resources.emptyCartMsg);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,266 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
var chai = require('chai');
|
||||
var chaiSubset = require('chai-subset');
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe('Add Product variants to cart', function () {
|
||||
this.timeout(5000);
|
||||
|
||||
it('should add variants of different and same products, returns total quantity of added items', function () {
|
||||
var cookieJar = request.jar();
|
||||
|
||||
// The myRequest object will be reused through out this file. The 'jar' property will be set once.
|
||||
// The 'url' property will be updated on every request to set the product ID (pid) and quantity.
|
||||
// All other properties remained unchanged.
|
||||
var myRequest = {
|
||||
url: '',
|
||||
method: 'POST',
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
var cookieString;
|
||||
|
||||
var totalQty;
|
||||
|
||||
var variantPid1 = '701643421084M';
|
||||
var qty1 = 2;
|
||||
var variantPid2 = '701642923459M';
|
||||
var qty2 = 1;
|
||||
var variantPid3 = '013742000252M';
|
||||
var qty3 = 11;
|
||||
var variantPid4 = '029407331258M';
|
||||
var qty4 = 3;
|
||||
|
||||
var action = 'Cart-AddProduct';
|
||||
var message = 'Product added to cart';
|
||||
var addProd = '/Cart-AddProduct';
|
||||
|
||||
// ----- adding product #1:
|
||||
totalQty = qty1;
|
||||
myRequest.url = config.baseUrl + addProd;
|
||||
myRequest.form = {
|
||||
pid: variantPid1,
|
||||
quantity: qty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200);
|
||||
|
||||
var expectedResBody = {
|
||||
'quantityTotal': totalQty,
|
||||
'action': action,
|
||||
'message': message
|
||||
};
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
assert.equal(bodyAsJson.quantityTotal, expectedResBody.quantityTotal);
|
||||
|
||||
cookieString = cookieJar.getCookieString(myRequest.url);
|
||||
})
|
||||
|
||||
// ----- adding product #2, a different variant of same product 1:
|
||||
.then(function () {
|
||||
totalQty += qty2;
|
||||
myRequest.url = config.baseUrl + addProd;
|
||||
myRequest.form = {
|
||||
pid: variantPid2,
|
||||
quantity: qty2
|
||||
};
|
||||
|
||||
var cookie = request.cookie(cookieString);
|
||||
cookieJar.setCookie(cookie, myRequest.url);
|
||||
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// Handle response from request #2
|
||||
.then(function (response2) {
|
||||
assert.equal(response2.statusCode, 200);
|
||||
|
||||
var expectedResBody2 = {
|
||||
'action': action,
|
||||
'quantityTotal': totalQty,
|
||||
'message': message
|
||||
|
||||
};
|
||||
|
||||
var bodyAsJson2 = JSON.parse(response2.body);
|
||||
assert.equal(bodyAsJson2.quantityTotal, expectedResBody2.quantityTotal);
|
||||
})
|
||||
|
||||
// ----- adding product #3:
|
||||
.then(function () {
|
||||
totalQty += qty3;
|
||||
myRequest.url = config.baseUrl + addProd;
|
||||
myRequest.form = {
|
||||
pid: variantPid3,
|
||||
quantity: qty3
|
||||
};
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// Handle response from request #3
|
||||
.then(function (response3) {
|
||||
assert.equal(response3.statusCode, 200);
|
||||
|
||||
var expectedResBody3 = {
|
||||
'action': action,
|
||||
'quantityTotal': totalQty,
|
||||
'message': message
|
||||
};
|
||||
|
||||
var bodyAsJson3 = JSON.parse(response3.body);
|
||||
assert.equal(bodyAsJson3.quantityTotal, expectedResBody3.quantityTotal);
|
||||
})
|
||||
|
||||
// ----- adding product #4:
|
||||
.then(function () {
|
||||
totalQty += qty4;
|
||||
myRequest.url = config.baseUrl + addProd;
|
||||
myRequest.form = {
|
||||
pid: variantPid4,
|
||||
quantity: qty4
|
||||
};
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// Handle response from request #4
|
||||
.then(function (response4) {
|
||||
assert.equal(response4.statusCode, 200);
|
||||
|
||||
var bodyAsJson = JSON.parse(response4.body);
|
||||
var expectedTotal = {
|
||||
'subTotal': '$381.97',
|
||||
'grandTotal': '$527.06',
|
||||
'totalTax': '$25.10',
|
||||
'totalShippingCost': '$119.99'
|
||||
};
|
||||
|
||||
var expectedShippingMethod = {
|
||||
'selectedShippingMethod': '001',
|
||||
'shippingMethods': [
|
||||
{
|
||||
'displayName': 'Ground',
|
||||
'ID': '001',
|
||||
'estimatedArrivalTime': '7-10 Business Days',
|
||||
'default': true,
|
||||
'selected': true,
|
||||
'shippingCost': '$9.99'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var expectedItems0 = {
|
||||
'id': variantPid1,
|
||||
'price': {
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 24
|
||||
}
|
||||
},
|
||||
'productType': 'variant',
|
||||
'variationAttributes': [
|
||||
{
|
||||
'attributeId': 'color',
|
||||
'id': 'color'
|
||||
},
|
||||
{
|
||||
'attributeId': 'size',
|
||||
'id': 'size'
|
||||
}
|
||||
],
|
||||
'quantity': qty1
|
||||
};
|
||||
|
||||
var expectedItems1 = {
|
||||
'id': variantPid2,
|
||||
'price': {
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 24
|
||||
}
|
||||
},
|
||||
'productType': 'variant',
|
||||
'variationAttributes': [
|
||||
{
|
||||
'attributeId': 'color',
|
||||
'id': 'color'
|
||||
},
|
||||
{
|
||||
'attributeId': 'size',
|
||||
'id': 'size'
|
||||
}
|
||||
],
|
||||
'quantity': qty2
|
||||
};
|
||||
|
||||
var expectedItems2 = {
|
||||
'id': variantPid3,
|
||||
'price': {
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 20
|
||||
}
|
||||
},
|
||||
'productType': 'variant',
|
||||
'variationAttributes': [
|
||||
{
|
||||
'attributeId': 'color',
|
||||
'id': 'color'
|
||||
}
|
||||
],
|
||||
'quantity': qty3
|
||||
};
|
||||
|
||||
var expectedItems3 = {
|
||||
'id': variantPid4,
|
||||
'price': {
|
||||
'list': {
|
||||
'currency': 'USD',
|
||||
'value': 39.5
|
||||
},
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 29.99
|
||||
}
|
||||
},
|
||||
'productType': 'variant',
|
||||
'variationAttributes': [
|
||||
{
|
||||
'attributeId': 'color',
|
||||
'id': 'color'
|
||||
}
|
||||
],
|
||||
'quantity': qty4
|
||||
};
|
||||
|
||||
// ----- Verify quantityTotal, message, action
|
||||
assert.equal(bodyAsJson.quantityTotal, totalQty);
|
||||
assert.equal(bodyAsJson.message, message);
|
||||
assert.equal(bodyAsJson.action, action);
|
||||
|
||||
// ----- Verify totals
|
||||
assert.containSubset(bodyAsJson.cart.totals, expectedTotal);
|
||||
|
||||
// ----- Verify Shipments
|
||||
assert.containSubset(bodyAsJson.cart.shipments[0], expectedShippingMethod);
|
||||
|
||||
// ----- Verify product line items in cart
|
||||
assert.lengthOf(bodyAsJson.cart.items, 4);
|
||||
|
||||
// ----- Verify Product id, quantity and name in Cart
|
||||
assert.containSubset(bodyAsJson.cart.items[0], expectedItems0);
|
||||
assert.containSubset(bodyAsJson.cart.items[1], expectedItems1);
|
||||
assert.containSubset(bodyAsJson.cart.items[2], expectedItems2);
|
||||
assert.containSubset(bodyAsJson.cart.items[3], expectedItems3);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,134 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
var chai = require('chai');
|
||||
var chaiSubset = require('chai-subset');
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe('Edit product bundle', function () {
|
||||
this.timeout(45000);
|
||||
|
||||
var variantPid1 = 'womens-jewelry-bundleM'; // womens jewelry bundle
|
||||
var qty1 = 1;
|
||||
|
||||
var newQty1;
|
||||
|
||||
var prodIdUuidMap = {};
|
||||
var variantUuid1;
|
||||
|
||||
var cookieJar = request.jar();
|
||||
var myRequest = {
|
||||
url: '',
|
||||
method: 'POST',
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
before(function () {
|
||||
// ----- adding product #1:
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid1,
|
||||
quantity: qty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
// ----- select a shipping method. Need to have shipping method so that shipping cost, sales tax,
|
||||
// and grand total can be calculated
|
||||
.then(function () {
|
||||
var shipMethodId = '001'; // 001 = Ground
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- Get UUID for each product line items
|
||||
.then(function (response4) {
|
||||
var bodyAsJson = JSON.parse(response4.body);
|
||||
|
||||
prodIdUuidMap[bodyAsJson.items[0].id] = bodyAsJson.items[0].UUID;
|
||||
|
||||
variantUuid1 = prodIdUuidMap[variantPid1];
|
||||
});
|
||||
});
|
||||
|
||||
it('should update the bundle quantity', function () {
|
||||
newQty1 = 3;
|
||||
var newTotalQty = newQty1;
|
||||
var expectQty1 = newQty1;
|
||||
|
||||
|
||||
var expectedUpdateRep = {
|
||||
'action': 'Cart-EditProductLineItem',
|
||||
'cartModel': {
|
||||
'totals': {
|
||||
'subTotal': '$339.00',
|
||||
'grandTotal': '$397.94',
|
||||
'totalTax': '$18.95',
|
||||
'totalShippingCost': '$39.99'
|
||||
},
|
||||
'items': [
|
||||
{
|
||||
'id': variantPid1,
|
||||
'productName': 'Turquoise Jewelry Bundle',
|
||||
'productType': 'bundle',
|
||||
'price': {
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 113,
|
||||
'formatted': '$113.00',
|
||||
'decimalPrice': '113.00'
|
||||
},
|
||||
'list': null
|
||||
},
|
||||
'availability': {
|
||||
'messages': [
|
||||
'2 Item(s) in Stock',
|
||||
'1 item(s) are available for pre-order'
|
||||
],
|
||||
'inStockDate': null
|
||||
},
|
||||
'available': true,
|
||||
'UUID': variantUuid1,
|
||||
'quantity': expectQty1,
|
||||
'priceTotal': {
|
||||
'price': '$339.00'
|
||||
}
|
||||
}
|
||||
],
|
||||
'numItems': newTotalQty,
|
||||
'locale': 'en_US',
|
||||
'resources': {
|
||||
'numberOfItems': newTotalQty + ' Items',
|
||||
'emptyCartMsg': 'Your Shopping Cart is Empty'
|
||||
}
|
||||
},
|
||||
'newProductId': variantPid1
|
||||
};
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-EditProductLineItem';
|
||||
myRequest.form = {
|
||||
uuid: variantUuid1,
|
||||
pid: variantPid1,
|
||||
quantity: newQty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (updateRsp) {
|
||||
assert.equal(updateRsp.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(updateRsp.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.cartModel.totals, expectedUpdateRep.cartModel.totals);
|
||||
assert.containSubset(bodyAsJson.cartModel.items, expectedUpdateRep.cartModel.items);
|
||||
assert.equal(bodyAsJson.cartModel.numItems, expectedUpdateRep.cartModel.numItems);
|
||||
assert.containSubset(bodyAsJson.cartModel.resources, expectedUpdateRep.cartModel.resources);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,306 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
var chai = require('chai');
|
||||
var chaiSubset = require('chai-subset');
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe('Edit product variant', function () {
|
||||
this.timeout(45000);
|
||||
|
||||
var variantPid1 = '701643421084M'; // 3/4 Sleeve V-Neck Top: icy mint, XS
|
||||
var qty1 = 1;
|
||||
var variantPid2 = '793775362380M'; // Striped Silk Tie: red, 29.99
|
||||
var qty2 = 1;
|
||||
|
||||
var newQty1;
|
||||
|
||||
var prodIdUuidMap = {};
|
||||
var variantUuid1;
|
||||
var variantUuid2;
|
||||
|
||||
var cookieJar = request.jar();
|
||||
var myRequest = {
|
||||
url: '',
|
||||
method: 'POST',
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
var cookieString;
|
||||
|
||||
before(function () {
|
||||
// ----- adding product #1:
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid1,
|
||||
quantity: qty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function () {
|
||||
cookieString = cookieJar.getCookieString(myRequest.url);
|
||||
})
|
||||
|
||||
// ----- adding product #2
|
||||
.then(function () {
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid2,
|
||||
quantity: qty2
|
||||
};
|
||||
|
||||
var cookie = request.cookie(cookieString);
|
||||
cookieJar.setCookie(cookie, myRequest.url);
|
||||
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- select a shipping method. Need to have shipping method so that shipping cost, sales tax,
|
||||
// and grand total can be calculated
|
||||
.then(function () {
|
||||
var shipMethodId = '001'; // 001 = Ground
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- Get UUID for each product line items
|
||||
.then(function (response4) {
|
||||
var bodyAsJson = JSON.parse(response4.body);
|
||||
|
||||
prodIdUuidMap[bodyAsJson.items[0].id] = bodyAsJson.items[0].UUID;
|
||||
prodIdUuidMap[bodyAsJson.items[1].id] = bodyAsJson.items[1].UUID;
|
||||
|
||||
variantUuid1 = prodIdUuidMap[variantPid1];
|
||||
variantUuid2 = prodIdUuidMap[variantPid2];
|
||||
});
|
||||
});
|
||||
|
||||
it('should update product line item 1 with the new variant and quantity', function () {
|
||||
// edit attributes of product variant 1
|
||||
|
||||
newQty1 = 3;
|
||||
var newTotalQty = newQty1 + qty2;
|
||||
var expectQty1 = newQty1;
|
||||
var expectQty2 = qty2;
|
||||
|
||||
var newVariantPid1 = '701642923541M'; // 3/4 Sleeve V-Neck Top: Grey Heather, S
|
||||
|
||||
var expectedUpdateRep = {
|
||||
'action': 'Cart-EditProductLineItem',
|
||||
'cartModel': {
|
||||
'totals': {
|
||||
'subTotal': '$101.99',
|
||||
'grandTotal': '$115.48',
|
||||
'totalTax': '$5.50',
|
||||
'totalShippingCost': '$7.99'
|
||||
},
|
||||
'items': [
|
||||
{
|
||||
'id': newVariantPid1,
|
||||
'productName': '3/4 Sleeve V-Neck Top',
|
||||
'price': {
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 24,
|
||||
'formatted': '$24.00',
|
||||
'decimalPrice': '24.00'
|
||||
}
|
||||
},
|
||||
'images': {
|
||||
'small': [
|
||||
{
|
||||
'alt': '3/4 Sleeve V-Neck Top, Grey Heather, small',
|
||||
'title': '3/4 Sleeve V-Neck Top, Grey Heather'
|
||||
}
|
||||
]
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Grey Heather',
|
||||
'attributeId': 'color'
|
||||
},
|
||||
{
|
||||
'displayName': 'Size',
|
||||
'displayValue': 'S',
|
||||
'attributeId': 'size'
|
||||
}
|
||||
],
|
||||
'availability': {
|
||||
'messages': [
|
||||
'In Stock'
|
||||
],
|
||||
'inStockDate': null
|
||||
},
|
||||
'UUID': variantUuid1,
|
||||
'quantity': expectQty1,
|
||||
'priceTotal': {
|
||||
'price': '$72.00'
|
||||
}
|
||||
},
|
||||
{
|
||||
'id': variantPid2,
|
||||
'productName': 'Striped Silk Tie',
|
||||
'price': {
|
||||
'list': {
|
||||
'currency': 'USD',
|
||||
'value': 39.5,
|
||||
'formatted': '$39.50',
|
||||
'decimalPrice': '39.50'
|
||||
},
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 29.99,
|
||||
'formatted': '$29.99',
|
||||
'decimalPrice': '29.99'
|
||||
}
|
||||
},
|
||||
'images': {
|
||||
'small': [
|
||||
{
|
||||
'alt': 'Striped Silk Tie, Red, small',
|
||||
'title': 'Striped Silk Tie, Red'
|
||||
}
|
||||
]
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Red',
|
||||
'attributeId': 'color'
|
||||
}
|
||||
],
|
||||
'availability': {
|
||||
'messages': [
|
||||
'In Stock'
|
||||
],
|
||||
'inStockDate': null
|
||||
},
|
||||
'UUID': variantUuid2,
|
||||
'quantity': expectQty2
|
||||
}
|
||||
],
|
||||
'numItems': newTotalQty,
|
||||
'locale': 'en_US',
|
||||
'resources': {
|
||||
'numberOfItems': newTotalQty + ' Items',
|
||||
'emptyCartMsg': 'Your Shopping Cart is Empty'
|
||||
}
|
||||
},
|
||||
'newProductId': newVariantPid1
|
||||
};
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-EditProductLineItem';
|
||||
myRequest.form = {
|
||||
uuid: variantUuid1,
|
||||
pid: newVariantPid1,
|
||||
quantity: newQty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (updateRsp) {
|
||||
assert.equal(updateRsp.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(updateRsp.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.cartModel.totals, expectedUpdateRep.cartModel.totals);
|
||||
assert.equal(bodyAsJson.cartModel.items.length, expectedUpdateRep.cartModel.items.length);
|
||||
assert.containSubset(bodyAsJson.cartModel.items, expectedUpdateRep.cartModel.items);
|
||||
assert.equal(bodyAsJson.cartModel.numItems, expectedUpdateRep.cartModel.numItems);
|
||||
assert.containSubset(bodyAsJson.cartModel.resources, expectedUpdateRep.cartModel.resources);
|
||||
|
||||
// Verify path to image source
|
||||
var prodImageSrc1 = bodyAsJson.cartModel.items[0].images.small[0].url;
|
||||
var prodImageSrc2 = bodyAsJson.cartModel.items[1].images.small[0].url;
|
||||
assert.isTrue(prodImageSrc1.endsWith('/images/small/PG.10221714.JJ908XX.PZ.jpg'));
|
||||
assert.isTrue(prodImageSrc2.endsWith('/images/small/PG.949114314S.REDSI.PZ.jpg'));
|
||||
|
||||
assert.equal(bodyAsJson.newProductId, expectedUpdateRep.newProductId);
|
||||
});
|
||||
});
|
||||
|
||||
// notice the product line 1 has been updated in the above test
|
||||
it('should update product line item 2 with new price', function () {
|
||||
// edit product variant 2 to have different price variant
|
||||
|
||||
var expectQty2 = qty2;
|
||||
|
||||
var newVariantPid2 = '793775370033M'; // Striped Silk Tie: Turquoise, 23.99
|
||||
|
||||
var expectedUpdateRep = {
|
||||
'action': 'Cart-EditProductLineItem',
|
||||
'cartModel': {
|
||||
'items': [
|
||||
{
|
||||
'id': newVariantPid2,
|
||||
'productName': 'Striped Silk Tie',
|
||||
'price': {
|
||||
'list': {
|
||||
'currency': 'USD',
|
||||
'value': 39.5,
|
||||
'formatted': '$39.50',
|
||||
'decimalPrice': '39.50'
|
||||
},
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 23.99,
|
||||
'formatted': '$23.99',
|
||||
'decimalPrice': '23.99'
|
||||
}
|
||||
},
|
||||
'images': {
|
||||
'small': [
|
||||
{
|
||||
'alt': 'Striped Silk Tie, Turquoise, small',
|
||||
'title': 'Striped Silk Tie, Turquoise'
|
||||
}
|
||||
]
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Turquoise',
|
||||
'attributeId': 'color'
|
||||
}
|
||||
],
|
||||
'UUID': variantUuid2,
|
||||
'quantity': expectQty2,
|
||||
'appliedPromotions': [
|
||||
{
|
||||
'callOutMsg': 'Get 20% off of this tie.'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
'newProductId': newVariantPid2
|
||||
};
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-EditProductLineItem';
|
||||
myRequest.form = {
|
||||
uuid: variantUuid2,
|
||||
pid: newVariantPid2,
|
||||
quantity: qty2
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (updateRsp) {
|
||||
assert.equal(updateRsp.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(updateRsp.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.cartModel.items, expectedUpdateRep.cartModel.items);
|
||||
assert.equal(bodyAsJson.newProductId, expectedUpdateRep.newProductId);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -0,0 +1,182 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
var chai = require('chai');
|
||||
var chaiSubset = require('chai-subset');
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe('Edit product variant for merging products', function () {
|
||||
this.timeout(45000);
|
||||
|
||||
var variantPid1 = '701643421084M'; // 3/4 Sleeve V-Neck Top: icy mint, XS
|
||||
var qty1 = 1;
|
||||
var variantPid2 = '701643421060M'; // 3/4 Sleeve V-Neck Top: yellow, XS
|
||||
var qty2 = 1;
|
||||
|
||||
var newQty1;
|
||||
|
||||
var prodIdUuidMap = {};
|
||||
var variantUuid1;
|
||||
|
||||
var cookieJar = request.jar();
|
||||
var myRequest = {
|
||||
url: '',
|
||||
method: 'POST',
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
var cookieString;
|
||||
|
||||
before(function () {
|
||||
// ----- adding product #1:
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid1,
|
||||
quantity: qty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function () {
|
||||
cookieString = cookieJar.getCookieString(myRequest.url);
|
||||
})
|
||||
|
||||
// ----- adding product #2
|
||||
.then(function () {
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid2,
|
||||
quantity: qty2
|
||||
};
|
||||
|
||||
var cookie = request.cookie(cookieString);
|
||||
cookieJar.setCookie(cookie, myRequest.url);
|
||||
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- select a shipping method. Need to have shipping method so that shipping cost, sales tax,
|
||||
// and grand total can be calculated
|
||||
.then(function () {
|
||||
var shipMethodId = '001'; // 001 = Ground
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- Get UUID for each product line items
|
||||
.then(function (response4) {
|
||||
var bodyAsJson = JSON.parse(response4.body);
|
||||
|
||||
prodIdUuidMap[bodyAsJson.items[0].id] = bodyAsJson.items[0].UUID;
|
||||
prodIdUuidMap[bodyAsJson.items[1].id] = bodyAsJson.items[1].UUID;
|
||||
|
||||
variantUuid1 = prodIdUuidMap[variantPid1];
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge product line items into 1 with the new variant and quantity value', function () {
|
||||
// edit attributes of product variant 1
|
||||
|
||||
newQty1 = 4;
|
||||
var newTotalQty = newQty1 + qty2;
|
||||
|
||||
var newVariantPid1 = '701643421060M'; // 3/4 Sleeve V-Neck Top: Yellow, S
|
||||
|
||||
var expectedUpdateRep = {
|
||||
'action': 'Cart-EditProductLineItem',
|
||||
'cartModel': {
|
||||
'totals': {
|
||||
'subTotal': '$120.00',
|
||||
'grandTotal': '$134.39',
|
||||
'totalTax': '$6.40',
|
||||
'totalShippingCost': '$7.99'
|
||||
},
|
||||
'items': [
|
||||
{
|
||||
'id': newVariantPid1,
|
||||
'productName': '3/4 Sleeve V-Neck Top',
|
||||
'price': {
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 24,
|
||||
'formatted': '$24.00',
|
||||
'decimalPrice': '24.00'
|
||||
}
|
||||
},
|
||||
'images': {
|
||||
'small': [
|
||||
{
|
||||
'alt': '3/4 Sleeve V-Neck Top, Butter, small',
|
||||
'title': '3/4 Sleeve V-Neck Top, Butter',
|
||||
'url': '/on/demandware.static/-/Sites-apparel-m-catalog/default/dwdd28bd60/images/small/PG.10221714.JJ370XX.PZ.jpg'
|
||||
}
|
||||
]
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Butter',
|
||||
'attributeId': 'color'
|
||||
},
|
||||
{
|
||||
'displayName': 'Size',
|
||||
'displayValue': 'XS',
|
||||
'attributeId': 'size'
|
||||
}
|
||||
],
|
||||
'availability': {
|
||||
'messages': [
|
||||
'In Stock'
|
||||
],
|
||||
'inStockDate': null
|
||||
},
|
||||
'UUID': variantUuid1,
|
||||
'quantity': 5,
|
||||
'priceTotal': {
|
||||
'price': '$120.00'
|
||||
}
|
||||
}
|
||||
],
|
||||
'numItems': newTotalQty,
|
||||
'locale': 'en_US',
|
||||
'resources': {
|
||||
'numberOfItems': newTotalQty + ' Items',
|
||||
'emptyCartMsg': 'Your Shopping Cart is Empty'
|
||||
}
|
||||
},
|
||||
'newProductId': newVariantPid1
|
||||
};
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-EditProductLineItem';
|
||||
myRequest.form = {
|
||||
uuid: variantUuid1,
|
||||
pid: newVariantPid1,
|
||||
quantity: newQty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (updateRsp) {
|
||||
assert.equal(updateRsp.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
var bodyAsJson = JSON.parse(updateRsp.body);
|
||||
|
||||
assert.containSubset(bodyAsJson.cartModel.totals, expectedUpdateRep.cartModel.totals);
|
||||
assert.equal(bodyAsJson.cartModel.items.length, expectedUpdateRep.cartModel.items.length);
|
||||
assert.equal(bodyAsJson.cartModel.items[0].id, variantPid2);
|
||||
assert.equal(bodyAsJson.cartModel.items[0].productName, '3/4 Sleeve V-Neck Top');
|
||||
assert.equal(bodyAsJson.cartModel.items[0].productType, 'variant');
|
||||
|
||||
// Verify path to image source
|
||||
var prodImageSrc1 = bodyAsJson.cartModel.items[0].images.small[0].url;
|
||||
assert.isTrue(prodImageSrc1.endsWith('/images/small/PG.10221714.JJ370XX.PZ.jpg'));
|
||||
assert.equal(bodyAsJson.newProductId, expectedUpdateRep.newProductId);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -0,0 +1,60 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
|
||||
describe('Cart: Get product variant in cart for edit', function () {
|
||||
this.timeout(45000);
|
||||
|
||||
var variantPid1 = '701643421084M'; // 3/4 Sleeve V-Neck Top: icy mint, XS
|
||||
var variantUuid1;
|
||||
|
||||
var cookieJar = request.jar();
|
||||
var myRequest = {
|
||||
url: '',
|
||||
method: 'POST',
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
var cookieString;
|
||||
|
||||
before(function () {
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid1,
|
||||
quantity: 1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200);
|
||||
|
||||
cookieString = cookieJar.getCookieString(myRequest.url);
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
|
||||
variantUuid1 = bodyAsJson.cart.items[0].UUID;
|
||||
});
|
||||
});
|
||||
|
||||
it('should get information on the specified product', function () {
|
||||
myRequest.method = 'GET';
|
||||
myRequest.url = config.baseUrl + '/Cart-GetProduct?uuid=' + variantUuid1;
|
||||
|
||||
var cookie = request.cookie(cookieString);
|
||||
cookieJar.setCookie(cookie, myRequest.url);
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 200);
|
||||
|
||||
var bodyAsJson = JSON.parse(response.body);
|
||||
assert.isNotNull(bodyAsJson.renderedTemplate);
|
||||
assert.isString(bodyAsJson.closeButtonText);
|
||||
assert.isString(bodyAsJson.enterDialogMessage);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,270 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
var chai = require('chai');
|
||||
var chaiSubset = require('chai-subset');
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe('Remove product variant from line item', function () {
|
||||
this.timeout(50000);
|
||||
|
||||
var variantPid1 = '701643421084M';
|
||||
var qty1 = 2;
|
||||
var variantPid2 = '701642923459M';
|
||||
var qty2 = 1;
|
||||
var variantPid3 = '029407331258M';
|
||||
var qty3 = 3;
|
||||
|
||||
var prodIdUuidMap = {};
|
||||
|
||||
var cookieJar = request.jar();
|
||||
var myRequest = {
|
||||
url: '',
|
||||
method: 'POST',
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
var cookieString;
|
||||
|
||||
before(function () {
|
||||
// ----- adding product #1:
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid1,
|
||||
quantity: qty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function () {
|
||||
cookieString = cookieJar.getCookieString(myRequest.url);
|
||||
})
|
||||
|
||||
// ----- adding product #2, a different variant of same product 1:
|
||||
.then(function () {
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid2,
|
||||
quantity: qty2
|
||||
};
|
||||
|
||||
var cookie = request.cookie(cookieString);
|
||||
cookieJar.setCookie(cookie, myRequest.url);
|
||||
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- adding product #3:
|
||||
.then(function () {
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid3,
|
||||
quantity: qty3
|
||||
};
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- select a shipping method. Need shipping method so that shipping cost, sales tax,
|
||||
// and grand total can be calculated.
|
||||
.then(function () {
|
||||
var shipMethodId = '001'; // 001 = Ground
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- Get UUID for each product line items
|
||||
.then(function (response4) {
|
||||
var bodyAsJson = JSON.parse(response4.body);
|
||||
|
||||
prodIdUuidMap[bodyAsJson.items[0].id] = bodyAsJson.items[0].UUID;
|
||||
prodIdUuidMap[bodyAsJson.items[1].id] = bodyAsJson.items[1].UUID;
|
||||
prodIdUuidMap[bodyAsJson.items[2].id] = bodyAsJson.items[2].UUID;
|
||||
});
|
||||
});
|
||||
|
||||
it(' 1>. should remove line item', function () {
|
||||
// removing product variant on line item 2
|
||||
|
||||
var variantUuid2 = prodIdUuidMap[variantPid2];
|
||||
var expectedItems = {
|
||||
'totals': {
|
||||
'subTotal': '$137.97',
|
||||
'totalShippingCost': '$7.99',
|
||||
'grandTotal': '$153.26',
|
||||
'totalTax': '$7.30'
|
||||
},
|
||||
'shipments': [
|
||||
{
|
||||
'shippingMethods': [
|
||||
{
|
||||
'ID': '001',
|
||||
'displayName': 'Ground',
|
||||
'shippingCost': '$7.99',
|
||||
'selected': true
|
||||
}
|
||||
],
|
||||
'selectedShippingMethod': '001'
|
||||
}
|
||||
],
|
||||
'items': [
|
||||
{
|
||||
'productName': '3/4 Sleeve V-Neck Top',
|
||||
'price': {
|
||||
'sales': {
|
||||
'value': 24,
|
||||
'currency': 'USD'
|
||||
}
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Icy Mint'
|
||||
},
|
||||
{
|
||||
'displayName': 'Size',
|
||||
'displayValue': 'XS'
|
||||
}
|
||||
],
|
||||
'quantity': 2
|
||||
},
|
||||
{
|
||||
'productName': 'Solid Silk Tie',
|
||||
'price': {
|
||||
'sales': {
|
||||
'value': 29.99,
|
||||
'currency': 'USD'
|
||||
},
|
||||
'list': {
|
||||
'value': 39.5,
|
||||
'currency': 'USD'
|
||||
}
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Red'
|
||||
}
|
||||
],
|
||||
'quantity': 3
|
||||
}
|
||||
]
|
||||
|
||||
};
|
||||
|
||||
myRequest.method = 'GET';
|
||||
myRequest.url = config.baseUrl + '/Cart-RemoveProductLineItem?pid=' + variantPid2 + '&uuid=' + variantUuid2;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (removedItemResponse) {
|
||||
assert.equal(removedItemResponse.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = JSON.parse(removedItemResponse.body);
|
||||
assert.containSubset(bodyAsJson.basket, expectedItems, 'Actual response dose not contain expected expectedResponse.');
|
||||
|
||||
// Verify path to image source
|
||||
var prodImageSrc1 = bodyAsJson.basket.items[0].images.small[0].url;
|
||||
var prodImageSrc2 = bodyAsJson.basket.items[1].images.small[0].url;
|
||||
assert.isTrue(prodImageSrc1.endsWith('/images/small/PG.10221714.JJ8UTXX.PZ.jpg'), 'product 1 item image: src not end with /images/small/PG.10221714.JJ8UTXX.PZ.jpg.');
|
||||
assert.isTrue(prodImageSrc2.endsWith('/images/small/PG.949432114S.REDSI.PZ.jpg'), 'product 2 item image: src not end with /images/small/PG.949432114S.REDSI.PZ.jpg.');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it(' 2>. should return error if PID and UUID does not match', function () {
|
||||
var variantUuid3 = prodIdUuidMap[variantPid3];
|
||||
|
||||
myRequest.url = config.baseUrl + '/Cart-RemoveProductLineItem?pid=' + variantPid1 + '&uuid=' + variantUuid3;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response) {
|
||||
assert.equal(response.statusCode, 500, 'Expected request to fail when PID and UUID do not match.');
|
||||
})
|
||||
.catch(function (err) {
|
||||
assert.equal(err.statusCode, 500, 'Expected statusCode to be 500 for removing product item with non-matching PID and UUID.');
|
||||
|
||||
var bodyAsJson = JSON.parse(err.response.body);
|
||||
|
||||
assert.equal(bodyAsJson.errorMessage,
|
||||
'Unable to remove item from the cart. Please try again! If the issue continues please contact customer service.',
|
||||
'Actual error message from removing product item with non-matching PID and UUID not as expected');
|
||||
});
|
||||
});
|
||||
|
||||
it(' 3>. should remove all line items', function () {
|
||||
var expectedRemoveAllResp = {
|
||||
'totals': {
|
||||
'subTotal': '$0.00',
|
||||
'grandTotal': '$0.00',
|
||||
'totalTax': '$0.00',
|
||||
'totalShippingCost': '$0.00'
|
||||
},
|
||||
'shipments': [
|
||||
{
|
||||
'selectedShippingMethod': '001',
|
||||
'shippingMethods': [
|
||||
{
|
||||
'description': 'Order received within 7-10 business days',
|
||||
'displayName': 'Ground',
|
||||
'ID': '001',
|
||||
'shippingCost': '$0.00',
|
||||
'estimatedArrivalTime': '7-10 Business Days',
|
||||
'default': true,
|
||||
'selected': true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
'numItems': 0,
|
||||
'resources': {
|
||||
'numberOfItems': '0 Items',
|
||||
'emptyCartMsg': 'Your Shopping Cart is Empty'
|
||||
}
|
||||
};
|
||||
|
||||
var variantUuid1 = prodIdUuidMap[variantPid1];
|
||||
var variantUuid3 = prodIdUuidMap[variantPid3];
|
||||
|
||||
myRequest.method = 'GET';
|
||||
myRequest.url = config.baseUrl + '/Cart-RemoveProductLineItem?pid=' + variantPid1 + '&uuid=' + variantUuid1;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function () {
|
||||
myRequest.url = config.baseUrl + '/Cart-RemoveProductLineItem?pid=' + variantPid3 + '&uuid=' + variantUuid3;
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// Handle response
|
||||
.then(function (response2) {
|
||||
assert.equal(response2.statusCode, 200, 'Expected statusCode from remove all product line item to be 200.');
|
||||
|
||||
var bodyAsJson2 = JSON.parse(response2.body);
|
||||
assert.containSubset(bodyAsJson2.basket, expectedRemoveAllResp, 'Actual response from removing all items does not contain expectedRemoveAllResp.');
|
||||
});
|
||||
});
|
||||
|
||||
it(' 4>. should return error if product does not exist in cart', function () {
|
||||
var variantPidNotExist = '701643421084Mabc';
|
||||
var variantUuidNotExist = '529f59ef63a0d238b8575c4f8fabc';
|
||||
myRequest.url = config.baseUrl + '/Cart-RemoveProductLineItem?pid=' + variantPidNotExist + '&uuid=' + variantUuidNotExist;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (response3) {
|
||||
assert.equal(response3.statusCode, 500, 'Expected request to fail when product does not exist.');
|
||||
})
|
||||
.catch(function (err) {
|
||||
assert.equal(err.statusCode, 500, 'Expected statusCode to be 500 for removing product item not in cart.');
|
||||
|
||||
var bodyAsJson = JSON.parse(err.response.body);
|
||||
|
||||
assert.equal(bodyAsJson.errorMessage,
|
||||
'Unable to remove item from the cart. Please try again! If the issue continues please contact customer service.',
|
||||
'Actual error message of removing non-existing product item not as expected');
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,239 @@
|
||||
var assert = require('chai').assert;
|
||||
var request = require('request-promise');
|
||||
var config = require('../it.config');
|
||||
var jsonHelpers = require('../helpers/jsonUtils');
|
||||
var chai = require('chai');
|
||||
var chaiSubset = require('chai-subset');
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe('Update quantity for product variant', function () {
|
||||
this.timeout(45000);
|
||||
|
||||
var variantPid1 = '701643421084M';
|
||||
var qty1 = 2;
|
||||
var variantPid2 = '701642923459M';
|
||||
var qty2 = 1;
|
||||
var variantPid3 = '029407331258M';
|
||||
var qty3 = 3;
|
||||
|
||||
var prodIdUuidMap = {};
|
||||
|
||||
var cookieJar = request.jar();
|
||||
var myRequest = {
|
||||
url: '',
|
||||
method: 'POST',
|
||||
rejectUnauthorized: false,
|
||||
resolveWithFullResponse: true,
|
||||
jar: cookieJar,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
var cookieString;
|
||||
|
||||
before(function () {
|
||||
// ----- adding product #1:
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid1,
|
||||
quantity: qty1
|
||||
};
|
||||
|
||||
return request(myRequest)
|
||||
.then(function () {
|
||||
cookieString = cookieJar.getCookieString(myRequest.url);
|
||||
})
|
||||
|
||||
// ----- adding product #2, a different variant of same product 1:
|
||||
.then(function () {
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid2,
|
||||
quantity: qty2
|
||||
};
|
||||
|
||||
var cookie = request.cookie(cookieString);
|
||||
cookieJar.setCookie(cookie, myRequest.url);
|
||||
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- adding product #3:
|
||||
.then(function () {
|
||||
myRequest.url = config.baseUrl + '/Cart-AddProduct';
|
||||
myRequest.form = {
|
||||
pid: variantPid3,
|
||||
quantity: qty3
|
||||
};
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- select a shipping method. Need to have shipping method so that shipping cost, sales tax,
|
||||
// and grand total can be calculated
|
||||
.then(function () {
|
||||
var shipMethodId = '001'; // 001 = Ground
|
||||
|
||||
myRequest.method = 'POST';
|
||||
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
|
||||
return request(myRequest);
|
||||
})
|
||||
|
||||
// ----- Get UUID for each product line items
|
||||
.then(function (response4) {
|
||||
var bodyAsJson = JSON.parse(response4.body);
|
||||
|
||||
prodIdUuidMap[bodyAsJson.items[0].id] = bodyAsJson.items[0].UUID;
|
||||
prodIdUuidMap[bodyAsJson.items[1].id] = bodyAsJson.items[1].UUID;
|
||||
prodIdUuidMap[bodyAsJson.items[2].id] = bodyAsJson.items[2].UUID;
|
||||
});
|
||||
});
|
||||
|
||||
it('1. should update line item quantity', function () {
|
||||
// updating quantity of poduct variant 2
|
||||
|
||||
var newQty2 = 5;
|
||||
var newTotal = qty1 + newQty2 + qty3;
|
||||
var expectQty1 = qty1;
|
||||
var expectQty2 = newQty2;
|
||||
var expectQty3 = qty3;
|
||||
|
||||
var variantUuid1 = prodIdUuidMap[variantPid1];
|
||||
var variantUuid2 = prodIdUuidMap[variantPid2];
|
||||
var variantUuid3 = prodIdUuidMap[variantPid3];
|
||||
|
||||
var expectedUpdateRep = {
|
||||
'action': 'Cart-UpdateQuantity',
|
||||
'totals': {
|
||||
'subTotal': '$257.97',
|
||||
'grandTotal': '$281.36',
|
||||
'totalTax': '$13.40',
|
||||
'totalShippingCost': '$9.99'
|
||||
},
|
||||
'items': [
|
||||
{
|
||||
'id': variantPid1,
|
||||
'productName': '3/4 Sleeve V-Neck Top',
|
||||
'price': {
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 24
|
||||
}
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Icy Mint'
|
||||
},
|
||||
{
|
||||
'displayName': 'Size',
|
||||
'displayValue': 'XS'
|
||||
}
|
||||
],
|
||||
'UUID': variantUuid1,
|
||||
'quantity': expectQty1
|
||||
},
|
||||
{
|
||||
'id': variantPid2,
|
||||
'productName': '3/4 Sleeve V-Neck Top',
|
||||
'price': {
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 24
|
||||
}
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Butter'
|
||||
},
|
||||
{
|
||||
'displayName': 'Size',
|
||||
'displayValue': 'M'
|
||||
}
|
||||
],
|
||||
'UUID': variantUuid2,
|
||||
'quantity': expectQty2
|
||||
},
|
||||
{
|
||||
'id': variantPid3,
|
||||
'productName': 'Solid Silk Tie',
|
||||
'price': {
|
||||
'list': {
|
||||
'currency': 'USD',
|
||||
'value': 39.5
|
||||
},
|
||||
'sales': {
|
||||
'currency': 'USD',
|
||||
'value': 29.99
|
||||
}
|
||||
},
|
||||
'variationAttributes': [
|
||||
{
|
||||
'displayName': 'Color',
|
||||
'displayValue': 'Red'
|
||||
}
|
||||
],
|
||||
'UUID': variantUuid3,
|
||||
'quantity': expectQty3
|
||||
}
|
||||
],
|
||||
'numItems': newTotal,
|
||||
'locale': 'en_US',
|
||||
'resources': {
|
||||
'numberOfItems': newTotal + ' Items',
|
||||
'emptyCartMsg': 'Your Shopping Cart is Empty'
|
||||
}
|
||||
};
|
||||
|
||||
myRequest.method = 'GET';
|
||||
myRequest.url = config.baseUrl + '/Cart-UpdateQuantity?pid=' + variantPid2 + '&uuid=' + variantUuid2 + '&quantity=' + newQty2;
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (updateRsp) {
|
||||
assert.equal(updateRsp.statusCode, 200, 'Expected statusCode to be 200.');
|
||||
|
||||
var bodyAsJson = jsonHelpers.deleteProperties(JSON.parse(updateRsp.body), ['queryString']);
|
||||
|
||||
assert.containSubset(bodyAsJson, expectedUpdateRep, 'Actual response does not contain expectedUpdateRep.');
|
||||
|
||||
// Verify path to image source
|
||||
var prodImageSrc1 = bodyAsJson.items[0].images.small[0].url;
|
||||
var prodImageSrc2 = bodyAsJson.items[1].images.small[0].url;
|
||||
var prodImageSrc3 = bodyAsJson.items[2].images.small[0].url;
|
||||
assert.isTrue(prodImageSrc1.endsWith('/images/small/PG.10221714.JJ8UTXX.PZ.jpg'), 'product 1 item image: src not end with /images/small/PG.10221714.JJ8UTXX.PZ.jpg.');
|
||||
assert.isTrue(prodImageSrc2.endsWith('/images/small/PG.10221714.JJ370XX.PZ.jpg'), 'product 2 item image: src not end with /images/small/PG.10221714.JJ370XX.PZ.jpg.');
|
||||
assert.isTrue(prodImageSrc3.endsWith('/images/small/PG.949432114S.REDSI.PZ.jpg'), 'product 3 item image: src not end with /images/small/PG.949432114S.REDSI.PZ.jpg.');
|
||||
});
|
||||
});
|
||||
|
||||
it('2. should return error if update line item quantity is 0', function () {
|
||||
var variantUuid1 = prodIdUuidMap[variantPid1];
|
||||
|
||||
myRequest.method = 'GET';
|
||||
myRequest.url = config.baseUrl + '/Cart-UpdateQuantity?pid=' + variantPid1 + '&uuid=' + variantUuid1 + '&quantity=0';
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (updateRsp) {
|
||||
assert.equal(updateRsp.statusCode, 500, 'Expected request to fail for quantity = 0.');
|
||||
})
|
||||
.catch(function (err) {
|
||||
assert.equal(err.statusCode, 500, 'Expected statusCode to be 500 for 0 quantity.');
|
||||
});
|
||||
});
|
||||
|
||||
it('3. should return error if update line item quantity is negative', function () {
|
||||
var variantUuid1 = prodIdUuidMap[variantPid1];
|
||||
|
||||
myRequest.method = 'GET';
|
||||
myRequest.url = config.baseUrl + '/Cart-UpdateQuantity?pid=' + variantPid1 + '&uuid=' + variantUuid1 + '&quantity=-1';
|
||||
|
||||
return request(myRequest)
|
||||
.then(function (updateRsp) {
|
||||
assert.equal(updateRsp.statusCode, 500, 'Expected request to fail for negative quantity.');
|
||||
})
|
||||
.catch(function (err) {
|
||||
assert.equal(err.statusCode, 500, 'Expected statusCode to be 500 for 0 quantity.');
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user