Adds SFRA 6.0
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user