Adds SFRA 6.0

This commit is contained in:
Isaac Vallee
2021-12-21 10:57:31 -08:00
parent d04eb5dd16
commit 823c7608c3
1257 changed files with 137087 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
describe('Choice Of Bonus Products: Show Bonus Products', function () {
this.timeout(45000);
var variantPid1 = '701642842675M'; // Long Center Seam Skirt
var cookieJar = request.jar();
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var cookieString;
var showBonusProductsParams;
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);
showBonusProductsParams = bodyAsJson.newBonusDiscountLineItem.showProductsUrlRuleBased.split('?')[1];
});
});
it('should get information on choice of bonus product', function () {
myRequest.method = 'GET';
myRequest.url = config.baseUrl + '/Product-ShowBonusProducts?' + showBonusProductsParams;
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);
});
});
});

View File

@@ -0,0 +1,50 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
describe('Add bundles to cart', function () {
this.timeout(5000);
it('should be able to add a bundle to Cart', function () {
var cookieJar = request.jar();
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var bundlePid = 'womens-jewelry-bundleM';
var qty = 1;
var childProducts = [
{ pid: '013742002836M' },
{ pid: '013742002805M' },
{ pid: '013742002799M' }
];
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: bundlePid,
childProducts: childProducts,
quantity: qty
};
return request(myRequest, function (error, response) {
var bodyAsJson = JSON.parse(response.body);
var cartItems = bodyAsJson.cart.items[0];
assert.equal(response.statusCode, 200, 'Expected Cart-AddProduct bundles statusCode to be 200.');
assert.equal(cartItems.productName, 'Turquoise Jewelry Bundle');
assert.equal(cartItems.productType, 'bundle');
assert.equal(cartItems.priceTotal.price, '$113.00');
assert.equal(cartItems.bundledProductLineItems[0].id, '013742002836M');
assert.equal(cartItems.bundledProductLineItems[0].productName, 'Turquoise and Gold Bracelet');
assert.equal(cartItems.bundledProductLineItems[1].id, '013742002805M');
assert.equal(cartItems.bundledProductLineItems[1].productName, 'Turquoise and Gold Necklace');
assert.equal(cartItems.bundledProductLineItems[2].id, '013742002799M');
assert.equal(cartItems.bundledProductLineItems[2].productName, 'Turquoise and Gold Hoop Earring');
});
});
});

View File

@@ -0,0 +1,88 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
describe('Remove bundle from product line item', function () {
this.timeout(50000);
var cookieJar = request.jar();
var UUID;
var bundlePid = 'womens-jewelry-bundleM';
var qty = 1;
var childProducts = [
{ pid: '013742002836M' },
{ pid: '013742002805M' },
{ pid: '013742002799M' }
];
var myRequest = {
url: config.baseUrl + '/Cart-AddProduct',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
form: {
pid: bundlePid,
childProducts: childProducts,
quantity: qty,
options: []
},
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
before(function () {
return request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected Cart-AddProduct bundles statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
UUID = bodyAsJson.cart.items[0].UUID;
});
});
it('1. should be able to remove a bundle from product line item', function () {
myRequest.method = 'GET';
myRequest.url = config.baseUrl + '/Cart-RemoveProductLineItem?pid=' + bundlePid + '&uuid=' + UUID;
return request(myRequest)
.then(function (removedItemResponse) {
assert.equal(removedItemResponse.statusCode, 200, 'Expected removeProductLineItem call statusCode to be 200.');
var bodyAsJson = JSON.parse(removedItemResponse.body);
assert.equal(bodyAsJson.basket.resources.emptyCartMsg, 'Your Shopping Cart is Empty', 'actual response from removing bundles not are expected');
assert.equal(bodyAsJson.basket.resources.numberOfItems, '0 Items', 'should return 0 items in basket');
});
});
it('2. should return error if UUID does not match', function () {
var bogusUUID = UUID + '3';
myRequest.url = config.baseUrl + '/Cart-RemoveProductLineItem?pid=' + bundlePid + '&uuid=' + bogusUUID;
return request(myRequest)
.then(function (removedItemResponse) {
assert.equal(removedItemResponse.statusCode, 500, 'Expected removeProductLineItem request to fail when UUID is incorrect.');
})
.catch(function (error) {
assert.equal(error.statusCode, 500, 'Expected statusCode to be 500 for removing product item with bogus UUID.');
var bodyAsJson = JSON.parse(error.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 return error if bundle does not exist in Cart', function () {
var bogusBundleId = 'mens-jewelry-bundle';
myRequest.url = config.baseUrl + '/Cart-RemoveProductLineItem?pid=' + bogusBundleId + '&uuid=' + UUID;
return request(myRequest)
.then(function (removedItemResponse) {
assert.equal(removedItemResponse.statusCode, 500, 'Expected removeProductLineItem call to fail when UUID is incorrect.');
})
.catch(function (error) {
assert.equal(error.statusCode, 500, 'Expected statusCode to be 500 for removing product item with bogus pid.');
var bodyAsJson = JSON.parse(error.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');
});
});
});

View File

@@ -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);
});
});
});

View File

@@ -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);
});
});
});

View File

@@ -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);
});
});
});

View File

@@ -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);
});
});
});

View File

@@ -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);
});
});
});

View File

@@ -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);
});
});
});

View File

@@ -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);
});
});
});

View File

@@ -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');
});
});
});

View File

@@ -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.');
});
});
});

View File

@@ -0,0 +1,113 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
var chai = require('chai');
var chaiSubset = require('chai-subset');
var jsonHelpers = require('../helpers/jsonUtils');
chai.use(chaiSubset);
/**
* Test case:
* should be able to submit an order with billingForm
*/
describe('billingForm', function () {
this.timeout(5000);
describe('positive test', function () {
var cookieJar = request.jar();
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var cookieString;
var variantPid1 = '701643421084M';
var qty1 = 2;
var addProd = '/Cart-AddProduct';
// ----- Step 1 adding product to Cart
myRequest.url = config.baseUrl + addProd;
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (addToCartResponse) {
assert.equal(addToCartResponse.statusCode, 200, 'Expected add to Cart request statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
myRequest.url = config.baseUrl + '/CSRF-Generate';
var cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
// step2 : get cookies, Generate CSRF, then set cookies
return request(myRequest);
})
.then(function (csrfResponse) {
var csrfJsonResponse = JSON.parse(csrfResponse.body);
// step3 : submit billing request with token aquired in step 2
myRequest.url = config.baseUrl + '/CheckoutServices-SubmitPayment?' +
csrfJsonResponse.csrf.tokenName + '=' +
csrfJsonResponse.csrf.token;
myRequest.form = {
dwfrm_billing_shippingAddressUseAsBillingAddress: 'true',
dwfrm_billing_addressFields_firstName: 'John',
dwfrm_billing_addressFields_lastName: 'Smith',
dwfrm_billing_addressFields_address1: '10 main St',
dwfrm_billing_addressFields_address2: '',
dwfrm_billing_addressFields_country: 'us',
dwfrm_billing_addressFields_states_stateCode: 'MA',
dwfrm_billing_addressFields_city: 'burlington',
dwfrm_billing_addressFields_postalCode: '09876',
dwfrm_billing_paymentMethod: 'CREDIT_CARD',
dwfrm_billing_creditCardFields_cardType: 'Visa',
dwfrm_billing_creditCardFields_cardNumber: '4111111111111111',
dwfrm_billing_creditCardFields_expirationMonth: '2',
dwfrm_billing_creditCardFields_expirationYear: '2030.0',
dwfrm_billing_contactInfoFields_phone: '9786543213',
dwfrm_billing_creditCardFields_securityCode: '342'
};
var ExpectedResBody = {
locale: 'en_US',
address: {
firstName: { value: 'John' },
lastName: { value: 'Smith' },
address1: { value: '10 main St' },
address2: { value: null },
city: { value: 'burlington' },
stateCode: { value: 'MA' },
postalCode: { value: '09876' },
countryCode: { value: 'us' }
},
paymentMethod: { value: 'CREDIT_CARD', htmlName: 'CREDIT_CARD' },
phone: { value: '9786543213' },
error: true,
cartError: true,
fieldErrors: [],
serverErrors: [],
saveCard: false
};
return request(myRequest)
.then(function (response) {
var bodyAsJson = JSON.parse(response.body);
var strippedBody = jsonHelpers.deleteProperties(bodyAsJson, ['redirectUrl', 'action', 'queryString']);
assert.equal(response.statusCode, 200, 'Expected CheckoutServices-SubmitPayment statusCode to be 200.');
assert.containSubset(strippedBody.address, ExpectedResBody.address, 'Expecting actual response address to be equal match expected response address');
assert.isFalse(strippedBody.error);
assert.equal(strippedBody.paymentMethod.value, ExpectedResBody.paymentMethod.value);
assert.equal(strippedBody.phone.value, ExpectedResBody.phone.value);
});
});
});
});

View File

@@ -0,0 +1,777 @@
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);
/**
* Test cases :
* 1. ProductSurchargeCost : Add Jewelery to cart with MA should show surcharge cost
* 2. When shipping to AK state, should return 2 applicableShipping methods only
* 3. When shipping to MA state, should return 4 applicableShipping methods
* 3. When Cart has over $100 product, shipping cost should be more for the same shipping method as #3 case
* 4. When State 'State' = 'AA' and 'AE' and 'AP' should output UPS as a shipping method
*/
describe('Select different State in Shipping Form', function () {
this.timeout(5000);
describe('productSurchargeCost with below $100 order', function () {
var cookieJar = request.jar();
var cookie;
before(function () {
var qty1 = 1;
var variantPid1 = '013742000443M';
var cookieString;
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
})
.then(function () {
cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
});
});
it('should add surcharge to the Ground Shipping cost for jewelery', function () {
var ExpectedResBody = {
'order': {
'totals': {
'subTotal': '$38.00',
'grandTotal': '$56.69',
'totalTax': '$2.70',
'totalShippingCost': '$15.99',
'orderLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'shippingLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'discounts': [],
'discountsHtml': '\n'
},
'shipping': [
{
'applicableShippingMethods': [
{
'description': 'Order received within 7-10 business days',
'displayName': 'Ground',
'ID': '001',
'shippingCost': '$5.99',
'estimatedArrivalTime': '7-10 Business Days'
},
{
'description': 'Order received in 2 business days',
'displayName': '2-Day Express',
'ID': '002',
'shippingCost': '$9.99',
'estimatedArrivalTime': '2 Business Days'
},
{
'description': 'Order received the next business day',
'displayName': 'Overnight',
'ID': '003',
'shippingCost': '$15.99',
'estimatedArrivalTime': 'Next Day'
}
],
'shippingAddress': {
'ID': null,
'postalCode': '09876',
'stateCode': 'MA',
'firstName': null,
'lastName': null,
'address1': null,
'address2': null,
'city': null,
'phone': null
},
'selectedShippingMethod': {
'ID': '001',
'displayName': 'Ground',
'description': 'Order received within 7-10 business days',
'estimatedArrivalTime': '7-10 Business Days',
'shippingCost': '$5.99'
}
}
]
}
};
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar
};
myRequest.url = config.baseUrl + '/CheckoutShippingServices-UpdateShippingMethodsList';
myRequest.form = {
'stateCode': 'MA',
'postalCode': '09876'
};
return request(myRequest)
// Handle response from request
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['selected', 'default', 'countryCode', 'addressId', 'jobTitle', 'postBox', 'salutation', 'secondName', 'companyName', 'suffix', 'suite', 'title']);
assert.containSubset(bodyAsJson.order.totals, ExpectedResBody.order.totals, 'Actual response.totals not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].applicableShippingMethods, ExpectedResBody.order.shipping[0].applicableShippingMethods, 'applicableShippingMethods not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].shippingAddress, ExpectedResBody.order.shipping[0].shippingAddress, 'shippingAddress is not as expected');
assert.containSubset(actualRespBodyStripped.order.shipping[0].selectedShippingMethod, ExpectedResBody.order.shipping[0].selectedShippingMethod, 'selectedShippingMethod is not as expected');
});
});
});
describe('productSurchargeCost with over $100 order', function () {
var cookieJar = request.jar();
var cookie;
before(function () {
var qty1 = 3;
var variantPid1 = '013742000443M';
var cookieString;
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
})
.then(function () {
cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
});
});
it('should add surcharge to the Ground Shipping cost for each jewelery item', function () {
var ExpectedResBody = {
'order': {
'totals': {
'subTotal': '$114.00',
'grandTotal': '$159.59',
'totalTax': '$7.60',
'totalShippingCost': '$37.99',
'orderLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'shippingLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'discounts': [],
'discountsHtml': '\n'
},
'shipping': [
{
'applicableShippingMethods': [
{
'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'
}
],
'shippingAddress': {
'ID': null,
'postalCode': '09876',
'stateCode': 'MA',
'firstName': null,
'lastName': null,
'address1': null,
'address2': null,
'city': null,
'phone': null
},
'selectedShippingMethod': {
'ID': '001',
'displayName': 'Ground',
'description': 'Order received within 7-10 business days',
'estimatedArrivalTime': '7-10 Business Days',
'shippingCost': '$7.99'
}
}
]
}
};
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/CheckoutShippingServices-UpdateShippingMethodsList';
myRequest.form = {
'stateCode': 'MA',
'postalCode': '09876'
};
return request(myRequest)
// Handle response from request
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['selected', 'default', 'countryCode', 'addressId', 'jobTitle', 'postBox', 'salutation', 'secondName', 'companyName', 'suffix', 'suite', 'title']);
assert.containSubset(bodyAsJson.order.totals, ExpectedResBody.order.totals, 'Actual response.totals not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].applicableShippingMethods, ExpectedResBody.order.shipping[0].applicableShippingMethods, 'applicableShippingMethods not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].shippingAddress, ExpectedResBody.order.shipping[0].shippingAddress, 'shippingAddress is not as expected');
assert.containSubset(actualRespBodyStripped.order.shipping[0].selectedShippingMethod, ExpectedResBody.order.shipping[0].selectedShippingMethod, 'selectedShippingMethod is not as expected');
});
});
});
describe('select state=AK in Shipping Form', function () {
var cookieJar = request.jar();
var cookie;
before(function () {
var qty1 = 1;
var variantPid1 = '708141677371M';
var cookieString;
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
})
.then(function () {
cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
});
});
it('should return 1 applicableShippingMethods for AK state', function () {
var ExpectedResBody = {
'order': {
'totals': {
'subTotal': '$49.99',
'grandTotal': '$70.33',
'totalTax': '$3.35',
'totalShippingCost': '$16.99',
'orderLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'shippingLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'discounts': [],
'discountsHtml': '\n'
},
'shipping': [
{
'applicableShippingMethods': [
{
'description': 'Orders shipped outside continental US received in 2-3 business days',
'displayName': 'Express',
'ID': '012',
'shippingCost': '$16.99',
'estimatedArrivalTime': '2-3 Business Days'
}
],
'shippingAddress': {
'ID': null,
'postalCode': '09876',
'stateCode': 'AK',
'firstName': null,
'lastName': null,
'address1': null,
'address2': null,
'city': null,
'phone': null
},
'selectedShippingMethod': {
'ID': '012',
'displayName': 'Express',
'description': 'Orders shipped outside continental US received in 2-3 business days',
'estimatedArrivalTime': '2-3 Business Days',
'shippingCost': '$16.99'
}
}
]
}
};
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar
};
myRequest.url = config.baseUrl + '/CheckoutShippingServices-UpdateShippingMethodsList';
myRequest.form = {
'stateCode': 'AK',
'postalCode': '09876'
};
return request(myRequest)
// Handle response from request
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['selected', 'default', 'countryCode', 'addressId', 'jobTitle', 'postBox', 'salutation', 'secondName', 'companyName', 'suffix', 'suite', 'title']);
assert.containSubset(bodyAsJson.order.totals, ExpectedResBody.order.totals, 'Actual response.totals not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].applicableShippingMethods, ExpectedResBody.order.shipping[0].applicableShippingMethods, 'applicableShippingMethods not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].shippingAddress, ExpectedResBody.order.shipping[0].shippingAddress, 'shippingAddress is not as expected');
assert.containSubset(actualRespBodyStripped.order.shipping[0].selectedShippingMethod, ExpectedResBody.order.shipping[0].selectedShippingMethod, 'selectedShippingMethod is not as expected');
});
});
});
describe('select state=MA in Shipping Form', function () {
var cookieJar = request.jar();
var cookie;
before(function () {
var qty1 = 1;
var variantPid1 = '708141677371M';
var cookieString;
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
})
.then(function () {
cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
});
});
it('should return 3 applicableShippingMethods for MA state', function () {
var ExpectedResBody = {
'order': {
'totals': {
'subTotal': '$49.99',
'grandTotal': '$58.78',
'totalTax': '$2.80',
'totalShippingCost': '$5.99',
'orderLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'shippingLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'discounts': [],
'discountsHtml': '\n'
},
'shipping': [
{
'applicableShippingMethods': [
{
'description': 'Order received within 7-10 business days',
'displayName': 'Ground',
'ID': '001',
'shippingCost': '$5.99',
'estimatedArrivalTime': '7-10 Business Days'
},
{
'description': 'Order received in 2 business days',
'displayName': '2-Day Express',
'ID': '002',
'shippingCost': '$9.99',
'estimatedArrivalTime': '2 Business Days'
},
{
'description': 'Order received the next business day',
'displayName': 'Overnight',
'ID': '003',
'shippingCost': '$15.99',
'estimatedArrivalTime': 'Next Day'
}
],
'shippingAddress': {
'ID': null,
'postalCode': '09876',
'stateCode': 'MA',
'firstName': null,
'lastName': null,
'address1': null,
'address2': null,
'city': null,
'phone': null
},
'selectedShippingMethod': {
'ID': '001',
'displayName': 'Ground',
'description': 'Order received within 7-10 business days',
'estimatedArrivalTime': '7-10 Business Days',
'shippingCost': '$5.99'
}
}
]
}
};
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/CheckoutShippingServices-UpdateShippingMethodsList';
myRequest.form = {
'stateCode': 'MA',
'postalCode': '09876'
};
return request(myRequest)
// Handle response from request
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
// var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['selected', 'default', 'countryCode', 'ID']);
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['selected', 'default', 'countryCode', 'addressId', 'jobTitle', 'postBox', 'salutation', 'secondName', 'companyName', 'suffix', 'suite', 'title']);
assert.containSubset(bodyAsJson.order.totals, ExpectedResBody.order.totals, 'Actual response.totals not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].applicableShippingMethods, ExpectedResBody.order.shipping[0].applicableShippingMethods, 'applicableShippingMethods not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].shippingAddress, ExpectedResBody.order.shipping[0].shippingAddress, 'shippingAddress is not as expected');
assert.containSubset(actualRespBodyStripped.order.shipping[0].selectedShippingMethod, ExpectedResBody.order.shipping[0].selectedShippingMethod, 'selectedShippingMethod is not as expected');
});
});
});
describe('select State=MA with more than $100 order in Shipping Form', function () {
var cookieJar = request.jar();
var cookie;
before(function () {
var qty1 = 3;
var variantPid1 = '708141677371M';
var cookieString;
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
})
.then(function () {
cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
});
});
it('shipping cost should be increased for State=MA', function () {
var ExpectedResBody = {
'order': {
'totals': {
'subTotal': '$149.97',
'grandTotal': '$165.86',
'totalTax': '$7.90',
'totalShippingCost': '$7.99',
'orderLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'shippingLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'discounts': [],
'discountsHtml': '\n'
},
'shipping': [
{
'applicableShippingMethods': [
{
'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'
}
],
'shippingAddress': {
'ID': null,
'postalCode': '09876',
'stateCode': 'MA',
'firstName': null,
'lastName': null,
'address1': null,
'address2': null,
'city': null,
'phone': null
},
'selectedShippingMethod': {
'ID': '001',
'displayName': 'Ground',
'description': 'Order received within 7-10 business days',
'estimatedArrivalTime': '7-10 Business Days',
'shippingCost': '$7.99'
}
}
]
}
};
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/CheckoutShippingServices-UpdateShippingMethodsList';
myRequest.form = {
'stateCode': 'MA',
'postalCode': '09876'
};
return request(myRequest)
// Handle response from request
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['selected', 'default', 'countryCode', 'addressId', 'jobTitle', 'postBox', 'salutation', 'secondName', 'companyName', 'suffix', 'suite', 'title']);
assert.containSubset(bodyAsJson.order.totals, ExpectedResBody.order.totals, 'Actual response.totals not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].applicableShippingMethods, ExpectedResBody.order.shipping[0].applicableShippingMethods, 'applicableShippingMethods not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].shippingAddress, ExpectedResBody.order.shipping[0].shippingAddress, 'shippingAddress is not as expected');
assert.containSubset(actualRespBodyStripped.order.shipping[0].selectedShippingMethod, ExpectedResBody.order.shipping[0].selectedShippingMethod, 'selectedShippingMethod is not as expected');
});
});
});
describe('UPS as applicable shipping methods', function () {
var cookieJar = request.jar();
var cookie;
before(function () {
var qty1 = 1;
var variantPid1 = '708141677371M';
var cookieString;
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
})
.then(function () {
cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
});
});
it('should include UPS as an applicable shipping methods for AP state', function () {
var ExpectedResBody = {
'order': {
'totals': {
'subTotal': '$49.99',
'grandTotal': '$58.78',
'totalTax': '$2.80',
'totalShippingCost': '$5.99',
'orderLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'shippingLevelDiscountTotal': {
'formatted': '$0.00',
'value': 0
},
'discounts': [],
'discountsHtml': '\n'
},
'shipping': [
{
'applicableShippingMethods': [
{
'description': 'Order shipped by USPS received within 7-10 business days',
'displayName': 'USPS',
'ID': '021',
'shippingCost': '$5.99',
'estimatedArrivalTime': '7-10 Business Days'
}
],
'shippingAddress': {
'ID': null,
'postalCode': '09876',
'stateCode': 'AP',
'firstName': null,
'lastName': null,
'address1': null,
'address2': null,
'city': null,
'phone': null
},
'selectedShippingMethod': {
'ID': '021',
'displayName': 'USPS',
'description': 'Order shipped by USPS received within 7-10 business days',
'estimatedArrivalTime': '7-10 Business Days',
'shippingCost': '$5.99'
}
}
]
}
};
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/CheckoutShippingServices-UpdateShippingMethodsList';
myRequest.form = {
'stateCode': 'AP',
'postalCode': '09876'
};
return request(myRequest)
// Handle response from request
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['selected', 'default', 'countryCode', 'addressId', 'jobTitle', 'postBox', 'salutation', 'secondName', 'companyName', 'suffix', 'suite', 'title']);
assert.containSubset(bodyAsJson.order.totals, ExpectedResBody.order.totals, 'Actual response.totals not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].applicableShippingMethods, ExpectedResBody.order.shipping[0].applicableShippingMethods, 'applicableShippingMethods not as expected.');
assert.containSubset(actualRespBodyStripped.order.shipping[0].shippingAddress, ExpectedResBody.order.shipping[0].shippingAddress, 'shippingAddress is not as expected');
assert.containSubset(actualRespBodyStripped.order.shipping[0].selectedShippingMethod, ExpectedResBody.order.shipping[0].selectedShippingMethod, 'selectedShippingMethod is not as expected');
});
});
});
});

View File

@@ -0,0 +1,60 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
describe('ContactUs-Subscribe', function () {
this.timeout(25000);
var cookieJar = request.jar();
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/ContactUs-Subscribe';
it('should successfully subscribe to contact us with valid email', function () {
myRequest.form = {
contactFirstName: 'Jane',
contactLastName: 'Smith',
contactEmail: 'JaneSmith@abc.com',
contactTopic: 'OS',
contactComment: 'Where is my order?'
};
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected add coupon request statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.isTrue(bodyAsJson.success);
assert.equal(bodyAsJson.msg, 'Subscribe to contact us success');
});
});
it('should error on subscribe to contact us with invalid email', function () {
myRequest.form = {
contactFirstName: 'Jane',
contactLastName: 'Smith',
contactEmail: 'JaneSmith@abc',
contactTopic: 'OS',
contactComment: 'Where is my order?'
};
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected add coupon request statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.isTrue(bodyAsJson.error);
assert.equal(bodyAsJson.msg, 'Please provide a valid email Id');
});
});
});

View File

@@ -0,0 +1,76 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
describe('Shipping Level Coupon - add coupon', function () {
this.timeout(25000);
var variantId = '740357377119M';
var quantity = 5;
var couponCode = 'shipping';
var cookieJar = request.jar();
var cookieString;
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantId,
quantity: quantity
};
before(function () {
// adding 5 products to Cart
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected add to Cart request statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
})
// select a shipping method in order to get cart content
.then(function () {
var shipMethodId = '001'; // 001 = Ground
myRequest.method = 'POST';
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
var cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
return request(myRequest);
})
// get CSRF token
.then(function () {
myRequest.method = 'POST';
myRequest.url = config.baseUrl + '/CSRF-Generate';
var cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
return request(myRequest)
.then(function (csrfResponse) {
var csrfJsonResponse = JSON.parse(csrfResponse.body);
myRequest.method = 'GET';
myRequest.url = config.baseUrl + '/Cart-AddCoupon?couponCode=' +
couponCode + '&' + csrfJsonResponse.csrf.tokenName + '=' +
csrfJsonResponse.csrf.token;
});
});
});
it('should return discounted total for shipping cost', function () {
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected add coupon request statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.equal(bodyAsJson.totals.shippingLevelDiscountTotal.value, 8, 'shippingLevelDiscountTotal.value should be 8');
assert.equal(bodyAsJson.totals.shippingLevelDiscountTotal.formatted, '$8.00', 'shippingLevelDiscountTotal.formatted should be $8.00');
assert.equal(bodyAsJson.totals.discounts[0].type, 'coupon', 'actual totals discounts type should be coupon');
assert.isTrue(bodyAsJson.totals.discounts[0].applied, 'actual totals discounts applied should be true');
assert.include(bodyAsJson.totals.discountsHtml, 'Spend 500 and receive 50% off shipping', 'actual promotion call out message is correct');
});
});
});

View File

@@ -0,0 +1,83 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
describe('Shipping Level Coupon - remove coupon', function () {
this.timeout(25000);
var variantId = '740357377119M';
var quantity = 5;
var couponCode = 'shipping';
var cookieJar = request.jar();
var cookieString;
var UUID;
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantId,
quantity: quantity
};
before(function () {
// ----- adding 5 products to Cart
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected add to Cart request statusCode to be 200.');
cookieString = cookieJar.getCookieString(myRequest.url);
})
// ----- select a shipping method in order to get cart content
.then(function () {
var shipMethodId = '001'; // 001 = Ground
myRequest.method = 'POST';
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod?methodID=' + shipMethodId;
var cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
return request(myRequest);
})
.then(function () {
myRequest.method = 'POST';
myRequest.url = config.baseUrl + '/CSRF-Generate';
var cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
return request(myRequest);
})
// ----- apply shipping level coupon
.then(function (csrfResponse) {
var csrfJsonResponse = JSON.parse(csrfResponse.body);
myRequest.method = 'GET';
myRequest.url = config.baseUrl + '/Cart-AddCoupon?couponCode=' + couponCode +
'&' + csrfJsonResponse.csrf.tokenName + '=' + csrfJsonResponse.csrf.token;
return request(myRequest);
})
// ----- Get UUID information
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected apply shipping level coupon request statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
UUID = bodyAsJson.totals.discounts[0].UUID;
});
});
it('should return non-discounted total after removal of shipping coupon', function () {
myRequest.url = config.baseUrl + '/Cart-RemoveCouponLineItem?code=' + couponCode + '&uuid=' + UUID;
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'Expected remove shipping level coupon request statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.equal(bodyAsJson.totals.shippingLevelDiscountTotal.value, 0, 'shippingLevelDiscountTotal value is 0');
assert.equal(bodyAsJson.totals.grandTotal, '$594.29', 'grandTotal is $594.29');
assert.equal(bodyAsJson.totals.totalTax, '$28.30', 'totalTax is $528.30');
});
});
});

View File

@@ -0,0 +1,55 @@
var _ = require('lodash');
function jsonUtils() {}
/**
* Duplicate the source object and delete specified key(s) from the new object.
*
* @param {JSON} srcObj
* @param {String[]} keys
* @returns {Object} - A new object with key(s) removed
*/
jsonUtils.deleteProperties = function (srcObj, keys) {
var newObj = _.cloneDeep(srcObj);
jsonUtils.removeProps(newObj, keys);
return newObj;
};
/**
* Delete specified key(s) from the object.
*
* @param {JSON} obj
* @param {String[]} keys
*/
jsonUtils.removeProps = function (obj, keys) {
if (obj instanceof Array && obj[0] !== null) {
obj.forEach(function (item) {
jsonUtils.removeProps(item, keys);
});
} else if (typeof obj === 'object') {
Object.getOwnPropertyNames(obj).forEach(function (key) {
if (keys.indexOf(key) !== -1) {
delete obj[key]; // eslint-disable-line no-param-reassign
} else if (obj[key] != null) {
jsonUtils.removeProps(obj[key], keys);
}
});
}
};
/**
* Return pretty-print JSON string
*
* @param {JSON} obj
*/
jsonUtils.toPrettyString = function (obj) {
var prettyString;
if (obj) {
prettyString = JSON.stringify(obj, null, '\t');
}
return prettyString;
};
module.exports = jsonUtils;

View File

@@ -0,0 +1,18 @@
function urlUtils() {}
/**
* Strips auth basic authentication parameters - if set - and returns the url
*
* @param {String} url - Url string
* @returns {String}
*/
urlUtils.stripBasicAuth = function (url) {
var sfIndex = url.indexOf('storefront');
var atIndex = url.indexOf('@');
if (sfIndex > -1 && atIndex > -1) {
return url.slice(0, sfIndex) + url.slice(atIndex + 1, url.length);
}
return url;
};
module.exports = urlUtils;

View File

@@ -0,0 +1,13 @@
'use strict';
var getConfig = require('@tridnguyen/config');
var opts = Object.assign({}, getConfig({
baseUrl: 'https://' + global.baseUrl + '/on/demandware.store/Sites-RefArch-Site/en_US',
suite: '*',
reporter: 'spec',
timeout: 60000,
locale: 'x_default'
}, './config.json'));
module.exports = opts;

View File

@@ -0,0 +1,38 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
describe('Add one Simple Product with Options to Cart', function () {
this.timeout(5000);
it('should add a simple product with options to Cart', function () {
var pid = 'mitsubishi-wd-73736M';
var quantity = '1';
var options = [{ 'optionId': 'tvWarranty', 'selectedValueId': '001' }];
var optionsString = JSON.stringify(options);
var myRequest = {
url: config.baseUrl + '/Cart-AddProduct',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
form: {
pid: pid,
childProducts: [],
quantity: quantity,
options: optionsString
},
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
return request(myRequest, function (error, response) {
var bodyAsJson = JSON.parse(response.body);
assert.equal(response.statusCode, 200, 'Cart-AddProduct call should return statusCode of 200');
assert.equal(bodyAsJson.message, 'Product added to cart');
assert.equal(bodyAsJson.cart.items[0].options[0].displayName, 'Extended Warranty: 1 Year Warranty');
assert.equal(bodyAsJson.cart.totals.subTotal, '$2,299.98');
});
});
});

View File

@@ -0,0 +1,114 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
describe('Edit Product Options for an Option Product in Cart', function () {
this.timeout(45000);
var productpid = 'mitsubishi-wd-73736M';
var quantity = 1;
var options = [{ 'optionId': 'tvWarranty', 'selectedValueId': '001' }];
var optionsString = JSON.stringify(options);
var productuuid;
var cookieString;
var cookieJar = request.jar();
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
before(function () {
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: productpid,
quantity: quantity,
options: optionsString
};
return request(myRequest).then(function (response) {
assert.equal(response.statusCode, 200);
cookieString = cookieJar.getCookieString(myRequest.url);
var bodyAsJson = JSON.parse(response.body);
productuuid = bodyAsJson.cart.items[0].UUID;
});
});
it('should get information including options on the specified product', function () {
myRequest.method = 'GET';
myRequest.url = config.baseUrl + '/Cart-GetProduct?uuid=' + productuuid;
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);
assert.equal(bodyAsJson.product.options[0].selectedValueId, '001');
assert.equal(bodyAsJson.selectedOptionValueId, '001');
assert.equal(bodyAsJson.selectedQuantity, 1);
});
});
it('should edit options of the specified product', function () {
var newSelectedOptionValueId = '003';
var expectedResp = {
'action': 'Cart-EditProductLineItem',
'cartModel': {
'items': [
{
'id': productpid,
'productName': 'Mitsubishi 735 Series 73" DLP® High Definition Television',
'productType': 'optionProduct',
'price': {
'sales': {
'value': 2379.98,
'currency': 'USD',
'formatted': '$2,379.98',
'decimalPrice': '2379.98'
},
'list': null
},
'quantity': quantity,
'options': [
{
'displayName': 'Extended Warranty: 5 Year Warranty',
'optionId': 'tvWarranty',
'selectedValueId': newSelectedOptionValueId
}
]
}
]
},
'newProductId': productpid
};
myRequest.method = 'POST';
myRequest.url = config.baseUrl + '/Cart-EditProductLineItem';
myRequest.form = {
uuid: productuuid,
pid: productpid,
quantity: quantity,
selectedOptionValueId: newSelectedOptionValueId
};
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.containSubset(bodyAsJson.cartModel, expectedResp.cartModel);
});
});
});

View File

@@ -0,0 +1,138 @@
var assert = require('chai').assert;
var request = require('request');
var config = require('../it.config');
var jsonHelpers = require('../helpers/jsonUtils');
var urlHelpers = require('../helpers/urlUtils');
describe('ProductVariation - Get product variation with only main product ID', function () {
this.timeout(5000);
var mainPid = '25604455M';
var myGetRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
it('should returns main product details and variant attributes', function (done) {
var resourcePath = config.baseUrl + '/Product-Variation?';
myGetRequest.url = resourcePath + 'pid=' + mainPid;
request(myGetRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
// Remove basic auth - to use intergration tests on test instances
var bodyAsJson = JSON.parse(response.body);
// strip out all "url" properties from the actual response
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['url', 'resetUrl', 'selectedProductUrl', 'raw', 'absURL']);
// Verify product
assert.equal(actualRespBodyStripped.product.productName, 'No-Iron Textured Dress Shirt');
assert.equal(actualRespBodyStripped.product.productType, 'master');
assert.equal(actualRespBodyStripped.product.id, mainPid);
assert.equal(actualRespBodyStripped.product.longDescription, 'This cotton dress shirt is available in white or blue. Both colors are a wardrobe necessity.');
// Verify product price
assert.equal(actualRespBodyStripped.product.price.sales.value, '49.99');
assert.equal(actualRespBodyStripped.product.price.sales.currency, 'USD');
assert.equal(actualRespBodyStripped.product.price.sales.formatted, '$49.99');
assert.equal(actualRespBodyStripped.product.price.list.value, '69.5');
assert.equal(actualRespBodyStripped.product.price.list.currency, 'USD');
assert.equal(actualRespBodyStripped.product.price.list.formatted, '$69.50');
// Verifying the following for product.variationAttributes of color swatch color= SLABLFB
var attrColorBlue = bodyAsJson.product.variationAttributes[0].values[0];
// Verify color swatch
assert.equal(attrColorBlue.value, 'SLABLFB');
assert.isTrue(bodyAsJson.product.variationAttributes[0].swatchable);
// Clean the resourcePath if basic auth is set
var resourcePathCleaned = urlHelpers.stripBasicAuth(resourcePath);
// Verify URL
assert.equal(attrColorBlue.url, resourcePathCleaned + 'dwvar_25604455M_color=SLABLFB&pid=25604455M&quantity=1', 'Actual color attribute = SLABLFB: url not as expected.');
// Verify Image
var colorBlueImages = attrColorBlue.images;
assert.isTrue(colorBlueImages.swatch[0].url.endsWith('SLABLFB.CP.jpg'), 'color SLABLFB image swatch[0]: url not ended with SLABLFB.CP.jpg.');
// Verify rating
assert.equal(bodyAsJson.product.rating, '3.3');
// Verify description
assert.equal(bodyAsJson.product.longDescription, 'This cotton dress shirt is available in white or blue. Both colors are a wardrobe necessity.');
assert.equal(bodyAsJson.product.shortDescription, 'This cotton dress shirt is available in white or blue. Both colors are a wardrobe necessity.');
// Verify availability
assert.equal(bodyAsJson.product.availability.messages, 'In Stock');
// Verifying the following for product.variationAttributes of color swatch color= WHITEFB
var attrColorWhite = bodyAsJson.product.variationAttributes[0].values[1];
// Verify color swatch
assert.equal(attrColorBlue.value, 'SLABLFB');
assert.equal(attrColorWhite.url, resourcePathCleaned + 'dwvar_25604455M_color=WHITEFB&pid=25604455M&quantity=1', 'Actual color attribute = WHITEFB: url not as expected.');
// Verify URL
var colorWhiteImages = attrColorWhite.images;
assert.isTrue(colorWhiteImages.swatch[0].url.endsWith('WHITEFB.CP.jpg'), 'color WHITEFB image swatch[0].url not ended with WHITEFB.CP.jpg.');
// Verify URL for product.variationAttributes of Size of id = 145
assert.equal(bodyAsJson.product.variationAttributes[1].values[0].url, resourcePathCleaned + 'dwvar_25604455M_size=145&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[0].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 150
assert.equal(bodyAsJson.product.variationAttributes[1].values[1].url, resourcePathCleaned + 'dwvar_25604455M_size=150&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[1].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 155
assert.equal(bodyAsJson.product.variationAttributes[1].values[2].url, resourcePathCleaned + 'dwvar_25604455M_size=155&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[2].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 160
assert.equal(bodyAsJson.product.variationAttributes[1].values[3].url, resourcePathCleaned + 'dwvar_25604455M_size=160&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[3].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 165
assert.equal(bodyAsJson.product.variationAttributes[1].values[4].url, resourcePathCleaned + 'dwvar_25604455M_size=165&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[4].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 170
assert.equal(bodyAsJson.product.variationAttributes[1].values[5].url, resourcePathCleaned + 'dwvar_25604455M_size=170&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[5].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 175
assert.equal(bodyAsJson.product.variationAttributes[1].values[6].url, resourcePathCleaned + 'dwvar_25604455M_size=175&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[6].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 180
assert.equal(bodyAsJson.product.variationAttributes[1].values[7].url, resourcePathCleaned + 'dwvar_25604455M_size=180&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[7].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 185
assert.equal(bodyAsJson.product.variationAttributes[1].values[8].url, resourcePathCleaned + 'dwvar_25604455M_size=185&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[8].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 190
assert.equal(bodyAsJson.product.variationAttributes[1].values[9].url, resourcePathCleaned + 'dwvar_25604455M_size=190&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[9].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 200
assert.equal(bodyAsJson.product.variationAttributes[1].values[10].url, resourcePathCleaned + 'dwvar_25604455M_size=200&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[10].url not as expected.');
// Verify URL for product.variationAttributes of Size of id = 220
assert.equal(bodyAsJson.product.variationAttributes[1].values[11].url, resourcePathCleaned + 'dwvar_25604455M_size=220&pid=25604455M&quantity=1', 'Actual product.variationAttributes[1].values[11].url not as expected.');
// Verify URL for product.variationAttributes of width = A (32/33)
assert.equal(bodyAsJson.product.variationAttributes[2].values[0].url, resourcePathCleaned + 'dwvar_25604455M_width=A&pid=25604455M&quantity=1', 'Actual product.variationAttributes[2].values[0].url not as expected.');
// Verify URL for product.variationAttributes of width = B (34/35)
assert.equal(bodyAsJson.product.variationAttributes[2].values[1].url, resourcePathCleaned + 'dwvar_25604455M_width=B&pid=25604455M&quantity=1', 'Actual product.variationAttributes[2].values[1].url not as expected.');
// Verify URL for product.variationAttributes of images
var prodImages = bodyAsJson.product.images;
assert.isTrue(prodImages.large[0].url.endsWith('WHITEFB.PZ.jpg'), 'product image large[0]: url not ended with WHITEFB.PZ.jpg');
assert.isTrue(prodImages.large[1].url.endsWith('WHITEFB.BZ.jpg'), 'product image large[1]: url not ended with WHITEFB.BZ.jpg');
assert.isTrue(prodImages.small[0].url.endsWith('WHITEFB.PZ.jpg'), 'product image small[0]: url not ended with WHITEFB.PZ.jpg');
assert.isTrue(prodImages.small[1].url.endsWith('WHITEFB.BZ.jpg'), 'product image small[1]: url not ended with WHITEFB.BZ.jpg');
done();
});
});
});

View File

@@ -0,0 +1,194 @@
var assert = require('chai').assert;
var request = require('request');
var _ = require('lodash');
var config = require('../it.config');
var jsonHelpers = require('../helpers/jsonUtils');
var urlHelpers = require('../helpers/urlUtils');
describe('ProductVariation - Get product variation with main product ID and all required variation attributes', function () {
this.timeout(5000);
var mainPid = '25604455M';
var paramColorWhite = 'dwvar_25604455M_color=WHITEFB';
var paramSize160 = 'dwvar_25604455M_size=160';
var paramWidth3233 = 'dwvar_25604455M_width=A';
var expectedVariant = '708141676220M';
var myGetRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
it('should returns variant for the selected attributes', function (done) {
var urlEndPoint = config.baseUrl + '/Product-Variation';
var urlWithMpid = urlEndPoint + '?pid=' + mainPid;
myGetRequest.url = urlWithMpid + '&' + paramColorWhite + '&' + paramSize160 + '&' + paramWidth3233;
request(myGetRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
// strip out all "url" properties from the actual response
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['url', 'resetUrl', 'selectedProductUrl', 'raw', 'absURL']);
var attrColor = actualRespBodyStripped.product.variationAttributes[0].values[0];
// Verify color swatch
assert.equal(attrColor.value, 'SLABLFB');
assert.isTrue(actualRespBodyStripped.product.variationAttributes[0].swatchable);
// Verify rating
assert.equal(actualRespBodyStripped.product.rating, '4.8');
// Verify description
assert.equal(actualRespBodyStripped.product.longDescription, 'This cotton dress shirt is available in white or blue. Both colors are a wardrobe necessity.');
assert.equal(actualRespBodyStripped.product.shortDescription, 'This cotton dress shirt is available in white or blue. Both colors are a wardrobe necessity.');
// Verify product
assert.equal(actualRespBodyStripped.product.productName, 'No-Iron Textured Dress Shirt');
assert.equal(actualRespBodyStripped.product.productType, 'variant');
assert.equal(actualRespBodyStripped.product.id, expectedVariant);
assert.equal(actualRespBodyStripped.product.longDescription, 'This cotton dress shirt is available in white or blue. Both colors are a wardrobe necessity.');
// Verify product price
assert.equal(actualRespBodyStripped.product.price.sales.value, '49.99');
assert.equal(actualRespBodyStripped.product.price.sales.currency, 'USD');
assert.equal(actualRespBodyStripped.product.price.sales.formatted, '$49.99');
assert.equal(actualRespBodyStripped.product.price.list.value, '69.5');
assert.equal(actualRespBodyStripped.product.price.list.currency, 'USD');
assert.equal(actualRespBodyStripped.product.price.list.formatted, '$69.50');
// Verify URL for product.variationAttributes of color = SLABLFB
var attrColorBlue = bodyAsJson.product.variationAttributes[0].values[0];
var urlSplit1 = attrColorBlue.url.split('?');
var urlParams = urlSplit1[1].split('&');
var urlEndPointCleaned = urlHelpers.stripBasicAuth(urlEndPoint);
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Color with id = SLABLFB: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Color with id = SLABLFB: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Color with id = SLABLFB: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Color with id = SLABLFB: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=SLABLFB'), 'product.variationAttributes Color with id = SLABLFB: url not include parameter dwvar_25604455M_color=SLABLFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Color with id = SLABLFB: url not include parameter dwvar_25604455M_size=160');
var colorBlueImages = attrColorBlue.images;
assert.isTrue(colorBlueImages.swatch[0].url.endsWith('SLABLFB.CP.jpg'), 'color SLABLFB image swatch[0]: url not ended with SLABLFB.CP.jpg.');
// Verify URL for product.variationAttributes of color = WHITEFB
var attrColorWhite = bodyAsJson.product.variationAttributes[0].values[1];
urlSplit1 = attrColorWhite.url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Color with id = WHITEFB: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Color with id = WHITEFB: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Color with id = WHITEFB: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Color with id = WHITEFB: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color='), 'product.variationAttributes Color with id = WHITEFB: url not include parameter dwvar_25604455M_color=');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Color with id = WHITEFB: url not include parameter dwvar_25604455M_size=160');
var colorWhiteImages = attrColorWhite.images;
assert.isTrue(colorWhiteImages.swatch[0].url.endsWith('WHITEFB.CP.jpg'), 'color WHITEFB image swatch[0]: url not ended with WHITEFB.CP.jpg.');
// Verify URL for product.variationAttributes Size with id = 145
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[0].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 145: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 145: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 145: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 145: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 145: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=145'), 'product.variationAttributes Size with id = 145: url not include parameter dwvar_25604455M_size=145');
// Verify URL for product.variationAttributes of Size of id = 150
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[1].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 150: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 150: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 150: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 150: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 150: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=150'), 'product.variationAttributes Size with id = 150: url not include parameter dwvar_25604455M_size=150');
// Verify URL for product.variationAttributes Size with id = 155
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[2].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 155: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 155: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 155: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 155: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 155: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=155'), 'product.variationAttributes Size with id = 155: url not include parameter dwvar_25604455M_size=155');
// Verify URL for product.variationAttributes Size with id = 160
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[3].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 160: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 160: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 160: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 160: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 160: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size='), 'product.variationAttributes Size with id = 160: url not include parameter dwvar_25604455M_size=');
// Verify URL for product.variationAttributes Size with id = 165
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[4].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 165: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 165 url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 165: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 165: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 165: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=165'), 'product.variationAttributes Size with id = 165: url not include parameter dwvar_25604455M_size=165');
// Verify URL for product.variationAttributes Size with id = 170
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[5].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 170: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 170 url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 170: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 170: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 170: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=170'), 'product.variationAttributes Size with id = 170: url not include parameter dwvar_25604455M_size=170');
// Verify URL for product.variationAttributes Size with id = 180
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[7].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 180: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 180 url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 180: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 180: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 180: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=180'), 'product.variationAttributes Size with id = 180: url not include parameter dwvar_25604455M_size=180');
// Verify URL for product.variationAttributes of width = A (32/33)
urlSplit1 = bodyAsJson.product.variationAttributes[2].values[0].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = A: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = A: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = A: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width='), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_width=');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_size=160');
// Verify URL for product.variationAttributes of width = B (34/35)
urlSplit1 = bodyAsJson.product.variationAttributes[2].values[1].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = B: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = B: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = B: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=B'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_width=B');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_size=160');
// Verify URL for product.variationAttributes of images
var prodImages = bodyAsJson.product.images;
assert.isTrue(prodImages.large[0].url.endsWith('WHITEFB.PZ.jpg'), 'product image large[0]: url not ended with WHITEFB.PZ.jpg.');
assert.isTrue(prodImages.large[1].url.endsWith('WHITEFB.BZ.jpg'), 'product image large[1]: url not ended with WHITEFB.BZ.jpg.');
assert.isTrue(prodImages.small[0].url.endsWith('WHITEFB.PZ.jpg'), 'product image small[0]: url not ended with WHITEFB.PZ.jpg.');
assert.isTrue(prodImages.small[1].url.endsWith('WHITEFB.BZ.jpg'), 'product image small[1]: url not ended with WHITEFB.BZ.jpg.');
done();
});
});
});

View File

@@ -0,0 +1,132 @@
var assert = require('chai').assert;
var request = require('request');
var _ = require('lodash');
var config = require('../it.config');
var jsonHelpers = require('../helpers/jsonUtils');
var urlHelpers = require('../helpers/urlUtils');
describe('ProductVariation - Get product variation with main product ID and partial variation attributes', function () {
this.timeout(5000);
var mainPid = '25604455M';
var myGetRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
it('should returns main product details and variant attributes', function (done) {
var urlEndPoint = config.baseUrl + '/Product-Variation';
var urlWithMpid = urlEndPoint + '?pid=' + mainPid;
myGetRequest.url = urlWithMpid + '&dwvar_25604455M_color=SLABLFB&dwvar_25604455M_size=155';
request(myGetRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
// strip out all "url" properties from the actual response
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['url', 'resetUrl', 'selectedProductUrl', 'raw', 'absURL']);
// Verify product
assert.equal(actualRespBodyStripped.product.productName, 'No-Iron Textured Dress Shirt');
assert.equal(actualRespBodyStripped.product.productType, 'master');
assert.equal(actualRespBodyStripped.product.id, mainPid);
assert.equal(actualRespBodyStripped.product.longDescription, 'This cotton dress shirt is available in white or blue. Both colors are a wardrobe necessity.');
// Verify product price
assert.equal(actualRespBodyStripped.product.price.sales.value, '49.99');
assert.equal(actualRespBodyStripped.product.price.sales.currency, 'USD');
assert.equal(actualRespBodyStripped.product.price.sales.formatted, '$49.99');
assert.equal(actualRespBodyStripped.product.price.list.value, '69.5');
assert.equal(actualRespBodyStripped.product.price.list.currency, 'USD');
assert.equal(actualRespBodyStripped.product.price.list.formatted, '$69.50');
// Verify URL for product.variationAttributes of color = SLABLFB
var attrColorBlue = bodyAsJson.product.variationAttributes[0].values[0];
var urlSplit1 = attrColorBlue.url.split('?');
var urlParams = urlSplit1[1].split('&');
var urlEndPointCleaned = urlHelpers.stripBasicAuth(urlEndPoint);
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Color with id = SLABLFB: actual request end point not equal expected value.');
assert.equal(urlParams.length, 4, 'product.variationAttributes Color with id = SLABLFB: url does not have 4 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Color with id = SLABLFB: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color='), 'product.variationAttributes Color with id = SLABLFB: url not include parameter dwvar_25604455M_color=');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=155'), 'product.variationAttributes Color with id = SLABLFB: url not include parameter dwvar_25604455M_size=155');
var colorBlueImages = attrColorBlue.images;
assert.isTrue(colorBlueImages.swatch[0].url.endsWith('SLABLFB.CP.jpg'), 'color SLABLFB image swatch[0]: url not ended with SLABLFB.CP.jpg.');
// Verify URL for product.variationAttributes of color = WHITEFB
var attrColorWhite = bodyAsJson.product.variationAttributes[0].values[1];
urlSplit1 = attrColorWhite.url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Color with id = WHITEFB: actual request end point not equal expected value.');
assert.equal(urlParams.length, 4, 'product.variationAttributes Color with id = WHITEFB: url does not have 4 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Color with id = WHITEFB: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Color with id = WHITEFB: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=155'), 'product.variationAttributes Color with id = WHITEFB: url not include parameter dwvar_25604455M_size=155');
var colorWhiteImages = attrColorWhite.images;
assert.isTrue(colorWhiteImages.swatch[0].url.endsWith('WHITEFB.CP.jpg'), 'color WHITEFB image swatch[0]: url not ended with WHITEFB.CP.jpg.');
// Verify URL for product.variationAttributes of Size of id = 145
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[0].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 145: actual request end point not equal expected value.');
assert.equal(urlParams.length, 4, 'product.variationAttributes[1].values[0].url does not have 3 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 145: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=SLABLFB'), 'product.variationAttributes Size with id = 145: url not include parameter dwvar_25604455M_color=SLABLFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=145'), 'product.variationAttributes Size with id = 145: url not include parameter dwvar_25604455M_size=145');
// Verify URL for product.variationAttributes of Size of id = 160
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[3].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 160: actual request end point not equal expected value.');
assert.equal(urlParams.length, 4, 'product.variationAttributes Size with id = 160: url does not have 3 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 160: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=SLABLFB'), 'product.variationAttributes Size with id = 160: url not include parameter dwvar_25604455M_color=SLABLFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Size with id = 160: url not include parameter dwvar_25604455M_size=160');
// Verify URL for product.variationAttributes of Size of id = 220
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[11].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 220: actual request end point not equal expected value.');
assert.equal(urlParams.length, 4, 'product.variationAttributes Size with id = 220: url does not have 3 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 220: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=SLABLFB'), 'product.variationAttributes Size with id = 220: url not include parameter dwvar_25604455M_color=SLABLFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=220'), 'product.variationAttributes Size with id = 220: url not include parameter dwvar_25604455M_size=220');
// Verify URL for product.variationAttributes of width = A (32/33)
urlSplit1 = bodyAsJson.product.variationAttributes[2].values[0].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = A: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = A: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = A: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=SLABLFB'), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_color=SLABLFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=155'), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_size=155');
// Verify URL for product.variationAttributes of width = B (34/35)
urlSplit1 = bodyAsJson.product.variationAttributes[2].values[1].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = B: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = B: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = B: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=B'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_width=B');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=SLABLFB'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_color=SLABLFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=155'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_size=155');
// Verify URL for product.variationAttributes of images
var prodImages = bodyAsJson.product.images;
assert.isTrue(prodImages.large[0].url.endsWith('SLABLFB.PZ.jpg'), 'product image large[0]: url not ended with SLABLFB.PZ.jpg.');
assert.isTrue(prodImages.large[1].url.endsWith('SLABLFB.BZ.jpg'), 'product image large[1]: url not ended with SLABLFB.BZ.jpg.');
assert.isTrue(prodImages.small[0].url.endsWith('SLABLFB.PZ.jpg'), 'product image small[0]: url not ended with SLABLFB.PZ.jpg.');
assert.isTrue(prodImages.small[1].url.endsWith('SLABLFB.BZ.jpg'), 'product image small[1]: url not ended with SLABLFB.BZ.jpg.');
done();
});
});
});

View File

@@ -0,0 +1,129 @@
var assert = require('chai').assert;
var request = require('request');
var _ = require('lodash');
var config = require('../it.config');
var jsonHelpers = require('../helpers/jsonUtils');
var urlHelpers = require('../helpers/urlUtils');
describe('ProductVariation - Get product variation with variant ID', function () {
this.timeout(5000);
var mainPid = '25604455M';
var variantPid = '708141676220M';
var myGetRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
it('should returns variant for the selected attributes', function (done) {
var urlEndPoint = config.baseUrl + '/Product-Variation';
var urlWithVpid = urlEndPoint + '?pid=' + variantPid;
myGetRequest.url = urlWithVpid;
request(myGetRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
// strip out all "url" properties from the actual response
var actualRespBodyStripped = jsonHelpers.deleteProperties(bodyAsJson, ['url', 'resetUrl', 'selectedProductUrl', 'raw', 'absURL']);
// Verify product
assert.equal(actualRespBodyStripped.product.productName, 'No-Iron Textured Dress Shirt');
assert.equal(actualRespBodyStripped.product.productType, 'variant');
assert.equal(actualRespBodyStripped.product.id, variantPid);
assert.equal(actualRespBodyStripped.product.longDescription, 'This cotton dress shirt is available in white or blue. Both colors are a wardrobe necessity.');
// Verify product price
assert.equal(actualRespBodyStripped.product.price.sales.value, '49.99');
assert.equal(actualRespBodyStripped.product.price.sales.currency, 'USD');
assert.equal(actualRespBodyStripped.product.price.sales.formatted, '$49.99');
assert.equal(actualRespBodyStripped.product.price.list.value, '69.5');
assert.equal(actualRespBodyStripped.product.price.list.currency, 'USD');
assert.equal(actualRespBodyStripped.product.price.list.formatted, '$69.50');
// Verify URL for product.variationAttributes of color = SLABLFB
var attrColorBlue = bodyAsJson.product.variationAttributes[0].values[0];
var urlSplit1 = attrColorBlue.url.split('?');
var urlParams = urlSplit1[1].split('&');
var urlEndPointCleaned = urlHelpers.stripBasicAuth(urlEndPoint);
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Color with id = SLABLFB: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Color with id = SLABLFB: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Color with id = SLABLFB: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Color with id = SLABLFB: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=SLABLFB'), 'product.variationAttributes Color with id = SLABLFB: url not include parameter dwvar_25604455M_color=SLABLFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Color with id = SLABLFB: url not include parameter dwvar_25604455M_size=160');
var colorBlueImages = attrColorBlue.images;
assert.isTrue(colorBlueImages.swatch[0].url.endsWith('SLABLFB.CP.jpg'), 'color SLABLFB image swatch[0]: url not ended with SLABLFB.CP.jpg.');
// Verify URL for product.variationAttributes of color = WHITEFB
var attrColorWhite = bodyAsJson.product.variationAttributes[0].values[1];
urlSplit1 = attrColorWhite.url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Color with id = WHITEFB: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Color with id = WHITEFB: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Color with id = WHITEFB: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Color with id = WHITEFB: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color='), 'product.variationAttributes Color with id = WHITEFB: url not include parameter dwvar_25604455M_color=');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Color with id = WHITEFB: url not include parameter dwvar_25604455M_size=160');
var colorWhiteImages = attrColorWhite.images;
assert.isTrue(colorWhiteImages.swatch[0].url.endsWith('WHITEFB.CP.jpg'), 'color WHITEFB image swatch[0]: url not ended with WHITEFB.CP.jpg.');
// Verify URL for product.variationAttributes Size with id = 145
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[0].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 145: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 145: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 145: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 145: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 145: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=145'), 'product.variationAttributes Size with id = 145: url not include parameter dwvar_25604455M_size=145');
// Verify URL for product.variationAttributes of Size of id = 150
urlSplit1 = bodyAsJson.product.variationAttributes[1].values[1].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = 150: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = 150: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = 150: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=A'), 'product.variationAttributes Size with id = 150: url not include parameter dwvar_25604455M_width=A');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = 150: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=150'), 'product.variationAttributes Size with id = 150: url not include parameter dwvar_25604455M_size=150');
// Verify URL for product.variationAttributes of width = A (32/33)
urlSplit1 = bodyAsJson.product.variationAttributes[2].values[0].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = A: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = A: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = A: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width='), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_width=');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Size with id = A: url not include parameter dwvar_25604455M_size=160');
// Verify URL for product.variationAttributes of width = B (34/35)
urlSplit1 = bodyAsJson.product.variationAttributes[2].values[1].url.split('?');
urlParams = urlSplit1[1].split('&');
assert.equal(urlSplit1[0], urlEndPointCleaned, 'product.variationAttributes Size with id = B: actual request end point not equal expected value.');
assert.equal(urlParams.length, 5, 'product.variationAttributes Size with id = B: url does not have 5 parameters.');
assert.isTrue(_.includes(urlParams, 'pid=' + mainPid), 'product.variationAttributes Size with id = B: url not include parameter pid=' + mainPid);
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_width=B'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_width=B');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_color=WHITEFB'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_color=WHITEFB');
assert.isTrue(_.includes(urlParams, 'dwvar_25604455M_size=160'), 'product.variationAttributes Size with id = B: url not include parameter dwvar_25604455M_size=160');
// Verify URL for product.variationAttributes of images
var prodImages = bodyAsJson.product.images;
assert.isTrue(prodImages.large[0].url.endsWith('WHITEFB.PZ.jpg'), 'product image large[0]: url not ended with WHITEFB.PZ.jpg.');
assert.isTrue(prodImages.large[1].url.endsWith('WHITEFB.BZ.jpg'), 'product image large[1]: url not ended with WHITEFB.BZ.jpg.');
assert.isTrue(prodImages.small[0].url.endsWith('WHITEFB.PZ.jpg'), 'product image small[0]: url not ended with WHITEFB.PZ.jpg.');
assert.isTrue(prodImages.small[1].url.endsWith('WHITEFB.BZ.jpg'), 'product image small[1]: url not ended with WHITEFB.BZ.jpg.');
done();
});
});
});

View File

@@ -0,0 +1,133 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
// Test Case
// pid=799927767720M
// 1. Product PDP page contains the promotional messages
// 2. Add 2 products to Cart, should return approaching order/shipping promotion messages
// 3. shipping cost and order discount
// 4. Shipping form updates
describe('Approaching order level promotion', function () {
this.timeout(5000);
var mainPid = '25594767M';
var variantPid = '799927767720M';
var qty = 2;
var cookieString;
var cookieJar = request.jar();
var UUID;
var myShippingMethodForm = {
methodID: '001'
};
var myNewShippingMethodForm = {
methodID: '021'
};
var myRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var myNewRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var myShippingRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var orderDiscountMsg = 'Purchase $24.00 or more and receive 20% off on your order';
var shippingDiscountMsg = 'Purchase $24.00 or more and receive Free Shipping with USPS (7-10 Business Days)';
it('1. should return a response containing promotional messages for the order and shipping discounts on PDP', function () {
myRequest.url = config.baseUrl + '/Product-Variation?pid='
+ mainPid + '&dwvar_' + mainPid + '_color=BLUJEFB&quantity=1';
return request(myRequest, function (error, response) {
var bodyAsJson = JSON.parse(response.body);
assert.equal(response.statusCode, 200, 'Expected GET Product-Variation statusCode to be 200.');
assert.isTrue(bodyAsJson.product.promotions[0].calloutMsg === '20% off on your order');
assert.isTrue(bodyAsJson.product.promotions[1].calloutMsg === 'Free Shipping with USPS (7-10 Business Days)');
});
});
it('2. should return a response containing approaching promotional call out messages', function () {
// add 2 product to Cart
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid,
quantity: qty
};
myRequest.method = 'POST';
return request(myRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'expected add variant to Cart call to return status code 200');
var bodyAsJson = JSON.parse(response.body);
UUID = bodyAsJson.cart.items[0].UUID;
assert.isTrue(bodyAsJson.quantityTotal === 2, 'should have 2 items added to Cart');
assert.isTrue(bodyAsJson.message === 'Product added to cart');
cookieString = cookieJar.getCookieString(myRequest.url);
})
// select a shipping method with Form is required before going to Cart
.then(function () {
myRequest.form = myShippingMethodForm; // Ground Shipping method
myRequest.method = 'POST';
myRequest.url = config.baseUrl + '/Cart-SelectShippingMethod';
var cookie = request.cookie(cookieString);
cookieJar.setCookie(cookie, myRequest.url);
return request(myRequest);
})
.then(function (response) {
assert.equal(response.statusCode, 200, 'expected add shipping method to return status code 200');
var bodyAsJson = JSON.parse(response.body);
assert.equal(bodyAsJson.approachingDiscounts[0].discountMsg, orderDiscountMsg);
assert.equal(bodyAsJson.approachingDiscounts[1].discountMsg, shippingDiscountMsg);
});
});
it('3. should return a response with Approaching Order Discount -$30.40 in Cart', function () {
// update the quantity to 4 to trigger the order level discount
myNewRequest.url = config.baseUrl + '/Cart-UpdateQuantity?pid=' + variantPid + '&quantity=4&uuid=' + UUID;
return request(myNewRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'expected update quantity call to return status code 200');
var bodyAsJson = JSON.parse(response.body);
var discounts = bodyAsJson.totals.discounts[0];
assert.equal(bodyAsJson.totals.orderLevelDiscountTotal.formatted, '$30.40');
assert.equal(discounts.lineItemText, 'Approaching Order Discount Test');
assert.equal(discounts.price, '-$30.40');
assert.equal(discounts.type, 'promotion');
});
});
it('4. should return a response with Approaching Shipping Discount -$7.99 in Cart', function () {
// update the shipping methods to be USPS to meet the promotion requirement
myShippingRequest.form = myNewShippingMethodForm; // Ground Shipping method
myShippingRequest.url = config.baseUrl + '/Cart-SelectShippingMethod';
return request(myShippingRequest)
.then(function (response) {
assert.equal(response.statusCode, 200, 'expected selectShippingMethod call to return status code 200');
var bodyAsJson = JSON.parse(response.body);
var discounts = bodyAsJson.totals.discounts[1];
assert.equal(bodyAsJson.totals.shippingLevelDiscountTotal.formatted, '$7.99');
assert.equal(discounts.lineItemText, 'Approaching Shipping Discount Test');
assert.equal(discounts.price, '-$7.99');
assert.equal(discounts.type, 'promotion');
});
});
});

View File

@@ -0,0 +1,287 @@
var assert = require('chai').assert;
var chai = require('chai');
var chaiSubset = require('chai-subset');
chai.use(chaiSubset);
var request = require('request-promise');
var config = require('../it.config');
describe('Test Choice of bonus Products promotion Mini cart response.', function () {
this.timeout(50000);
var VARIANT_PID = '013742002454M';
var QTY = 3;
var UUID;
var cookieJar = request.jar();
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
it('should not return the bonus products, if qty is too low.', function () {
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: VARIANT_PID,
quantity: QTY
};
var expectedResponse = {};
return request(myRequest)
.then(function (myResponse) {
assert.equal(myResponse.statusCode, 200);
var bodyAsJson = JSON.parse(myResponse.body);
assert.equal(
JSON.stringify(bodyAsJson.newBonusDiscountLineItem),
JSON.stringify(expectedResponse));
});
});
it('should return the bonus products, if qty is sufficient.', function () {
// ----- adding product item #1:
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: VARIANT_PID,
quantity: QTY
};
var expectedPidArray = [
'008885004540M',
'008884304047M',
'883360390116M',
'pioneer-pdp-6010fdM'];
var expectedLabels = {
'close': 'Close',
'maxprods': 'of 2 Bonus Products Selected:',
'selectprods': 'Select Bonus Products'
};
return request(myRequest)
.then(function (myResponse) {
var bodyAsJson = JSON.parse(myResponse.body);
UUID = bodyAsJson.newBonusDiscountLineItem.uuid;
assert.equal(myResponse.statusCode, 200);
assert.equal(bodyAsJson.newBonusDiscountLineItem.bonuspids.length, expectedPidArray.length);
assert.containSubset(bodyAsJson.newBonusDiscountLineItem.bonuspids, expectedPidArray);
assert.containSubset(bodyAsJson.newBonusDiscountLineItem.maxBonusItems, 2);
assert.containSubset(bodyAsJson.newBonusDiscountLineItem.labels, expectedLabels);
});
});
it('should return an error if too many bonus products are added to the cart', function () {
// ----- adding product item #1:
var urlQuerystring = '?pids=' +
JSON.stringify({
'bonusProducts':
[{
'pid': '008885004540M',
'qty': 3,
'options': [null]
}],
'totalQty': 2 });
urlQuerystring += '&uuid=' + UUID;
myRequest.url = config.baseUrl + '/Cart-AddBonusProducts' + urlQuerystring;
var expectedSubSet = {
'errorMessage': 'You can choose 2 products, but you have selected 3 products.',
'error': true,
'success': false
};
return request(myRequest)
.then(function (myResponse) {
var bodyAsJson = JSON.parse(myResponse.body);
assert.equal(myResponse.statusCode, 200);
assert.containSubset(bodyAsJson, expectedSubSet);
});
});
});
describe('Add rule base Bonus Product to cart', function () {
this.timeout(45000);
var variantPid1 = '701642842668M';
var qty1 = 1;
var cookieJar = request.jar();
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var duuid;
var pliuuid;
var pageSize;
var bonusChoiceRuleBased;
before(function () {
// ----- adding qualifying product #1:
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (response) {
var bodyAsJson = JSON.parse(response.body);
duuid = bodyAsJson.newBonusDiscountLineItem.uuid;
bonusChoiceRuleBased = bodyAsJson.newBonusDiscountLineItem.bonusChoiceRuleBased;
pageSize = parseInt(bodyAsJson.newBonusDiscountLineItem.pageSize, 10);
pliuuid = bodyAsJson.newBonusDiscountLineItem.pliUUID;
});
});
it('It should reflect as a rule based bonus product', function () {
assert.equal(pageSize, 6);
assert.equal(bonusChoiceRuleBased, true);
assert.isNotNull(duuid);
});
it('bring up the edit bonus product window', function () {
// console.log('duuid ' + duuid);
myRequest.url = config.baseUrl + '/Cart-EditBonusProduct?duuid=' + duuid;
myRequest.form = {
duuid: duuid
};
myRequest.method = 'GET';
// console.log(myRequest.url);
return request(myRequest)
.then(function (response) {
var bodyAsJson = JSON.parse(response.body);
assert.equal(bodyAsJson.action, 'Cart-EditBonusProduct');
assert.equal(bodyAsJson.addToCartUrl, '/on/demandware.store/Sites-RefArch-Site/en_US/Cart-AddBonusProducts');
assert.equal(bodyAsJson.showProductsUrl, '/on/demandware.store/Sites-RefArch-Site/en_US/Product-ShowBonusProducts');
assert.equal(bodyAsJson.maxBonusItems, 2);
assert.equal(pageSize, 6);
assert.equal(bodyAsJson.pliUUID, pliuuid);
assert.equal(bodyAsJson.uuid, duuid);
assert.equal(bodyAsJson.bonusChoiceRuleBased, true);
assert.equal(bodyAsJson.showProductsUrlRuleBased, '/on/demandware.store/Sites-RefArch-Site/en_US/Product-ShowBonusProducts?DUUID=' + duuid + '&pagesize=' + pageSize + '&pagestart=0&maxpids=' + bodyAsJson.maxBonusItems);
});
});
it('Add Bonus Product to cart', function () {
var addBonusQueryString = '?pids={%22bonusProducts%22:[{%22pid%22:%22008884304023M%22,%22qty%22:1,%22options%22:[null]}],%22totalQty%22:1}&uuid=' + duuid + '&pliuuid=' + pliuuid;
myRequest.url = config.baseUrl + '/Cart-AddBonusProducts' + addBonusQueryString;
myRequest.form = {
duuid: duuid
};
myRequest.method = 'POST';
return request(myRequest)
.then(function (response) {
var bodyAsJson = JSON.parse(response.body);
assert.equal(bodyAsJson.action, 'Cart-AddBonusProducts');
assert.equal(bodyAsJson.totalQty, 2);
assert.equal(bodyAsJson.msgSuccess, 'Bonus products added to your cart');
assert.isTrue(bodyAsJson.success);
assert.isFalse(bodyAsJson.error);
});
});
});
describe('Add list base Bonus Product to cart', function () {
this.timeout(45000);
var variantPid1 = '013742002454M';
var qty1 = 5;
var cookieJar = request.jar();
var myRequest = {
url: '',
method: 'POST',
rejectUnauthorized: false,
resolveWithFullResponse: true,
jar: cookieJar,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var duuid;
var pliuuid;
var bonusChoiceRuleBased;
var bonuspids;
before(function () {
// ----- adding qualifying product #1:
myRequest.url = config.baseUrl + '/Cart-AddProduct';
myRequest.form = {
pid: variantPid1,
quantity: qty1
};
return request(myRequest)
.then(function (response) {
var bodyAsJson = JSON.parse(response.body);
duuid = bodyAsJson.newBonusDiscountLineItem.uuid;
bonusChoiceRuleBased = bodyAsJson.newBonusDiscountLineItem.bonusChoiceRuleBased;
pliuuid = bodyAsJson.newBonusDiscountLineItem.pliUUID;
bonuspids = bodyAsJson.newBonusDiscountLineItem.bonuspids;
});
});
it('It should reflect as a rule based bonus product', function () {
var bonuspidsExpected = [
'008885004540M',
'008884304047M',
'883360390116M',
'pioneer-pdp-6010fdM'
];
assert.equal(bonusChoiceRuleBased, false);
assert.isNotNull(duuid);
assert.equal(bonuspids[0], bonuspidsExpected[0]);
assert.equal(bonuspids[1], bonuspidsExpected[1]);
assert.equal(bonuspids[2], bonuspidsExpected[2]);
assert.equal(bonuspids[3], bonuspidsExpected[3]);
});
it('bring up the edit bonus product window', function () {
myRequest.url = config.baseUrl + '/Cart-EditBonusProduct?duuid=' + duuid;
myRequest.form = {
duuid: duuid
};
myRequest.method = 'GET';
return request(myRequest)
.then(function (response) {
var bodyAsJson = JSON.parse(response.body);
assert.equal(bodyAsJson.action, 'Cart-EditBonusProduct');
assert.equal(bodyAsJson.addToCartUrl, '/on/demandware.store/Sites-RefArch-Site/en_US/Cart-AddBonusProducts');
assert.equal(bodyAsJson.showProductsUrl, '/on/demandware.store/Sites-RefArch-Site/en_US/Product-ShowBonusProducts');
assert.equal(bodyAsJson.maxBonusItems, 2);
assert.equal(bodyAsJson.pliUUID, pliuuid);
assert.equal(bodyAsJson.uuid, duuid);
assert.equal(bodyAsJson.bonusChoiceRuleBased, false);
});
});
it('Add Bonus Product to cart', function () {
var addBonusQueryString = '?pids={%22bonusProducts%22:[{%22pid%22:%22008885004540M%22,%22qty%22:1,%22options%22:[null]}],%22totalQty%22:1}&uuid=' + duuid + '&pliuuid=' + pliuuid;
myRequest.url = config.baseUrl + '/Cart-AddBonusProducts' + addBonusQueryString;
myRequest.form = {
duuid: duuid
};
myRequest.method = 'POST';
return request(myRequest)
.then(function (response) {
var bodyAsJson = JSON.parse(response.body);
assert.equal(bodyAsJson.action, 'Cart-AddBonusProducts');
assert.equal(bodyAsJson.totalQty, 6);
assert.equal(bodyAsJson.msgSuccess, 'Bonus products added to your cart');
assert.isTrue(bodyAsJson.success);
assert.isFalse(bodyAsJson.error);
});
});
});

View File

@@ -0,0 +1,53 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
/**
* Test Case:
* Verify promotion enabled product variant id = 793775370033 should contain
* The promotion text message as well as the price adjustment
*/
describe('Product Variant Promotion on Product Details Page', function () {
this.timeout(5000);
var mainPid = '25752986M';
var myGetRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
it('should return a response containing promotion message and sale price ', function (done) {
myGetRequest.url = config.baseUrl + '/Product-Variation?pid='
+ mainPid + '&dwvar_' + mainPid + '_color=TURQUSI&quantity=1';
var expectedSalesPrice = { value: 23.99, currency: 'USD', formatted: '$23.99', 'decimalPrice': '23.99' };
var expectedListPrice = { value: 39.5, currency: 'USD', formatted: '$39.50', 'decimalPrice': '39.50' };
var expectedPromotion = {
'promotions': [
{
'calloutMsg': 'Get 20% off of this tie.',
'details': 'Buy a tie with 20% percent off.',
'enabled': true,
'id': 'PromotionTest_WithoutQualifying',
'name': 'PromotionTest_WithoutQualifying',
'promotionClass': 'PRODUCT',
'rank': null
}
]
};
request(myGetRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected GET Product-Variation statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.deepEqual(bodyAsJson.product.promotions[0], expectedPromotion.promotions[0]);
assert.deepEqual(bodyAsJson.product.price.sales, expectedSalesPrice);
assert.deepEqual(bodyAsJson.product.price.list, expectedListPrice);
done();
});
});
});

View File

@@ -0,0 +1,40 @@
var assert = require('chai').assert;
var request = require('request');
var config = require('../it.config');
describe('Product-ShowQuickView', function () {
this.timeout(5000);
var variantPid = '708141676220M';
var myGetRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
it('should return renderedTemplate and productURL', function (done) {
var urlEndPoint = config.baseUrl + '/Product-ShowQuickView';
var urlWithVpid = urlEndPoint + '?pid=' + variantPid;
myGetRequest.url = urlWithVpid;
request(myGetRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.isNotNull(bodyAsJson.renderedTemplate);
assert.isString(bodyAsJson.renderedTemplate);
assert.isNotNull(bodyAsJson.productUrl);
assert.isString(bodyAsJson.productUrl);
assert.isString(bodyAsJson.closeButtonText);
assert.isString(bodyAsJson.enterDialogMessage);
done();
});
});
});

View File

@@ -0,0 +1,49 @@
var assert = require('chai').assert;
var request = require('request-promise');
var config = require('../it.config');
var cheerio = require('cheerio');
/**
* Test Case :
* Verify 'SearchServices-GetSuggestions?q=tops' call submitted successful and the response contains the following :
* - Do you mean? Tops
* - Products : Log Sleeve Turtleneck Top; Cowl Neck Top; Paisley Turtleneck Top
* - Categories : Tops; Top Sellers
* - Content : FAQs
*/
describe('Search As You Type - general product', function () {
this.timeout(5000);
var product = 'Tops';
var myRequest = {
url: '',
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
it('should remove line item', function (done) {
myRequest.url = config.baseUrl + '/SearchServices-GetSuggestions?q=' + product;
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected GET SearchServices-GetSuggestions call statusCode to be 200.');
var $ = cheerio.load(response.body);
var prod = $('.container a');
// Determining if pretty-URLs is enabled to differentiate test case usage
var prettyURL = prod.get(0).attribs.href;
if (prettyURL.includes('/s/RefArch/')) {
assert.isTrue(prod.get(0).children[0].next.attribs.alt.endsWith('Top'));
assert.isTrue(prod.get(1).children[0].next.attribs.alt.endsWith('Top'));
assert.isTrue(prod.get(2).children[0].next.attribs.alt.endsWith('Top'));
} else {
assert.isTrue(prod.get(0).children[0].next.next.attribs.alt.endsWith('Top'));
assert.isTrue(prod.get(1).children[0].next.next.attribs.alt.endsWith('Top'));
assert.isTrue(prod.get(2).children[0].next.next.attribs.alt.endsWith('Top'));
}
done();
});
});
});

View File

@@ -0,0 +1,396 @@
var assert = require('chai').assert;
var chaiSubset = require('chai-subset');
var chai = require('chai');
chai.use(chaiSubset);
var request = require('request');
var config = require('../it.config');
describe('Store Locator', function () {
this.timeout(5000);
describe('FindStores using Postal Code and radius', function () {
it('should returns locations for valid postal code and radius', function (done) {
var url = config.baseUrl + '/Stores-FindStores?postalCode=01803&radius=15';
var myRequest = {
url: url,
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var ExpectedResBody = {
'stores': [
{
'ID': 'store1',
'name': 'Commerce Cloud',
'address1': '10 Presidential Way',
'address2': null,
'city': 'Woburn',
'countryCode': 'US',
'latitude': 42.5273334,
'longitude': -71.13758250000001,
'postalCode': '01801',
'stateCode': 'MA',
'storeHours': 'Mon - Sat: 10am - 9pm<br />\r\nSun: 12pm - 6pm'
},
{
'ID': 'store4',
'name': 'Champaign Electronic Shop',
'address1': '1001 Cambridge St',
'address2': null,
'city': 'Cambridge',
'countryCode': 'US',
'latitude': 42.3729794,
'longitude': -71.09346089999997,
'postalCode': '02141',
'phone': '+1-617-714-2640',
'stateCode': 'MA'
},
{
'ID': 'store10',
'name': 'Downtown TV Shop',
'address1': '333 Washington St',
'address2': null,
'city': 'Boston',
'countryCode': 'US',
'latitude': 42.3569512,
'longitude': -71.05902600000002,
'postalCode': '02108',
'phone': '+1-617-695-1565',
'stateCode': 'MA',
'storeHours': 'Mon - Sat: 10am - 9pm<br />\r\n Sun: 12pm - 6pm'
},
{
'ID': 'store5',
'name': 'Short Electro',
'address1': '584 Columbus Ave',
'address2': null,
'city': 'Boston',
'countryCode': 'US',
'latitude': 42.3403189,
'longitude': -71.0817859,
'postalCode': '02118',
'phone': '+1-617-888-7276',
'stateCode': 'MA',
'storeHours': 'Mon - Sat: 10am - 9pm<br />\r\n Sun: 12pm - 6pm'
},
{
'ID': 'store6',
'name': 'Khale Street Electronics',
'address1': '150 Winthrop Ave',
'address2': null,
'city': 'Lawrence',
'countryCode': 'US',
'latitude': 42.6895548,
'longitude': -71.14878340000001,
'postalCode': '01843',
'phone': '+1-978-580-2704',
'stateCode': 'MA'
}
],
'locations': [
{ 'name': 'Commerce Cloud',
'latitude': 42.5273334,
'longitude': -71.13758250000001 },
{ 'name': 'Champaign Electronic Shop',
'latitude': 42.3729794,
'longitude': -71.09346089999997 },
{ 'name': 'Downtown TV Shop',
'latitude': 42.3569512,
'longitude': -71.05902600000002 },
{ 'name': 'Short Electro',
'latitude': 42.3403189,
'longitude': -71.0817859 },
{ 'name': 'Khale Street Electronics',
'latitude': 42.6895548,
'longitude': -71.14878340000001 }
],
'searchKey': {
'postalCode': '01803'
},
'radius': 15,
'radiusOptions': [
15,
30,
50,
100,
300
]
};
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
var bodyAsJsonLocations = JSON.parse(bodyAsJson.locations);
assert.containSubset(bodyAsJson.stores, ExpectedResBody.stores, 'Actual response.stores not as expected.');
assert.containSubset(bodyAsJsonLocations, ExpectedResBody.locations);
assert.containSubset(bodyAsJson.searchKey, ExpectedResBody.searchKey, 'Actual response.searchKey not as expected.');
assert.containSubset(bodyAsJson.radius, ExpectedResBody.radius, 'Actual response.radius not as expected.');
assert.containSubset(bodyAsJson.radiusOptions, ExpectedResBody.radiusOptions, 'Actual response.radiusOptions not as expected.');
done();
});
});
it('should returns location for specified postal code and default radius = 15', function (done) {
var url = config.baseUrl + '/Stores-FindStores?postalCode=04330';
var myRequest = {
url: url,
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var ExpectedResBody = {
'stores': [],
'locations': '[]',
'searchKey': {
'postalCode': '04330'
},
'radius': 15
};
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.deepEqual(bodyAsJson.stores, ExpectedResBody.stores, 'Actual response.stores not as expected.');
assert.deepEqual(bodyAsJson.locations, ExpectedResBody.locations, 'Actual response.locations not as expected.');
assert.deepEqual(bodyAsJson.radius, ExpectedResBody.radius, 'Actual response.radius not as expected.');
done();
});
});
it('should returns 0 location for non-exist postal code', function (done) {
var url = config.baseUrl + '/Stores-FindStores?postalCode=012AB&radius=5';
var myRequest = {
url: url,
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var ExpectedResBody = {
'stores': [],
'locations': '[]'
};
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.deepEqual(bodyAsJson.stores, ExpectedResBody.stores, 'Actual response.stores not as expected.');
assert.deepEqual(bodyAsJson.locations, ExpectedResBody.locations, 'Actual response.locations not as expected.');
done();
});
});
it('should returns 0 location for negative radius', function (done) {
var url = config.baseUrl + '/Stores-FindStores?postalCode=01803&radius=-15';
var myRequest = {
url: url,
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var ExpectedResBody = {
'stores': [],
'locations': '[]'
};
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.deepEqual(bodyAsJson.stores, ExpectedResBody.stores, 'Actual response.stores not as expected.');
assert.deepEqual(bodyAsJson.locations, ExpectedResBody.locations, 'Actual response.locations not as expected.');
done();
});
});
});
describe('FindStores using valid longitude, latitude and radius.', function () {
it('should returns locations for specified longitude, latitude and radius', function (done) {
var url = config.baseUrl + '/Stores-FindStores?long=-71.14878340000001&lat=42.6895548&radius=23';
var myRequest = {
url: url,
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var ExpectedResBody = {
'stores': [
{
'ID': 'store6',
'name': 'Khale Street Electronics',
'address1': '150 Winthrop Ave',
'address2': null,
'city': 'Lawrence',
'countryCode': 'US',
'latitude': 42.6895548,
'longitude': -71.14878340000001,
'postalCode': '01843',
'phone': '+1-978-580-2704',
'stateCode': 'MA'
},
{
'ID': 'store1',
'name': 'Commerce Cloud',
'address1': '10 Presidential Way',
'address2': null,
'city': 'Woburn',
'countryCode': 'US',
'latitude': 42.5273334,
'longitude': -71.13758250000001,
'postalCode': '01801',
'stateCode': 'MA',
'storeHours': 'Mon - Sat: 10am - 9pm<br />\r\nSun: 12pm - 6pm'
},
{
'ID': 'store4',
'name': 'Champaign Electronic Shop',
'address1': '1001 Cambridge St',
'address2': null,
'city': 'Cambridge',
'countryCode': 'US',
'latitude': 42.3729794,
'longitude': -71.09346089999997,
'postalCode': '02141',
'phone': '+1-617-714-2640',
'stateCode': 'MA'
}
],
'locations': [
{ 'name': 'Khale Street Electronics',
'latitude': 42.6895548,
'longitude': -71.14878340000001 },
{ 'name': 'Commerce Cloud',
'latitude': 42.5273334,
'longitude': -71.13758250000001 },
{ 'name': 'Champaign Electronic Shop',
'latitude': 42.3729794,
'longitude': -71.09346089999997 }
],
'searchKey': {
'lat': 42.6895548,
'long': -71.14878340000001
},
'radius': 23,
'radiusOptions': [
15,
30,
50,
100,
300
]
};
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
var bodyAsJsonLocations = JSON.parse(bodyAsJson.locations);
assert.containSubset(bodyAsJson.stores, ExpectedResBody.stores, 'Actual response.stores not as expected.');
assert.containSubset(bodyAsJsonLocations, ExpectedResBody.locations);
assert.containSubset(bodyAsJson.searchKey, ExpectedResBody.searchKey, 'Actual response.searchKey not as expected.');
assert.containSubset(bodyAsJson.radius, ExpectedResBody.radius, 'Actual response.radius not as expected.');
assert.containSubset(bodyAsJson.radiusOptions, ExpectedResBody.radiusOptions, 'Actual response.radiusOptions not as expected.');
done();
});
});
it('should returns 0 location for the specified longitude and latitude', function (done) {
var url = config.baseUrl + '/Stores-FindStores?long=0&lat=0';
var myRequest = {
url: url,
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var ExpectedResBody = {
'stores': [],
'locations': '[]'
};
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.deepEqual(bodyAsJson.stores, ExpectedResBody.stores, 'Actual response.stores not as expected.');
assert.deepEqual(bodyAsJson.locations, ExpectedResBody.locations, 'Actual response.locations not as expected.');
done();
});
});
it('should returns 0 location for invalid longitude and latitude', function (done) {
var url = config.baseUrl + '/Stores-FindStores?long=190&lat=100&radius=15';
var myRequest = {
url: url,
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
var ExpectedResBody = {
'stores': [],
'locations': '[]'
};
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.deepEqual(bodyAsJson.stores, ExpectedResBody.stores, 'Actual response.stores not as expected.');
assert.deepEqual(bodyAsJson.locations, ExpectedResBody.locations, 'Actual response.locations not as expected.');
done();
});
});
it('should returns succesful response with no parameter', function (done) {
// when no parameter specified, it uses geolocation.latitude and geolocation.longitude
// for the latitude and longitude; therefore the search result could be vary depending on
// the current location
var url = config.baseUrl + '/Stores-FindStores';
var myRequest = {
url: url,
method: 'GET',
rejectUnauthorized: false,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
};
request(myRequest, function (error, response) {
assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');
var bodyAsJson = JSON.parse(response.body);
assert.isNotNull(bodyAsJson.stores, 'Expect stores property in response.');
assert.isArray(bodyAsJson.stores, 'Expect stores property as array.');
assert.isNotNull(bodyAsJson.locations, 'Expect locations property in response.');
assert.isString(bodyAsJson.locations, 'Expect locations property as array.');
done();
});
});
});
});