Adds SFRA 6.0
This commit is contained in:
@@ -0,0 +1,228 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var ArrayList = require('../../../mocks/dw.util.Collection');
|
||||
|
||||
var currentCustomer = {
|
||||
addressBook: {
|
||||
addresses: {},
|
||||
preferredAddress: {
|
||||
address1: '15 South Point Drive',
|
||||
address2: null,
|
||||
city: 'Boston',
|
||||
countryCode: {
|
||||
displayValue: 'United States',
|
||||
value: 'US'
|
||||
},
|
||||
firstName: 'John',
|
||||
lastName: 'Snow',
|
||||
ID: 'Home',
|
||||
postalCode: '02125',
|
||||
stateCode: 'MA'
|
||||
}
|
||||
},
|
||||
customer: {},
|
||||
profile: {
|
||||
firstName: 'John',
|
||||
lastName: 'Snow',
|
||||
email: 'jsnow@starks.com'
|
||||
},
|
||||
wallet: {
|
||||
paymentInstruments: [
|
||||
{
|
||||
creditCardExpirationMonth: '3',
|
||||
creditCardExpirationYear: '2019',
|
||||
maskedCreditCardNumber: '***********4215',
|
||||
creditCardType: 'Visa',
|
||||
paymentMethod: 'CREDIT_CARD'
|
||||
},
|
||||
{
|
||||
creditCardExpirationMonth: '4',
|
||||
creditCardExpirationYear: '2019',
|
||||
maskedCreditCardNumber: '***********4215',
|
||||
creditCardType: 'Amex',
|
||||
paymentMethod: 'CREDIT_CARD'
|
||||
},
|
||||
{
|
||||
creditCardExpirationMonth: '6',
|
||||
creditCardExpirationYear: '2019',
|
||||
maskedCreditCardNumber: '***********4215',
|
||||
creditCardType: 'Master Card',
|
||||
paymentMethod: 'CREDIT_CARD'
|
||||
},
|
||||
{
|
||||
creditCardExpirationMonth: '5',
|
||||
creditCardExpirationYear: '2019',
|
||||
maskedCreditCardNumber: '***********4215',
|
||||
creditCardType: 'Discover',
|
||||
paymentMethod: 'CREDIT_CARD'
|
||||
}
|
||||
]
|
||||
},
|
||||
raw: {
|
||||
authenticated: true,
|
||||
registered: true
|
||||
}
|
||||
};
|
||||
|
||||
var addressModel = {
|
||||
address: {
|
||||
address1: '15 South Point Drive',
|
||||
address2: null,
|
||||
city: 'Boston',
|
||||
countryCode: {
|
||||
displayValue: 'United States',
|
||||
value: 'US'
|
||||
},
|
||||
firstName: 'John',
|
||||
lastName: 'Snow',
|
||||
ID: 'Home',
|
||||
postalCode: '02125',
|
||||
stateCode: 'MA'
|
||||
}
|
||||
};
|
||||
|
||||
var orderModel = {
|
||||
orderNumber: '00000204',
|
||||
orderStatus: {
|
||||
displayValue: 'NEW'
|
||||
},
|
||||
creationDate: 'some Date',
|
||||
shippedToFirstName: 'John',
|
||||
shippedToLastName: 'Snow',
|
||||
shipping: {
|
||||
shippingAddress: {
|
||||
address1: '15 South Point Drive',
|
||||
address2: null,
|
||||
city: 'Boston',
|
||||
countryCode: {
|
||||
displayValue: 'United States',
|
||||
value: 'US'
|
||||
},
|
||||
firstName: 'John',
|
||||
lastName: 'Snow',
|
||||
ID: 'Home',
|
||||
phone: '123-123-1234',
|
||||
postalCode: '02125',
|
||||
stateCode: 'MA'
|
||||
}
|
||||
},
|
||||
items: new ArrayList([
|
||||
{
|
||||
product: {
|
||||
getImage: function () {
|
||||
return {
|
||||
URL: {
|
||||
relative: function () {
|
||||
return 'Some String';
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
]),
|
||||
priceTotal: 125.99,
|
||||
totals: {
|
||||
grandTotal: 125.99
|
||||
},
|
||||
productQuantityTotal: 3
|
||||
};
|
||||
|
||||
function MockCustomer() {}
|
||||
|
||||
describe('account', function () {
|
||||
var AddressModel = require('../../../mocks/models/address');
|
||||
var AccountModel = proxyquire('../../../../cartridges/app_storefront_base/cartridge/models/account', {
|
||||
'*/cartridge/models/address': AddressModel,
|
||||
'dw/web/URLUtils': { staticURL: function () { return 'some URL'; } },
|
||||
'dw/customer/Customer': MockCustomer
|
||||
});
|
||||
|
||||
it('should receive customer profile', function () {
|
||||
var result = new AccountModel(currentCustomer);
|
||||
assert.equal(result.profile.firstName, 'John');
|
||||
assert.equal(result.profile.lastName, 'Snow');
|
||||
assert.equal(result.profile.email, 'jsnow@starks.com');
|
||||
});
|
||||
|
||||
it('should receive customer wallet', function () {
|
||||
var result = new AccountModel(currentCustomer);
|
||||
assert.equal(result.payment.creditCardExpirationMonth, '3');
|
||||
assert.equal(result.payment.creditCardExpirationYear, '2019');
|
||||
assert.equal(result.payment.creditCardType, 'Visa');
|
||||
assert.equal(result.payment.maskedCreditCardNumber, '***********4215');
|
||||
|
||||
assert.equal(result.customerPaymentInstruments.length, 4);
|
||||
assert.equal(result.customerPaymentInstruments[0].cardTypeImage.src, 'some URL');
|
||||
assert.equal(result.customerPaymentInstruments[0].cardTypeImage.alt, 'Visa');
|
||||
});
|
||||
|
||||
it('should receive an account with address book, payment method and order history', function () {
|
||||
var result = new AccountModel(currentCustomer, addressModel, orderModel);
|
||||
|
||||
assert.equal(result.profile.firstName, 'John');
|
||||
assert.equal(result.profile.lastName, 'Snow');
|
||||
assert.equal(result.profile.email, 'jsnow@starks.com');
|
||||
|
||||
assert.equal(result.preferredAddress.address.address1, '15 South Point Drive');
|
||||
assert.equal(result.preferredAddress.address.address2, null);
|
||||
assert.equal(result.preferredAddress.address.city, 'Boston');
|
||||
assert.equal(result.preferredAddress.address.countryCode.displayValue, 'United States');
|
||||
assert.equal(result.preferredAddress.address.countryCode.value, 'US');
|
||||
assert.equal(result.preferredAddress.address.firstName, 'John');
|
||||
assert.equal(result.preferredAddress.address.lastName, 'Snow');
|
||||
assert.equal(result.preferredAddress.address.ID, 'Home');
|
||||
assert.equal(result.preferredAddress.address.postalCode, '02125');
|
||||
assert.equal(result.preferredAddress.address.stateCode, 'MA');
|
||||
|
||||
assert.equal(result.orderHistory.orderNumber, '00000204');
|
||||
assert.equal(result.orderHistory.creationDate, 'some Date');
|
||||
assert.equal(result.orderHistory.orderStatus.displayValue, 'NEW');
|
||||
assert.equal(result.orderHistory.shippedToFirstName, 'John');
|
||||
assert.equal(result.orderHistory.shippedToLastName, 'Snow');
|
||||
assert.equal(result.orderHistory.priceTotal, 125.99);
|
||||
assert.equal(result.orderHistory.productQuantityTotal, 3);
|
||||
|
||||
assert.equal(result.payment.maskedCreditCardNumber, '***********4215');
|
||||
assert.equal(result.payment.creditCardType, 'Visa');
|
||||
assert.equal(result.payment.creditCardExpirationMonth, '3');
|
||||
assert.equal(result.payment.creditCardExpirationYear, '2019');
|
||||
});
|
||||
|
||||
// it('should receive an account with null addressbook', function () {
|
||||
// var result = new AccountModel(currentCustomer);
|
||||
// assert.equal(result.preferredAddress, null);
|
||||
// });
|
||||
|
||||
describe('with a wallet that has no payment instruments', function () {
|
||||
before(function () {
|
||||
currentCustomer.wallet.paymentInstruments = [];
|
||||
});
|
||||
|
||||
it('should receive an account with null payment and empty payment instruments', function () {
|
||||
var result = new AccountModel(currentCustomer);
|
||||
assert.equal(result.payment, null);
|
||||
assert.equal(result.customerPaymentInstruments.length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a null wallet', function () {
|
||||
before(function () {
|
||||
currentCustomer.wallet = null;
|
||||
});
|
||||
|
||||
it('should receive an account with null payment and payment instruments', function () {
|
||||
var result = new AccountModel(currentCustomer);
|
||||
assert.equal(result.payment, null);
|
||||
assert.equal(result.customerPaymentInstruments, null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should receive an account with null order history', function () {
|
||||
var result = new AccountModel(currentCustomer, addressModel, null);
|
||||
assert.equal(result.orderHistory, null);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var AddressModel = require('../../../mocks/models/address');
|
||||
|
||||
var createOrderAddress = function () {
|
||||
return {
|
||||
address1: '1 Drury Lane',
|
||||
address2: null,
|
||||
countryCode: {
|
||||
displayValue: 'United States',
|
||||
value: 'US'
|
||||
},
|
||||
firstName: 'The Muffin',
|
||||
lastName: 'Man',
|
||||
city: 'Far Far Away',
|
||||
phone: '333-333-3333',
|
||||
postalCode: '04330',
|
||||
stateCode: 'ME'
|
||||
};
|
||||
};
|
||||
|
||||
describe('address', function () {
|
||||
it('should receive an null address', function () {
|
||||
var result = new AddressModel(null);
|
||||
assert.equal(result.address, null);
|
||||
});
|
||||
|
||||
it('should convert API Order Address to an object', function () {
|
||||
var result = new AddressModel(createOrderAddress());
|
||||
assert.equal(result.address.address1, '1 Drury Lane');
|
||||
assert.equal(result.address.address2, null);
|
||||
assert.equal(result.address.firstName, 'The Muffin');
|
||||
assert.equal(result.address.lastName, 'Man');
|
||||
assert.equal(result.address.city, 'Far Far Away');
|
||||
assert.equal(result.address.phone, '333-333-3333');
|
||||
assert.equal(result.address.postalCode, '04330');
|
||||
assert.equal(result.address.stateCode, 'ME');
|
||||
assert.deepEqual(result.address.countryCode, { displayValue: 'United States', value: 'US' });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var BillingModel = require('../../../mocks/models/billing');
|
||||
|
||||
var billingAddress = {
|
||||
address: {}
|
||||
};
|
||||
|
||||
var paymentModel = {
|
||||
applicablePaymentMethods: 'array of payment methods',
|
||||
applicablePaymentCards: 'array of credit cards',
|
||||
selectedPaymentInstruments: 'array of selected payment options'
|
||||
};
|
||||
|
||||
describe('billing', function () {
|
||||
it('should handle a null address', function () {
|
||||
var result = new BillingModel(null);
|
||||
assert.equal(result.billingAddress, null);
|
||||
});
|
||||
|
||||
it('should handle an address', function () {
|
||||
var result = new BillingModel(billingAddress);
|
||||
assert.deepEqual(result.billingAddress.address, {});
|
||||
});
|
||||
|
||||
it('should handle a paymentModel', function () {
|
||||
var result = new BillingModel(null, paymentModel);
|
||||
assert.equal(result.payment.applicablePaymentMethods, 'array of payment methods');
|
||||
assert.equal(result.payment.applicablePaymentCards, 'array of credit cards');
|
||||
assert.equal(
|
||||
result.payment.selectedPaymentInstruments,
|
||||
'array of selected payment options'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,127 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var ArrayList = require('../../../mocks/dw.util.Collection');
|
||||
|
||||
var toProductMock = require('../../../util');
|
||||
|
||||
var productVariantMock = {
|
||||
ID: '1234567',
|
||||
name: 'test product',
|
||||
variant: true,
|
||||
availabilityModel: {
|
||||
isOrderable: {
|
||||
return: true,
|
||||
type: 'function'
|
||||
},
|
||||
inventoryRecord: {
|
||||
ATS: {
|
||||
value: 100
|
||||
}
|
||||
}
|
||||
},
|
||||
minOrderQuantity: {
|
||||
value: 2
|
||||
}
|
||||
};
|
||||
|
||||
var productMock = {
|
||||
variationModel: {
|
||||
productVariationAttributes: new ArrayList([{
|
||||
attributeID: '',
|
||||
value: ''
|
||||
}]),
|
||||
selectedVariant: productVariantMock
|
||||
}
|
||||
};
|
||||
|
||||
var Money = require('../../../mocks/dw.value.Money');
|
||||
|
||||
|
||||
var createApiBasket = function (options) {
|
||||
var safeOptions = options || {};
|
||||
|
||||
var basket = {
|
||||
allProductLineItems: new ArrayList([{
|
||||
bonusProductLineItem: false,
|
||||
gift: false,
|
||||
UUID: 'some UUID',
|
||||
adjustedPrice: {
|
||||
value: 'some value',
|
||||
currencyCode: 'US'
|
||||
},
|
||||
quantity: {
|
||||
value: 1
|
||||
},
|
||||
product: toProductMock(productMock)
|
||||
}]),
|
||||
totalGrossPrice: new Money(true),
|
||||
totalTax: new Money(true),
|
||||
shippingTotalPrice: new Money(true)
|
||||
};
|
||||
|
||||
|
||||
if (safeOptions.shipping) {
|
||||
basket.shipments = [safeOptions.shipping];
|
||||
} else {
|
||||
basket.shipments = [{
|
||||
shippingMethod: {
|
||||
ID: '005'
|
||||
}
|
||||
}];
|
||||
}
|
||||
basket.defaultShipment = basket.shipments[0];
|
||||
|
||||
basket.getShipments = function () {
|
||||
return basket.shipments;
|
||||
};
|
||||
basket.getAdjustedMerchandizeTotalPrice = function () {
|
||||
return new Money(true);
|
||||
};
|
||||
|
||||
if (safeOptions.productLineItems) {
|
||||
basket.productLineItems = safeOptions.productLineItems;
|
||||
}
|
||||
|
||||
if (safeOptions.totals) {
|
||||
basket.totals = safeOptions.totals;
|
||||
}
|
||||
|
||||
return basket;
|
||||
};
|
||||
|
||||
describe('cart', function () {
|
||||
var Cart = require('../../../mocks/models/cart');
|
||||
|
||||
it('should accept/process a null Basket object', function () {
|
||||
var nullBasket = null;
|
||||
var result = new Cart(nullBasket);
|
||||
|
||||
assert.equal(result.items.length, 0);
|
||||
assert.equal(result.numItems, 0);
|
||||
});
|
||||
|
||||
it('should get shippingMethods from the shipping model', function () {
|
||||
var result = new Cart(createApiBasket());
|
||||
assert.equal(result.shipments[0].shippingMethods[0].description, 'Order received within 7-10 ' +
|
||||
'business days'
|
||||
);
|
||||
assert.equal(result.shipments[0].shippingMethods[0].displayName, 'Ground');
|
||||
assert.equal(result.shipments[0].shippingMethods[0].ID, '001');
|
||||
assert.equal(result.shipments[0].shippingMethods[0].shippingCost, '$0.00');
|
||||
assert.equal(result.shipments[0].shippingMethods[0].estimatedArrivalTime, '7-10 Business Days');
|
||||
});
|
||||
|
||||
it('should get totals from totals model', function () {
|
||||
var result = new Cart(createApiBasket());
|
||||
assert.equal(result.totals.subTotal, 'formatted money');
|
||||
assert.equal(result.totals.grandTotal, 'formatted money');
|
||||
assert.equal(result.totals.totalTax, 'formatted money');
|
||||
assert.equal(result.totals.totalShippingCost, 'formatted money');
|
||||
});
|
||||
// it('should get approaching discounts', function () {
|
||||
// var result = new Cart(createApiBasket());
|
||||
// assert.equal(result.approachingDiscounts[0].discountMsg, 'someString');
|
||||
// assert.equal(result.approachingDiscounts[1].discountMsg, 'someString');
|
||||
// });
|
||||
});
|
||||
@@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var ArrayList = require('../../../mocks/dw.util.Collection');
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var urlUtilsMock = {
|
||||
url: function (a, b, id) {
|
||||
return id;
|
||||
}
|
||||
};
|
||||
|
||||
var createApiCategory = function (name, id, hasOnlineSubCategories, hasOnlineProducts) {
|
||||
return {
|
||||
custom: {
|
||||
showInMenu: true
|
||||
},
|
||||
hasOnlineSubCategories: function () {
|
||||
return hasOnlineSubCategories;
|
||||
},
|
||||
hasOnlineProducts: function () {
|
||||
return hasOnlineProducts;
|
||||
},
|
||||
getDisplayName: function () {
|
||||
return name;
|
||||
},
|
||||
getOnlineSubCategories: function () {
|
||||
return new ArrayList([]);
|
||||
},
|
||||
getID: function () {
|
||||
return id;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
describe('categories', function () {
|
||||
var Categories = null;
|
||||
beforeEach(function () {
|
||||
var collections = proxyquire('../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
Categories = proxyquire('../../../../cartridges/app_storefront_base/cartridge/models/categories', {
|
||||
'*/cartridge/scripts/util/collections': collections,
|
||||
'dw/web/URLUtils': urlUtilsMock
|
||||
});
|
||||
});
|
||||
it('should convert API response to an object', function () {
|
||||
var apiCategories = new ArrayList([createApiCategory('foo', 1, true, true)]);
|
||||
|
||||
var result = new Categories(apiCategories);
|
||||
assert.equal(result.categories.length, 1);
|
||||
assert.equal(result.categories[0].name, 'foo');
|
||||
assert.equal(result.categories[0].url, 1);
|
||||
});
|
||||
it('should convert API response to nested object', function () {
|
||||
var category = createApiCategory('foo', 1, true, true);
|
||||
category.getOnlineSubCategories = function () {
|
||||
return new ArrayList([createApiCategory('bar', 2, true, true), createApiCategory('baz', 3, true, true)]);
|
||||
};
|
||||
|
||||
var result = new Categories(new ArrayList([category]));
|
||||
assert.equal(result.categories.length, 1);
|
||||
assert.equal(result.categories[0].name, 'foo');
|
||||
assert.equal(result.categories[0].url, 1);
|
||||
assert.equal(result.categories[0].subCategories.length, 2);
|
||||
assert.isFalse(result.categories[0].complexSubCategories);
|
||||
assert.equal(result.categories[0].subCategories[0].name, 'bar');
|
||||
assert.equal(result.categories[0].subCategories[1].name, 'baz');
|
||||
});
|
||||
it('should convertAPI response to object with complex sub category', function () {
|
||||
var category = createApiCategory('foo', 1, true, true);
|
||||
category.getOnlineSubCategories = function () {
|
||||
var child = createApiCategory('bar', 2, true, true);
|
||||
child.getOnlineSubCategories = function () {
|
||||
return new ArrayList([createApiCategory('baz', 3, true, true)]);
|
||||
};
|
||||
return new ArrayList([child]);
|
||||
};
|
||||
|
||||
var result = new Categories(new ArrayList([category]));
|
||||
assert.equal(result.categories.length, 1);
|
||||
assert.equal(result.categories[0].subCategories.length, 1);
|
||||
assert.isTrue(result.categories[0].complexSubCategories);
|
||||
assert.equal(result.categories[0].subCategories[0].name, 'bar');
|
||||
assert.equal(result.categories[0].subCategories[0].subCategories[0].name, 'baz');
|
||||
});
|
||||
it('should not show menu that hasOnlineSubCategories and hasOnlineProducts return false', function () {
|
||||
var category = createApiCategory('foo', 1, true, false);
|
||||
category.getOnlineSubCategories = function () {
|
||||
var child = createApiCategory('bar', 2, false, false);
|
||||
return new ArrayList([child]);
|
||||
};
|
||||
|
||||
var result = new Categories(new ArrayList([category]));
|
||||
assert.equal(result.categories.length, 1);
|
||||
assert.equal(result.categories[0].name, 'foo');
|
||||
assert.isUndefined(result.categories[0].subCategories);
|
||||
});
|
||||
it('should not show menu that is marked as showInMenu false', function () {
|
||||
var category = createApiCategory('foo', 1, true, true);
|
||||
category.getOnlineSubCategories = function () {
|
||||
var child = createApiCategory('bar', 2, true, true);
|
||||
child.getOnlineSubCategories = function () {
|
||||
var subChild = createApiCategory('baz', 3, true, true);
|
||||
subChild.custom.showInMenu = false;
|
||||
return new ArrayList([subChild]);
|
||||
};
|
||||
return new ArrayList([child]);
|
||||
};
|
||||
|
||||
var result = new Categories(new ArrayList([category]));
|
||||
assert.equal(result.categories.length, 1);
|
||||
assert.equal(result.categories[0].subCategories.length, 1);
|
||||
assert.isFalse(result.categories[0].complexSubCategories);
|
||||
assert.equal(result.categories[0].subCategories[0].name, 'bar');
|
||||
assert.isUndefined(result.categories[0].subCategories[0].subCategories);
|
||||
});
|
||||
it('should use alternativeUrl', function () {
|
||||
var category = createApiCategory('foo', 1, true, true);
|
||||
category.custom.alternativeUrl = 22;
|
||||
var apiCategories = new ArrayList([category]);
|
||||
|
||||
var result = new Categories(apiCategories);
|
||||
assert.equal(result.categories.length, 1);
|
||||
assert.equal(result.categories[0].name, 'foo');
|
||||
assert.equal(result.categories[0].url, 22);
|
||||
});
|
||||
it('should not return any categories', function () {
|
||||
var category = createApiCategory('foo', 1, true, true);
|
||||
category.custom.showInMenu = false;
|
||||
var apiCategories = new ArrayList([category]);
|
||||
|
||||
var result = new Categories(apiCategories);
|
||||
assert.equal(result.categories.length, 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var Content = require('../../../../cartridges/app_storefront_base/cartridge/models/content');
|
||||
|
||||
describe('Content', function () {
|
||||
it('should return converted content model', function () {
|
||||
var contentValue = {
|
||||
custom: {
|
||||
body: 'Hello'
|
||||
},
|
||||
name: 'contentAssetName',
|
||||
template: 'templateName',
|
||||
UUID: 22,
|
||||
ID: 'contentAssetID',
|
||||
online: true,
|
||||
pageTitle: 'some title',
|
||||
pageDescription: 'some description',
|
||||
pageKeywords: 'some keywords',
|
||||
pageMetaTags: [{}]
|
||||
};
|
||||
|
||||
var content = new Content(contentValue);
|
||||
|
||||
assert.deepEqual(content, {
|
||||
body: 'Hello',
|
||||
name: 'contentAssetName',
|
||||
template: 'templateName',
|
||||
ID: 'contentAssetID',
|
||||
UUID: 22,
|
||||
pageTitle: 'some title',
|
||||
pageDescription: 'some description',
|
||||
pageKeywords: 'some keywords',
|
||||
pageMetaTags: [{}]
|
||||
});
|
||||
});
|
||||
|
||||
it('should return converted content model without a body', function () {
|
||||
var contentValue = {
|
||||
name: 'contentAssetName',
|
||||
template: 'templateName',
|
||||
UUID: 22,
|
||||
online: true
|
||||
};
|
||||
|
||||
var content = new Content(contentValue);
|
||||
|
||||
assert.isNull(content.body);
|
||||
});
|
||||
|
||||
it('should return converted content model with null for a body', function () {
|
||||
var contentValue = {
|
||||
custom: {},
|
||||
name: 'contentAssetName',
|
||||
template: 'templateName',
|
||||
UUID: 22,
|
||||
online: true
|
||||
};
|
||||
|
||||
var content = new Content(contentValue);
|
||||
|
||||
assert.isNull(content.body);
|
||||
});
|
||||
|
||||
it('should return converted content model with default template', function () {
|
||||
var contentValue = {
|
||||
custom: { body: 'Hello' },
|
||||
name: 'contentAssetName',
|
||||
UUID: 22,
|
||||
online: true
|
||||
};
|
||||
|
||||
var content = new Content(contentValue);
|
||||
|
||||
assert.equal(content.template, 'components/content/contentAssetInc');
|
||||
});
|
||||
|
||||
it('should return undefined for the body if online flag is false', function () {
|
||||
var contentValue = {
|
||||
custom: { body: 'Hello' },
|
||||
name: 'contentAssetName',
|
||||
UUID: 22,
|
||||
online: false
|
||||
};
|
||||
|
||||
var content = new Content(contentValue);
|
||||
|
||||
assert.isUndefined(content.body);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,468 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var allowedLocales;
|
||||
|
||||
describe('locale', function () {
|
||||
var LocaleModel = proxyquire('../../../../cartridges/app_storefront_base/cartridge/models/locale', {
|
||||
'*/cartridge/config/countries': [{
|
||||
'id': 'en_US',
|
||||
'currencyCode': 'USD'
|
||||
}, {
|
||||
'id': 'en_GB',
|
||||
'currencyCode': 'GBP'
|
||||
}, {
|
||||
'id': 'ja_JP',
|
||||
'currencyCode': 'JPY'
|
||||
}, {
|
||||
'id': 'zh_CN',
|
||||
'currencyCode': 'CNY'
|
||||
}, {
|
||||
'id': 'fr_FR',
|
||||
'currencyCode': 'EUR'
|
||||
}, {
|
||||
'id': 'it_IT',
|
||||
'currencyCode': 'EUR'
|
||||
}],
|
||||
'dw/util/Locale': {
|
||||
getLocale: function (localeID) {
|
||||
var returnValue;
|
||||
switch (localeID) {
|
||||
case 'en_US':
|
||||
returnValue = {
|
||||
country: 'US',
|
||||
displayCountry: 'United States',
|
||||
currencyCode: 'USD',
|
||||
displayName: 'English (US)',
|
||||
language: 'en',
|
||||
displayLanguage: 'English'
|
||||
};
|
||||
break;
|
||||
case 'en_GB':
|
||||
returnValue = {
|
||||
country: 'GB',
|
||||
displayCountry: 'United Kingdom',
|
||||
currencyCode: 'GBP',
|
||||
displayName: 'English (UK)',
|
||||
language: 'en',
|
||||
displayLanguage: 'English'
|
||||
};
|
||||
break;
|
||||
case 'fr_FR':
|
||||
returnValue = {
|
||||
country: 'FR',
|
||||
displayCountry: 'France',
|
||||
currencyCode: 'EUR',
|
||||
displayName: 'français',
|
||||
language: 'fr',
|
||||
displayLanguage: 'Français'
|
||||
};
|
||||
break;
|
||||
case 'it_IT':
|
||||
returnValue = {
|
||||
country: 'IT',
|
||||
displayCountry: 'Italia',
|
||||
currencyCode: 'EUR',
|
||||
displayName: 'italiano',
|
||||
language: 'it',
|
||||
displayLanguage: 'Italiano'
|
||||
|
||||
};
|
||||
break;
|
||||
case 'ja_JP':
|
||||
returnValue = {
|
||||
country: 'JP',
|
||||
displayCountry: '日本',
|
||||
currencyCode: 'JPY',
|
||||
displayName: '日本の',
|
||||
language: 'ja',
|
||||
displayLanguage: '日本語'
|
||||
};
|
||||
break;
|
||||
case 'zh_CN':
|
||||
returnValue = {
|
||||
country: 'CN',
|
||||
displayCountry: '中国',
|
||||
currencyCode: 'CNY',
|
||||
displayName: '日本',
|
||||
language: 'zh',
|
||||
displayLanguage: '中国語'
|
||||
};
|
||||
break;
|
||||
default:
|
||||
returnValue = null;
|
||||
}
|
||||
return returnValue;
|
||||
},
|
||||
ID: 'LocaleID'
|
||||
}
|
||||
});
|
||||
|
||||
before(function () {
|
||||
allowedLocales = ['en_GB', 'fr_FR', 'ja_JP', 'zh_CN', 'default', 'it_IT'];
|
||||
});
|
||||
it('should expected locales for en_GB', function () {
|
||||
var currentLocale = {
|
||||
ID: 'en_GB',
|
||||
displayCountry: 'United Kingdom',
|
||||
country: 'GB',
|
||||
displayName: 'English (UK)',
|
||||
language: 'en',
|
||||
displayLanguage: 'English'
|
||||
};
|
||||
var siteId = 'RefArch';
|
||||
var localeModel = new LocaleModel(currentLocale, allowedLocales, siteId);
|
||||
var localeLinksFixtureGB = [
|
||||
{
|
||||
'country': 'JP',
|
||||
'currencyCode': 'JPY',
|
||||
'displayCountry': '日本',
|
||||
'localID': 'ja_JP',
|
||||
'displayName': '日本の',
|
||||
'language': 'ja',
|
||||
'displayLanguage': '日本語'
|
||||
}, {
|
||||
'country': 'CN',
|
||||
'currencyCode': 'CNY',
|
||||
'displayCountry': '中国',
|
||||
'localID': 'zh_CN',
|
||||
'displayName': '日本',
|
||||
'language': 'zh',
|
||||
'displayLanguage': '中国語'
|
||||
}, {
|
||||
'country': 'FR',
|
||||
'currencyCode': 'EUR',
|
||||
'displayCountry': 'France',
|
||||
'localID': 'fr_FR',
|
||||
'displayName': 'français',
|
||||
'language': 'fr',
|
||||
'displayLanguage': 'Français'
|
||||
}, {
|
||||
'country': 'IT',
|
||||
'currencyCode': 'EUR',
|
||||
'displayCountry': 'Italia',
|
||||
'localID': 'it_IT',
|
||||
'displayName': 'italiano',
|
||||
'language': 'it',
|
||||
'displayLanguage': 'Italiano'
|
||||
}
|
||||
];
|
||||
|
||||
assert.deepEqual(localeModel, {
|
||||
'locale': {
|
||||
'countryCode': 'GB',
|
||||
'currencyCode': 'GBP',
|
||||
'localeLinks': localeLinksFixtureGB,
|
||||
'localLinks': localeLinksFixtureGB,
|
||||
'name': 'United Kingdom',
|
||||
'displayName': 'English (UK)',
|
||||
'language': 'en',
|
||||
'displayLanguage': 'English'
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should return proper fr_FR info', function () {
|
||||
var currentLocale = {
|
||||
ID: 'fr_FR',
|
||||
displayCountry: 'France',
|
||||
country: 'FR',
|
||||
displayName: 'français',
|
||||
language: 'fr',
|
||||
displayLanguage: 'Français'
|
||||
};
|
||||
var siteId = 'RefArch';
|
||||
var localeModel = new LocaleModel(currentLocale, allowedLocales, siteId);
|
||||
var localeLinksFixtureFR = [
|
||||
{
|
||||
'country': 'GB',
|
||||
'currencyCode': 'GBP',
|
||||
'displayCountry': 'United Kingdom',
|
||||
'localID': 'en_GB',
|
||||
'displayName': 'English (UK)',
|
||||
'language': 'en',
|
||||
'displayLanguage': 'English'
|
||||
}, {
|
||||
'country': 'JP',
|
||||
'currencyCode': 'JPY',
|
||||
'displayCountry': '日本',
|
||||
'localID': 'ja_JP',
|
||||
'displayName': '日本の',
|
||||
'language': 'ja',
|
||||
'displayLanguage': '日本語'
|
||||
}, {
|
||||
'country': 'CN',
|
||||
'currencyCode': 'CNY',
|
||||
'displayCountry': '中国',
|
||||
'localID': 'zh_CN',
|
||||
'displayName': '日本',
|
||||
'language': 'zh',
|
||||
'displayLanguage': '中国語'
|
||||
}, {
|
||||
'country': 'IT',
|
||||
'currencyCode': 'EUR',
|
||||
'displayCountry': 'Italia',
|
||||
'localID': 'it_IT',
|
||||
'displayName': 'italiano',
|
||||
'language': 'it',
|
||||
'displayLanguage': 'Italiano'
|
||||
}
|
||||
];
|
||||
|
||||
assert.deepEqual(localeModel, {
|
||||
'locale': {
|
||||
'countryCode': 'FR',
|
||||
'currencyCode': 'EUR',
|
||||
'localeLinks': localeLinksFixtureFR,
|
||||
'localLinks': localeLinksFixtureFR,
|
||||
'name': 'France',
|
||||
'displayName': 'français',
|
||||
'language': 'fr',
|
||||
'displayLanguage': 'Français'
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should return proper it_IT info', function () {
|
||||
var currentLocale = {
|
||||
ID: 'it_IT',
|
||||
displayCountry: 'Italia',
|
||||
country: 'IT',
|
||||
displayName: 'italiano',
|
||||
language: 'it',
|
||||
displayLanguage: 'Italiano'
|
||||
};
|
||||
var siteId = 'RefArch';
|
||||
var localeModel = new LocaleModel(currentLocale, allowedLocales, siteId);
|
||||
var localeLinksFixtureIT = [
|
||||
{
|
||||
'country': 'GB',
|
||||
'currencyCode': 'GBP',
|
||||
'displayCountry': 'United Kingdom',
|
||||
'localID': 'en_GB',
|
||||
'displayName': 'English (UK)',
|
||||
'language': 'en',
|
||||
'displayLanguage': 'English'
|
||||
}, {
|
||||
'country': 'JP',
|
||||
'currencyCode': 'JPY',
|
||||
'displayCountry': '日本',
|
||||
'localID': 'ja_JP',
|
||||
'displayName': '日本の',
|
||||
'language': 'ja',
|
||||
'displayLanguage': '日本語'
|
||||
}, {
|
||||
'country': 'CN',
|
||||
'currencyCode': 'CNY',
|
||||
'displayCountry': '中国',
|
||||
'localID': 'zh_CN',
|
||||
'displayName': '日本',
|
||||
'language': 'zh',
|
||||
'displayLanguage': '中国語'
|
||||
}, {
|
||||
'country': 'FR',
|
||||
'currencyCode': 'EUR',
|
||||
'displayCountry': 'France',
|
||||
'localID': 'fr_FR',
|
||||
'displayName': 'français',
|
||||
'language': 'fr',
|
||||
'displayLanguage': 'Français'
|
||||
}
|
||||
];
|
||||
|
||||
assert.deepEqual(localeModel, {
|
||||
'locale': {
|
||||
'countryCode': 'IT',
|
||||
'currencyCode': 'EUR',
|
||||
'localeLinks': localeLinksFixtureIT,
|
||||
'localLinks': localeLinksFixtureIT,
|
||||
'name': 'Italia',
|
||||
'displayName': 'italiano',
|
||||
'language': 'it',
|
||||
'displayLanguage': 'Italiano'
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should return proper JA info', function () {
|
||||
var currentLocale = {
|
||||
ID: 'ja_JP',
|
||||
displayCountry: '日本',
|
||||
country: 'JA',
|
||||
displayName: '日本の',
|
||||
language: 'ja',
|
||||
displayLanguage: '日本語'
|
||||
};
|
||||
var siteId = 'RefArch';
|
||||
var localeModel = new LocaleModel(currentLocale, allowedLocales, siteId);
|
||||
var localeLinksFixtureJP = [
|
||||
{
|
||||
'country': 'GB',
|
||||
'currencyCode': 'GBP',
|
||||
'displayCountry': 'United Kingdom',
|
||||
'localID': 'en_GB',
|
||||
'displayName': 'English (UK)',
|
||||
'language': 'en',
|
||||
'displayLanguage': 'English'
|
||||
}, {
|
||||
'country': 'CN',
|
||||
'currencyCode': 'CNY',
|
||||
'displayCountry': '中国',
|
||||
'localID': 'zh_CN',
|
||||
'displayName': '日本',
|
||||
'language': 'zh',
|
||||
'displayLanguage': '中国語'
|
||||
}, {
|
||||
'country': 'FR',
|
||||
'currencyCode': 'EUR',
|
||||
'displayCountry': 'France',
|
||||
'localID': 'fr_FR',
|
||||
'displayName': 'français',
|
||||
'language': 'fr',
|
||||
'displayLanguage': 'Français'
|
||||
}, {
|
||||
'country': 'IT',
|
||||
'currencyCode': 'EUR',
|
||||
'displayCountry': 'Italia',
|
||||
'localID': 'it_IT',
|
||||
'displayName': 'italiano',
|
||||
'language': 'it',
|
||||
'displayLanguage': 'Italiano'
|
||||
}
|
||||
];
|
||||
|
||||
assert.deepEqual(localeModel, {
|
||||
'locale': {
|
||||
'countryCode': 'JA',
|
||||
'currencyCode': 'JPY',
|
||||
'localeLinks': localeLinksFixtureJP,
|
||||
'localLinks': localeLinksFixtureJP,
|
||||
'name': '日本',
|
||||
'displayName': '日本の',
|
||||
'language': 'ja',
|
||||
'displayLanguage': '日本語'
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should return proper ZN info', function () {
|
||||
var currentLocale = {
|
||||
ID: 'zh_CN',
|
||||
displayCountry: '中国',
|
||||
country: 'CN',
|
||||
displayName: '日本',
|
||||
language: 'zh',
|
||||
displayLanguage: '中国語'
|
||||
};
|
||||
var siteId = 'RefArch';
|
||||
var localeModel = new LocaleModel(currentLocale, allowedLocales, siteId);
|
||||
var localeLinksFixtureZN = [
|
||||
{
|
||||
'country': 'GB',
|
||||
'currencyCode': 'GBP',
|
||||
'displayCountry': 'United Kingdom',
|
||||
'localID': 'en_GB',
|
||||
'displayName': 'English (UK)',
|
||||
'language': 'en',
|
||||
'displayLanguage': 'English'
|
||||
}, {
|
||||
'country': 'JP',
|
||||
'currencyCode': 'JPY',
|
||||
'displayCountry': '日本',
|
||||
'localID': 'ja_JP',
|
||||
'displayName': '日本の',
|
||||
'language': 'ja',
|
||||
'displayLanguage': '日本語'
|
||||
}, {
|
||||
'country': 'FR',
|
||||
'currencyCode': 'EUR',
|
||||
'displayCountry': 'France',
|
||||
'localID': 'fr_FR',
|
||||
'displayName': 'français',
|
||||
'language': 'fr',
|
||||
'displayLanguage': 'Français'
|
||||
}, {
|
||||
'country': 'IT',
|
||||
'currencyCode': 'EUR',
|
||||
'displayCountry': 'Italia',
|
||||
'localID': 'it_IT',
|
||||
'displayName': 'italiano',
|
||||
'language': 'it',
|
||||
'displayLanguage': 'Italiano'
|
||||
}
|
||||
];
|
||||
|
||||
assert.deepEqual(localeModel, {
|
||||
'locale': {
|
||||
'countryCode': 'CN',
|
||||
'currencyCode': 'CNY',
|
||||
'localeLinks': localeLinksFixtureZN,
|
||||
'localLinks': localeLinksFixtureZN,
|
||||
'name': '中国',
|
||||
'displayName': '日本',
|
||||
'language': 'zh',
|
||||
'displayLanguage': '中国語'
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should return proper US info', function () {
|
||||
allowedLocales = ['en_US', 'default'];
|
||||
var currentLocale = {
|
||||
ID: 'en_US',
|
||||
displayCountry: 'United States',
|
||||
country: 'US',
|
||||
displayName: 'English (US)',
|
||||
language: 'en',
|
||||
displayLanguage: 'English'
|
||||
};
|
||||
var siteId = 'RefArch';
|
||||
var localeModel = new LocaleModel(currentLocale, allowedLocales, siteId);
|
||||
var localeLinksFixtureUS = [];
|
||||
|
||||
assert.deepEqual(localeModel, {
|
||||
'locale': {
|
||||
'countryCode': 'US',
|
||||
'currencyCode': 'USD',
|
||||
'localeLinks': localeLinksFixtureUS,
|
||||
'localLinks': localeLinksFixtureUS,
|
||||
'name': 'United States',
|
||||
'displayName': 'English (US)',
|
||||
'language': 'en',
|
||||
'displayLanguage': 'English'
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should return a currentCountry if currentLocale is not set', function () {
|
||||
var currentLocale = {
|
||||
ID: '',
|
||||
displayCountry: '',
|
||||
country: '',
|
||||
displayName: '',
|
||||
language: '',
|
||||
displayLanguage: ''
|
||||
};
|
||||
var siteId = 'RefArch';
|
||||
var localeModel = new LocaleModel(currentLocale, allowedLocales, siteId);
|
||||
var localeLinksFixtureNA = [
|
||||
{
|
||||
'country': 'US',
|
||||
'currencyCode': 'USD',
|
||||
'displayCountry': 'United States',
|
||||
'displayLanguage': 'English',
|
||||
'displayName': 'English (US)',
|
||||
'language': 'en',
|
||||
'localID': 'en_US'
|
||||
}
|
||||
];
|
||||
|
||||
assert.deepEqual(localeModel, {
|
||||
'locale': {
|
||||
'countryCode': '',
|
||||
'currencyCode': 'USD',
|
||||
'name': '',
|
||||
'displayName': '',
|
||||
'language': '',
|
||||
'displayLanguage': '',
|
||||
'localeLinks': localeLinksFixtureNA,
|
||||
'localLinks': localeLinksFixtureNA
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,168 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var Order = require('../../../mocks/models/order');
|
||||
|
||||
var createApiBasket = function () {
|
||||
return {
|
||||
billingAddress: true,
|
||||
defaultShipment: {
|
||||
shippingAddress: true
|
||||
},
|
||||
orderNo: 'some String',
|
||||
creationDate: 'some Date',
|
||||
customerEmail: 'some Email',
|
||||
status: 'some status',
|
||||
productQuantityTotal: 1,
|
||||
totalGrossPrice: {
|
||||
available: true,
|
||||
value: 180.00
|
||||
},
|
||||
totalTax: {
|
||||
available: true,
|
||||
value: 20.00
|
||||
},
|
||||
shippingTotalPrice: {
|
||||
available: true,
|
||||
value: 20.00,
|
||||
subtract: function () {
|
||||
return {
|
||||
value: 20.00
|
||||
};
|
||||
}
|
||||
},
|
||||
discounts: [],
|
||||
adjustedShippingTotalPrice: {
|
||||
value: 20.00,
|
||||
available: true
|
||||
},
|
||||
shipments: [{
|
||||
id: 'me'
|
||||
}],
|
||||
|
||||
getAdjustedMerchandizeTotalPrice: function () {
|
||||
return {
|
||||
subtract: function () {
|
||||
return {
|
||||
value: 100.00
|
||||
};
|
||||
},
|
||||
value: 140.00,
|
||||
available: true
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var config = {
|
||||
numberOfLineItems: '*'
|
||||
};
|
||||
|
||||
describe('Order', function () {
|
||||
it('should handle null parameters', function () {
|
||||
var result = new Order(null, null);
|
||||
assert.equal(result.shipping, null);
|
||||
assert.equal(result.billing, null);
|
||||
assert.equal(result.totals, null);
|
||||
assert.equal(result.items, null);
|
||||
assert.equal(result.steps, null);
|
||||
assert.equal(result.orderNumber, null);
|
||||
assert.equal(result.creationDate, null);
|
||||
assert.equal(result.orderEmail, null);
|
||||
});
|
||||
|
||||
it('should handle a basket object ', function () {
|
||||
var result = new Order(createApiBasket(), { config: config });
|
||||
assert.deepEqual(result.steps, {
|
||||
shipping: {
|
||||
iscompleted: true
|
||||
},
|
||||
billing: {
|
||||
iscompleted: true
|
||||
}
|
||||
});
|
||||
assert.equal(result.orderNumber, 'some String');
|
||||
assert.equal(result.creationDate, 'some Date');
|
||||
assert.equal(result.orderEmail, 'some Email');
|
||||
});
|
||||
|
||||
it('should handle a single lineitem basket object ', function () {
|
||||
var result = new Order(createApiBasket(), { config: {
|
||||
numberOfLineItems: 'single'
|
||||
} });
|
||||
assert.equal(result.shippedToFirstName, 'someString');
|
||||
assert.equal(result.shippedToLastName, '');
|
||||
assert.equal(result.orderNumber, 'some String');
|
||||
assert.equal(result.creationDate, 'some Date');
|
||||
assert.equal(result.orderEmail, 'some Email');
|
||||
});
|
||||
|
||||
// !!! NOT APPLICABLE
|
||||
// ... every lineItemContainer (basket/order) has a defaultShipment
|
||||
it('should handle a basket that does not have a defaultShipment', function () {
|
||||
var basket = createApiBasket();
|
||||
basket.billingAddress = true;
|
||||
basket.defaultShipment = null;
|
||||
|
||||
var result = new Order(basket, { config: config });
|
||||
assert.deepEqual(result.steps, {
|
||||
shipping: {
|
||||
iscompleted: true
|
||||
},
|
||||
billing: {
|
||||
iscompleted: true
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the subset of the order model when using config.numberOfLineItems = "single".', function () {
|
||||
var basket = createApiBasket();
|
||||
config = {
|
||||
numberOfLineItems: 'single'
|
||||
};
|
||||
|
||||
basket.productLineItems = [{
|
||||
length: 2,
|
||||
quantity: {
|
||||
value: 1
|
||||
},
|
||||
|
||||
items: [
|
||||
{
|
||||
product: {
|
||||
images: {
|
||||
small: [
|
||||
{
|
||||
url: 'url to small image',
|
||||
alt: 'url to small image',
|
||||
title: 'url to small image'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
}];
|
||||
|
||||
basket.shipping = [{
|
||||
shippingAddress: {
|
||||
firstName: 'John',
|
||||
lastName: 'Snow'
|
||||
}
|
||||
}];
|
||||
|
||||
basket.totals = {
|
||||
grandTotal: '$129.87'
|
||||
};
|
||||
|
||||
var result = new Order(basket, { config: config });
|
||||
assert.equal(result.creationDate, 'some Date');
|
||||
assert.equal(result.productQuantityTotal, 1);
|
||||
// assert.equal(result.priceTotal, basket.totalGrossPrice.value);
|
||||
assert.equal(result.orderStatus, 'some status');
|
||||
assert.equal(result.orderNumber, 'some String');
|
||||
assert.equal(result.orderEmail, 'some Email');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var ArrayList = require('../../../mocks/dw.util.Collection');
|
||||
|
||||
var paymentMethods = new ArrayList([
|
||||
{
|
||||
ID: 'GIFT_CERTIFICATE',
|
||||
name: 'Gift Certificate'
|
||||
},
|
||||
{
|
||||
ID: 'CREDIT_CARD',
|
||||
name: 'Credit Card'
|
||||
}
|
||||
]);
|
||||
|
||||
var paymentCards = new ArrayList([
|
||||
{
|
||||
cardType: 'Visa',
|
||||
name: 'Visa',
|
||||
UUID: 'some UUID'
|
||||
},
|
||||
{
|
||||
cardType: 'Amex',
|
||||
name: 'American Express',
|
||||
UUID: 'some UUID'
|
||||
},
|
||||
{
|
||||
cardType: 'Discover',
|
||||
name: 'Discover'
|
||||
}
|
||||
]);
|
||||
|
||||
var paymentInstruments = new ArrayList([
|
||||
{
|
||||
creditCardNumberLastDigits: '1111',
|
||||
creditCardHolder: 'The Muffin Man',
|
||||
creditCardExpirationYear: 2018,
|
||||
creditCardType: 'Visa',
|
||||
maskedCreditCardNumber: '************1111',
|
||||
paymentMethod: 'CREDIT_CARD',
|
||||
creditCardExpirationMonth: 1,
|
||||
paymentTransaction: {
|
||||
amount: {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
giftCertificateCode: 'someString',
|
||||
maskedGiftCertificateCode: 'some masked string',
|
||||
paymentMethod: 'GIFT_CERTIFICATE',
|
||||
paymentTransaction: {
|
||||
amount: {
|
||||
value: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
function createApiBasket(options) {
|
||||
var basket = {
|
||||
totalGrossPrice: {
|
||||
value: 'some value'
|
||||
}
|
||||
};
|
||||
|
||||
if (options && options.paymentMethods) {
|
||||
basket.paymentMethods = options.paymentMethods;
|
||||
}
|
||||
|
||||
if (options && options.paymentCards) {
|
||||
basket.paymentCards = options.paymentCards;
|
||||
}
|
||||
|
||||
if (options && options.paymentInstruments) {
|
||||
basket.paymentInstruments = options.paymentInstruments;
|
||||
}
|
||||
|
||||
return basket;
|
||||
}
|
||||
|
||||
describe('Payment', function () {
|
||||
var PaymentModel = require('../../../mocks/models/payment');
|
||||
|
||||
it('should take payment Methods and convert to a plain object ', function () {
|
||||
var result = new PaymentModel(createApiBasket({ paymentMethods: paymentMethods }), null);
|
||||
assert.equal(result.applicablePaymentMethods.length, 2);
|
||||
assert.equal(result.applicablePaymentMethods[0].ID, 'GIFT_CERTIFICATE');
|
||||
assert.equal(result.applicablePaymentMethods[0].name, 'Gift Certificate');
|
||||
assert.equal(result.applicablePaymentMethods[1].ID, 'CREDIT_CARD');
|
||||
assert.equal(result.applicablePaymentMethods[1].name, 'Credit Card');
|
||||
});
|
||||
|
||||
it('should take payment cards and convert to a plain object ', function () {
|
||||
var result = new PaymentModel(createApiBasket({ paymentCards: paymentCards }), null);
|
||||
assert.equal(
|
||||
result.applicablePaymentCards.length, 3
|
||||
);
|
||||
assert.equal(result.applicablePaymentCards[0].cardType, 'Visa');
|
||||
assert.equal(result.applicablePaymentCards[0].name, 'Visa');
|
||||
assert.equal(result.applicablePaymentCards[1].cardType, 'Amex');
|
||||
assert.equal(result.applicablePaymentCards[1].name, 'American Express');
|
||||
});
|
||||
|
||||
it('should take payment instruments and convert to a plain object ', function () {
|
||||
var result = new PaymentModel(createApiBasket({ paymentInstruments: paymentInstruments }), null);
|
||||
assert.equal(
|
||||
result.selectedPaymentInstruments.length, 2
|
||||
);
|
||||
assert.equal(result.selectedPaymentInstruments[0].lastFour, '1111');
|
||||
assert.equal(result.selectedPaymentInstruments[0].owner, 'The Muffin Man');
|
||||
assert.equal(result.selectedPaymentInstruments[0].expirationYear, 2018);
|
||||
assert.equal(result.selectedPaymentInstruments[0].type, 'Visa');
|
||||
assert.equal(
|
||||
result.selectedPaymentInstruments[0].maskedCreditCardNumber,
|
||||
'************1111'
|
||||
);
|
||||
assert.equal(result.selectedPaymentInstruments[0].paymentMethod, 'CREDIT_CARD');
|
||||
assert.equal(result.selectedPaymentInstruments[0].expirationMonth, 1);
|
||||
assert.equal(result.selectedPaymentInstruments[0].amount, 0);
|
||||
|
||||
assert.equal(result.selectedPaymentInstruments[1].giftCertificateCode, 'someString');
|
||||
assert.equal(
|
||||
result.selectedPaymentInstruments[1].maskedGiftCertificateCode,
|
||||
'some masked string'
|
||||
);
|
||||
assert.equal(result.selectedPaymentInstruments[1].paymentMethod, 'GIFT_CERTIFICATE');
|
||||
assert.equal(result.selectedPaymentInstruments[1].amount, 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
|
||||
describe('DefaultPrice model', function () {
|
||||
var formattedMoney = '₪moolah';
|
||||
var DefaultPrice = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/price/default.js', {
|
||||
'dw/value/Money': function () {},
|
||||
'dw/util/StringUtils': {
|
||||
formatMoney: function () { return formattedMoney; }
|
||||
}
|
||||
});
|
||||
var salesPrice;
|
||||
var listPrice;
|
||||
var decimalValue = 'decimalValue';
|
||||
var currencyCode = 'ABC';
|
||||
var defaultPrice;
|
||||
function getDecimalValue() {
|
||||
return {
|
||||
get: function () {
|
||||
return decimalValue;
|
||||
}
|
||||
};
|
||||
}
|
||||
function getCurrencyCode() {
|
||||
return currencyCode;
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
salesPrice = {
|
||||
available: true,
|
||||
getDecimalValue: getDecimalValue,
|
||||
getCurrencyCode: getCurrencyCode
|
||||
};
|
||||
|
||||
listPrice = {
|
||||
available: true,
|
||||
getDecimalValue: getDecimalValue,
|
||||
getCurrencyCode: getCurrencyCode
|
||||
};
|
||||
});
|
||||
|
||||
it('should have a sales price', function () {
|
||||
defaultPrice = new DefaultPrice(salesPrice);
|
||||
|
||||
assert.deepEqual(defaultPrice, {
|
||||
list: null,
|
||||
sales: {
|
||||
currency: currencyCode,
|
||||
formatted: formattedMoney,
|
||||
value: decimalValue,
|
||||
decimalPrice: '[object Object]'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should set property values to null if price is not available', function () {
|
||||
salesPrice.available = false;
|
||||
defaultPrice = new DefaultPrice(salesPrice);
|
||||
assert.deepEqual(defaultPrice, {
|
||||
list: null,
|
||||
sales: {
|
||||
currency: null,
|
||||
formatted: null,
|
||||
value: null,
|
||||
decimalPrice: undefined
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should set list price when provided', function () {
|
||||
defaultPrice = new DefaultPrice(salesPrice, listPrice);
|
||||
assert.deepEqual(defaultPrice, {
|
||||
list: {
|
||||
currency: currencyCode,
|
||||
formatted: formattedMoney,
|
||||
value: decimalValue,
|
||||
decimalPrice: '[object Object]'
|
||||
},
|
||||
sales: {
|
||||
currency: currencyCode,
|
||||
formatted: formattedMoney,
|
||||
value: decimalValue,
|
||||
decimalPrice: '[object Object]'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
|
||||
describe('Range Price Model', function () {
|
||||
var defaultPrice = sinon.spy();
|
||||
var RangePrice = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/price/range.js', {
|
||||
'*/cartridge/models/price/default': defaultPrice
|
||||
});
|
||||
var minPrice = '$5';
|
||||
var maxPrice = '$15';
|
||||
|
||||
it('should set type property value to "range"', function () {
|
||||
var rangePrice = new RangePrice(minPrice, maxPrice);
|
||||
assert.equal(rangePrice.type, 'range');
|
||||
});
|
||||
|
||||
it('should set min property to a DefaultPrice instance', function () {
|
||||
new RangePrice(minPrice, maxPrice);
|
||||
assert.isTrue(defaultPrice.calledWithNew());
|
||||
assert.isTrue(defaultPrice.calledWith(minPrice));
|
||||
defaultPrice.reset();
|
||||
});
|
||||
|
||||
it('should set max property to a DefaultPrice instance', function () {
|
||||
new RangePrice(minPrice, maxPrice);
|
||||
assert.isTrue(defaultPrice.calledWithNew());
|
||||
assert.isTrue(defaultPrice.calledWith(maxPrice));
|
||||
defaultPrice.reset();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var mockCollections = require('../../../../mocks/util/collections');
|
||||
var sinon = require('sinon');
|
||||
|
||||
|
||||
describe('Tiered Price Model', function () {
|
||||
function MockQuantity(qty) {
|
||||
this.getValue = function () { return qty; };
|
||||
}
|
||||
|
||||
var tierValues = {
|
||||
'1-5': { value: 20 },
|
||||
'6-10': { value: 10 }
|
||||
};
|
||||
var tierQty = Object.keys(tierValues);
|
||||
var stubDefaultPrice = sinon.stub();
|
||||
var firstTierPrice = { sales: tierValues[tierQty[0]] };
|
||||
var secondTierPrice = { sales: tierValues[tierQty[1]] };
|
||||
var lowestTierPrice = secondTierPrice;
|
||||
stubDefaultPrice.onCall(0).returns(firstTierPrice);
|
||||
stubDefaultPrice.onCall(1).returns(secondTierPrice);
|
||||
|
||||
var priceTable = {
|
||||
getQuantities: function () {
|
||||
return Object.keys(tierValues).map(function (qty) {
|
||||
return new MockQuantity(qty);
|
||||
});
|
||||
},
|
||||
getPrice: function (qty) {
|
||||
return tierValues[qty.getValue()];
|
||||
}
|
||||
};
|
||||
var TieredPrice = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/price/tiered.js', {
|
||||
'*/cartridge/scripts/util/collections': { map: mockCollections.map },
|
||||
'*/cartridge/models/price/default': stubDefaultPrice
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
stubDefaultPrice.reset();
|
||||
});
|
||||
|
||||
it('should set startingFromPrice to the lowest tier price', function () {
|
||||
var tieredPrice = new TieredPrice(priceTable);
|
||||
assert.equal(tieredPrice.startingFromPrice, lowestTierPrice);
|
||||
});
|
||||
|
||||
it('should set a tier to its proper quantity/price pairing', function () {
|
||||
var tieredPrice = new TieredPrice(priceTable);
|
||||
assert.equal(tieredPrice.tiers[1].quantity, tierQty[1]);
|
||||
assert.equal(tieredPrice.tiers[1].price, secondTierPrice);
|
||||
});
|
||||
|
||||
it('should have type property value of "tiered"', function () {
|
||||
var tieredPrice = new TieredPrice(priceTable);
|
||||
assert.equal(tieredPrice.type, 'tiered');
|
||||
});
|
||||
|
||||
it('should set useSimplePrice to false by default', function () {
|
||||
var tieredPrice = new TieredPrice(priceTable);
|
||||
assert.equal(tieredPrice.useSimplePrice, false);
|
||||
});
|
||||
|
||||
it('should set useSimplePrice to true when provided', function () {
|
||||
var tieredPrice = new TieredPrice(priceTable, true);
|
||||
assert.equal(tieredPrice.useSimplePrice, true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,176 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var object = {};
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID'
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: []
|
||||
};
|
||||
|
||||
describe('Bonus Product Model Model', function () {
|
||||
var decorators = require('../../../../mocks/productDecoratorsMock');
|
||||
|
||||
var bonusProduct = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/product/bonusProduct', {
|
||||
'*/cartridge/models/product/decorators/index': decorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
decorators.stubs.stubBase.reset();
|
||||
decorators.stubs.stubPrice.reset();
|
||||
decorators.stubs.stubImages.reset();
|
||||
decorators.stubs.stubAvailability.reset();
|
||||
decorators.stubs.stubDescription.reset();
|
||||
decorators.stubs.stubSearchPrice.reset();
|
||||
decorators.stubs.stubPromotions.reset();
|
||||
decorators.stubs.stubQuantity.reset();
|
||||
decorators.stubs.stubQuantitySelector.reset();
|
||||
decorators.stubs.stubRatings.reset();
|
||||
decorators.stubs.stubSizeChart.reset();
|
||||
decorators.stubs.stubVariationAttributes.reset();
|
||||
decorators.stubs.stubSearchVariationAttributes.reset();
|
||||
decorators.stubs.stubAttributes.reset();
|
||||
decorators.stubs.stubOptions.reset();
|
||||
decorators.stubs.stubCurrentUrl.reset();
|
||||
decorators.stubs.stubReadyToOrder.reset();
|
||||
decorators.stubs.stubSetReadyToOrder.reset();
|
||||
decorators.stubs.stubBundleReadyToOrder.reset();
|
||||
decorators.stubs.stubSetIndividualProducts.reset();
|
||||
decorators.stubs.stubBundledProducts.reset();
|
||||
decorators.stubs.stubBonusUnitPrice.reset();
|
||||
});
|
||||
|
||||
it('should call base for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call price for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantity for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should call variationAttributes for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call description for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubDescription.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call ratings for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubRatings.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call promotion for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call attributes for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call availability for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should call options for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantitySelector for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubQuantitySelector.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call sizeChart for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubSizeChart.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call currentUrl for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubCurrentUrl.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call setIndividualProducts for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubSetIndividualProducts.calledOnce);
|
||||
});
|
||||
|
||||
it('should call setReadyToOrder for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubSetReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call bundleReadyToOrder for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubBundleReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should call readyToOrder for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bonusUnitPrice for bonus product', function () {
|
||||
bonusProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubBonusUnitPrice.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var attributeModel = {
|
||||
visibleAttributeGroups: new ArrayList([{
|
||||
ID: 'some ID',
|
||||
displayName: 'some name'
|
||||
}]),
|
||||
getVisibleAttributeDefinitions: function () {
|
||||
return new ArrayList([{
|
||||
multiValueType: false,
|
||||
displayName: 'some name'
|
||||
}]);
|
||||
},
|
||||
getDisplayValue: function () {
|
||||
return 'some value';
|
||||
}
|
||||
};
|
||||
|
||||
var multiValueTypeAttribute = {
|
||||
visibleAttributeGroups: new ArrayList([{
|
||||
ID: 'some ID',
|
||||
displayName: 'some name'
|
||||
}]),
|
||||
getVisibleAttributeDefinitions: function () {
|
||||
return new ArrayList([{
|
||||
multiValueType: true,
|
||||
displayName: 'some name'
|
||||
}]);
|
||||
},
|
||||
getDisplayValue: function () {
|
||||
return [1, 2, 3];
|
||||
}
|
||||
};
|
||||
|
||||
describe('product attributes decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var attributes = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/attributes', {
|
||||
'*/cartridge/scripts/util/collections': collections
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called attributes', function () {
|
||||
var object = {};
|
||||
attributes(object, attributeModel);
|
||||
|
||||
assert.equal(object.attributes.length, 1);
|
||||
assert.equal(object.attributes[0].ID, 'some ID');
|
||||
assert.equal(object.attributes[0].name, 'some name');
|
||||
assert.equal(object.attributes[0].attributes.length, 1);
|
||||
});
|
||||
|
||||
it('should handle no visible attribute groups', function () {
|
||||
var object = {};
|
||||
attributeModel.visibleAttributeGroups = new ArrayList([]);
|
||||
attributes(object, attributeModel);
|
||||
|
||||
assert.equal(object.attributes, null);
|
||||
});
|
||||
|
||||
it('should handle multi value type attribute definition', function () {
|
||||
var object = {};
|
||||
attributes(object, multiValueTypeAttribute);
|
||||
|
||||
assert.equal(object.attributes.length, 1);
|
||||
assert.equal(object.attributes[0].ID, 'some ID');
|
||||
assert.equal(object.attributes[0].name, 'some name');
|
||||
assert.equal(object.attributes[0].attributes.length, 1);
|
||||
assert.equal(object.attributes[0].attributes[0].label, 'some name');
|
||||
assert.equal(object.attributes[0].attributes[0].value.length, 3);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,146 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var stockLevels = {
|
||||
inStock: {
|
||||
value: 2
|
||||
},
|
||||
preorder: {
|
||||
value: 0
|
||||
},
|
||||
backorder: {
|
||||
value: 0
|
||||
},
|
||||
notAvailable: {
|
||||
value: 0
|
||||
}
|
||||
};
|
||||
|
||||
var availabilityModelMock = {
|
||||
getAvailabilityLevels: function () {
|
||||
return stockLevels;
|
||||
},
|
||||
inventoryRecord: {
|
||||
inStockDate: {
|
||||
toDateString: function () {
|
||||
return 'some date';
|
||||
}
|
||||
}
|
||||
},
|
||||
isOrderable: function () {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
describe('product availability decorator', function () {
|
||||
var availability = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/availability', {
|
||||
'dw/web/Resource': {
|
||||
msgf: function (params) { return params; },
|
||||
msg: function (params) { return params; }
|
||||
}
|
||||
});
|
||||
|
||||
it('should receive product in stock availability message', function () {
|
||||
var object = {};
|
||||
availability(object, 2, 2, availabilityModelMock);
|
||||
|
||||
assert.equal(object.availability.messages.length, 1);
|
||||
assert.equal(object.availability.messages[0], 'label.instock');
|
||||
assert.equal(object.availability.inStockDate, 'some date');
|
||||
});
|
||||
|
||||
it('should receive product pre order stock availability message', function () {
|
||||
var object = {};
|
||||
stockLevels.inStock.value = 0;
|
||||
stockLevels.preorder.value = 2;
|
||||
availability(object, null, 2, availabilityModelMock);
|
||||
|
||||
assert.equal(object.availability.messages.length, 1);
|
||||
assert.equal(object.availability.messages[0], 'label.preorder');
|
||||
});
|
||||
|
||||
it('should receive product back order stock availability message', function () {
|
||||
var object = {};
|
||||
stockLevels.inStock.value = 0;
|
||||
stockLevels.preorder.value = 0;
|
||||
stockLevels.backorder.value = 2;
|
||||
|
||||
availability(object, 2, 2, availabilityModelMock);
|
||||
|
||||
assert.equal(object.availability.messages.length, 1);
|
||||
assert.equal(object.availability.messages[0], 'label.back.order');
|
||||
});
|
||||
|
||||
it('should receive product not available message', function () {
|
||||
var object = {};
|
||||
stockLevels.inStock.value = 0;
|
||||
stockLevels.preorder.value = 0;
|
||||
stockLevels.backorder.value = 0;
|
||||
stockLevels.notAvailable.value = 2;
|
||||
|
||||
availability(object, 2, 2, availabilityModelMock);
|
||||
|
||||
assert.equal(object.availability.messages.length, 1);
|
||||
assert.equal(object.availability.messages[0], 'label.not.available');
|
||||
});
|
||||
|
||||
it('should receive in stock and not available messages', function () {
|
||||
var object = {};
|
||||
stockLevels.inStock.value = 1;
|
||||
stockLevels.preorder.value = 0;
|
||||
stockLevels.backorder.value = 0;
|
||||
stockLevels.notAvailable.value = 1;
|
||||
|
||||
availability(object, 2, 2, availabilityModelMock);
|
||||
|
||||
assert.equal(object.availability.messages.length, 2);
|
||||
assert.equal(object.availability.messages[0], 'label.quantity.in.stock');
|
||||
assert.equal(object.availability.messages[1], 'label.not.available.items');
|
||||
});
|
||||
|
||||
it('should receive in stock and pre order messages', function () {
|
||||
var object = {};
|
||||
stockLevels.inStock.value = 1;
|
||||
stockLevels.preorder.value = 1;
|
||||
stockLevels.backorder.value = 0;
|
||||
stockLevels.notAvailable.value = 0;
|
||||
|
||||
availability(object, 2, 2, availabilityModelMock);
|
||||
|
||||
assert.equal(object.availability.messages.length, 2);
|
||||
assert.equal(object.availability.messages[0], 'label.quantity.in.stock');
|
||||
assert.equal(object.availability.messages[1], 'label.preorder.items');
|
||||
});
|
||||
|
||||
it('should receive in stock and back order messages', function () {
|
||||
var object = {};
|
||||
stockLevels.inStock.value = 1;
|
||||
stockLevels.preorder.value = 0;
|
||||
stockLevels.backorder.value = 1;
|
||||
stockLevels.notAvailable.value = 0;
|
||||
|
||||
availability(object, 2, 2, availabilityModelMock);
|
||||
|
||||
assert.equal(object.availability.messages.length, 2);
|
||||
assert.equal(object.availability.messages[0], 'label.quantity.in.stock');
|
||||
assert.equal(object.availability.messages[1], 'label.back.order.items');
|
||||
});
|
||||
|
||||
it('should receive in stock date null', function () {
|
||||
var object = {};
|
||||
availabilityModelMock.inventoryRecord = null;
|
||||
|
||||
availability(object, 2, 2, availabilityModelMock);
|
||||
|
||||
assert.equal(object.availability.inStockDate, null);
|
||||
});
|
||||
|
||||
it('should receive in available true', function () {
|
||||
var object = {};
|
||||
availability(object, 2, 2, availabilityModelMock);
|
||||
|
||||
assert.isTrue(object.available);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var productModelMock = {
|
||||
ID: 'some ID',
|
||||
name: 'some name',
|
||||
UUID: 'some UUID',
|
||||
brand: 'some brand'
|
||||
};
|
||||
|
||||
describe('product base decorator', function () {
|
||||
var base = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/base');
|
||||
|
||||
it('should create uuid property for passed in object', function () {
|
||||
var object = {};
|
||||
base(object, productModelMock, 'variant');
|
||||
|
||||
assert.equal(object.uuid, 'some UUID');
|
||||
});
|
||||
|
||||
it('should create id property for passed in object', function () {
|
||||
var object = {};
|
||||
base(object, productModelMock, 'variant');
|
||||
|
||||
assert.equal(object.id, 'some ID');
|
||||
});
|
||||
|
||||
it('should create productName property for passed in object', function () {
|
||||
var object = {};
|
||||
base(object, productModelMock, 'variant');
|
||||
|
||||
assert.equal(object.productName, 'some name');
|
||||
});
|
||||
|
||||
it('should create productType property for passed in object', function () {
|
||||
var object = {};
|
||||
base(object, productModelMock, 'variant');
|
||||
|
||||
assert.equal(object.productType, 'variant');
|
||||
});
|
||||
|
||||
it('should create brand property for passed in object', function () {
|
||||
var object = {};
|
||||
base(object, productModelMock, 'variant');
|
||||
|
||||
assert.equal(object.brand, 'some brand');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var currentBasketMock = {
|
||||
getBonusDiscountLineItems: function () {
|
||||
return new ArrayList([
|
||||
{
|
||||
UUID: 'someUUID',
|
||||
getBonusProductPrice: function () {
|
||||
return {
|
||||
toFormattedString: function () {
|
||||
return 'someFormattedString';
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
var productMock = {};
|
||||
|
||||
describe('bonus product unit price', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
var bonusUnitPrice = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/bonusUnitPrice', {
|
||||
'dw/order/BasketMgr': {
|
||||
getCurrentBasket: function () {
|
||||
return currentBasketMock;
|
||||
}
|
||||
},
|
||||
'*/cartridge/scripts/util/collections': collections
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called bonusUnitPrice', function () {
|
||||
var object = {};
|
||||
var discountLineItemUUIDMock = 'someUUID';
|
||||
bonusUnitPrice(object, productMock, discountLineItemUUIDMock);
|
||||
|
||||
assert.equal(object.bonusUnitPrice, 'someFormattedString');
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called bonusUnitPrice when UUIDs do not match', function () {
|
||||
var object = {};
|
||||
var discountLineItemUUIDMock = 'someOtherUUID';
|
||||
bonusUnitPrice(object, productMock, discountLineItemUUIDMock);
|
||||
|
||||
assert.equal(object.bonusUnitPrice, '');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('bundle ready to order decorator', function () {
|
||||
var readyToOrder = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/bundleReadyToOrder');
|
||||
|
||||
it('should create readyToOrder property for passed in object', function () {
|
||||
var object = {};
|
||||
object.bundledProducts = [{
|
||||
available: true,
|
||||
readyToOrder: true
|
||||
}];
|
||||
readyToOrder(object);
|
||||
|
||||
assert.isTrue(object.readyToOrder);
|
||||
});
|
||||
|
||||
it('should create readyToOrder property for passed in object', function () {
|
||||
var object = {};
|
||||
object.bundledProducts = [{
|
||||
available: false,
|
||||
readyToOrder: false
|
||||
}];
|
||||
readyToOrder(object);
|
||||
|
||||
assert.isFalse(object.readyToOrder);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var productMock = {
|
||||
bundledProducts: new ArrayList([{
|
||||
ID: 'some id'
|
||||
}]),
|
||||
getBundledProductQuantity: function () {
|
||||
return 'quantity of individual product';
|
||||
}
|
||||
};
|
||||
|
||||
var quantity = 1;
|
||||
|
||||
var productFactoryMock = {
|
||||
get: function () {
|
||||
return 'some product';
|
||||
}
|
||||
};
|
||||
|
||||
describe('bundled product decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var bundledProducts = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/bundledProducts', {
|
||||
'*/cartridge/scripts/util/collections': collections
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called bundledProducts', function () {
|
||||
var object = {};
|
||||
bundledProducts(object, productMock, quantity, productFactoryMock);
|
||||
|
||||
assert.equal(object.bundledProducts.length, 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var variationModelMock = {
|
||||
url: function () {
|
||||
return { relative: function () { return { toString: function () { return 'some string url'; } }; } };
|
||||
}
|
||||
};
|
||||
var optionModelMock = {};
|
||||
var endpoint = 'some end point';
|
||||
var id = 'some id';
|
||||
var quantity = 1;
|
||||
|
||||
describe('selected product url decorator', function () {
|
||||
var currentUrl = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/currentUrl', {
|
||||
'*/cartridge/scripts/helpers/productHelpers': {
|
||||
getSelectedOptionsUrl: function () { return 'Some-EndPoint?dwopt_sony-kdl-70xbr7_tvWarranty=000&pid=sony-kdl-70xbr7'; }
|
||||
},
|
||||
'*/cartridge/scripts/helpers/urlHelpers': {
|
||||
appendQueryParams: function () { return 'Target URL appended with query params from sourceQueryString'; }
|
||||
},
|
||||
'dw/web/URLUtils': {
|
||||
url: function () {
|
||||
return { relative: function () { return { toString: function () { return 'some string url'; } }; } };
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called selectedProductUrl', function () {
|
||||
var object = {};
|
||||
currentUrl(object, variationModelMock, optionModelMock, endpoint, id, quantity);
|
||||
|
||||
assert.equal(object.selectedProductUrl, 'Target URL appended with query params from sourceQueryString');
|
||||
});
|
||||
|
||||
it('selectedProductUrl when no endpoint is passed in', function () {
|
||||
var object = {};
|
||||
currentUrl(object, variationModelMock, optionModelMock, null, id, quantity);
|
||||
|
||||
assert.equal(object.selectedProductUrl, 'Target URL appended with query params from sourceQueryString');
|
||||
});
|
||||
|
||||
it('selectedProductUrl when no variation model is passed in', function () {
|
||||
var object = {};
|
||||
currentUrl(object, null, optionModelMock, null, id, quantity);
|
||||
|
||||
assert.equal(object.selectedProductUrl, 'Target URL appended with query params from sourceQueryString');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var productMock = {
|
||||
longDescription: {
|
||||
markup: 'long description mark up'
|
||||
},
|
||||
shortDescription: {
|
||||
markup: 'short description mark up'
|
||||
}
|
||||
};
|
||||
|
||||
var productMockNoDescription = {};
|
||||
|
||||
describe('product description decorator', function () {
|
||||
var description = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/description');
|
||||
|
||||
it('should create longDescription property for passed in object', function () {
|
||||
var object = {};
|
||||
description(object, productMock);
|
||||
|
||||
assert.equal(object.longDescription, 'long description mark up');
|
||||
});
|
||||
|
||||
it('should handle null long description', function () {
|
||||
var object = {};
|
||||
description(object, productMockNoDescription);
|
||||
|
||||
assert.equal(object.longDescription, null);
|
||||
});
|
||||
|
||||
it('should create shortDescription property for passed in object', function () {
|
||||
var object = {};
|
||||
description(object, productMock);
|
||||
|
||||
assert.equal(object.shortDescription, 'short description mark up');
|
||||
});
|
||||
|
||||
it('should handel null short description', function () {
|
||||
var object = {};
|
||||
description(object, productMockNoDescription);
|
||||
|
||||
assert.equal(object.shortDescription, null);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var productMock = {
|
||||
getImages: function () {
|
||||
return new ArrayList([]);
|
||||
}
|
||||
};
|
||||
|
||||
describe('product images decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var imagesModel = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/productImages', {
|
||||
'*/cartridge/scripts/util/collections': collections
|
||||
});
|
||||
|
||||
var images = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/images', {
|
||||
'*/cartridge/models/product/productImages': imagesModel
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called images', function () {
|
||||
var object = {};
|
||||
images(object, productMock, { types: ['large', 'small'], quantity: 'all' });
|
||||
|
||||
assert.equal(object.images.large.length, 0);
|
||||
assert.equal(object.images.small.length, 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('product is online decorator', function () {
|
||||
var online = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/online');
|
||||
|
||||
var apiProductMock = {
|
||||
online: true
|
||||
};
|
||||
|
||||
var apiProductMock2 = {};
|
||||
|
||||
it('should return true property for passed in object', function () {
|
||||
var object = {};
|
||||
online(object, apiProductMock);
|
||||
assert.equal(object.online, true);
|
||||
});
|
||||
|
||||
it('should return false property for passed in object', function () {
|
||||
var object = {};
|
||||
online(object, apiProductMock2);
|
||||
assert.equal(object.online, false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
describe('product options decorator', function () {
|
||||
var options = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/options', {
|
||||
'*/cartridge/scripts/helpers/productHelpers': {
|
||||
getOptions: function () { return []; }
|
||||
}
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called options', function () {
|
||||
var object = {};
|
||||
options(object, {}, {}, 1);
|
||||
|
||||
assert.equal(object.options.length, 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var productModelMock = {
|
||||
pageTitle: 'some title',
|
||||
pageDescription: 'some description',
|
||||
pageKeywords: 'some keywords',
|
||||
pageMetaTags: [{}]
|
||||
};
|
||||
|
||||
describe('product pageMetaData decorator', function () {
|
||||
var pageMetaData = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/pageMetaData');
|
||||
|
||||
it('should create pageTitle property for passed in object', function () {
|
||||
var object = {};
|
||||
pageMetaData(object, productModelMock);
|
||||
|
||||
assert.equal(object.pageTitle, 'some title');
|
||||
});
|
||||
|
||||
it('should create pageDescription property for passed in object', function () {
|
||||
var object = {};
|
||||
pageMetaData(object, productModelMock);
|
||||
|
||||
assert.equal(object.pageDescription, 'some description');
|
||||
});
|
||||
|
||||
it('should create pageKeywords property for passed in object', function () {
|
||||
var object = {};
|
||||
pageMetaData(object, productModelMock);
|
||||
|
||||
assert.equal(object.pageKeywords, 'some keywords');
|
||||
});
|
||||
|
||||
it('should create pageMetaTags property for passed in object', function () {
|
||||
var object = {};
|
||||
pageMetaData(object, productModelMock);
|
||||
|
||||
assert.deepEqual(object.pageMetaTags, [{}]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
var renderHtmlStub = sinon.stub();
|
||||
var getHtmlContextStub = sinon.stub();
|
||||
|
||||
describe('product price decorator', function () {
|
||||
var price = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/price', {
|
||||
'*/cartridge/scripts/factories/price': {
|
||||
getPrice: function () { return 'Product Price'; }
|
||||
},
|
||||
'../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/price': {
|
||||
getRenderedPrice: function () { return 'Rendered Price'; }
|
||||
},
|
||||
'*/cartridge/scripts/helpers/pricing': {
|
||||
renderHtml: renderHtmlStub.returns('Rendered Price'),
|
||||
getHtmlContext: getHtmlContextStub
|
||||
}
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called price', function () {
|
||||
var object = {};
|
||||
price(object, {}, {}, true, {});
|
||||
assert.equal(object.price, 'Product Price');
|
||||
});
|
||||
it('should create a property on the passed in object called renderedPrice', function () {
|
||||
var renderedObject = {};
|
||||
price(renderedObject);
|
||||
assert.equal(renderedObject.renderedPrice, 'Rendered Price');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var promotionMock = {
|
||||
calloutMsg: {
|
||||
markup: 'callout message mark up'
|
||||
},
|
||||
details: {
|
||||
markup: 'details mark up'
|
||||
},
|
||||
enabled: true,
|
||||
ID: 'someID',
|
||||
name: 'someName',
|
||||
promotionClass: 'someClass',
|
||||
rank: 'someRank'
|
||||
};
|
||||
|
||||
var promotionsMock = new ArrayList([promotionMock]);
|
||||
|
||||
var noPromotions = new ArrayList([]);
|
||||
|
||||
describe('product promotions decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var promotions = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/promotions', {
|
||||
'*/cartridge/scripts/util/collections': collections
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called promotions', function () {
|
||||
var object = {};
|
||||
promotions(object, promotionsMock);
|
||||
|
||||
assert.equal(object.promotions.length, 1);
|
||||
assert.equal(object.promotions[0].id, 'someID');
|
||||
assert.equal(object.promotions[0].name, 'someName');
|
||||
assert.equal(object.promotions[0].calloutMsg, 'callout message mark up');
|
||||
assert.equal(object.promotions[0].details, 'details mark up');
|
||||
assert.isTrue(object.promotions[0].enabled);
|
||||
assert.equal(object.promotions[0].promotionClass, 'someClass');
|
||||
assert.equal(object.promotions[0].rank, 'someRank');
|
||||
});
|
||||
|
||||
it('should handle empty array of promotions', function () {
|
||||
var object = {};
|
||||
promotions(object, noPromotions);
|
||||
|
||||
assert.equal(object.promotions, null);
|
||||
});
|
||||
|
||||
it('should handle promotions with no callout message', function () {
|
||||
var object = {};
|
||||
promotionMock.calloutMsg = null;
|
||||
promotionMock.details = null;
|
||||
promotions(object, promotionsMock);
|
||||
|
||||
assert.equal(object.promotions[0].calloutMsg, '');
|
||||
});
|
||||
|
||||
it('should handle promotions with no details', function () {
|
||||
var object = {};
|
||||
promotionMock.details = null;
|
||||
promotions(object, promotionsMock);
|
||||
|
||||
assert.equal(object.promotions[0].details, '');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productMock = {
|
||||
minOrderQuantity: {
|
||||
value: 1
|
||||
}
|
||||
};
|
||||
|
||||
describe('product quantity decorator', function () {
|
||||
var quantity = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/quantity', {
|
||||
'*/cartridge/config/preferences': {
|
||||
maxOrderQty: 10
|
||||
}
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called selectedQuantity', function () {
|
||||
var object = {};
|
||||
quantity(object, productMock, 1);
|
||||
|
||||
assert.equal(object.selectedQuantity, 1);
|
||||
});
|
||||
|
||||
it('should handle null quantity', function () {
|
||||
var object = {};
|
||||
quantity(object, productMock);
|
||||
|
||||
assert.equal(object.selectedQuantity, 1);
|
||||
});
|
||||
|
||||
it('should handle empty product', function () {
|
||||
var object = {};
|
||||
quantity(object, {}, 1);
|
||||
|
||||
assert.equal(object.selectedQuantity, 1);
|
||||
});
|
||||
|
||||
it('should handle empty product and no quantity', function () {
|
||||
var object = {};
|
||||
quantity(object, {});
|
||||
|
||||
assert.equal(object.selectedQuantity, 1);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called minOrderQuantity', function () {
|
||||
var object = {};
|
||||
quantity(object, productMock, 1);
|
||||
|
||||
assert.equal(object.minOrderQuantity, 1);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called maxOrderQuantity', function () {
|
||||
var object = {};
|
||||
quantity(object, productMock, 1);
|
||||
|
||||
assert.equal(object.maxOrderQuantity, 10);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
describe('quantity selector decorator', function () {
|
||||
var quantities = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/quantitySelector', {
|
||||
'dw/web/URLUtils': {
|
||||
url: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () {
|
||||
return 'string';
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
'*/cartridge/scripts/helpers/urlHelpers': {
|
||||
appendQueryParams: function () {
|
||||
return 'url';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called quantities', function () {
|
||||
var object = {
|
||||
minOrderQuantity: 1,
|
||||
maxOrderQuantity: 10,
|
||||
selectedQuantity: 2,
|
||||
id: 'someID'
|
||||
};
|
||||
quantities(object, 1, {}, []);
|
||||
assert.equal(object.quantities.length, 10);
|
||||
});
|
||||
|
||||
it('should handle selected quantity being null', function () {
|
||||
var object = {
|
||||
minOrderQuantity: 1,
|
||||
maxOrderQuantity: 10,
|
||||
selectedQuantity: null,
|
||||
id: 'someID'
|
||||
};
|
||||
|
||||
quantities(object, 1, {}, []);
|
||||
assert.equal(object.quantities.length, 10);
|
||||
});
|
||||
|
||||
it('should handle null attributes', function () {
|
||||
var object = {
|
||||
minOrderQuantity: 1,
|
||||
maxOrderQuantity: 10,
|
||||
selectedQuantity: null,
|
||||
id: 'someID'
|
||||
};
|
||||
|
||||
quantities(object, 1, null, null);
|
||||
assert.equal(object.quantities.length, 10);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('product rating decorator', function () {
|
||||
var rating = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/ratings');
|
||||
|
||||
it('should create rating property for passed in object', function () {
|
||||
var object = {
|
||||
id: '1234567'
|
||||
};
|
||||
rating(object);
|
||||
|
||||
assert.equal(object.rating, 4.5);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('raw product decorator', function () {
|
||||
var raw = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/raw');
|
||||
|
||||
it('should create someRawProduct for passed in object', function () {
|
||||
var object = {};
|
||||
raw(object, 'someRawProduct');
|
||||
|
||||
assert.equal(object.raw, 'someRawProduct');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var variationModelMock = {
|
||||
selectedVariant: {}
|
||||
};
|
||||
|
||||
describe('product ready to order decorator', function () {
|
||||
var readyToOrder = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/readyToOrder');
|
||||
|
||||
it('should create readyToOrder property for passed in object', function () {
|
||||
var object = {};
|
||||
readyToOrder(object, variationModelMock);
|
||||
|
||||
assert.equal(object.readyToOrder, true);
|
||||
});
|
||||
|
||||
it('should handle no variation model', function () {
|
||||
var object = {};
|
||||
readyToOrder(object, null);
|
||||
|
||||
assert.equal(object.readyToOrder, true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var stubRangePrice = sinon.stub();
|
||||
var stubDefaultPrice = sinon.stub();
|
||||
var stubListPrices = sinon.stub();
|
||||
|
||||
|
||||
var searchHitMock = {
|
||||
minPrice: { value: 100, available: true },
|
||||
maxPrice: { value: 100, available: true },
|
||||
discountedPromotionIDs: ['someID']
|
||||
};
|
||||
|
||||
var noActivePromotionsMock = [];
|
||||
var activePromotionsMock = ['someID'];
|
||||
var activePromotionsNoMatchMock = [];
|
||||
|
||||
function getSearchHit() {
|
||||
return searchHitMock;
|
||||
}
|
||||
|
||||
describe('search price decorator', function () {
|
||||
var searchPrice = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/searchPrice', {
|
||||
'*/cartridge/scripts/helpers/pricing': {
|
||||
getPromotionPrice: function () { return { value: 50, available: true }; },
|
||||
getPromotions: function (searchHit, activePromotions) { return new ArrayList(activePromotions); },
|
||||
getListPrices: stubListPrices
|
||||
},
|
||||
'*/cartridge/models/price/default': stubDefaultPrice,
|
||||
'*/cartridge/models/price/range': stubRangePrice
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
stubRangePrice.reset();
|
||||
stubDefaultPrice.reset();
|
||||
stubListPrices.reset();
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called price with no active promotions', function () {
|
||||
var object = {};
|
||||
|
||||
stubListPrices.returns({
|
||||
minPrice: { value: 100, available: true },
|
||||
maxPrice: { value: 100, available: true }
|
||||
});
|
||||
|
||||
searchPrice(object, searchHitMock, noActivePromotionsMock, getSearchHit);
|
||||
|
||||
assert.isTrue(stubDefaultPrice.withArgs({ value: 100, available: true }).calledOnce);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called price when there are active promotion but they do not match', function () {
|
||||
var object = {};
|
||||
|
||||
searchPrice(object, searchHitMock, activePromotionsNoMatchMock, getSearchHit);
|
||||
|
||||
assert.isTrue(stubDefaultPrice.withArgs({ value: 100, available: true }).calledOnce);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called price when there active promotions that do match', function () {
|
||||
var object = {};
|
||||
|
||||
searchPrice(object, searchHitMock, activePromotionsMock, getSearchHit);
|
||||
|
||||
assert.isTrue(stubDefaultPrice.withArgs({ value: 50, available: true }, { value: 100, available: true }).calledOnce);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called price', function () {
|
||||
var object = {};
|
||||
|
||||
searchPrice(object, searchHitMock, activePromotionsMock, getSearchHit);
|
||||
|
||||
assert.isTrue(stubDefaultPrice.withArgs({ value: 50, available: true }).calledOnce);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called price', function () {
|
||||
var object = {};
|
||||
|
||||
searchPrice(object, searchHitMock, activePromotionsMock, getSearchHit);
|
||||
|
||||
assert.isTrue(stubDefaultPrice.withArgs({ value: 50, available: true }, { value: 100, available: true }).calledOnce);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called price', function () {
|
||||
var object = {};
|
||||
|
||||
searchHitMock.maxPrice.value = 200;
|
||||
searchPrice(object, searchHitMock, noActivePromotionsMock, getSearchHit);
|
||||
|
||||
assert.isTrue(stubRangePrice.withArgs({ value: 100, available: true }, { value: 200, available: true }).calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var stubGetImage = sinon.stub();
|
||||
|
||||
var representedVariationValuesMock = {
|
||||
getImage: stubGetImage,
|
||||
value: 'someColor',
|
||||
ID: 'someColorID',
|
||||
description: 'someDescription',
|
||||
displayValue: 'someDisplayValue'
|
||||
};
|
||||
|
||||
var searchHitMock = {
|
||||
getRepresentedVariationValues: function () {
|
||||
return new ArrayList([representedVariationValuesMock]);
|
||||
}
|
||||
};
|
||||
|
||||
describe('search variation attributes decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var variationAttributes = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/searchVariationAttributes', {
|
||||
'*/cartridge/scripts/util/collections': collections,
|
||||
'dw/web/URLUtils': {
|
||||
url: function () {
|
||||
return 'someURL';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called variationAttributes', function () {
|
||||
var object = {};
|
||||
stubGetImage.returns({
|
||||
alt: 'alt',
|
||||
URL: {
|
||||
toString: function () {
|
||||
return 'string url';
|
||||
}
|
||||
},
|
||||
title: 'someTitle'
|
||||
});
|
||||
variationAttributes(object, searchHitMock);
|
||||
|
||||
assert.equal(object.variationAttributes.length, 1);
|
||||
assert.equal(object.variationAttributes[0].attributeId, 'color');
|
||||
assert.equal(object.variationAttributes[0].id, 'color');
|
||||
assert.isTrue(object.variationAttributes[0].swatchable);
|
||||
assert.equal(object.variationAttributes[0].values.length, 1);
|
||||
assert.equal(object.variationAttributes[0].values[0].id, 'someColorID');
|
||||
assert.equal(object.variationAttributes[0].values[0].description, 'someDescription');
|
||||
assert.equal(object.variationAttributes[0].values[0].displayValue, 'someDisplayValue');
|
||||
assert.equal(object.variationAttributes[0].values[0].value, 'someColor');
|
||||
assert.isTrue(object.variationAttributes[0].values[0].selectable);
|
||||
assert.isTrue(object.variationAttributes[0].values[0].selected);
|
||||
assert.equal(object.variationAttributes[0].values[0].images.swatch[0].alt, 'alt');
|
||||
assert.equal(object.variationAttributes[0].values[0].images.swatch[0].url, 'string url');
|
||||
assert.equal(object.variationAttributes[0].values[0].images.swatch[0].title, 'someTitle');
|
||||
assert.equal(object.variationAttributes[0].values[0].url, 'someURL');
|
||||
});
|
||||
|
||||
it('should handle no images returned by the api for represented variation values', function () {
|
||||
var object = {};
|
||||
stubGetImage.returns(null);
|
||||
variationAttributes(object, searchHitMock);
|
||||
|
||||
assert.equal(object.variationAttributes.length, 1);
|
||||
assert.deepEqual(object.variationAttributes[0].values[0], {});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var productMock = {
|
||||
bundledProducts: new ArrayList([{
|
||||
ID: 'some id'
|
||||
}])
|
||||
};
|
||||
|
||||
var productFactoryMock = {
|
||||
get: function () {
|
||||
return 'some product';
|
||||
}
|
||||
};
|
||||
|
||||
describe(' set individual products decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var individualProducts = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/setIndividualProducts', {
|
||||
'*/cartridge/scripts/util/collections': collections
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called individualProducts', function () {
|
||||
var object = {};
|
||||
individualProducts(object, productMock, productFactoryMock);
|
||||
|
||||
assert.equal(object.individualProducts.length, 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productFactoryMock = {
|
||||
productSetProducts: {
|
||||
length: 2
|
||||
}
|
||||
};
|
||||
|
||||
describe(' productSetProducts decorator', function () {
|
||||
var numberOfProductsInSet = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/setProductsCollection', {
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called numberOfProductsInSet', function () {
|
||||
var object = {};
|
||||
numberOfProductsInSet(object, productFactoryMock);
|
||||
assert.equal(object.numberOfProductsInSet, 2);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('set ready to order decorator', function () {
|
||||
var readyToOrder = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/setReadyToOrder');
|
||||
|
||||
it('should create readyToOrder property for passed in object', function () {
|
||||
var object = {};
|
||||
object.individualProducts = [{
|
||||
readyToOrder: true
|
||||
}];
|
||||
readyToOrder(object);
|
||||
|
||||
assert.isTrue(object.readyToOrder);
|
||||
});
|
||||
|
||||
it('should create readyToOrder property for passed in object', function () {
|
||||
var object = {};
|
||||
object.individualProducts = [{
|
||||
readyToOrder: false
|
||||
}];
|
||||
readyToOrder(object);
|
||||
|
||||
assert.isFalse(object.readyToOrder);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('size chart decorator', function () {
|
||||
var sizeChart = require('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/sizeChart');
|
||||
|
||||
it('should create someSizeChartID property for passed in object', function () {
|
||||
var object = {};
|
||||
sizeChart(object, 'someSizeChartID');
|
||||
|
||||
assert.equal(object.sizeChartId, 'someSizeChartID');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
var stubVariationAttributesModel = sinon.stub();
|
||||
stubVariationAttributesModel.returns(['attribute1']);
|
||||
|
||||
describe('product variation attributes decorator', function () {
|
||||
var variationAttributes = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/product/decorators/variationAttributes', {
|
||||
'*/cartridge/models/product/productAttributes': stubVariationAttributesModel
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called variationAttributes', function () {
|
||||
var object = { selectedQuantity: 2 };
|
||||
variationAttributes(object, {}, { selectedOptionsQueryParams: 'selectedOptionsParams' });
|
||||
|
||||
assert.isTrue(stubVariationAttributesModel.calledOnce);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called variationAttributes', function () {
|
||||
var object = { selectedQuantity: 2 };
|
||||
stubVariationAttributesModel.reset();
|
||||
variationAttributes(object, null);
|
||||
|
||||
assert.isTrue(stubVariationAttributesModel.notCalled);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,223 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID',
|
||||
pageTitle: 'some title',
|
||||
pageDescription: 'some description',
|
||||
pageKeywords: 'some keywords',
|
||||
pageMetaData: [{}],
|
||||
template: 'some template'
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: []
|
||||
};
|
||||
|
||||
describe('Full Product Model', function () {
|
||||
var decorators = require('../../../../mocks/productDecoratorsMock');
|
||||
|
||||
var fullProduct = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/product/fullProduct', {
|
||||
'*/cartridge/models/product/decorators/index': decorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
decorators.stubs.stubBase.reset();
|
||||
decorators.stubs.stubPrice.reset();
|
||||
decorators.stubs.stubImages.reset();
|
||||
decorators.stubs.stubAvailability.reset();
|
||||
decorators.stubs.stubDescription.reset();
|
||||
decorators.stubs.stubSearchPrice.reset();
|
||||
decorators.stubs.stubPromotions.reset();
|
||||
decorators.stubs.stubQuantity.reset();
|
||||
decorators.stubs.stubQuantitySelector.reset();
|
||||
decorators.stubs.stubRatings.reset();
|
||||
decorators.stubs.stubSizeChart.reset();
|
||||
decorators.stubs.stubVariationAttributes.reset();
|
||||
decorators.stubs.stubSearchVariationAttributes.reset();
|
||||
decorators.stubs.stubAttributes.reset();
|
||||
decorators.stubs.stubOptions.reset();
|
||||
decorators.stubs.stubCurrentUrl.reset();
|
||||
decorators.stubs.stubReadyToOrder.reset();
|
||||
decorators.stubs.stubOnline.reset();
|
||||
decorators.stubs.stubSetReadyToOrder.reset();
|
||||
decorators.stubs.stubBundleReadyToOrder.reset();
|
||||
decorators.stubs.stubSetIndividualProducts.reset();
|
||||
decorators.stubs.stubBundledProducts.reset();
|
||||
decorators.stubs.stubBonusUnitPrice.reset();
|
||||
decorators.stubs.stubPageMetaData.reset();
|
||||
decorators.stubs.stubTemplate.reset();
|
||||
});
|
||||
|
||||
it('should call base for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should call price for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubImages.calledWith(object, optionsMock.variationModel));
|
||||
});
|
||||
|
||||
it('should call images for full product when there is no variation model', function () {
|
||||
var object = {};
|
||||
optionsMock.variationModel = null;
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubImages.calledWith(object, productMock));
|
||||
});
|
||||
|
||||
it('should call quantity for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should call variationAttributes for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call description for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubDescription.calledOnce);
|
||||
});
|
||||
|
||||
it('should call ratings for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubRatings.calledOnce);
|
||||
});
|
||||
|
||||
it('should call promotion for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call attributes for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call availability for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should call options for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantitySelector for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubQuantitySelector.calledOnce);
|
||||
});
|
||||
|
||||
it('should call sizeChart for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSizeChart.calledOnce);
|
||||
});
|
||||
|
||||
it('should call currentUrl for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubCurrentUrl.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call sizeChart for full product when no primary category for api product', function () {
|
||||
var object = {};
|
||||
optionsMock.productType = 'master';
|
||||
productMock.getPrimaryCategory = function () { return null; };
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubSizeChart.calledOnce);
|
||||
});
|
||||
|
||||
it('should call sizeChart for full product when no primary category for api product', function () {
|
||||
var object = {};
|
||||
optionsMock.productType = 'variant';
|
||||
productMock.getPrimaryCategory = function () { return null; };
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSizeChart.calledOnce);
|
||||
});
|
||||
|
||||
it('should call readyToOrder for full product', function () {
|
||||
var object = {};
|
||||
productMock.getPrimaryCategory = function () { return null; };
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should call online for full product', function () {
|
||||
var object = {};
|
||||
productMock.getPrimaryCategory = function () { return null; };
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubOnline.calledOnce);
|
||||
});
|
||||
|
||||
it('should call pageMetaData for full product', function () {
|
||||
var object = {};
|
||||
productMock.getPrimaryCategory = function () { return null; };
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPageMetaData.calledOnce);
|
||||
});
|
||||
|
||||
it('should call template for full product', function () {
|
||||
var object = {};
|
||||
fullProduct(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubTemplate.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,318 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../mocks/dw.util.Collection');
|
||||
var toProductMock = require('../../../../util');
|
||||
|
||||
describe('productAttributes', function () {
|
||||
var ProductAttributes = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/product/productAttributes', {
|
||||
'*/cartridge/models/product/productImages': function () {},
|
||||
'*/cartridge/scripts/util/collections': proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
}),
|
||||
'*/cartridge/scripts/helpers/urlHelpers': { appendQueryParams: function () {
|
||||
return '?pid=25604524&dwvar_25604524_size=038&dwvar_25604524_color=BLACKFB';
|
||||
} }
|
||||
});
|
||||
|
||||
var variationsMock = {
|
||||
productVariationAttributes: new ArrayList([]),
|
||||
getSelectedValue: {
|
||||
return: {
|
||||
equals: {
|
||||
return: true,
|
||||
type: 'function'
|
||||
}
|
||||
},
|
||||
type: 'function'
|
||||
},
|
||||
getAllValues: {
|
||||
return: new ArrayList([]),
|
||||
type: 'function'
|
||||
},
|
||||
hasOrderableVariants: {
|
||||
return: false,
|
||||
type: 'function'
|
||||
},
|
||||
urlUnselectVariationValue: {
|
||||
return: 'unselect_url',
|
||||
type: 'function'
|
||||
},
|
||||
urlSelectVariationValue: {
|
||||
return: 'select_url',
|
||||
type: 'function'
|
||||
}
|
||||
};
|
||||
|
||||
it('should return empty array if product doesn not have attributes', function () {
|
||||
var mock = toProductMock(variationsMock);
|
||||
var attributeConfig = {
|
||||
attributes: ['color'],
|
||||
endPoint: 'Show'
|
||||
};
|
||||
var attrs = new ProductAttributes(mock, attributeConfig);
|
||||
|
||||
assert.equal(attrs.length, 0);
|
||||
});
|
||||
|
||||
it('should return color attributes', function () {
|
||||
var tempMock = Object.assign({}, variationsMock);
|
||||
tempMock.productVariationAttributes = new ArrayList([{
|
||||
attributeID: 'color',
|
||||
displayName: 'color',
|
||||
ID: 'COLOR_ID'
|
||||
}]);
|
||||
|
||||
tempMock.getSelectedValue = {
|
||||
return: {
|
||||
description: 'lorum ipsum',
|
||||
displayValue: 'Black',
|
||||
ID: 'BlackFB',
|
||||
value: 'BlackFB',
|
||||
equals: {
|
||||
return: true,
|
||||
type: 'function'
|
||||
}
|
||||
},
|
||||
type: 'function'
|
||||
};
|
||||
|
||||
var mock = toProductMock(tempMock);
|
||||
var attributeConfig = {
|
||||
attributes: ['color'],
|
||||
endPoint: 'Show'
|
||||
};
|
||||
var attrs = new ProductAttributes(mock, attributeConfig);
|
||||
|
||||
assert.equal(attrs.length, 1);
|
||||
assert.equal(attrs[0].displayName, 'color');
|
||||
assert.equal(attrs[0].attributeId, 'color');
|
||||
assert.equal(attrs[0].id, 'COLOR_ID');
|
||||
assert.isTrue(attrs[0].swatchable);
|
||||
assert.equal(attrs[0].values.length, 0);
|
||||
assert.equal(attrs[0].displayValue, 'Black');
|
||||
});
|
||||
|
||||
it('should return color attributes with multiple values', function () {
|
||||
var tempMock = Object.assign({}, variationsMock);
|
||||
tempMock.productVariationAttributes = new ArrayList([{
|
||||
attributeID: 'color',
|
||||
displayName: 'color',
|
||||
ID: 'COLOR_ID'
|
||||
}, {
|
||||
attributeID: 'size',
|
||||
displayName: 'size',
|
||||
ID: 'SIZE_ID'
|
||||
}]);
|
||||
tempMock.getAllValues.return = new ArrayList([{
|
||||
ID: 'asdfa9s87sad',
|
||||
description: '',
|
||||
displayValue: 'blue',
|
||||
value: 'asdfa9s87sad'
|
||||
}, {
|
||||
ID: 'asd98f7asdf',
|
||||
description: '',
|
||||
displayValue: 'grey',
|
||||
value: 'asd98f7asdf'
|
||||
}]);
|
||||
var mock = toProductMock(tempMock);
|
||||
var attributeConfig = {
|
||||
attributes: ['color'],
|
||||
endPoint: 'Show'
|
||||
};
|
||||
var attrs = new ProductAttributes(mock, attributeConfig);
|
||||
|
||||
assert.equal(attrs.length, 1);
|
||||
assert.equal(attrs[0].displayName, 'color');
|
||||
assert.equal(attrs[0].values.length, 2);
|
||||
assert.equal(attrs[0].values[0].displayValue, 'blue');
|
||||
assert.equal(attrs[0].values[1].displayValue, 'grey');
|
||||
});
|
||||
|
||||
it('should return size attributes with multiple values', function () {
|
||||
var tempMock = Object.assign({}, variationsMock);
|
||||
tempMock.productVariationAttributes = new ArrayList([{
|
||||
attributeID: 'color',
|
||||
displayName: 'color',
|
||||
ID: 'COLOR_ID'
|
||||
}, {
|
||||
attributeID: 'size',
|
||||
displayName: 'size',
|
||||
ID: 'SIZE_ID'
|
||||
}]);
|
||||
tempMock.getAllValues.return = new ArrayList([{
|
||||
ID: '038',
|
||||
description: '',
|
||||
displayValue: '38',
|
||||
value: '038'
|
||||
}, {
|
||||
ID: '039',
|
||||
description: '',
|
||||
displayValue: '39',
|
||||
value: '039'
|
||||
}]);
|
||||
var mock = toProductMock(tempMock);
|
||||
var attributeConfig = {
|
||||
attributes: ['size'],
|
||||
endPoint: 'Show'
|
||||
};
|
||||
var attrs = new ProductAttributes(mock, attributeConfig);
|
||||
|
||||
assert.equal(attrs.length, 1);
|
||||
assert.equal(attrs[0].displayName, 'size');
|
||||
assert.equal(attrs[0].values.length, 2);
|
||||
assert.equal(attrs[0].values[0].displayValue, '38');
|
||||
assert.equal(attrs[0].values[1].displayValue, '39');
|
||||
});
|
||||
|
||||
it('should return size attributes with a resetUrl', function () {
|
||||
var tempMock = Object.assign({}, variationsMock);
|
||||
|
||||
tempMock.productVariationAttributes = new ArrayList([{
|
||||
attributeID: 'color',
|
||||
displayName: 'color',
|
||||
ID: 'color'
|
||||
}, {
|
||||
attributeID: 'size',
|
||||
displayName: 'size',
|
||||
ID: 'size',
|
||||
resetUrl: ''
|
||||
}]);
|
||||
|
||||
tempMock.getAllValues.return = new ArrayList([{
|
||||
ID: '038',
|
||||
description: '',
|
||||
displayValue: '38',
|
||||
value: '038',
|
||||
selectable: true,
|
||||
selected: false,
|
||||
url: 'attrID=something'
|
||||
}, {
|
||||
ID: '039',
|
||||
description: '',
|
||||
displayValue: '39',
|
||||
value: '039',
|
||||
selectable: true,
|
||||
selected: false,
|
||||
url: 'attrID=something'
|
||||
|
||||
}]);
|
||||
|
||||
tempMock.getSelectedValue.return = false;
|
||||
tempMock.hasOrderableVariants.return = true;
|
||||
tempMock.urlSelectVariationValue.return = '?pid=25604524&dwvar_25604524_size=038&dwvar_25604524_color=BLACKFB';
|
||||
|
||||
var mock = toProductMock(tempMock);
|
||||
var attributeConfig = {
|
||||
attributes: ['size'],
|
||||
endPoint: 'Show'
|
||||
};
|
||||
var attrs = new ProductAttributes(mock, attributeConfig);
|
||||
|
||||
assert.equal(attrs[0].resetUrl, '?pid=25604524&dwvar_25604524_size=&dwvar_25604524_color=BLACKFB');
|
||||
});
|
||||
|
||||
it('should return all atributes when using "*" as the attributeConfig', function () {
|
||||
var tempMock = Object.assign({}, variationsMock);
|
||||
|
||||
tempMock.productVariationAttributes = new ArrayList([{
|
||||
attributeID: 'color',
|
||||
displayName: 'color',
|
||||
ID: 'color'
|
||||
}, {
|
||||
attributeID: 'size',
|
||||
displayName: 'size',
|
||||
ID: 'size',
|
||||
resetUrl: ''
|
||||
}, {
|
||||
attributeID: 'width',
|
||||
displayName: 'width',
|
||||
ID: 'width',
|
||||
resetUrl: ''
|
||||
}]);
|
||||
|
||||
tempMock.getAllValues.return = new ArrayList([{
|
||||
ID: '038',
|
||||
description: '',
|
||||
displayValue: '38',
|
||||
value: '038',
|
||||
selectable: true,
|
||||
selected: false,
|
||||
url: ''
|
||||
}, {
|
||||
ID: '039',
|
||||
description: '',
|
||||
displayValue: '39',
|
||||
value: '039',
|
||||
selectable: true,
|
||||
selected: false,
|
||||
url: ''
|
||||
|
||||
}]);
|
||||
|
||||
var attributeConfig = {
|
||||
attributes: '*',
|
||||
endPoint: 'Show'
|
||||
};
|
||||
|
||||
tempMock.getSelectedValue.return = false;
|
||||
tempMock.hasOrderableVariants.return = true;
|
||||
tempMock.urlSelectVariationValue.return = '?pid=25604524&dwvar_25604524_size=038&dwvar_25604524_color=BLACKFB';
|
||||
|
||||
var mock = toProductMock(tempMock);
|
||||
|
||||
var attrs = new ProductAttributes(mock, attributeConfig);
|
||||
|
||||
assert.equal(attrs.length, 3);
|
||||
assert.equal(attrs[0].id, 'color');
|
||||
assert.equal(attrs[1].id, 'size');
|
||||
assert.equal(attrs[2].id, 'width');
|
||||
});
|
||||
|
||||
it('should return a subset of properties per attribute when attributeConfig.attributes = "selected"', function () {
|
||||
var tempMock = Object.assign({}, variationsMock);
|
||||
|
||||
tempMock.productVariationAttributes = new ArrayList([{
|
||||
attributeID: 'color',
|
||||
displayName: 'color',
|
||||
displayValue: '',
|
||||
ID: 'color'
|
||||
}]);
|
||||
|
||||
var attributeConfig = {
|
||||
attributes: 'selected'
|
||||
};
|
||||
|
||||
tempMock.getSelectedValue = {
|
||||
return: {
|
||||
description: 'lorum ipsum',
|
||||
displayValue: 'Black',
|
||||
ID: 'BlackFB',
|
||||
value: 'BlackFB',
|
||||
equals: {
|
||||
return: true,
|
||||
type: 'function'
|
||||
}
|
||||
},
|
||||
type: 'function'
|
||||
};
|
||||
|
||||
tempMock.hasOrderableVariants.return = true;
|
||||
|
||||
var mock = toProductMock(tempMock);
|
||||
|
||||
var attrs = new ProductAttributes(mock, attributeConfig);
|
||||
|
||||
assert.equal(attrs.length, 1);
|
||||
assert.isDefined(attrs[0].attributeId);
|
||||
assert.isDefined(attrs[0].displayName);
|
||||
assert.isDefined(attrs[0].displayValue);
|
||||
assert.equal(attrs[0].displayValue, 'Black');
|
||||
assert.isDefined(attrs[0].id);
|
||||
|
||||
assert.isUndefined(attrs[0].swatchable);
|
||||
assert.isUndefined(attrs[0].values);
|
||||
assert.isUndefined(attrs[0].resetUrl);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,178 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var object = {};
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID',
|
||||
pageTitle: 'some title',
|
||||
pageDescription: 'some description',
|
||||
pageKeywords: 'some keywords',
|
||||
pageMetaData: [{}]
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: []
|
||||
};
|
||||
|
||||
describe('Product Bundle Model', function () {
|
||||
var decorators = require('../../../../mocks/productDecoratorsMock');
|
||||
|
||||
var productBundle = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/product/productBundle', {
|
||||
'*/cartridge/models/product/decorators/index': decorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
decorators.stubs.stubBase.reset();
|
||||
decorators.stubs.stubPrice.reset();
|
||||
decorators.stubs.stubImages.reset();
|
||||
decorators.stubs.stubAvailability.reset();
|
||||
decorators.stubs.stubDescription.reset();
|
||||
decorators.stubs.stubTemplate.reset();
|
||||
decorators.stubs.stubSearchPrice.reset();
|
||||
decorators.stubs.stubPromotions.reset();
|
||||
decorators.stubs.stubQuantity.reset();
|
||||
decorators.stubs.stubQuantitySelector.reset();
|
||||
decorators.stubs.stubRatings.reset();
|
||||
decorators.stubs.stubSizeChart.reset();
|
||||
decorators.stubs.stubVariationAttributes.reset();
|
||||
decorators.stubs.stubSearchVariationAttributes.reset();
|
||||
decorators.stubs.stubAttributes.reset();
|
||||
decorators.stubs.stubOptions.reset();
|
||||
decorators.stubs.stubCurrentUrl.reset();
|
||||
decorators.stubs.stubReadyToOrder.reset();
|
||||
decorators.stubs.stubSetReadyToOrder.reset();
|
||||
decorators.stubs.stubBundleReadyToOrder.reset();
|
||||
decorators.stubs.stubSetIndividualProducts.reset();
|
||||
decorators.stubs.stubBundledProducts.reset();
|
||||
decorators.stubs.stubPageMetaData.reset();
|
||||
});
|
||||
|
||||
it('should call base for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should call price for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantity for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should call variationAttributes for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call description for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubDescription.calledOnce);
|
||||
});
|
||||
|
||||
it('should call template for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubTemplate.calledOnce);
|
||||
});
|
||||
|
||||
it('should call ratings for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubRatings.calledOnce);
|
||||
});
|
||||
|
||||
it('should call promotion for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call attributes for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call availability for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should call options for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantitySelector for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubQuantitySelector.calledOnce);
|
||||
});
|
||||
|
||||
it('should call sizeChart for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSizeChart.calledOnce);
|
||||
});
|
||||
|
||||
it('should call currentUrl for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubCurrentUrl.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bundleReadyToOrder for bundle product', function () {
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubBundleReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call readyToOrder for bundle product', function () {
|
||||
productMock.getPrimaryCategory = function () { return null; };
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should call pageMetaData for bundle product', function () {
|
||||
object = {};
|
||||
productMock.getPrimaryCategory = function () { return null; };
|
||||
productBundle(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPageMetaData.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../mocks/dw.util.Collection');
|
||||
var toProductMock = require('../../../../util');
|
||||
|
||||
describe('productImages', function () {
|
||||
var ProductImages = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/product/productImages', {
|
||||
'*/cartridge/scripts/util/collections': proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
})
|
||||
});
|
||||
|
||||
var productMock = {
|
||||
getImages: {
|
||||
return: new ArrayList([{
|
||||
alt: 'First Image',
|
||||
title: 'First Image',
|
||||
index: '0',
|
||||
URL: {
|
||||
toString: function () {
|
||||
return '/first_image_url';
|
||||
}
|
||||
},
|
||||
absURL: {
|
||||
toString: function () {
|
||||
return 'path/first_image_url';
|
||||
}
|
||||
}
|
||||
}, {
|
||||
alt: 'Second Image',
|
||||
title: 'Second Image',
|
||||
index: '1',
|
||||
URL: {
|
||||
toString: function () {
|
||||
return '/second_image_url';
|
||||
}
|
||||
},
|
||||
absURL: {
|
||||
toString: function () {
|
||||
return 'path/second_image_url';
|
||||
}
|
||||
}
|
||||
}]),
|
||||
type: 'function'
|
||||
}
|
||||
};
|
||||
|
||||
it('should get all small images', function () {
|
||||
var images = new ProductImages(toProductMock(productMock), { types: ['small'], quantity: '*' });
|
||||
assert.equal(images.small.length, 2);
|
||||
assert.equal(images.small[0].alt, 'First Image');
|
||||
assert.equal(images.small[0].index, '0');
|
||||
assert.equal(images.small[0].title, 'First Image');
|
||||
assert.equal(images.small[0].url, '/first_image_url');
|
||||
assert.equal(images.small[0].absURL, 'path/first_image_url');
|
||||
assert.equal(images.small[1].url, '/second_image_url');
|
||||
assert.equal(images.small[1].absURL, 'path/second_image_url');
|
||||
assert.equal(images.small[1].index, '1');
|
||||
});
|
||||
|
||||
it('should get only first small image', function () {
|
||||
var images = new ProductImages(toProductMock(productMock), { types: ['small'], quantity: 'single' });
|
||||
assert.equal(images.small.length, 1);
|
||||
assert.equal(images.small[0].alt, 'First Image');
|
||||
assert.equal(images.small[0].title, 'First Image');
|
||||
assert.equal(images.small[0].index, '0');
|
||||
assert.equal(images.small[0].url, '/first_image_url');
|
||||
assert.equal(images.small[0].absURL, 'path/first_image_url');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,189 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var object = {};
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID',
|
||||
pageTitle: 'some title',
|
||||
pageDescription: 'some description',
|
||||
pageKeywords: 'some keywords',
|
||||
pageMetaData: [{}]
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: []
|
||||
};
|
||||
|
||||
describe('Product Set Model', function () {
|
||||
var decorators = require('../../../../mocks/productDecoratorsMock');
|
||||
|
||||
var productSet = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/product/productSet', {
|
||||
'*/cartridge/models/product/decorators/index': decorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
decorators.stubs.stubBase.reset();
|
||||
decorators.stubs.stubPrice.reset();
|
||||
decorators.stubs.stubImages.reset();
|
||||
decorators.stubs.stubAvailability.reset();
|
||||
decorators.stubs.stubDescription.reset();
|
||||
decorators.stubs.stubTemplate.reset();
|
||||
decorators.stubs.stubSearchPrice.reset();
|
||||
decorators.stubs.stubPromotions.reset();
|
||||
decorators.stubs.stubQuantity.reset();
|
||||
decorators.stubs.stubQuantitySelector.reset();
|
||||
decorators.stubs.stubRatings.reset();
|
||||
decorators.stubs.stubSizeChart.reset();
|
||||
decorators.stubs.stubVariationAttributes.reset();
|
||||
decorators.stubs.stubSearchVariationAttributes.reset();
|
||||
decorators.stubs.stubAttributes.reset();
|
||||
decorators.stubs.stubOptions.reset();
|
||||
decorators.stubs.stubCurrentUrl.reset();
|
||||
decorators.stubs.stubReadyToOrder.reset();
|
||||
decorators.stubs.stubSetReadyToOrder.reset();
|
||||
decorators.stubs.stubBundleReadyToOrder.reset();
|
||||
decorators.stubs.stubSetIndividualProducts.reset();
|
||||
decorators.stubs.stubBundledProducts.reset();
|
||||
decorators.stubs.stubPageMetaData.reset();
|
||||
});
|
||||
|
||||
it('should call base for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should call price for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantity for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call variationAttributes for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call description for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubDescription.calledOnce);
|
||||
});
|
||||
|
||||
it('should call template for bundle product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubTemplate.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call ratings for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubRatings.calledOnce);
|
||||
});
|
||||
|
||||
it('should call promotion for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call attributes for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call availability for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call options for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call quantitySelector for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubQuantitySelector.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call sizeChart for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubSizeChart.calledOnce);
|
||||
});
|
||||
|
||||
it('should call currentUrl for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubCurrentUrl.calledOnce);
|
||||
});
|
||||
|
||||
it('should call setIndividualProducts for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSetIndividualProducts.calledOnce);
|
||||
});
|
||||
|
||||
it('should call setReadyToOrder for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSetReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call bundleReadyToOrder for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubBundleReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call readyToOrder for set product', function () {
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(decorators.stubs.stubReadyToOrder.calledOnce);
|
||||
});
|
||||
|
||||
it('should call pageMetaData for set product', function () {
|
||||
object = {};
|
||||
productMock.getPrimaryCategory = function () { return null; };
|
||||
productSet(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubPageMetaData.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,100 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var object = {};
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID'
|
||||
};
|
||||
|
||||
describe('Product Tile Model', function () {
|
||||
var decorators = require('../../../../mocks/productDecoratorsMock');
|
||||
|
||||
var productTile = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/product/productTile', {
|
||||
'*/cartridge/models/product/decorators/index': decorators.mocks,
|
||||
'*/cartridge/scripts/util/promotionCache': {
|
||||
promotions: []
|
||||
},
|
||||
'*/cartridge/scripts/helpers/productHelpers': {
|
||||
getProductSearchHit: function () {}
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
decorators.stubs.stubBase.reset();
|
||||
decorators.stubs.stubPrice.reset();
|
||||
decorators.stubs.stubImages.reset();
|
||||
decorators.stubs.stubAvailability.reset();
|
||||
decorators.stubs.stubDescription.reset();
|
||||
decorators.stubs.stubSearchPrice.reset();
|
||||
decorators.stubs.stubPromotions.reset();
|
||||
decorators.stubs.stubQuantity.reset();
|
||||
decorators.stubs.stubQuantitySelector.reset();
|
||||
decorators.stubs.stubRatings.reset();
|
||||
decorators.stubs.stubSizeChart.reset();
|
||||
decorators.stubs.stubVariationAttributes.reset();
|
||||
decorators.stubs.stubSearchVariationAttributes.reset();
|
||||
decorators.stubs.stubAttributes.reset();
|
||||
decorators.stubs.stubOptions.reset();
|
||||
decorators.stubs.stubCurrentUrl.reset();
|
||||
decorators.stubs.stubReadyToOrder.reset();
|
||||
decorators.stubs.stubSetReadyToOrder.reset();
|
||||
decorators.stubs.stubBundleReadyToOrder.reset();
|
||||
decorators.stubs.stubSetIndividualProducts.reset();
|
||||
decorators.stubs.stubBundledProducts.reset();
|
||||
});
|
||||
|
||||
it('should call base for product tile', function () {
|
||||
productTile(object, productMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should call searchPrice for product tile', function () {
|
||||
productTile(object, productMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSearchPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for product tile', function () {
|
||||
productTile(object, productMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should call ratings for product tile', function () {
|
||||
productTile(object, productMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubRatings.calledOnce);
|
||||
});
|
||||
|
||||
it('should call searchVariationAttributes for product tile', function () {
|
||||
productTile(object, productMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSearchVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call searchVariationAttributes for product tile', function () {
|
||||
productTile(object, productMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSearchVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call searchVariationAttributes for product tile', function () {
|
||||
productTile(object, productMock);
|
||||
|
||||
assert.isTrue(decorators.stubs.stubSearchVariationAttributes.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,198 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID'
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: []
|
||||
};
|
||||
|
||||
var object = {};
|
||||
|
||||
describe('Bonus Order Line Item', function () {
|
||||
var productDecorators = require('../../../../mocks/productDecoratorsMock');
|
||||
var productLineItemDecorators = require('../../../../mocks/productLineItemDecoratorsMock');
|
||||
|
||||
var bonusOrderLineItem = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/bonusOrderLineItem', {
|
||||
'*/cartridge/models/product/decorators/index': productDecorators.mocks,
|
||||
'*/cartridge/models/productLineItem/decorators/index': productLineItemDecorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
productDecorators.stubs.stubBase.reset();
|
||||
productDecorators.stubs.stubPrice.reset();
|
||||
productDecorators.stubs.stubImages.reset();
|
||||
productDecorators.stubs.stubAvailability.reset();
|
||||
productDecorators.stubs.stubDescription.reset();
|
||||
productDecorators.stubs.stubSearchPrice.reset();
|
||||
productDecorators.stubs.stubPromotions.reset();
|
||||
productDecorators.stubs.stubQuantity.reset();
|
||||
productDecorators.stubs.stubQuantitySelector.reset();
|
||||
productDecorators.stubs.stubRatings.reset();
|
||||
productDecorators.stubs.stubSizeChart.reset();
|
||||
productDecorators.stubs.stubVariationAttributes.reset();
|
||||
productDecorators.stubs.stubSearchVariationAttributes.reset();
|
||||
productDecorators.stubs.stubAttributes.reset();
|
||||
productDecorators.stubs.stubOptions.reset();
|
||||
productDecorators.stubs.stubCurrentUrl.reset();
|
||||
productDecorators.stubs.stubReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetReadyToOrder.reset();
|
||||
productDecorators.stubs.stubBundleReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetIndividualProducts.reset();
|
||||
productDecorators.stubs.stubBundledProducts.reset();
|
||||
productLineItemDecorators.stubs.stubQuantity.reset();
|
||||
productLineItemDecorators.stubs.stubGift.reset();
|
||||
productLineItemDecorators.stubs.stubAppliedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubRenderedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubUuid.reset();
|
||||
productLineItemDecorators.stubs.stubOrderable.reset();
|
||||
productLineItemDecorators.stubs.stubShipment.reset();
|
||||
productLineItemDecorators.stubs.stubBonusProductLineItem.reset();
|
||||
productLineItemDecorators.stubs.stubPriceTotal.reset();
|
||||
productLineItemDecorators.stubs.stubQuantityOptions.reset();
|
||||
productLineItemDecorators.stubs.stubOptions.reset();
|
||||
productLineItemDecorators.stubs.stubBundledProductLineItems.reset();
|
||||
productLineItemDecorators.stubs.stubBonusProductLineItemUUID.reset();
|
||||
productLineItemDecorators.stubs.stubPreOrderUUID.reset();
|
||||
productLineItemDecorators.stubs.stubBonusUnitPrice.reset();
|
||||
});
|
||||
|
||||
it('should call base for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call price for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productDecorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should call variationAttributes for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call availability for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productDecorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantity for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call gift for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubGift.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call appliedPromotions for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubAppliedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call renderedPromotions for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubRenderedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call uuid for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubUuid.calledOnce);
|
||||
});
|
||||
|
||||
it('should call orderable for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOrderable.calledOnce);
|
||||
});
|
||||
|
||||
it('should call shipment for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubShipment.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call bonusProductLineItem for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubBonusProductLineItem.calledOnce);
|
||||
});
|
||||
|
||||
it('should call priceTotal for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubPriceTotal.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call quantityOptions for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubQuantityOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call options for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call bundledProductLineItems for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubBundledProductLineItems.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bonusProductLineItemUUID for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBonusProductLineItemUUID.calledOnce);
|
||||
});
|
||||
|
||||
it('should call preOrderUUID for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubPreOrderUUID.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call bonusUnitPrice for bonus line item model (order)', function () {
|
||||
bonusOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubBonusUnitPrice.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,198 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID'
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: []
|
||||
};
|
||||
|
||||
var object = {};
|
||||
|
||||
describe('Bonus Product Line Item', function () {
|
||||
var productDecorators = require('../../../../mocks/productDecoratorsMock');
|
||||
var productLineItemDecorators = require('../../../../mocks/productLineItemDecoratorsMock');
|
||||
|
||||
var bonusProductLineItem = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/bonusProductLineItem', {
|
||||
'*/cartridge/models/product/decorators/index': productDecorators.mocks,
|
||||
'*/cartridge/models/productLineItem/decorators/index': productLineItemDecorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
productDecorators.stubs.stubBase.reset();
|
||||
productDecorators.stubs.stubPrice.reset();
|
||||
productDecorators.stubs.stubImages.reset();
|
||||
productDecorators.stubs.stubAvailability.reset();
|
||||
productDecorators.stubs.stubDescription.reset();
|
||||
productDecorators.stubs.stubSearchPrice.reset();
|
||||
productDecorators.stubs.stubPromotions.reset();
|
||||
productDecorators.stubs.stubQuantity.reset();
|
||||
productDecorators.stubs.stubQuantitySelector.reset();
|
||||
productDecorators.stubs.stubRatings.reset();
|
||||
productDecorators.stubs.stubSizeChart.reset();
|
||||
productDecorators.stubs.stubVariationAttributes.reset();
|
||||
productDecorators.stubs.stubSearchVariationAttributes.reset();
|
||||
productDecorators.stubs.stubAttributes.reset();
|
||||
productDecorators.stubs.stubOptions.reset();
|
||||
productDecorators.stubs.stubCurrentUrl.reset();
|
||||
productDecorators.stubs.stubReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetReadyToOrder.reset();
|
||||
productDecorators.stubs.stubBundleReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetIndividualProducts.reset();
|
||||
productDecorators.stubs.stubBundledProducts.reset();
|
||||
productLineItemDecorators.stubs.stubQuantity.reset();
|
||||
productLineItemDecorators.stubs.stubGift.reset();
|
||||
productLineItemDecorators.stubs.stubAppliedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubRenderedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubUuid.reset();
|
||||
productLineItemDecorators.stubs.stubOrderable.reset();
|
||||
productLineItemDecorators.stubs.stubShipment.reset();
|
||||
productLineItemDecorators.stubs.stubBonusProductLineItem.reset();
|
||||
productLineItemDecorators.stubs.stubPriceTotal.reset();
|
||||
productLineItemDecorators.stubs.stubQuantityOptions.reset();
|
||||
productLineItemDecorators.stubs.stubOptions.reset();
|
||||
productLineItemDecorators.stubs.stubBundledProductLineItems.reset();
|
||||
productLineItemDecorators.stubs.stubBonusProductLineItemUUID.reset();
|
||||
productLineItemDecorators.stubs.stubPreOrderUUID.reset();
|
||||
productLineItemDecorators.stubs.stubBonusUnitPrice.reset();
|
||||
});
|
||||
|
||||
it('should call base for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call price for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productDecorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should call variationAttributes for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call availability for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productDecorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantity for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call gift for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubGift.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call appliedPromotions for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubAppliedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call renderedPromotions for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubRenderedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call uuid for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubUuid.calledOnce);
|
||||
});
|
||||
|
||||
it('should call orderable for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOrderable.calledOnce);
|
||||
});
|
||||
|
||||
it('should call shipment for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubShipment.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call bonusProductLineItem for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubBonusProductLineItem.calledOnce);
|
||||
});
|
||||
|
||||
it('should call priceTotal for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubPriceTotal.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call quantityOptions for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubQuantityOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call options for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call bundledProductLineItems for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubBundledProductLineItems.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bonusProductLineItemUUID for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBonusProductLineItemUUID.calledOnce);
|
||||
});
|
||||
|
||||
it('should call preOrderUUID for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubPreOrderUUID.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bonusUnitPrice for bonus line item model', function () {
|
||||
bonusProductLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBonusUnitPrice.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,177 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID'
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: []
|
||||
};
|
||||
|
||||
var object = {};
|
||||
|
||||
describe('Bundle Product Line Item Model', function () {
|
||||
var productDecorators = require('../../../../mocks/productDecoratorsMock');
|
||||
var productLineItemDecorators = require('../../../../mocks/productLineItemDecoratorsMock');
|
||||
|
||||
var bundleLineItem = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/bundleLineItem', {
|
||||
'*/cartridge/models/product/decorators/index': productDecorators.mocks,
|
||||
'*/cartridge/models/productLineItem/decorators/index': productLineItemDecorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
productDecorators.stubs.stubBase.reset();
|
||||
productDecorators.stubs.stubPrice.reset();
|
||||
productDecorators.stubs.stubImages.reset();
|
||||
productDecorators.stubs.stubAvailability.reset();
|
||||
productDecorators.stubs.stubDescription.reset();
|
||||
productDecorators.stubs.stubSearchPrice.reset();
|
||||
productDecorators.stubs.stubPromotions.reset();
|
||||
productDecorators.stubs.stubQuantity.reset();
|
||||
productDecorators.stubs.stubQuantitySelector.reset();
|
||||
productDecorators.stubs.stubRatings.reset();
|
||||
productDecorators.stubs.stubSizeChart.reset();
|
||||
productDecorators.stubs.stubVariationAttributes.reset();
|
||||
productDecorators.stubs.stubSearchVariationAttributes.reset();
|
||||
productDecorators.stubs.stubAttributes.reset();
|
||||
productDecorators.stubs.stubOptions.reset();
|
||||
productDecorators.stubs.stubCurrentUrl.reset();
|
||||
productDecorators.stubs.stubReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetReadyToOrder.reset();
|
||||
productDecorators.stubs.stubBundleReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetIndividualProducts.reset();
|
||||
productDecorators.stubs.stubBundledProducts.reset();
|
||||
productLineItemDecorators.stubs.stubQuantity.reset();
|
||||
productLineItemDecorators.stubs.stubGift.reset();
|
||||
productLineItemDecorators.stubs.stubAppliedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubRenderedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubUuid.reset();
|
||||
productLineItemDecorators.stubs.stubOrderable.reset();
|
||||
productLineItemDecorators.stubs.stubShipment.reset();
|
||||
productLineItemDecorators.stubs.stubBonusProductLineItem.reset();
|
||||
productLineItemDecorators.stubs.stubPriceTotal.reset();
|
||||
productLineItemDecorators.stubs.stubQuantityOptions.reset();
|
||||
productLineItemDecorators.stubs.stubOptions.reset();
|
||||
productLineItemDecorators.stubs.stubBundledProductLineItems.reset();
|
||||
});
|
||||
|
||||
it('should call base for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should call price for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call variationAttributes for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productDecorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call availability for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantity for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should call gift for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubGift.calledOnce);
|
||||
});
|
||||
|
||||
it('should call appliedPromotions for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubAppliedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call renderedPromotions for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubRenderedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call uuid for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubUuid.calledOnce);
|
||||
});
|
||||
|
||||
it('should call orderable for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOrderable.calledOnce);
|
||||
});
|
||||
|
||||
it('should call shipment for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubShipment.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bonusProductLineItem for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBonusProductLineItem.calledOnce);
|
||||
});
|
||||
|
||||
it('should call priceTotal for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubPriceTotal.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantityOptions for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubQuantityOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call options for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bundledProductLineItems for bundle line item model', function () {
|
||||
bundleLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBundledProductLineItems.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,170 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID'
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: []
|
||||
};
|
||||
|
||||
var object = {};
|
||||
|
||||
describe('Bundle Product Line Item Model', function () {
|
||||
var productDecorators = require('../../../../mocks/productDecoratorsMock');
|
||||
var productLineItemDecorators = require('../../../../mocks/productLineItemDecoratorsMock');
|
||||
|
||||
var bundleOrderLineItem = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/bundleOrderLineItem', {
|
||||
'*/cartridge/models/product/decorators/index': productDecorators.mocks,
|
||||
'*/cartridge/models/productLineItem/decorators/index': productLineItemDecorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
productDecorators.stubs.stubBase.reset();
|
||||
productDecorators.stubs.stubPrice.reset();
|
||||
productDecorators.stubs.stubImages.reset();
|
||||
productDecorators.stubs.stubAvailability.reset();
|
||||
productDecorators.stubs.stubDescription.reset();
|
||||
productDecorators.stubs.stubSearchPrice.reset();
|
||||
productDecorators.stubs.stubPromotions.reset();
|
||||
productDecorators.stubs.stubQuantity.reset();
|
||||
productDecorators.stubs.stubQuantitySelector.reset();
|
||||
productDecorators.stubs.stubRatings.reset();
|
||||
productDecorators.stubs.stubSizeChart.reset();
|
||||
productDecorators.stubs.stubVariationAttributes.reset();
|
||||
productDecorators.stubs.stubSearchVariationAttributes.reset();
|
||||
productDecorators.stubs.stubAttributes.reset();
|
||||
productDecorators.stubs.stubOptions.reset();
|
||||
productDecorators.stubs.stubCurrentUrl.reset();
|
||||
productDecorators.stubs.stubReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetReadyToOrder.reset();
|
||||
productDecorators.stubs.stubBundleReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetIndividualProducts.reset();
|
||||
productDecorators.stubs.stubBundledProducts.reset();
|
||||
productLineItemDecorators.stubs.stubQuantity.reset();
|
||||
productLineItemDecorators.stubs.stubGift.reset();
|
||||
productLineItemDecorators.stubs.stubAppliedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubRenderedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubUuid.reset();
|
||||
productLineItemDecorators.stubs.stubOrderable.reset();
|
||||
productLineItemDecorators.stubs.stubShipment.reset();
|
||||
productLineItemDecorators.stubs.stubBonusProductLineItem.reset();
|
||||
productLineItemDecorators.stubs.stubPriceTotal.reset();
|
||||
productLineItemDecorators.stubs.stubOptions.reset();
|
||||
productLineItemDecorators.stubs.stubBundledProductLineItems.reset();
|
||||
});
|
||||
|
||||
it('should call base for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should call price for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productDecorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call variationAttributes for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productDecorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call availability for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantity for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should call gift for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubGift.calledOnce);
|
||||
});
|
||||
|
||||
it('should call appliedPromotions for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubAppliedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call renderedPromotions for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubRenderedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call uuid for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubUuid.calledOnce);
|
||||
});
|
||||
|
||||
it('should call orderable for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOrderable.calledOnce);
|
||||
});
|
||||
|
||||
it('should call shipment for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubShipment.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bonusProductLineItem for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBonusProductLineItem.calledOnce);
|
||||
});
|
||||
|
||||
it('should call priceTotal for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubPriceTotal.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call options for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productLineItemDecorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bundledProductLineItems for bundle line item model (order)', function () {
|
||||
bundleOrderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBundledProductLineItems.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,101 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
describe('product line item applied promotions decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var appliedPromotions = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/appliedPromotions', {
|
||||
'*/cartridge/scripts/util/collections': collections,
|
||||
'dw/web/Resource': { msg: function () { return 'test discount'; } }
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called appliedPromotions', function () {
|
||||
var object = {};
|
||||
|
||||
var promotionMock = {
|
||||
promotion: {
|
||||
calloutMsg: {
|
||||
markup: 'someCallOutMsg'
|
||||
},
|
||||
name: 'somePromotionName',
|
||||
details: {
|
||||
markup: 'someDetails'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var lineItemMock = { priceAdjustments: new ArrayList([promotionMock]) };
|
||||
appliedPromotions(object, lineItemMock);
|
||||
|
||||
assert.equal(object.appliedPromotions.length, 1);
|
||||
assert.equal(object.appliedPromotions[0].callOutMsg, 'someCallOutMsg');
|
||||
assert.equal(object.appliedPromotions[0].name, 'somePromotionName');
|
||||
assert.equal(object.appliedPromotions[0].details, 'someDetails');
|
||||
});
|
||||
|
||||
it('should handle no applied promotions', function () {
|
||||
var object = {};
|
||||
|
||||
var lineItemMock = { priceAdjustments: new ArrayList([]) };
|
||||
appliedPromotions(object, lineItemMock);
|
||||
|
||||
assert.equal(object.appliedPromotions, undefined);
|
||||
});
|
||||
|
||||
it('should handle no callout message', function () {
|
||||
var object = {};
|
||||
|
||||
var promotionMock = {
|
||||
promotion: {
|
||||
name: 'somePromotionName',
|
||||
details: {
|
||||
markup: 'someDetails'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var lineItemMock = { priceAdjustments: new ArrayList([promotionMock]) };
|
||||
appliedPromotions(object, lineItemMock);
|
||||
|
||||
assert.equal(object.appliedPromotions.length, 1);
|
||||
assert.equal(object.appliedPromotions[0].callOutMsg, '');
|
||||
assert.equal(object.appliedPromotions[0].name, 'somePromotionName');
|
||||
assert.equal(object.appliedPromotions[0].details, 'someDetails');
|
||||
});
|
||||
|
||||
it('should handle no details', function () {
|
||||
var object = {};
|
||||
|
||||
var promotionMock = {
|
||||
promotion: {
|
||||
calloutMsg: {
|
||||
markup: 'someCallOutMsg'
|
||||
},
|
||||
name: 'somePromotionName'
|
||||
}
|
||||
};
|
||||
|
||||
var lineItemMock = { priceAdjustments: new ArrayList([promotionMock]) };
|
||||
appliedPromotions(object, lineItemMock);
|
||||
|
||||
assert.equal(object.appliedPromotions.length, 1);
|
||||
assert.equal(object.appliedPromotions[0].callOutMsg, 'someCallOutMsg');
|
||||
assert.equal(object.appliedPromotions[0].name, 'somePromotionName');
|
||||
assert.equal(object.appliedPromotions[0].details, '');
|
||||
});
|
||||
|
||||
it('should use default message if no promotion is available', function () {
|
||||
var object = {};
|
||||
|
||||
var lineItemMock = { priceAdjustments: new ArrayList([{}]) };
|
||||
appliedPromotions(object, lineItemMock);
|
||||
|
||||
assert.equal(object.appliedPromotions.length, 1);
|
||||
assert.equal(object.appliedPromotions[0].callOutMsg, 'test discount');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var lineItemMock = {
|
||||
bonusProductLineItem: true
|
||||
};
|
||||
|
||||
describe('set ready to order decorator', function () {
|
||||
var isBonusProductLineItem = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/bonusProductLineItem');
|
||||
|
||||
it('should create isBonusProductLineItem property for passed in object', function () {
|
||||
var object = {};
|
||||
isBonusProductLineItem(object, lineItemMock);
|
||||
|
||||
assert.isTrue(object.isBonusProductLineItem);
|
||||
});
|
||||
|
||||
it('should create isBonusProductLineItem property for passed in object', function () {
|
||||
var object = {};
|
||||
lineItemMock.bonusProductLineItem = false;
|
||||
isBonusProductLineItem(object, lineItemMock);
|
||||
|
||||
assert.isFalse(object.isBonusProductLineItem);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var lineItemMock = {
|
||||
custom: {
|
||||
bonusProductLineItemUUID: 'someUUID'
|
||||
}
|
||||
};
|
||||
|
||||
describe('bonus product line item uuid decorator', function () {
|
||||
var bonusProductLineItemUUID = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/bonusProductLineItemUUID');
|
||||
|
||||
it('should create bonusProductLineItemUUID property for passed in object', function () {
|
||||
var object = {};
|
||||
bonusProductLineItemUUID(object, lineItemMock);
|
||||
|
||||
assert.equal(object.bonusProductLineItemUUID, 'someUUID');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var currentBasketMock = {
|
||||
getBonusDiscountLineItems: function () {
|
||||
return new ArrayList([
|
||||
{
|
||||
custom: { bonusProductLineItemUUID: 'someUUID' },
|
||||
getBonusProductPrice: function () {
|
||||
return {
|
||||
toFormattedString: function () {
|
||||
return 'someFormattedString';
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
var lineItemMock = {
|
||||
custom: {
|
||||
bonusProductLineItemUUID: 'someUUID'
|
||||
}
|
||||
};
|
||||
|
||||
var otherLineItemMock = {
|
||||
custom: {
|
||||
bonusProductLineItemUUID: 'someOtherUUID'
|
||||
}
|
||||
};
|
||||
|
||||
var productMock = {};
|
||||
|
||||
describe('bonus product unit price', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
var bonusUnitPrice = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/bonusUnitPrice', {
|
||||
'dw/order/BasketMgr': {
|
||||
getCurrentBasket: function () {
|
||||
return currentBasketMock;
|
||||
}
|
||||
},
|
||||
'*/cartridge/scripts/util/collections': collections
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called bonusUnitPrice', function () {
|
||||
var object = {};
|
||||
|
||||
bonusUnitPrice(object, lineItemMock, productMock);
|
||||
|
||||
assert.equal(object.bonusUnitPrice, 'someFormattedString');
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called bonusUnitPrice when UUIDs do not match', function () {
|
||||
var object = {};
|
||||
bonusUnitPrice(object, otherLineItemMock, productMock);
|
||||
|
||||
assert.equal(object.bonusUnitPrice, '');
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called bonusUnitPrice when no current basket', function () {
|
||||
var object = {};
|
||||
currentBasketMock = null;
|
||||
bonusUnitPrice(object, lineItemMock, productMock);
|
||||
|
||||
assert.equal(object.bonusUnitPrice, '');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var bundledProductLineItemMock = {
|
||||
product: {
|
||||
ID: 'someID'
|
||||
},
|
||||
quantity: {
|
||||
value: 2
|
||||
}
|
||||
};
|
||||
|
||||
var lineItemMock = {
|
||||
bundledProductLineItems: new ArrayList([bundledProductLineItemMock])
|
||||
};
|
||||
|
||||
var productFactoryMock = {
|
||||
get: function () {
|
||||
return 'some product';
|
||||
}
|
||||
};
|
||||
|
||||
describe('bundled product decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var bundledProducts = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/bundledProductLineItems', {
|
||||
'*/cartridge/scripts/util/collections': collections
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called bundledProductLineItems', function () {
|
||||
var object = {};
|
||||
bundledProducts(object, lineItemMock, productFactoryMock);
|
||||
|
||||
assert.equal(object.bundledProductLineItems.length, 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var bonusDiscountLineItem = {
|
||||
custom: {
|
||||
bonusProductLineItemUUID: 'someBonusProductLineItemUUID'
|
||||
},
|
||||
UUID: 'someUUID',
|
||||
maxBonusItems: 1,
|
||||
quantityValue: 1,
|
||||
bonusProductLineItems: new ArrayList([{
|
||||
quantityValue: 1
|
||||
}])
|
||||
};
|
||||
|
||||
var getCurrentBasketStub = sinon.stub();
|
||||
|
||||
var currentBasketMock = {
|
||||
bonusDiscountLineItems: new ArrayList([bonusDiscountLineItem])
|
||||
};
|
||||
|
||||
describe('discount bonus line item decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
var discountBonusLineItems = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/discountBonusLineItems', {
|
||||
'dw/order/BasketMgr': {
|
||||
getCurrentBasket: getCurrentBasketStub
|
||||
},
|
||||
'*/cartridge/scripts/util/collections': collections,
|
||||
'dw/web/URLUtils': {
|
||||
url: function () {
|
||||
return 'someURL';
|
||||
}
|
||||
},
|
||||
'dw/web/Resource': {
|
||||
msg: function () {
|
||||
return 'someResourceString';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called discountLineItems', function () {
|
||||
var object = {};
|
||||
var UUIDMock = 'someBonusProductLineItemUUID';
|
||||
getCurrentBasketStub.returns(currentBasketMock);
|
||||
discountBonusLineItems(object, UUIDMock);
|
||||
|
||||
assert.equal(object.discountLineItems.length, 1);
|
||||
assert.equal(object.discountLineItems[0].pliuuid, 'someBonusProductLineItemUUID');
|
||||
assert.equal(object.discountLineItems[0].uuid, 'someUUID');
|
||||
assert.isFalse(object.discountLineItems[0].full);
|
||||
assert.equal(object.discountLineItems[0].maxpids, 1);
|
||||
assert.equal(object.discountLineItems[0].url, 'someURL');
|
||||
assert.equal(object.discountLineItems[0].msg, 'someResourceString');
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called discountLineItems when UUID and bonusProductLineItemUUID are not a match ', function () {
|
||||
var object = {};
|
||||
var UUIDMock = 'someUUID';
|
||||
getCurrentBasketStub.returns(currentBasketMock);
|
||||
discountBonusLineItems(object, UUIDMock);
|
||||
|
||||
assert.equal(object.discountLineItems.length, 0);
|
||||
});
|
||||
|
||||
it('should create a property on the passed in object called discountLineItems when the max items have not been selected', function () {
|
||||
var object = {};
|
||||
getCurrentBasketStub.returns(currentBasketMock);
|
||||
bonusDiscountLineItem.maxBonusItems = 2;
|
||||
bonusDiscountLineItem.quantityValue = 0;
|
||||
var UUIDMock = 'someBonusProductLineItemUUID';
|
||||
discountBonusLineItems(object, UUIDMock);
|
||||
|
||||
assert.equal(object.discountLineItems.length, 1);
|
||||
});
|
||||
it('should create a property on the passed in object when getCurrentBasket returns null', function () {
|
||||
var object = {};
|
||||
var UUIDMock = 'someUUID';
|
||||
getCurrentBasketStub.returns(null);
|
||||
discountBonusLineItems(object, UUIDMock);
|
||||
|
||||
assert.equal(object.discountLineItems.length, 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var lineItemMock = {
|
||||
gift: true
|
||||
};
|
||||
|
||||
describe('product line item gift decorator', function () {
|
||||
var isGift = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/gift');
|
||||
|
||||
it('should create isGift property for passed in object', function () {
|
||||
var object = {};
|
||||
isGift(object, lineItemMock);
|
||||
|
||||
assert.isTrue(object.isGift);
|
||||
});
|
||||
|
||||
it('should create isGift property for passed in object', function () {
|
||||
var object = {};
|
||||
lineItemMock.gift = false;
|
||||
isGift(object, lineItemMock);
|
||||
|
||||
assert.isFalse(object.isGift);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('product line item options decorator', function () {
|
||||
var options = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/options');
|
||||
|
||||
it('should create options property for passed in object', function () {
|
||||
var object = {};
|
||||
options(object, [{}]);
|
||||
|
||||
assert.equal(object.options.length, 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var productMock = {
|
||||
availabilityModel: {
|
||||
isOrderable: function () { return true; }
|
||||
}
|
||||
};
|
||||
|
||||
describe('product line item orderable decorator', function () {
|
||||
var isOrderable = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/orderable');
|
||||
|
||||
it('should create isOrderable property for passed in object', function () {
|
||||
var object = {};
|
||||
isOrderable(object, productMock, 1);
|
||||
|
||||
assert.isTrue(object.isOrderable);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var lineItemMock = {
|
||||
custom: {
|
||||
preOrderUUID: 'someUUID'
|
||||
}
|
||||
};
|
||||
|
||||
describe('bonus product line item pre order uuid decorator', function () {
|
||||
var preOrderUUID = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/preOrderUUID');
|
||||
|
||||
it('should create preOrderUUID property for passed in object', function () {
|
||||
var object = {};
|
||||
preOrderUUID(object, lineItemMock);
|
||||
|
||||
assert.equal(object.preOrderUUID, 'someUUID');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../../mocks/dw.util.Collection');
|
||||
|
||||
var lineItemMock = {
|
||||
priceAdjustments: new ArrayList([]),
|
||||
getPrice: function () {},
|
||||
adjustedPrice: {
|
||||
add: function () {}
|
||||
},
|
||||
optionProductLineItems: new ArrayList([{
|
||||
adjustedPrice: {}
|
||||
}])
|
||||
};
|
||||
|
||||
describe('product line item price total decorator', function () {
|
||||
var collections = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var priceTotal = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/priceTotal', {
|
||||
'*/cartridge/scripts/util/collections': collections,
|
||||
'*/cartridge/scripts/renderTemplateHelper': {
|
||||
getRenderedHtml: function () { return 'rendered HTML'; }
|
||||
},
|
||||
'dw/util/StringUtils': {
|
||||
formatMoney: function () { return 'formatted Money'; }
|
||||
}
|
||||
});
|
||||
|
||||
it('should create priceTotal property for passed in object', function () {
|
||||
var object = {};
|
||||
priceTotal(object, lineItemMock);
|
||||
|
||||
assert.equal(object.priceTotal.price, 'formatted Money');
|
||||
assert.equal(object.priceTotal.renderedPrice, 'rendered HTML');
|
||||
});
|
||||
|
||||
it('should handel price adjustments', function () {
|
||||
var object = {};
|
||||
lineItemMock.priceAdjustments = new ArrayList([{}]);
|
||||
priceTotal(object, lineItemMock);
|
||||
|
||||
assert.equal(object.priceTotal.nonAdjustedPrice, 'formatted Money');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('product line item quantity decorator', function () {
|
||||
var quantity = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/quantity');
|
||||
|
||||
it('should create quantity property for passed in object', function () {
|
||||
var object = {};
|
||||
quantity(object, 1);
|
||||
|
||||
assert.equal(object.quantity, 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var quantityOptions = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/quantityOptions', {
|
||||
'dw/catalog/ProductInventoryMgr': require('../../../../../mocks/dw/catalog/ProductInventoryMgr'),
|
||||
'*/cartridge/config/preferences': {
|
||||
maxOrderQty: 10
|
||||
}
|
||||
});
|
||||
|
||||
describe('product line item quantity options decorator', function () {
|
||||
describe('When no inventory list provided', function () {
|
||||
var productLineItemMock = {
|
||||
product: {
|
||||
availabilityModel: {
|
||||
inventoryRecord: {
|
||||
ATS: {
|
||||
value: 5
|
||||
}
|
||||
}
|
||||
},
|
||||
minOrderQuantity: {
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
it('should create quantityOptions property for passed in object', function () {
|
||||
var object = {};
|
||||
quantityOptions(object, productLineItemMock, 1);
|
||||
|
||||
assert.equal(object.quantityOptions.minOrderQuantity, 1);
|
||||
assert.equal(object.quantityOptions.maxOrderQuantity, 5);
|
||||
});
|
||||
|
||||
it('should handle no minOrderQuantity on the product', function () {
|
||||
var object = {};
|
||||
productLineItemMock.product.minOrderQuantity.value = null;
|
||||
quantityOptions(object, productLineItemMock, 1);
|
||||
|
||||
assert.equal(object.quantityOptions.minOrderQuantity, 1);
|
||||
assert.equal(object.quantityOptions.maxOrderQuantity, 5);
|
||||
});
|
||||
|
||||
it('should handle perpetual inventory on the product', function () {
|
||||
var object = {};
|
||||
productLineItemMock.product.availabilityModel.inventoryRecord.perpetual = true;
|
||||
quantityOptions(object, productLineItemMock, 1);
|
||||
|
||||
assert.equal(object.quantityOptions.minOrderQuantity, 1);
|
||||
assert.equal(object.quantityOptions.maxOrderQuantity, 10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When inventory list provided', function () {
|
||||
it('should return inventory of the specified productInventoryListID', function () {
|
||||
var productLineItemMock = {
|
||||
product: {
|
||||
availabilityModel: {
|
||||
inventoryRecord: {
|
||||
ATS: {
|
||||
value: 5
|
||||
}
|
||||
}
|
||||
},
|
||||
minOrderQuantity: {
|
||||
value: 2
|
||||
},
|
||||
ID: '000002'
|
||||
},
|
||||
productInventoryListID: 'inventoryListId0001'
|
||||
};
|
||||
|
||||
var object = {};
|
||||
quantityOptions(object, productLineItemMock, 1);
|
||||
|
||||
assert.equal(object.quantityOptions.minOrderQuantity, 2);
|
||||
assert.equal(object.quantityOptions.maxOrderQuantity, 3);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
describe('product line item price total decorator', function () {
|
||||
var renderedPromotions = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/renderedPromotions', {
|
||||
'*/cartridge/scripts/renderTemplateHelper': {
|
||||
getRenderedHtml: function () { return 'rendered HTML'; }
|
||||
}
|
||||
});
|
||||
|
||||
it('should create renderedPromotions property for passed in object', function () {
|
||||
var object = {};
|
||||
object.appliedPromotions = {};
|
||||
renderedPromotions(object);
|
||||
|
||||
assert.equal(object.renderedPromotions, 'rendered HTML');
|
||||
});
|
||||
|
||||
it('should handle no applied promotions', function () {
|
||||
var object = {};
|
||||
renderedPromotions(object);
|
||||
|
||||
assert.equal(object.renderedPromotions, '');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var lineItemMock = {
|
||||
shipment: {
|
||||
UUID: 'someUUID'
|
||||
}
|
||||
};
|
||||
|
||||
describe('product line item shipment decorator', function () {
|
||||
var shipmentUUID = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/shipment');
|
||||
|
||||
it('should create shipmentUUID property for passed in object', function () {
|
||||
var object = {};
|
||||
shipmentUUID(object, lineItemMock);
|
||||
|
||||
assert.equal(object.shipmentUUID, 'someUUID');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var lineItemMock = {
|
||||
UUID: 'someUUID'
|
||||
};
|
||||
|
||||
describe('product line item uuid decorator', function () {
|
||||
var uuid = require('../../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/decorators/uuid');
|
||||
|
||||
it('should create UUID property for passed in object', function () {
|
||||
var object = {};
|
||||
uuid(object, lineItemMock);
|
||||
|
||||
assert.equal(object.UUID, 'someUUID');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,153 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID'
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: [],
|
||||
lineItem: { UUID: '123' }
|
||||
};
|
||||
|
||||
var object = {};
|
||||
|
||||
describe('Order Line Item Model', function () {
|
||||
var productDecorators = require('../../../../mocks/productDecoratorsMock');
|
||||
var productLineItemDecorators = require('../../../../mocks/productLineItemDecoratorsMock');
|
||||
|
||||
var orderLineItem = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/orderLineItem', {
|
||||
'*/cartridge/models/product/decorators/index': productDecorators.mocks,
|
||||
'*/cartridge/models/productLineItem/decorators/index': productLineItemDecorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
productDecorators.stubs.stubBase.reset();
|
||||
productDecorators.stubs.stubPrice.reset();
|
||||
productDecorators.stubs.stubImages.reset();
|
||||
productDecorators.stubs.stubAvailability.reset();
|
||||
productDecorators.stubs.stubDescription.reset();
|
||||
productDecorators.stubs.stubSearchPrice.reset();
|
||||
productDecorators.stubs.stubPromotions.reset();
|
||||
productDecorators.stubs.stubQuantity.reset();
|
||||
productDecorators.stubs.stubQuantitySelector.reset();
|
||||
productDecorators.stubs.stubRatings.reset();
|
||||
productDecorators.stubs.stubSizeChart.reset();
|
||||
productDecorators.stubs.stubVariationAttributes.reset();
|
||||
productDecorators.stubs.stubSearchVariationAttributes.reset();
|
||||
productDecorators.stubs.stubAttributes.reset();
|
||||
productDecorators.stubs.stubOptions.reset();
|
||||
productDecorators.stubs.stubCurrentUrl.reset();
|
||||
productDecorators.stubs.stubReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetReadyToOrder.reset();
|
||||
productDecorators.stubs.stubBundleReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetIndividualProducts.reset();
|
||||
productDecorators.stubs.stubBundledProducts.reset();
|
||||
productLineItemDecorators.stubs.stubQuantity.reset();
|
||||
productLineItemDecorators.stubs.stubGift.reset();
|
||||
productLineItemDecorators.stubs.stubAppliedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubRenderedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubUuid.reset();
|
||||
productLineItemDecorators.stubs.stubOrderable.reset();
|
||||
productLineItemDecorators.stubs.stubShipment.reset();
|
||||
productLineItemDecorators.stubs.stubBonusProductLineItem.reset();
|
||||
productLineItemDecorators.stubs.stubPriceTotal.reset();
|
||||
productLineItemDecorators.stubs.stubOptions.reset();
|
||||
});
|
||||
|
||||
it('should call base for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should not call price for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isFalse(productDecorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should call variationAttributes for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
|
||||
it('should call quantity for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should call gift for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubGift.calledOnce);
|
||||
});
|
||||
|
||||
it('should call appliedPromotions for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubAppliedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call renderedPromotions for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubRenderedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call uuid for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubUuid.calledOnce);
|
||||
});
|
||||
|
||||
it('should call shipment for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubShipment.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bonusOderLineItem for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBonusProductLineItem.calledOnce);
|
||||
});
|
||||
|
||||
it('should call priceTotal for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubPriceTotal.calledOnce);
|
||||
});
|
||||
|
||||
it('should call options for order line item model', function () {
|
||||
orderLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,171 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var productMock = {
|
||||
attributeModel: {},
|
||||
minOrderQuantity: { value: 'someValue' },
|
||||
availabilityModel: {},
|
||||
stepQuantity: { value: 'someOtherValue' },
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; },
|
||||
getMasterProduct: function () {
|
||||
return {
|
||||
getPrimaryCategory: function () { return { custom: { sizeChartID: 'someID' } }; }
|
||||
};
|
||||
},
|
||||
ID: 'someID'
|
||||
};
|
||||
|
||||
var optionsMock = {
|
||||
productType: 'someProductType',
|
||||
optionModel: {},
|
||||
quantity: 1,
|
||||
variationModel: {},
|
||||
promotions: [],
|
||||
variables: [],
|
||||
lineItem: { UUID: '123' }
|
||||
};
|
||||
|
||||
var object = {};
|
||||
|
||||
describe('Product Line Item Model', function () {
|
||||
var productDecorators = require('../../../../mocks/productDecoratorsMock');
|
||||
var productLineItemDecorators = require('../../../../mocks/productLineItemDecoratorsMock');
|
||||
|
||||
var productLineItem = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/productLineItem/productLineItem', {
|
||||
'*/cartridge/models/product/decorators/index': productDecorators.mocks,
|
||||
'*/cartridge/models/productLineItem/decorators/index': productLineItemDecorators.mocks
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
productDecorators.stubs.stubBase.reset();
|
||||
productDecorators.stubs.stubPrice.reset();
|
||||
productDecorators.stubs.stubImages.reset();
|
||||
productDecorators.stubs.stubAvailability.reset();
|
||||
productDecorators.stubs.stubDescription.reset();
|
||||
productDecorators.stubs.stubSearchPrice.reset();
|
||||
productDecorators.stubs.stubPromotions.reset();
|
||||
productDecorators.stubs.stubQuantity.reset();
|
||||
productDecorators.stubs.stubQuantitySelector.reset();
|
||||
productDecorators.stubs.stubRatings.reset();
|
||||
productDecorators.stubs.stubSizeChart.reset();
|
||||
productDecorators.stubs.stubVariationAttributes.reset();
|
||||
productDecorators.stubs.stubSearchVariationAttributes.reset();
|
||||
productDecorators.stubs.stubAttributes.reset();
|
||||
productDecorators.stubs.stubOptions.reset();
|
||||
productDecorators.stubs.stubCurrentUrl.reset();
|
||||
productDecorators.stubs.stubReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetReadyToOrder.reset();
|
||||
productDecorators.stubs.stubBundleReadyToOrder.reset();
|
||||
productDecorators.stubs.stubSetIndividualProducts.reset();
|
||||
productDecorators.stubs.stubBundledProducts.reset();
|
||||
productLineItemDecorators.stubs.stubQuantity.reset();
|
||||
productLineItemDecorators.stubs.stubGift.reset();
|
||||
productLineItemDecorators.stubs.stubAppliedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubRenderedPromotions.reset();
|
||||
productLineItemDecorators.stubs.stubUuid.reset();
|
||||
productLineItemDecorators.stubs.stubOrderable.reset();
|
||||
productLineItemDecorators.stubs.stubShipment.reset();
|
||||
productLineItemDecorators.stubs.stubBonusProductLineItem.reset();
|
||||
productLineItemDecorators.stubs.stubPriceTotal.reset();
|
||||
productLineItemDecorators.stubs.stubQuantityOptions.reset();
|
||||
productLineItemDecorators.stubs.stubOptions.reset();
|
||||
});
|
||||
|
||||
it('should call base for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubBase.calledOnce);
|
||||
});
|
||||
|
||||
it('should call price for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubPrice.calledOnce);
|
||||
});
|
||||
|
||||
it('should call images for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubImages.calledOnce);
|
||||
});
|
||||
|
||||
it('should call variationAttributes for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubVariationAttributes.calledOnce);
|
||||
});
|
||||
|
||||
it('should call availability for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productDecorators.stubs.stubAvailability.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantity for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubQuantity.calledOnce);
|
||||
});
|
||||
|
||||
it('should call gift for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubGift.calledOnce);
|
||||
});
|
||||
|
||||
it('should call appliedPromotions for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubAppliedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call renderedPromotions for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubRenderedPromotions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call uuid for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubUuid.calledOnce);
|
||||
});
|
||||
|
||||
it('should call orderable for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOrderable.calledOnce);
|
||||
});
|
||||
|
||||
it('should call shipment for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubShipment.calledOnce);
|
||||
});
|
||||
|
||||
it('should call bonusProductLineItem for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubBonusProductLineItem.calledOnce);
|
||||
});
|
||||
|
||||
it('should call priceTotal for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubPriceTotal.calledOnce);
|
||||
});
|
||||
|
||||
it('should call quantityOptions for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubQuantityOptions.calledOnce);
|
||||
});
|
||||
|
||||
it('should call options for product line item model', function () {
|
||||
productLineItem(object, productMock, optionsMock);
|
||||
|
||||
assert.isTrue(productLineItemDecorators.stubs.stubOptions.calledOnce);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,129 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var ArrayList = require('../../../mocks/dw.util.Collection');
|
||||
var toProductMock = require('../../../util');
|
||||
|
||||
var ProductLineItemsModel = require('../../../mocks/models/productLineItems');
|
||||
|
||||
var productVariantMock = {
|
||||
ID: '1234567',
|
||||
name: 'test product',
|
||||
variant: true,
|
||||
availabilityModel: {
|
||||
isOrderable: {
|
||||
return: true,
|
||||
type: 'function'
|
||||
},
|
||||
inventoryRecord: {
|
||||
ATS: {
|
||||
value: 100
|
||||
}
|
||||
}
|
||||
},
|
||||
minOrderQuantity: {
|
||||
value: 2
|
||||
}
|
||||
};
|
||||
|
||||
var productMock = {
|
||||
variationModel: {
|
||||
productVariationAttributes: new ArrayList([{
|
||||
attributeID: '',
|
||||
value: ''
|
||||
}]),
|
||||
selectedVariant: productVariantMock
|
||||
}
|
||||
};
|
||||
|
||||
var apiBasketNoBonusLineItems = {
|
||||
productLineItems: new ArrayList([{
|
||||
bonusProductLineItem: false,
|
||||
gift: false,
|
||||
UUID: 'some UUID',
|
||||
adjustedPrice: {
|
||||
value: 'some value',
|
||||
currencyCode: 'US'
|
||||
},
|
||||
quantity: {
|
||||
value: 1
|
||||
},
|
||||
product: toProductMock(productMock),
|
||||
custom: { bonusProductLineItemUUID: '' }
|
||||
}])
|
||||
};
|
||||
|
||||
var apiBasketUncategorizedLineItem = {
|
||||
productLineItems: new ArrayList([{
|
||||
product: toProductMock(null),
|
||||
quantity: {
|
||||
item: {
|
||||
quantity: {
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
noProduct: true
|
||||
}])
|
||||
};
|
||||
|
||||
var apiBasketBonusLineItems = {
|
||||
productLineItems: new ArrayList([{
|
||||
bonusProductLineItem: true,
|
||||
gift: false,
|
||||
UUID: 'some UUID',
|
||||
adjustedPrice: {
|
||||
value: 'some value',
|
||||
currencyCode: 'US'
|
||||
},
|
||||
quantity: {
|
||||
value: 1
|
||||
},
|
||||
product: toProductMock(productMock),
|
||||
custom: { bonusProductLineItemUUID: '', preOrderUUID: '' }
|
||||
},
|
||||
{
|
||||
bonusProductLineItem: false,
|
||||
gift: false,
|
||||
UUID: 'some UUID',
|
||||
adjustedPrice: {
|
||||
value: 'some value',
|
||||
currencyCode: 'US'
|
||||
},
|
||||
quantity: {
|
||||
value: 1
|
||||
},
|
||||
product: toProductMock(productMock),
|
||||
custom: { bonusProductLineItemUUID: 'someUUID', preOrderUUID: 'someUUID' },
|
||||
optionProductLineItems: new ArrayList([{ optionID: 'someOptionID', optionValueID: 'someIDValue' }])
|
||||
}])
|
||||
};
|
||||
|
||||
describe('ProductLineItems model', function () {
|
||||
it('should accept/process a null Basket object', function () {
|
||||
var lineItems = null;
|
||||
var result = new ProductLineItemsModel(lineItems);
|
||||
assert.equal(result.items.length, 0);
|
||||
assert.equal(result.totalQuantity, 0);
|
||||
});
|
||||
|
||||
it('should create product line items and get total quantity', function () {
|
||||
var result = new ProductLineItemsModel(apiBasketNoBonusLineItems.productLineItems);
|
||||
assert.equal(result.items.length, 1);
|
||||
assert.equal(result.totalQuantity, 1);
|
||||
});
|
||||
|
||||
it('should create product line items with bonus line items present', function () {
|
||||
var result = new ProductLineItemsModel(apiBasketBonusLineItems.productLineItems);
|
||||
assert.equal(result.items.length, 2);
|
||||
assert.equal(result.totalQuantity, 2);
|
||||
});
|
||||
|
||||
it('should return product line item with no product image and noProduct equals true', function () {
|
||||
var result = new ProductLineItemsModel(apiBasketUncategorizedLineItem.productLineItems);
|
||||
assert.equal(result.items.length, 1);
|
||||
assert.equal(result.items[0].product, null);
|
||||
assert.equal(result.items[0].noProduct, true);
|
||||
assert.equal(result.items[0].images.small[0].url, '/images/noimagelarge.png');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
|
||||
describe('BaseAttributeValue model', function () {
|
||||
var refinementDefinition = {};
|
||||
var baseAttributeValue = {};
|
||||
|
||||
var BaseAttributeValue = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/base', {
|
||||
'dw/web/Resource': {
|
||||
msgf: function () { return 'some product title'; }
|
||||
}
|
||||
});
|
||||
|
||||
var productSearch = {
|
||||
isRefinedByAttributeValue: function () { return true; },
|
||||
urlRelaxAttributeValue: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'relax url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
var refinementValue = {
|
||||
ID: 'product 1',
|
||||
presentationID: 'prez',
|
||||
value: 'some value',
|
||||
displayValue: 'some display value',
|
||||
hitCount: 10
|
||||
};
|
||||
|
||||
it('should instantiate a Base Attribute Value model', function () {
|
||||
baseAttributeValue = new BaseAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(baseAttributeValue, {
|
||||
actionEndpoint: 'Search-ShowAjax',
|
||||
hitCount: 10,
|
||||
id: 'product 1',
|
||||
presentationId: 'prez',
|
||||
productSearch: productSearch,
|
||||
refinementDefinition: refinementDefinition,
|
||||
refinementValue: refinementValue,
|
||||
selectable: true,
|
||||
value: 'some value',
|
||||
'__proto__': BaseAttributeValue.prototype
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
|
||||
describe('BooleanAttributeValue model', function () {
|
||||
var refinementDefinition = {};
|
||||
var booleanAttributeValue = {};
|
||||
|
||||
var BooleanAttributeValue = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/boolean', {
|
||||
'*/cartridge/models/search/attributeRefinementValue/base': proxyquire(
|
||||
'../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/base', {
|
||||
'dw/web/Resource': {
|
||||
msgf: function () { return 'some product title'; }
|
||||
}
|
||||
}
|
||||
),
|
||||
'dw/web/Resource': {
|
||||
msg: function () { return 'some display value'; }
|
||||
}
|
||||
});
|
||||
|
||||
var productSearch = {
|
||||
isRefinedByAttributeValue: function () { return true; },
|
||||
urlRelaxAttributeValue: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'relax url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
urlRefineAttributeValue: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'select url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
var refinementValue = {
|
||||
ID: 'product 1',
|
||||
presentationID: 'prez',
|
||||
value: 'some value',
|
||||
displayValue: 'some display value',
|
||||
hitCount: 10
|
||||
};
|
||||
|
||||
it('should instantiate a Boolean Attribute Value model', function () {
|
||||
booleanAttributeValue = new BooleanAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(booleanAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'boolean',
|
||||
displayValue: 'some display value',
|
||||
selected: true,
|
||||
selectable: true,
|
||||
title: 'some product title',
|
||||
url: 'relax url'
|
||||
});
|
||||
});
|
||||
|
||||
it('should instantiate a unselected Boolean Attribute Value model', function () {
|
||||
productSearch.isRefinedByAttributeValue = function () { return false; };
|
||||
booleanAttributeValue = new BooleanAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(booleanAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'boolean',
|
||||
displayValue: 'some display value',
|
||||
selected: false,
|
||||
selectable: true,
|
||||
title: 'some product title',
|
||||
url: 'select url'
|
||||
});
|
||||
});
|
||||
|
||||
it('should instantiate a unselectable Boolean Attribute Value model', function () {
|
||||
productSearch.isRefinedByAttributeValue = function () { return false; };
|
||||
refinementValue.hitCount = 0;
|
||||
booleanAttributeValue = new BooleanAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(booleanAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'boolean',
|
||||
displayValue: 'some display value',
|
||||
selected: false,
|
||||
selectable: false,
|
||||
title: 'some product title',
|
||||
url: '#'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
|
||||
describe('CategoryAttributeValue model', function () {
|
||||
var refinementDefinition = {};
|
||||
var booleanAttributeValue = {};
|
||||
|
||||
var CategoryAttributeValue = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/category', {
|
||||
'*/cartridge/models/search/attributeRefinementValue/base': proxyquire(
|
||||
'../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/base', {
|
||||
'dw/web/Resource': {
|
||||
msgf: function () { return 'some product title'; }
|
||||
}
|
||||
}
|
||||
),
|
||||
'dw/web/Resource': {
|
||||
msg: function () { return 'some display value'; }
|
||||
}
|
||||
});
|
||||
|
||||
var productSearch = {
|
||||
isRefinedByAttributeValue: function () { return true; },
|
||||
urlRefineCategory: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'category url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
var refinementValue = {
|
||||
ID: 'product 1',
|
||||
presentationID: 'prez',
|
||||
value: 'some value',
|
||||
displayName: 'some display value',
|
||||
hitCount: 10
|
||||
};
|
||||
|
||||
it('should instantiate a selected root Category Attribute Value model', function () {
|
||||
booleanAttributeValue = new CategoryAttributeValue(productSearch, refinementDefinition, refinementValue, true);
|
||||
|
||||
assert.deepEqual(booleanAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'category',
|
||||
displayValue: 'some display value',
|
||||
selected: true,
|
||||
selectable: true,
|
||||
title: 'some product title',
|
||||
url: 'category url',
|
||||
subCategories: []
|
||||
});
|
||||
});
|
||||
|
||||
it('should instantiate a selected non-root Category Attribute Value model', function () {
|
||||
productSearch.category = {
|
||||
parent: {
|
||||
ID: 'test'
|
||||
}
|
||||
};
|
||||
|
||||
booleanAttributeValue = new CategoryAttributeValue(productSearch, refinementDefinition, refinementValue, true);
|
||||
|
||||
assert.deepEqual(booleanAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'category',
|
||||
displayValue: 'some display value',
|
||||
selected: true,
|
||||
selectable: true,
|
||||
title: 'some product title',
|
||||
url: 'category url',
|
||||
subCategories: []
|
||||
});
|
||||
});
|
||||
|
||||
it('should instantiate a unselected Category Attribute Value model', function () {
|
||||
booleanAttributeValue = new CategoryAttributeValue(productSearch, refinementDefinition, refinementValue, false);
|
||||
|
||||
assert.deepEqual(booleanAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'category',
|
||||
displayValue: 'some display value',
|
||||
selected: false,
|
||||
selectable: true,
|
||||
title: 'some product title',
|
||||
url: 'category url',
|
||||
subCategories: []
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
|
||||
describe('ColorAttributeValue model', function () {
|
||||
var productSearch = {};
|
||||
var refinementDefinition = {};
|
||||
var refinementValue = {};
|
||||
var colorAttributeValue = {};
|
||||
|
||||
var ColorAttributeValue = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/color', {
|
||||
'*/cartridge/models/search/attributeRefinementValue/base': proxyquire(
|
||||
'../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/base', {
|
||||
'dw/web/Resource': {
|
||||
msgf: function () { return 'some product title'; }
|
||||
}
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
it('should instantiate a Color Attribute Value model', function () {
|
||||
productSearch = {
|
||||
isRefinedByAttributeValue: function () { return true; },
|
||||
urlRelaxAttributeValue: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'relax url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
refinementValue = {
|
||||
ID: 'product 1',
|
||||
presentationID: 'prez',
|
||||
value: 'some value',
|
||||
displayValue: 'some display value',
|
||||
hitCount: 10
|
||||
};
|
||||
colorAttributeValue = new ColorAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(colorAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'color',
|
||||
displayValue: 'some display value',
|
||||
presentationId: 'prez',
|
||||
selected: true,
|
||||
selectable: true,
|
||||
swatchId: 'swatch-circle-prez',
|
||||
title: 'some product title',
|
||||
url: 'relax url'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
|
||||
describe('PriceAttributeValue model', function () {
|
||||
var refinementDefinition = {};
|
||||
var priceAttributeValue = {};
|
||||
|
||||
var PriceAttributeValue = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/price', {
|
||||
'*/cartridge/models/search/attributeRefinementValue/base': proxyquire(
|
||||
'../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/base', {
|
||||
'dw/web/Resource': {
|
||||
msgf: function () { return 'some product title'; }
|
||||
}
|
||||
}
|
||||
),
|
||||
'dw/web/Resource': {
|
||||
msg: function () { return 'some display value'; }
|
||||
}
|
||||
});
|
||||
|
||||
var productSearch = {
|
||||
isRefinedByPriceRange: function () { return true; },
|
||||
urlRelaxPrice: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'relax url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
urlRefinePrice: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'select url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
var refinementValue = {
|
||||
ID: 'product 1',
|
||||
presentationID: 'prez',
|
||||
value: 'some value',
|
||||
displayValue: 'some display value',
|
||||
hitCount: 10
|
||||
};
|
||||
|
||||
it('should instantiate a Price Attribute Value model', function () {
|
||||
priceAttributeValue = new PriceAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(priceAttributeValue, {
|
||||
displayValue: 'some display value',
|
||||
selected: true,
|
||||
title: 'some product title',
|
||||
url: 'relax url'
|
||||
});
|
||||
});
|
||||
|
||||
it('should instantiate an unselected Price Attribute Value model', function () {
|
||||
productSearch.isRefinedByPriceRange = function () {
|
||||
return false;
|
||||
};
|
||||
priceAttributeValue = new PriceAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(priceAttributeValue, {
|
||||
displayValue: 'some display value',
|
||||
selected: false,
|
||||
title: 'some product title',
|
||||
url: 'select url'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
|
||||
describe('PromotionAttributeValue model', function () {
|
||||
var refinementDefinition = {};
|
||||
var promotionAttributeValue = {};
|
||||
|
||||
var PromotionAttributeValue = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/promotion', {
|
||||
'*/cartridge/models/search/attributeRefinementValue/base': proxyquire(
|
||||
'../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/base', {
|
||||
'dw/web/Resource': {
|
||||
msgf: function () { return 'some product title'; }
|
||||
}
|
||||
}
|
||||
),
|
||||
'dw/web/Resource': {
|
||||
msg: function () { return 'some display value'; }
|
||||
}
|
||||
});
|
||||
|
||||
var productSearch = {
|
||||
isRefinedByPromotion: function () { return true; },
|
||||
urlRefinePromotion: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'select url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
urlRelaxPromotion: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'relax url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
var refinementValue = {
|
||||
ID: 'product 1',
|
||||
presentationID: 'prez',
|
||||
value: 'some value',
|
||||
displayValue: 'some display value',
|
||||
hitCount: 10
|
||||
};
|
||||
|
||||
it('should instantiate a Promotion Attribute Value model', function () {
|
||||
promotionAttributeValue = new PromotionAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(promotionAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'promotion',
|
||||
displayValue: 'some display value',
|
||||
selected: true,
|
||||
selectable: true,
|
||||
title: 'some product title',
|
||||
url: 'relax url'
|
||||
});
|
||||
});
|
||||
|
||||
it('should instantiate a unselected Promotion Attribute Value model', function () {
|
||||
productSearch.isRefinedByPromotion = function () { return false; };
|
||||
promotionAttributeValue = new PromotionAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(promotionAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'promotion',
|
||||
displayValue: 'some display value',
|
||||
selected: false,
|
||||
selectable: true,
|
||||
title: 'some product title',
|
||||
url: 'select url'
|
||||
});
|
||||
});
|
||||
|
||||
it('should instantiate a unselectable Promotion Attribute Value model', function () {
|
||||
productSearch.isRefinedByPromotion = function () { return false; };
|
||||
refinementValue.hitCount = 0;
|
||||
promotionAttributeValue = new PromotionAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(promotionAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'promotion',
|
||||
displayValue: 'some display value',
|
||||
selected: false,
|
||||
selectable: false,
|
||||
title: 'some product title',
|
||||
url: '#'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
|
||||
describe('SizeAttributeValue model', function () {
|
||||
var productSearch = {};
|
||||
var refinementDefinition = {};
|
||||
var refinementValue = {};
|
||||
var sizeAttributeValue = {};
|
||||
|
||||
var SizeAttributeValue = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/size', {
|
||||
'*/cartridge/models/search/attributeRefinementValue/base': proxyquire(
|
||||
'../../../../../../cartridges/app_storefront_base/cartridge/models/search/attributeRefinementValue/base', {
|
||||
'dw/web/Resource': {
|
||||
msgf: function () { return 'some product title'; }
|
||||
}
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
it('should instantiate a Size Attribute Value model', function () {
|
||||
productSearch = {
|
||||
isRefinedByAttributeValue: function () { return true; },
|
||||
urlRelaxAttributeValue: function () {
|
||||
return {
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () { return 'relax url'; }
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
refinementValue = {
|
||||
ID: 'product 1',
|
||||
presentationID: 'presentationId mock',
|
||||
value: 'some value',
|
||||
displayValue: 'some display value',
|
||||
hitCount: 10
|
||||
};
|
||||
sizeAttributeValue = new SizeAttributeValue(productSearch, refinementDefinition, refinementValue);
|
||||
|
||||
assert.deepEqual(sizeAttributeValue, {
|
||||
id: 'product 1',
|
||||
type: 'size',
|
||||
displayValue: 'some display value',
|
||||
presentationId: 'presentationId mock',
|
||||
selected: true,
|
||||
selectable: true,
|
||||
title: 'some product title',
|
||||
url: 'relax url'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,256 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
var ACTION_ENDPOINT_GRID = 'Search-Content';
|
||||
var ACTION_ENDPOINT_CONTENT = 'Page-Show';
|
||||
var DEFAULT_PAGE_SIZE = 12;
|
||||
var QUERY_PHRASE = 'queryPhraseString';
|
||||
var startingPage;
|
||||
var stubPagingModel = sinon.stub();
|
||||
var mockCollections = require('../../../../mocks/util/collections');
|
||||
|
||||
var contentAssets = [
|
||||
{
|
||||
name: 'name1',
|
||||
ID: 'ID1',
|
||||
description: 'description 1'
|
||||
}, {
|
||||
name: 'name2',
|
||||
ID: 'ID2',
|
||||
description: 'description 2'
|
||||
}, {
|
||||
name: 'name3',
|
||||
ID: 'ID3',
|
||||
description: 'description 3'
|
||||
}, {
|
||||
name: 'name4',
|
||||
ID: 'ID4',
|
||||
description: 'description 4'
|
||||
}, {
|
||||
name: 'name5',
|
||||
ID: 'ID5',
|
||||
description: 'description 5'
|
||||
}, {
|
||||
name: 'name6',
|
||||
ID: 'ID6',
|
||||
description: 'description 6'
|
||||
}, {
|
||||
name: 'name7',
|
||||
ID: 'ID7',
|
||||
description: 'description 7'
|
||||
}, {
|
||||
name: 'name8',
|
||||
ID: 'ID8',
|
||||
description: 'description 8'
|
||||
}, {
|
||||
name: 'name9',
|
||||
ID: 'ID9',
|
||||
description: 'description 9'
|
||||
}, {
|
||||
name: 'name10',
|
||||
ID: 'ID10',
|
||||
description: 'description 10'
|
||||
}, {
|
||||
name: 'name11',
|
||||
ID: 'ID11',
|
||||
description: 'description 11'
|
||||
}, {
|
||||
name: 'name12',
|
||||
ID: 'ID12',
|
||||
description: 'description 12'
|
||||
}, {
|
||||
name: 'name13',
|
||||
ID: 'ID13',
|
||||
description: 'description 13'
|
||||
}
|
||||
];
|
||||
|
||||
var expectedResultpage1 = {
|
||||
queryPhrase: 'queryPhraseString',
|
||||
contents: [
|
||||
{
|
||||
name: 'name1',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID1',
|
||||
description: 'description 1'
|
||||
}, {
|
||||
name: 'name2',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID2',
|
||||
description: 'description 2'
|
||||
}, {
|
||||
name: 'name3',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID3',
|
||||
description: 'description 3'
|
||||
}, {
|
||||
name: 'name4',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID4',
|
||||
description: 'description 4'
|
||||
}, {
|
||||
name: 'name5',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID5',
|
||||
description: 'description 5'
|
||||
}, {
|
||||
name: 'name6',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID6',
|
||||
description: 'description 6'
|
||||
}, {
|
||||
name: 'name7',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID7',
|
||||
description: 'description 7'
|
||||
}, {
|
||||
name: 'name8',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID8',
|
||||
description: 'description 8'
|
||||
}, {
|
||||
name: 'name9',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID9',
|
||||
description: 'description 9'
|
||||
}, {
|
||||
name: 'name10',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID10',
|
||||
description: 'description 10'
|
||||
}, {
|
||||
name: 'name11',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID11',
|
||||
description: 'description 11'
|
||||
}, {
|
||||
name: 'name12',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID12',
|
||||
description: 'description 12'
|
||||
}
|
||||
],
|
||||
contentCount: 13,
|
||||
moreContentUrl: ACTION_ENDPOINT_GRID + ' q queryPhraseString',
|
||||
hasMessage: true
|
||||
};
|
||||
|
||||
var expectedResultpage2 = {
|
||||
queryPhrase: 'queryPhraseString',
|
||||
contents: [
|
||||
{
|
||||
name: 'name13',
|
||||
url: ACTION_ENDPOINT_CONTENT + ' cid ID13',
|
||||
description: 'description 13'
|
||||
}
|
||||
],
|
||||
contentCount: 13,
|
||||
moreContentUrl: null,
|
||||
hasMessage: false
|
||||
};
|
||||
|
||||
var ContentSearch = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/search/contentSearch.js', {
|
||||
'dw/web/URLUtils': {
|
||||
url: function (endpoint, param, value) { return [endpoint, param, value].join(' '); }
|
||||
},
|
||||
'*/cartridge/scripts/util/collections': {
|
||||
map: mockCollections.map
|
||||
},
|
||||
'dw/web/PagingModel': stubPagingModel,
|
||||
'*/cartridge/config/preferences': {
|
||||
maxOrderQty: 10,
|
||||
defaultPageSize: 12
|
||||
}
|
||||
});
|
||||
|
||||
var createApiContentSearchResult = function (queryPhrase, Page) {
|
||||
var index = 0;
|
||||
var contentIterator = {
|
||||
items: contentAssets,
|
||||
hasNext: function () {
|
||||
return index < contentAssets.length;
|
||||
},
|
||||
next: function () {
|
||||
return contentAssets[index++];
|
||||
}
|
||||
};
|
||||
return new ContentSearch(contentIterator, contentAssets.length, queryPhrase, Page, DEFAULT_PAGE_SIZE);
|
||||
};
|
||||
|
||||
describe('ContentSearch model', function () {
|
||||
var index = 0;
|
||||
var theCurrentPage;
|
||||
|
||||
var pagingModelInstance = {
|
||||
currentPage: undefined,
|
||||
setPageSize: function () {
|
||||
},
|
||||
setStart: function (startPage) {
|
||||
this.startPage = startPage;
|
||||
this.maxPage = Math.ceil(contentAssets.length / DEFAULT_PAGE_SIZE);
|
||||
index = startPage;
|
||||
theCurrentPage = Math.ceil((startPage + 1) / DEFAULT_PAGE_SIZE);
|
||||
this.currentPage = theCurrentPage;
|
||||
},
|
||||
startPage: undefined,
|
||||
maxPage: undefined,
|
||||
pageElements: {
|
||||
hasNext: function () {
|
||||
return index < contentAssets.length && index < DEFAULT_PAGE_SIZE * theCurrentPage;
|
||||
},
|
||||
next: function () {
|
||||
return contentAssets[index++];
|
||||
},
|
||||
asList: function () {
|
||||
return contentAssets.slice(startingPage, theCurrentPage * DEFAULT_PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
stubPagingModel.returns(pagingModelInstance);
|
||||
|
||||
describe('First page of results', function () {
|
||||
beforeEach(function () {
|
||||
startingPage = 0;
|
||||
});
|
||||
|
||||
it('should return a page worth of content', function () {
|
||||
var result = createApiContentSearchResult(QUERY_PHRASE, startingPage);
|
||||
assert.deepEqual(result, expectedResultpage1);
|
||||
});
|
||||
|
||||
it('should return no more content then the page size value', function () {
|
||||
var result = createApiContentSearchResult(QUERY_PHRASE, startingPage);
|
||||
assert.isAtMost(result.contents.length, DEFAULT_PAGE_SIZE);
|
||||
});
|
||||
|
||||
it('should return the total number of content', function () {
|
||||
var result = createApiContentSearchResult(QUERY_PHRASE, startingPage);
|
||||
assert.equal(contentAssets.length, result.contentCount);
|
||||
});
|
||||
|
||||
it('should return a link for more content if there is more content to display', function () {
|
||||
var result = createApiContentSearchResult(QUERY_PHRASE, startingPage);
|
||||
assert.equal(expectedResultpage1.moreContentUrl, result.moreContentUrl);
|
||||
assert.isBelow(DEFAULT_PAGE_SIZE, result.contentCount);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Second / Last page of results', function () {
|
||||
beforeEach(function () {
|
||||
startingPage = 0;
|
||||
startingPage += DEFAULT_PAGE_SIZE;
|
||||
});
|
||||
|
||||
it('should return the second page worth of content', function () {
|
||||
var result = createApiContentSearchResult(QUERY_PHRASE, startingPage);
|
||||
assert.deepEqual(result, expectedResultpage2);
|
||||
});
|
||||
|
||||
it('should return less content then the page size for the last page', function () {
|
||||
var result = createApiContentSearchResult(QUERY_PHRASE, startingPage + DEFAULT_PAGE_SIZE);
|
||||
assert.isAtMost(result.contents.length, DEFAULT_PAGE_SIZE);
|
||||
});
|
||||
|
||||
it('should return the total number of content', function () {
|
||||
var result = createApiContentSearchResult(QUERY_PHRASE, startingPage + DEFAULT_PAGE_SIZE);
|
||||
assert.equal(contentAssets.length, result.contentCount);
|
||||
});
|
||||
|
||||
it('should return null if there is there is no more content to display', function () {
|
||||
var result = createApiContentSearchResult(QUERY_PHRASE, startingPage + DEFAULT_PAGE_SIZE);
|
||||
assert.equal(expectedResultpage2.moreContentUrl, result.moreContentUrl);
|
||||
assert.isBelow(DEFAULT_PAGE_SIZE, result.contentCount);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,283 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
var mockCollections = require('../../../../mocks/util/collections');
|
||||
|
||||
describe('ProductSearch model', function () {
|
||||
var endpointSearchShow = 'Search-ShowAjax';
|
||||
var endpointSearchUpdateGrid = 'Search-UpdateGrid';
|
||||
var pluckValue = 'plucked';
|
||||
var spySetPageSize = sinon.spy();
|
||||
var spySetStart = sinon.spy();
|
||||
var stubAppendPaging = sinon.stub();
|
||||
var stubGetPageSize = sinon.stub();
|
||||
var stubAppendQueryParams = sinon.stub();
|
||||
stubAppendQueryParams.returns({ toString: function () {} });
|
||||
|
||||
var defaultPageSize = 12;
|
||||
var pagingModelInstance = {
|
||||
appendPaging: stubAppendPaging,
|
||||
getPageSize: stubGetPageSize,
|
||||
getEnd: function () { return 10; },
|
||||
setPageSize: spySetPageSize,
|
||||
setStart: spySetStart
|
||||
};
|
||||
var stubPagingModel = sinon.stub();
|
||||
var refinementValues = [{
|
||||
value: 1,
|
||||
selected: false
|
||||
}, {
|
||||
value: 2,
|
||||
selected: true
|
||||
}, {
|
||||
value: 3,
|
||||
selected: false
|
||||
}];
|
||||
var ProductSearch = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/search/productSearch', {
|
||||
'*/cartridge/scripts/util/collections': {
|
||||
map: mockCollections.map,
|
||||
pluck: function () { return pluckValue; }
|
||||
},
|
||||
'*/cartridge/scripts/factories/searchRefinements': {
|
||||
get: function () { return refinementValues; }
|
||||
},
|
||||
'*/cartridge/models/search/productSortOptions': proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/search/productSortOptions', {
|
||||
'*/cartridge/scripts/util/collections': {
|
||||
map: mockCollections.map
|
||||
},
|
||||
'*/cartridge/scripts/helpers/urlHelpers': {
|
||||
appendQueryParams: function () {}
|
||||
}
|
||||
}),
|
||||
'*/cartridge/scripts/helpers/urlHelpers': {
|
||||
appendQueryParams: stubAppendQueryParams
|
||||
},
|
||||
'*/cartridge/scripts/helpers/searchHelpers': {
|
||||
getBannerImageUrl: function (category) { return (category && category.weAreMockingThings) || ''; }
|
||||
},
|
||||
'dw/web/URLUtils': {
|
||||
url: function (endpoint, param, value) { return [endpoint, param, value].join(' '); }
|
||||
},
|
||||
'dw/web/PagingModel': stubPagingModel,
|
||||
'*/cartridge/config/preferences': {
|
||||
maxOrderQty: 10,
|
||||
defaultPageSize: 12
|
||||
}
|
||||
});
|
||||
|
||||
var apiProductSearch;
|
||||
var httpParams = {};
|
||||
var result = '';
|
||||
|
||||
stubPagingModel.returns(pagingModelInstance);
|
||||
stubGetPageSize.returns(defaultPageSize);
|
||||
|
||||
afterEach(function () {
|
||||
spySetStart.reset();
|
||||
spySetPageSize.reset();
|
||||
stubAppendQueryParams.reset();
|
||||
});
|
||||
|
||||
describe('.getRefinements()', function () {
|
||||
var displayName = 'zodiac sign';
|
||||
var categoryRefinement = { cat: 'catRefinement' };
|
||||
var attrRefinement = { attr: 'attrRefinement' };
|
||||
|
||||
beforeEach(function () {
|
||||
apiProductSearch = {
|
||||
isCategorySearch: false,
|
||||
refinements: {
|
||||
refinementDefinitions: [{
|
||||
displayName: displayName,
|
||||
categoryRefinement: categoryRefinement,
|
||||
attributeRefinement: attrRefinement,
|
||||
values: refinementValues
|
||||
}],
|
||||
getAllRefinementValues: function () {}
|
||||
},
|
||||
url: function () { return 'http://some.url'; }
|
||||
};
|
||||
});
|
||||
|
||||
it('should return refinements with a display name', function () {
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.deepEqual(result.refinements[0].displayName, displayName);
|
||||
});
|
||||
|
||||
it('should return refinements with a categoryRefinement value', function () {
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.deepEqual(result.refinements[0].isCategoryRefinement, categoryRefinement);
|
||||
});
|
||||
|
||||
it('should return refinements with an attribute refinement value', function () {
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.deepEqual(result.refinements[0].isAttributeRefinement, attrRefinement);
|
||||
});
|
||||
|
||||
it('should return an object with refinement values', function () {
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.deepEqual(result.refinements[0].values, refinementValues);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getSelectedFilters()', function () {
|
||||
beforeEach(function () {
|
||||
apiProductSearch = {
|
||||
isCategorySearch: false,
|
||||
refinements: {
|
||||
refinementDefinitions: [{}],
|
||||
getAllRefinementValues: function () {}
|
||||
},
|
||||
url: function () { return 'http://some.url'; }
|
||||
};
|
||||
});
|
||||
|
||||
it('should retrieve filter values that have been selected', function () {
|
||||
var selectedFilter = refinementValues.find(function (value) { return value.selected === true; });
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.equal(result.selectedFilters[0], selectedFilter);
|
||||
});
|
||||
|
||||
it('should retrieve filter values that have been selected', function () {
|
||||
var selectedFilter = refinementValues.find(function (value) { return value.selected === true; });
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.equal(result.selectedFilters[0], selectedFilter);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getResetLink()', function () {
|
||||
var expectedLink = '';
|
||||
|
||||
beforeEach(function () {
|
||||
apiProductSearch = {
|
||||
categorySearch: false,
|
||||
refinements: {
|
||||
refinementDefinitions: []
|
||||
},
|
||||
url: function () { return 'http://some.url'; }
|
||||
};
|
||||
|
||||
httpParams = {
|
||||
cgid: 'cat123',
|
||||
q: 'keyword'
|
||||
};
|
||||
});
|
||||
|
||||
it('should return a reset link for keyword searches', function () {
|
||||
expectedLink = [endpointSearchShow, 'q', httpParams.q].join(' ');
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.equal(result.resetLink, expectedLink);
|
||||
});
|
||||
|
||||
it('should return a reset link for category searches', function () {
|
||||
apiProductSearch.categorySearch = true;
|
||||
expectedLink = [endpointSearchShow, 'cgid', httpParams.cgid].join(' ');
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.equal(result.resetLink, expectedLink);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getBannerImageUrl()', function () {
|
||||
it('should use the searchHelper to resolve the banner URL', function () {
|
||||
apiProductSearch = {
|
||||
refinements: {
|
||||
refinementDefinitions: []
|
||||
},
|
||||
url: function () { return 'http://some.url'; },
|
||||
category: {
|
||||
weAreMockingThings: 'withMockData'
|
||||
}
|
||||
};
|
||||
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.equal(result.bannerImageUrl, 'withMockData');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getPagingModel()', function () {
|
||||
beforeEach(function () {
|
||||
apiProductSearch = {
|
||||
isCategorySearch: false,
|
||||
refinements: {
|
||||
refinementDefinitions: []
|
||||
},
|
||||
url: function () { return 'http://some.url'; }
|
||||
};
|
||||
});
|
||||
|
||||
it('should call the PagingModel.setStart() method', function () {
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.isTrue(spySetStart.called);
|
||||
});
|
||||
|
||||
it('should call the PagingModel.setPageSize() method', function () {
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.isTrue(spySetPageSize.called);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getShowMoreUrl()', function () {
|
||||
var currentPageSize = 12;
|
||||
var expectedUrl = 'some url';
|
||||
|
||||
beforeEach(function () {
|
||||
apiProductSearch = {
|
||||
isCategorySearch: false,
|
||||
refinements: {
|
||||
refinementDefinitions: []
|
||||
},
|
||||
url: function () { return endpointSearchUpdateGrid; }
|
||||
};
|
||||
|
||||
stubGetPageSize.returns(currentPageSize);
|
||||
stubAppendPaging.returns(expectedUrl);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
stubGetPageSize.reset();
|
||||
});
|
||||
|
||||
it('should return a url string if not on final results page', function () {
|
||||
expectedUrl = 'some url';
|
||||
apiProductSearch.count = 14;
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.equal(result.showMoreUrl, expectedUrl);
|
||||
});
|
||||
|
||||
it('should return an empty string if last results page', function () {
|
||||
expectedUrl = '';
|
||||
apiProductSearch.count = 10;
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.equal(result.showMoreUrl, expectedUrl);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getPermaLink()', function () {
|
||||
var expectedPermalink = 'permalink url';
|
||||
var mockToString = function () { return expectedPermalink; };
|
||||
stubAppendQueryParams.returns({ toString: mockToString });
|
||||
|
||||
beforeEach(function () {
|
||||
httpParams = {
|
||||
start: '100'
|
||||
};
|
||||
});
|
||||
|
||||
it('should produce a permalink URL', function () {
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.equal(result.permalink, expectedPermalink);
|
||||
});
|
||||
|
||||
it('should append sz query param to a url = to start and default page size', function () {
|
||||
result = new ProductSearch(apiProductSearch, httpParams, 'sorting-rule-1', [], {});
|
||||
assert.isTrue(stubAppendQueryParams.calledWith(endpointSearchUpdateGrid));
|
||||
assert.deepEqual(stubAppendQueryParams.args[0][1], {
|
||||
start: '0',
|
||||
// start of 100 + default page size of 12
|
||||
sz: 112
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var mockCollections = require('../../../../mocks/util/collections');
|
||||
|
||||
describe('ProductSortOptions model', function () {
|
||||
var sortRuleUrlWithParams = 'some url with params';
|
||||
var ProductSortOptions = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/models/search/productSortOptions', {
|
||||
'*/cartridge/scripts/util/collections': {
|
||||
map: mockCollections.map
|
||||
},
|
||||
'*/cartridge/scripts/helpers/urlHelpers': {
|
||||
appendQueryParams: function () {
|
||||
return {
|
||||
toString: function () {
|
||||
return sortRuleUrlWithParams;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var sortRuleUrl = 'some url';
|
||||
var productSearch = {
|
||||
category: {
|
||||
defaultSortingRule: {
|
||||
ID: 'defaultRule1'
|
||||
}
|
||||
},
|
||||
urlSortingRule: function () {
|
||||
return {
|
||||
toString: function () { return sortRuleUrl; }
|
||||
};
|
||||
}
|
||||
};
|
||||
var sortingRuleId = 'provided sort rule ID';
|
||||
var sortingOption1 = {
|
||||
displayName: 'Sort Option 1',
|
||||
ID: 'abc',
|
||||
sortingRule: 'rule1'
|
||||
};
|
||||
var sortingOption2 = {
|
||||
displayName: 'Sort Option 2',
|
||||
ID: 'cde',
|
||||
sortingRule: 'rule2'
|
||||
};
|
||||
var sortingOptions = [sortingOption1, sortingOption2];
|
||||
var rootCategory = {
|
||||
defaultSortingRule: {
|
||||
ID: 'defaultRule2'
|
||||
}
|
||||
};
|
||||
var pagingModel = { end: 5 };
|
||||
|
||||
it('should set a list of sorting rule options', function () {
|
||||
var productSortOptions = new ProductSortOptions(productSearch, null, sortingOptions, null, pagingModel);
|
||||
assert.deepEqual(productSortOptions.options, [{
|
||||
displayName: sortingOption1.displayName,
|
||||
id: sortingOption1.ID,
|
||||
url: sortRuleUrlWithParams
|
||||
}, {
|
||||
displayName: sortingOption2.displayName,
|
||||
id: sortingOption2.ID,
|
||||
url: sortRuleUrlWithParams
|
||||
}]);
|
||||
});
|
||||
|
||||
it('should set rule ID to provided sort rule ID', function () {
|
||||
var productSortOptions = new ProductSortOptions(productSearch, sortingRuleId, sortingOptions, null, pagingModel);
|
||||
assert.isTrue(productSortOptions.ruleId === sortingRuleId);
|
||||
});
|
||||
|
||||
it('should set rule ID to category\'s default sort rule ID when no rule provided', function () {
|
||||
var productSearchWithNoCategory = {
|
||||
category: null,
|
||||
urlSortingRule: productSearch.urlSortingRule
|
||||
};
|
||||
var productSortOptions = new ProductSortOptions(productSearchWithNoCategory, null, sortingOptions, rootCategory, pagingModel);
|
||||
assert.isTrue(productSortOptions.ruleId === rootCategory.defaultSortingRule.ID);
|
||||
});
|
||||
|
||||
it('should set rule ID to product search\'s category\'s default sort rule ID when no rule provided', function () {
|
||||
var productSortOptions = new ProductSortOptions(productSearch, null, sortingOptions, null, pagingModel);
|
||||
assert.isTrue(productSortOptions.ruleId === productSearch.category.defaultSortingRule.ID);
|
||||
});
|
||||
|
||||
it('should set rule ID to \'null\' when no rule provided and there is no default rule for category', function () {
|
||||
var productSearchWithNoCategoryDefaultSortingRule = {
|
||||
category: {
|
||||
defaultSortingRule: null
|
||||
},
|
||||
urlSortingRule: productSearch.urlSortingRule
|
||||
};
|
||||
var productSortOptions = new ProductSortOptions(productSearchWithNoCategoryDefaultSortingRule, null, sortingOptions, rootCategory, pagingModel);
|
||||
assert.isTrue(productSortOptions.ruleId === null);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,100 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
|
||||
describe('Category Suggestions model', function () {
|
||||
var nextCategoryStub = sinon.stub();
|
||||
var urlStub = sinon.stub();
|
||||
var CategorySuggestions = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/suggestions/category.js', {
|
||||
'dw/web/URLUtils': {
|
||||
url: urlStub
|
||||
}
|
||||
});
|
||||
var category1 = {
|
||||
category: {
|
||||
ID: 1,
|
||||
displayName: 'Category 1',
|
||||
image: {
|
||||
url: 'image url 1'
|
||||
},
|
||||
parent: {
|
||||
ID: 4,
|
||||
displayName: 'Category 1 Parent'
|
||||
}
|
||||
}
|
||||
};
|
||||
var category2 = {
|
||||
category: {
|
||||
ID: 2,
|
||||
displayName: 'Category 2',
|
||||
image: {
|
||||
url: 'image url 2'
|
||||
},
|
||||
parent: {
|
||||
ID: 5,
|
||||
displayName: 'Category 2 Parent'
|
||||
}
|
||||
}
|
||||
};
|
||||
var category3 = {
|
||||
category: {
|
||||
ID: 3,
|
||||
displayName: 'Category 3',
|
||||
image: {
|
||||
url: 'image url 3'
|
||||
},
|
||||
parent: {
|
||||
ID: 6,
|
||||
displayName: 'Category 3 Parent'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
nextCategoryStub.onCall(0).returns(category1);
|
||||
nextCategoryStub.onCall(1).returns(category2);
|
||||
nextCategoryStub.onCall(2).returns(category3);
|
||||
|
||||
urlStub.onCall(0).returns('url1');
|
||||
urlStub.onCall(1).returns('url2');
|
||||
urlStub.onCall(2).returns('url3');
|
||||
|
||||
it('should produce a CategorySuggestions instance', function () {
|
||||
var suggestions = {
|
||||
categorySuggestions: {
|
||||
suggestedCategories: {
|
||||
next: nextCategoryStub,
|
||||
hasNext: function () { return true; }
|
||||
},
|
||||
hasSuggestions: function () { return true; }
|
||||
}
|
||||
};
|
||||
|
||||
var categorySuggestions = new CategorySuggestions(suggestions, 3);
|
||||
|
||||
assert.deepEqual(categorySuggestions, {
|
||||
available: true,
|
||||
categories: [{
|
||||
imageUrl: 'image url 1',
|
||||
name: 'Category 1',
|
||||
url: 'url1',
|
||||
parentID: 4,
|
||||
parentName: 'Category 1 Parent'
|
||||
}, {
|
||||
imageUrl: 'image url 2',
|
||||
name: 'Category 2',
|
||||
url: 'url2',
|
||||
parentID: 5,
|
||||
parentName: 'Category 2 Parent'
|
||||
}, {
|
||||
imageUrl: 'image url 3',
|
||||
name: 'Category 3',
|
||||
url: 'url3',
|
||||
parentID: 6,
|
||||
parentName: 'Category 3 Parent'
|
||||
}]
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
|
||||
describe('Content Suggestions model', function () {
|
||||
var nextSuggestionStub = sinon.stub();
|
||||
var urlStub = sinon.stub();
|
||||
var ContentSuggestions = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/suggestions/content.js', {
|
||||
'dw/web/URLUtils': {
|
||||
url: urlStub
|
||||
}
|
||||
});
|
||||
var content1 = {
|
||||
content: {
|
||||
name: 'Content 1',
|
||||
ID: 1
|
||||
}
|
||||
};
|
||||
var content2 = {
|
||||
content: {
|
||||
name: 'Content 2',
|
||||
ID: 2
|
||||
}
|
||||
};
|
||||
var content3 = {
|
||||
content: {
|
||||
name: 'Content 3',
|
||||
ID: 3
|
||||
}
|
||||
};
|
||||
|
||||
urlStub.onCall(0).returns('url1');
|
||||
urlStub.onCall(1).returns('url2');
|
||||
urlStub.onCall(2).returns('url3');
|
||||
|
||||
nextSuggestionStub.onCall(0).returns(content1);
|
||||
nextSuggestionStub.onCall(1).returns(content2);
|
||||
nextSuggestionStub.onCall(2).returns(content3);
|
||||
|
||||
it('should produce a ContentSuggestions instance', function () {
|
||||
var suggestions = {
|
||||
contentSuggestions: {
|
||||
suggestedContent: {
|
||||
next: nextSuggestionStub,
|
||||
hasNext: function () { return true; }
|
||||
},
|
||||
hasSuggestions: function () { return true; }
|
||||
}
|
||||
};
|
||||
|
||||
var contentSuggestions = new ContentSuggestions(suggestions, 3);
|
||||
|
||||
assert.deepEqual(contentSuggestions, {
|
||||
available: true,
|
||||
contents: [{
|
||||
name: 'Content 1',
|
||||
url: 'url1'
|
||||
}, {
|
||||
name: 'Content 2',
|
||||
url: 'url2'
|
||||
}, {
|
||||
name: 'Content 3',
|
||||
url: 'url3'
|
||||
}]
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
|
||||
describe('Product Suggestions model', function () {
|
||||
var nextProductStub = sinon.stub();
|
||||
var nextPhraseStub = sinon.stub();
|
||||
var urlStub = sinon.stub();
|
||||
var ProductSuggestions = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/suggestions/product.js', {
|
||||
'dw/web/URLUtils': { url: urlStub },
|
||||
'*/cartridge/config/preferences': {
|
||||
suggestionsActionEnpoint: 'Product-Show',
|
||||
imageSize: 'medium'
|
||||
}
|
||||
});
|
||||
var variationModel = {
|
||||
defaultVariant: {
|
||||
getImage: function () {
|
||||
return {
|
||||
URL: {
|
||||
toString: function () { return 'image url'; }
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
var product1 = {
|
||||
productSearchHit: {
|
||||
product: {
|
||||
name: 'Content 1',
|
||||
ID: 1,
|
||||
master: true,
|
||||
variationModel: variationModel
|
||||
}
|
||||
}
|
||||
};
|
||||
var product2 = {
|
||||
productSearchHit: {
|
||||
product: {
|
||||
name: 'Content 2',
|
||||
ID: 2,
|
||||
master: true,
|
||||
variationModel: variationModel
|
||||
}
|
||||
}
|
||||
};
|
||||
var product3 = {
|
||||
productSearchHit: {
|
||||
product: {
|
||||
name: 'Content 3',
|
||||
ID: 3,
|
||||
master: true,
|
||||
variationModel: variationModel
|
||||
}
|
||||
}
|
||||
};
|
||||
var phrase1 = {
|
||||
exactMatch: true,
|
||||
phrase: 'phrase 1'
|
||||
};
|
||||
var phrase2 = {
|
||||
exactMatch: true,
|
||||
phrase: 'phrase 2'
|
||||
};
|
||||
var phrase3 = {
|
||||
exactMatch: true,
|
||||
phrase: 'phrase 3'
|
||||
};
|
||||
|
||||
urlStub.onCall(0).returns('url1');
|
||||
urlStub.onCall(1).returns('url2');
|
||||
urlStub.onCall(2).returns('url3');
|
||||
|
||||
nextProductStub.onCall(0).returns(product1);
|
||||
nextProductStub.onCall(1).returns(product2);
|
||||
nextProductStub.onCall(2).returns(product3);
|
||||
|
||||
nextPhraseStub.onCall(0).returns(phrase1);
|
||||
nextPhraseStub.onCall(1).returns(phrase2);
|
||||
nextPhraseStub.onCall(2).returns(phrase3);
|
||||
|
||||
it('should product a ProductSuggestions instance', function () {
|
||||
var suggestions = {
|
||||
productSuggestions: {
|
||||
searchPhraseSuggestions: {
|
||||
suggestedPhrases: {
|
||||
hasNext: function () { return true; },
|
||||
next: nextPhraseStub
|
||||
}
|
||||
},
|
||||
suggestedProducts: {
|
||||
hasNext: function () { return true; },
|
||||
next: nextProductStub
|
||||
},
|
||||
hasSuggestions: function () { return true; }
|
||||
}
|
||||
};
|
||||
|
||||
var productSuggestions = new ProductSuggestions(suggestions, 3);
|
||||
|
||||
assert.deepEqual(productSuggestions, {
|
||||
available: true,
|
||||
phrases: [{
|
||||
exactMatch: true,
|
||||
value: 'phrase 1'
|
||||
}, {
|
||||
exactMatch: true,
|
||||
value: 'phrase 2'
|
||||
}, {
|
||||
exactMatch: true,
|
||||
value: 'phrase 3'
|
||||
}],
|
||||
products: [{
|
||||
imageUrl: 'image url',
|
||||
name: 'Content 1',
|
||||
url: 'url1'
|
||||
}, {
|
||||
imageUrl: 'image url',
|
||||
name: 'Content 2',
|
||||
url: 'url2'
|
||||
}, {
|
||||
imageUrl: 'image url',
|
||||
name: 'Content 3',
|
||||
url: 'url3'
|
||||
}]
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,115 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
|
||||
describe('SearchPhrase Suggestions model', function () {
|
||||
var nextPhraseStub = sinon.stub();
|
||||
var urlStub = sinon.stub();
|
||||
var SearchPhraseSuggestions = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/models/search/suggestions/searchPhrase.js', {
|
||||
'dw/web/URLUtils': {
|
||||
url: urlStub
|
||||
}
|
||||
});
|
||||
var phrase1 = {
|
||||
phrase: 'phrase 1'
|
||||
};
|
||||
var phrase2 = {
|
||||
phrase: 'phrase 2'
|
||||
};
|
||||
var phrase3 = {
|
||||
phrase: 'phrase 3'
|
||||
};
|
||||
|
||||
urlStub.onCall(0).returns('url1');
|
||||
urlStub.onCall(1).returns('url2');
|
||||
urlStub.onCall(2).returns('url3');
|
||||
|
||||
nextPhraseStub.onCall(0).returns(phrase1);
|
||||
nextPhraseStub.onCall(1).returns(phrase2);
|
||||
nextPhraseStub.onCall(2).returns(phrase3);
|
||||
|
||||
afterEach(function () {
|
||||
urlStub.reset();
|
||||
nextPhraseStub.reset();
|
||||
});
|
||||
|
||||
it('should produce a BrandSuggestions instance', function () {
|
||||
var suggestions = {
|
||||
brandSuggestions: {
|
||||
searchPhraseSuggestions: {
|
||||
hasSuggestedPhrases: function () { return true; },
|
||||
suggestedPhrases: {
|
||||
hasNext: function () { return true; },
|
||||
next: nextPhraseStub
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var brandSuggestions = new SearchPhraseSuggestions(suggestions.brandSuggestions, 3);
|
||||
|
||||
assert.deepEqual(brandSuggestions, {
|
||||
available: true,
|
||||
phrases: [{
|
||||
value: 'phrase 1',
|
||||
url: 'url1'
|
||||
}, {
|
||||
value: 'phrase 2',
|
||||
url: 'url2'
|
||||
}, {
|
||||
value: 'phrase 3',
|
||||
url: 'url3'
|
||||
}]
|
||||
});
|
||||
});
|
||||
it('should produce a RecentSuggestions instance', function () {
|
||||
var suggestions = {
|
||||
recentSearchPhrases: {
|
||||
hasNext: function () { return true; },
|
||||
next: nextPhraseStub
|
||||
}
|
||||
};
|
||||
|
||||
var recentSuggestions = new SearchPhraseSuggestions(suggestions.recentSearchPhrases, 3);
|
||||
|
||||
assert.deepEqual(recentSuggestions, {
|
||||
available: true,
|
||||
phrases: [{
|
||||
value: 'phrase 1',
|
||||
url: 'url1'
|
||||
}, {
|
||||
value: 'phrase 2',
|
||||
url: 'url2'
|
||||
}, {
|
||||
value: 'phrase 3',
|
||||
url: 'url3'
|
||||
}]
|
||||
});
|
||||
});
|
||||
it('should produce a PopularSuggestions instance', function () {
|
||||
var suggestions = {
|
||||
popularSearchPhrases: {
|
||||
hasNext: function () { return true; },
|
||||
next: nextPhraseStub
|
||||
}
|
||||
};
|
||||
|
||||
var popularSuggestions = new SearchPhraseSuggestions(suggestions.popularSearchPhrases, 3);
|
||||
|
||||
assert.deepEqual(popularSuggestions, {
|
||||
available: true,
|
||||
phrases: [{
|
||||
value: 'phrase 1',
|
||||
url: 'url1'
|
||||
}, {
|
||||
value: 'phrase 2',
|
||||
url: 'url2'
|
||||
}, {
|
||||
value: 'phrase 3',
|
||||
url: 'url3'
|
||||
}]
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,190 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var otherAddress = {
|
||||
'city': 'Boston',
|
||||
'postalCode': '12345'
|
||||
};
|
||||
|
||||
var defaultShipment = {
|
||||
UUID: '1234-1234-1234-1234',
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
return shippingMethod;
|
||||
},
|
||||
shippingMethod: {
|
||||
ID: '001',
|
||||
displayName: 'Ground',
|
||||
description: 'Order received within 7-10 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '7-10 Business Days'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var defaultShipmentWithAddress = {
|
||||
UUID: '1234-1234-1234-1235',
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
return shippingMethod;
|
||||
},
|
||||
shippingAddress: {
|
||||
address1: '1 Drury Lane',
|
||||
address2: null,
|
||||
countryCode: {
|
||||
displayValue: 'United States',
|
||||
value: 'US'
|
||||
},
|
||||
firstName: 'The Muffin',
|
||||
lastName: 'Man',
|
||||
city: 'Far Far Away',
|
||||
phone: '333-333-3333',
|
||||
postalCode: '04330',
|
||||
stateCode: 'ME'
|
||||
},
|
||||
shippingMethod: {
|
||||
ID: '001',
|
||||
displayName: 'Ground',
|
||||
description: 'Order received within 7-10 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '7-10 Business Days'
|
||||
}
|
||||
},
|
||||
gift: true
|
||||
};
|
||||
|
||||
describe('Shipping', function () {
|
||||
var ShippingModel = require('../../../mocks/models/shipping');
|
||||
|
||||
it('should receive object with null properties ', function () {
|
||||
var result = new ShippingModel(null, null);
|
||||
assert.deepEqual(result, {
|
||||
UUID: null,
|
||||
productLineItems: null,
|
||||
applicableShippingMethods: null,
|
||||
matchingAddressId: false,
|
||||
shippingAddress: null,
|
||||
selectedShippingMethod: null,
|
||||
isGift: null,
|
||||
giftMessage: null
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the selected shipping method information', function () {
|
||||
var result = new ShippingModel(defaultShipment, null);
|
||||
|
||||
assert.equal(result.selectedShippingMethod.ID, '001');
|
||||
assert.equal(result.selectedShippingMethod.displayName, 'Ground');
|
||||
assert.equal(
|
||||
result.selectedShippingMethod.description,
|
||||
'Order received within 7-10 business days'
|
||||
);
|
||||
});
|
||||
|
||||
it('should get shipping methods and convert to a plain object', function () {
|
||||
var result = new ShippingModel(defaultShipment, null);
|
||||
assert.equal(
|
||||
result.applicableShippingMethods[0].description,
|
||||
'Order received within 7-10 business days'
|
||||
);
|
||||
assert.equal(result.applicableShippingMethods[0].displayName, 'Ground');
|
||||
assert.equal(result.applicableShippingMethods[0].ID, '001');
|
||||
assert.equal(result.applicableShippingMethods[0].estimatedArrivalTime, '7-10 Business Days');
|
||||
});
|
||||
|
||||
it('should get shipping address from shipment', function () {
|
||||
var result = new ShippingModel(defaultShipmentWithAddress, null);
|
||||
assert.equal(result.shippingAddress.firstName, 'The Muffin');
|
||||
});
|
||||
|
||||
it('should get shipping address from another address', function () {
|
||||
var result = new ShippingModel(defaultShipment, otherAddress);
|
||||
assert.equal(result.shippingAddress.postalCode, '12345');
|
||||
});
|
||||
|
||||
it('should prefer shipping address from shipment', function () {
|
||||
var result = new ShippingModel(defaultShipmentWithAddress, otherAddress);
|
||||
assert.equal(result.shippingAddress.postalCode, '04330');
|
||||
});
|
||||
|
||||
it('should return shipment without an address', function () {
|
||||
var shipment = Object.assign({}, defaultShipmentWithAddress);
|
||||
shipment.shippingAddress = Object.assign({}, defaultShipmentWithAddress.shippingAddress);
|
||||
|
||||
shipment.shippingAddress = {
|
||||
address1: null,
|
||||
address2: null,
|
||||
countryCode: null,
|
||||
firstName: null,
|
||||
lastName: null,
|
||||
city: null,
|
||||
phone: null,
|
||||
postalCode: null,
|
||||
stateCode: null
|
||||
};
|
||||
var result = new ShippingModel(shipment);
|
||||
assert.isUndefined(result.shippingAddress);
|
||||
});
|
||||
|
||||
// it('should set default shipping method when shippingMethodID is supplied', function () {
|
||||
// var shippingMethodID = '002';
|
||||
// var shippingMethod = {
|
||||
// description: 'Order received in 2 business days',
|
||||
// displayName: '2-Day Express',
|
||||
// ID: '002',
|
||||
// shippingCost: '$0.00',
|
||||
// custom: {
|
||||
// estimatedArrivalTime: '2 Business Days'
|
||||
// }
|
||||
// };
|
||||
// var spy = sinon.spy(defaultShipment, 'setShippingMethod');
|
||||
// spy.withArgs(shippingMethod);
|
||||
|
||||
// ShippingModel.selectShippingMethod(defaultShipment, shippingMethodID);
|
||||
|
||||
// assert.isTrue(spy.calledOnce);
|
||||
// assert.isTrue(spy.withArgs(shippingMethod).calledOnce);
|
||||
// defaultShipment.setShippingMethod.restore();
|
||||
// });
|
||||
|
||||
// it('should set default shipping method when shippingMethodID is not supplied', function () {
|
||||
// var shippingMethodID = null;
|
||||
// var spy = sinon.spy(defaultShipment, 'setShippingMethod');
|
||||
// spy.withArgs(null);
|
||||
|
||||
// ShippingModel.selectShippingMethod(defaultShipment, shippingMethodID);
|
||||
|
||||
// assert.isTrue(spy.calledOnce);
|
||||
// assert.isTrue(spy.withArgs(null).calledOnce);
|
||||
// defaultShipment.setShippingMethod.restore();
|
||||
// });
|
||||
|
||||
// it('should set default shipping method when shippingMethods are supplied', function () {
|
||||
// var shippingMethodID = '001';
|
||||
// var shippingMethods = new ArrayList([
|
||||
// {
|
||||
// description: 'Order received within 7-10 business days',
|
||||
// displayName: 'Ground',
|
||||
// ID: '001',
|
||||
// custom: {
|
||||
// estimatedArrivalTime: '7-10 Business Days'
|
||||
// }
|
||||
// }
|
||||
// ]);
|
||||
// var shippingMethod = {
|
||||
// description: 'Order received within 7-10 business days',
|
||||
// displayName: 'Ground',
|
||||
// ID: '001',
|
||||
// custom: {
|
||||
// estimatedArrivalTime: '7-10 Business Days'
|
||||
// }
|
||||
// };
|
||||
// var spy = sinon.spy(defaultShipment, 'setShippingMethod');
|
||||
// spy.withArgs(shippingMethod);
|
||||
|
||||
// ShippingModel.selectShippingMethod(defaultShipment, shippingMethodID, shippingMethods);
|
||||
|
||||
// assert.isTrue(spy.calledOnce);
|
||||
// assert.isTrue(spy.withArgs(shippingMethod).calledOnce);
|
||||
// defaultShipment.setShippingMethod.restore();
|
||||
// });
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
describe('ShippingMethod', function () {
|
||||
var ShippingMethodModel = require('../../../../mocks/models/shippingMethod');
|
||||
|
||||
it('should receive object with empty properties ', function () {
|
||||
var result = new ShippingMethodModel(null, null);
|
||||
assert.isNull(result.ID);
|
||||
assert.isNull(result.displayName);
|
||||
assert.isNull(result.description);
|
||||
});
|
||||
|
||||
it('should set cost with no shipment parameter ', function () {
|
||||
var result = new ShippingMethodModel({
|
||||
ID: 'an ID',
|
||||
displayName: 'a diplayName',
|
||||
description: 'a description',
|
||||
custom: {
|
||||
estimatedArrivalTime: 'whenever'
|
||||
}
|
||||
}, null);
|
||||
assert.equal(result.ID, 'an ID');
|
||||
assert.equal(result.displayName, 'a diplayName');
|
||||
assert.equal(result.description, 'a description');
|
||||
assert.equal(result.estimatedArrivalTime, 'whenever');
|
||||
});
|
||||
|
||||
it('should set cost with no custom attributes ', function () {
|
||||
var result = new ShippingMethodModel({
|
||||
ID: 'an ID',
|
||||
displayName: 'a diplayName',
|
||||
description: 'a description'
|
||||
}, null);
|
||||
assert.isNull(result.estimatedArrivalTime);
|
||||
});
|
||||
|
||||
it('should set cost with defaultMethod ', function () {
|
||||
var result = new ShippingMethodModel({
|
||||
ID: 'an ID',
|
||||
displayName: 'a diplayName',
|
||||
description: 'a description',
|
||||
defaultMethod: true
|
||||
}, null);
|
||||
assert.isTrue(result.default);
|
||||
});
|
||||
|
||||
it('should set cost with shipment parameter ', function () {
|
||||
var result = new ShippingMethodModel({
|
||||
ID: 'an ID',
|
||||
displayName: 'a diplayName',
|
||||
description: 'a description'
|
||||
}, {});
|
||||
|
||||
assert.isDefined(result.shippingCost);
|
||||
assert.isDefined(result.selected);
|
||||
});
|
||||
|
||||
it('should set isSelected shipment parameter with selected method', function () {
|
||||
var result = new ShippingMethodModel({
|
||||
ID: 'an ID',
|
||||
displayName: 'a diplayName',
|
||||
description: 'a description'
|
||||
}, {
|
||||
shippingMethod: {
|
||||
ID: 'an ID'
|
||||
}
|
||||
});
|
||||
|
||||
assert.isTrue(result.selected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var StoreModel = require('../../../mocks/models/store');
|
||||
|
||||
var createStoreObject = function () {
|
||||
return {
|
||||
ID: 'Any ID',
|
||||
name: 'Downtown TV Shop',
|
||||
address1: '333 Washington St',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
postalCode: '02108',
|
||||
phone: '333-333-3333',
|
||||
stateCode: 'MA',
|
||||
countryCode: {
|
||||
value: 'us'
|
||||
},
|
||||
latitude: 42.5273334,
|
||||
longitude: -71.13758250000001,
|
||||
storeHours: {
|
||||
markup: 'Mon - Sat: 10am - 9pm'
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
describe('store', function () {
|
||||
it('should receive an null store', function () {
|
||||
var result = new StoreModel(null);
|
||||
assert.deepEqual(result, {});
|
||||
});
|
||||
|
||||
it('should convert API Store to an object', function () {
|
||||
var result = new StoreModel(createStoreObject());
|
||||
assert.equal(result.ID, 'Any ID');
|
||||
assert.equal(result.name, 'Downtown TV Shop');
|
||||
assert.equal(result.address1, '333 Washington St');
|
||||
assert.equal(result.address2, '');
|
||||
assert.equal(result.city, 'Boston');
|
||||
assert.equal(result.postalCode, '02108');
|
||||
assert.equal(result.phone, '333-333-3333');
|
||||
assert.equal(result.stateCode, 'MA');
|
||||
assert.equal(result.countryCode, 'us');
|
||||
assert.equal(result.latitude, 42.5273334);
|
||||
assert.equal(result.longitude, -71.13758250000001);
|
||||
assert.equal(result.storeHours, 'Mon - Sat: 10am - 9pm');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,189 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
describe('stores', function () {
|
||||
var StoreModel = require('../../../mocks/models/store');
|
||||
var StoresModel = proxyquire('../../../../cartridges/app_storefront_base/cartridge/models/stores', {
|
||||
'*/cartridge/models/store': StoreModel,
|
||||
'dw/util/HashMap': function () {
|
||||
return {
|
||||
result: {},
|
||||
put: function (key, context) {
|
||||
this.result[key] = context;
|
||||
}
|
||||
};
|
||||
},
|
||||
'dw/value/Money': function () {},
|
||||
'dw/util/Template': function () {
|
||||
return {
|
||||
render: function () {
|
||||
return { text: 'someString' };
|
||||
}
|
||||
};
|
||||
},
|
||||
'*/cartridge/scripts/renderTemplateHelper': {
|
||||
getRenderedHtml: function () { return 'someString'; }
|
||||
},
|
||||
|
||||
'*/cartridge/scripts/helpers/storeHelpers': {
|
||||
createStoresResultsHtml: function () {
|
||||
return 'someString';
|
||||
}
|
||||
}
|
||||
});
|
||||
var actionUrl = '/on/demandware.store/Sites-MobileFirst-Site/en_US/Stores-FindStores';
|
||||
var apiKey = 'YOUR_API_KEY';
|
||||
var searchKey = { lat: 42.4019, long: -71.1193 };
|
||||
var radius = 100;
|
||||
var radiusOptions = [15, 30, 50, 100, 300];
|
||||
|
||||
it('should return Stores Model with stores found', function () {
|
||||
var storesResults = [{
|
||||
ID: 'Any ID',
|
||||
name: 'Downtown TV Shop',
|
||||
address1: '333 Washington St',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
postalCode: '02108',
|
||||
phone: '333-333-3333',
|
||||
stateCode: 'MA',
|
||||
countryCode: {
|
||||
value: 'us'
|
||||
},
|
||||
latitude: 42.5273334,
|
||||
longitude: -71.13758250000001,
|
||||
storeHours: {
|
||||
markup: 'Mon - Sat: 10am - 9pm'
|
||||
}
|
||||
}];
|
||||
var stores = new StoresModel(storesResults, searchKey, radius, actionUrl, apiKey);
|
||||
|
||||
assert.deepEqual(stores, {
|
||||
stores: [
|
||||
{
|
||||
ID: 'Any ID',
|
||||
name: 'Downtown TV Shop',
|
||||
address1: '333 Washington St',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
latitude: 42.5273334,
|
||||
longitude: -71.13758250000001,
|
||||
postalCode: '02108',
|
||||
phone: '333-333-3333',
|
||||
stateCode: 'MA',
|
||||
countryCode: 'us',
|
||||
storeHours: 'Mon - Sat: 10am - 9pm'
|
||||
}
|
||||
],
|
||||
locations: '[{"name":"Downtown TV Shop","latitude":42.5273334,"longitude":-71.13758250000001,"infoWindowHtml":"someString"}]',
|
||||
searchKey: searchKey,
|
||||
radius: radius,
|
||||
actionUrl: actionUrl,
|
||||
googleMapsApi: 'https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY',
|
||||
radiusOptions: radiusOptions,
|
||||
storesResultsHtml: 'someString'
|
||||
});
|
||||
});
|
||||
|
||||
it('should return Stores Model with stores that do not have a phone or state', function () {
|
||||
var storesResults = [{
|
||||
ID: 'Any ID',
|
||||
name: 'Downtown TV Shop',
|
||||
address1: '333 Washington St',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
postalCode: '02108',
|
||||
countryCode: {
|
||||
value: 'us'
|
||||
},
|
||||
latitude: 42.5273334,
|
||||
longitude: -71.13758250000001
|
||||
}];
|
||||
var stores = new StoresModel(storesResults, searchKey, radius, actionUrl, apiKey);
|
||||
|
||||
assert.deepEqual(stores, {
|
||||
stores: [
|
||||
{
|
||||
ID: 'Any ID',
|
||||
name: 'Downtown TV Shop',
|
||||
address1: '333 Washington St',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
latitude: 42.5273334,
|
||||
longitude: -71.13758250000001,
|
||||
postalCode: '02108',
|
||||
countryCode: 'us'
|
||||
}
|
||||
],
|
||||
locations: '[{"name":"Downtown TV Shop","latitude":42.5273334,"longitude":-71.13758250000001,"infoWindowHtml":"someString"}]',
|
||||
searchKey: searchKey,
|
||||
radius: radius,
|
||||
actionUrl: actionUrl,
|
||||
googleMapsApi: 'https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY',
|
||||
radiusOptions: radiusOptions,
|
||||
storesResultsHtml: 'someString'
|
||||
});
|
||||
});
|
||||
|
||||
it('should return Stores Model with no stores found', function () {
|
||||
var stores = new StoresModel([], searchKey, radius, actionUrl, apiKey);
|
||||
|
||||
assert.deepEqual(stores, {
|
||||
stores: [],
|
||||
locations: '[]',
|
||||
searchKey: searchKey,
|
||||
radius: 100,
|
||||
actionUrl: actionUrl,
|
||||
googleMapsApi: 'https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY',
|
||||
radiusOptions: radiusOptions,
|
||||
storesResultsHtml: 'someString'
|
||||
});
|
||||
});
|
||||
|
||||
it('should return Stores Model without google maps api', function () {
|
||||
var storesResults = [{
|
||||
ID: 'Any ID',
|
||||
name: 'Downtown TV Shop',
|
||||
address1: '333 Washington St',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
postalCode: '02108',
|
||||
phone: '333-333-3333',
|
||||
stateCode: 'MA',
|
||||
countryCode: {
|
||||
value: 'us'
|
||||
},
|
||||
latitude: 42.5273334,
|
||||
longitude: -71.13758250000001
|
||||
}];
|
||||
var noApiKey = null;
|
||||
var stores = new StoresModel(storesResults, searchKey, radius, actionUrl, noApiKey);
|
||||
|
||||
assert.deepEqual(stores, {
|
||||
stores: [
|
||||
{
|
||||
ID: 'Any ID',
|
||||
name: 'Downtown TV Shop',
|
||||
address1: '333 Washington St',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
latitude: 42.5273334,
|
||||
longitude: -71.13758250000001,
|
||||
postalCode: '02108',
|
||||
countryCode: 'us',
|
||||
phone: '333-333-3333',
|
||||
stateCode: 'MA'
|
||||
}
|
||||
],
|
||||
locations: '[{"name":"Downtown TV Shop","latitude":42.5273334,"longitude":-71.13758250000001,"infoWindowHtml":"someString"}]',
|
||||
searchKey: searchKey,
|
||||
radius: radius,
|
||||
actionUrl: actionUrl,
|
||||
googleMapsApi: null,
|
||||
radiusOptions: radiusOptions,
|
||||
storesResultsHtml: 'someString'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var Money = require('../../../mocks/dw.value.Money');
|
||||
var ArrayList = require('../../../mocks/dw.util.Collection');
|
||||
|
||||
|
||||
var createApiBasket = function (isAvailable) {
|
||||
return {
|
||||
totalGrossPrice: new Money(isAvailable),
|
||||
totalTax: new Money(isAvailable),
|
||||
shippingTotalPrice: new Money(isAvailable),
|
||||
getAdjustedMerchandizeTotalPrice: function () {
|
||||
return new Money(isAvailable);
|
||||
},
|
||||
adjustedShippingTotalPrice: new Money(isAvailable),
|
||||
couponLineItems: new ArrayList([
|
||||
{
|
||||
UUID: 1234567890,
|
||||
couponCode: 'some coupon code',
|
||||
applied: true,
|
||||
valid: true,
|
||||
priceAdjustments: new ArrayList([{
|
||||
promotion: { calloutMsg: 'some call out message' }
|
||||
}])
|
||||
}
|
||||
]),
|
||||
priceAdjustments: new ArrayList([{
|
||||
UUID: 10987654321,
|
||||
calloutMsg: 'some call out message',
|
||||
basedOnCoupon: false,
|
||||
price: { value: 'some value', currencyCode: 'usd' },
|
||||
lineItemText: 'someString',
|
||||
promotion: { calloutMsg: 'some call out message' }
|
||||
},
|
||||
{
|
||||
UUID: 10987654322,
|
||||
calloutMsg: 'price adjustment without promotion msg',
|
||||
basedOnCoupon: false,
|
||||
price: { value: 'some value', currencyCode: 'usd' },
|
||||
lineItemText: 'someString'
|
||||
}]),
|
||||
allShippingPriceAdjustments: new ArrayList([{
|
||||
UUID: 12029384756,
|
||||
calloutMsg: 'some call out message',
|
||||
basedOnCoupon: false,
|
||||
price: { value: 'some value', currencyCode: 'usd' },
|
||||
lineItemText: 'someString',
|
||||
promotion: { calloutMsg: 'some call out message' }
|
||||
}])
|
||||
};
|
||||
};
|
||||
|
||||
describe('Totals', function () {
|
||||
var Totals = require('../../../mocks/models/totals');
|
||||
|
||||
it('should accept/process a null Basket object', function () {
|
||||
var result = new Totals(null);
|
||||
assert.equal(result.subTotal, '-');
|
||||
assert.equal(result.grandTotal, '-');
|
||||
assert.equal(result.totalTax, '-');
|
||||
assert.equal(result.totalShippingCost, '-');
|
||||
});
|
||||
|
||||
it('should accept a basket and format the totals', function () {
|
||||
var basket = createApiBasket(true);
|
||||
var result = new Totals(basket);
|
||||
assert.equal(result.subTotal, 'formatted money');
|
||||
assert.equal(result.grandTotal, 'formatted money');
|
||||
assert.equal(result.totalTax, 'formatted money');
|
||||
assert.equal(result.totalShippingCost, 'formatted money');
|
||||
});
|
||||
|
||||
it('should get discounts', function () {
|
||||
var result = new Totals(createApiBasket(true));
|
||||
assert.equal(result.discounts.length, 4);
|
||||
assert.equal(result.discounts[0].UUID, 1234567890);
|
||||
assert.equal(result.discounts[0].type, 'coupon');
|
||||
assert.equal(result.discounts[0].applied, true);
|
||||
assert.equal(result.discounts[1].type, 'promotion');
|
||||
assert.equal(result.discounts[1].callOutMsg, 'some call out message');
|
||||
assert.equal(result.discounts[1].UUID, 10987654321);
|
||||
assert.equal(result.discounts[2].UUID, 10987654322);
|
||||
assert.equal(result.discounts[3].UUID, 12029384756);
|
||||
});
|
||||
|
||||
it('should accept a basket where the totals are unavailable', function () {
|
||||
var result = new Totals(createApiBasket(false));
|
||||
assert.equal(result.subTotal, '-');
|
||||
assert.equal(result.grandTotal, '-');
|
||||
assert.equal(result.totalTax, '-');
|
||||
assert.equal(result.totalShippingCost, '-');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var accountHelpers = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/account/accountHelpers', {
|
||||
'*/cartridge/models/account': function () {
|
||||
return {
|
||||
email: 'abc@test.com'
|
||||
};
|
||||
},
|
||||
'*/cartridge/models/address': function () {
|
||||
return {};
|
||||
},
|
||||
'*/cartridge/scripts/order/orderHelpers': {
|
||||
getLastOrder: function () {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe('orderHelpers', function () {
|
||||
describe('getAccountModel', function () {
|
||||
it('should return an account model', function () {
|
||||
var req = {
|
||||
currentCustomer: {
|
||||
profile: {
|
||||
email: 'abc@test.com'
|
||||
},
|
||||
addressBook: {
|
||||
preferredAddress: {
|
||||
address1: '5 Wall St.'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var accountModel = accountHelpers.getAccountModel(req);
|
||||
assert.equal(accountModel.email, 'abc@test.com');
|
||||
});
|
||||
|
||||
it('should return null as account model if customer profile is null', function () {
|
||||
var req = {
|
||||
currentCustomer: {}
|
||||
};
|
||||
|
||||
var accountModel = accountHelpers.getAccountModel(req);
|
||||
assert.isNull(accountModel);
|
||||
});
|
||||
|
||||
it('should return an account model when no preferredAddress', function () {
|
||||
var req = {
|
||||
currentCustomer: {
|
||||
profile: {
|
||||
email: 'abc@test.com'
|
||||
},
|
||||
addressBook: {}
|
||||
}
|
||||
};
|
||||
|
||||
var accountModel = accountHelpers.getAccountModel(req);
|
||||
assert.equal(accountModel.email, 'abc@test.com');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var urlUtilsMock = {
|
||||
staticURL: function (a) {
|
||||
return 'test' + a;
|
||||
}
|
||||
};
|
||||
|
||||
describe('assets', function () {
|
||||
var assets = null;
|
||||
|
||||
beforeEach(function () {
|
||||
assets = proxyquire('../../../../cartridges/app_storefront_base/cartridge/scripts/assets', {
|
||||
'dw/web/URLUtils': urlUtilsMock
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a new JavaScript file', function () {
|
||||
assert.deepEqual(assets.scripts, []);
|
||||
assets.addJs('../test.js');
|
||||
assert.equal(assets.scripts[0].src, 'test../test.js');
|
||||
});
|
||||
|
||||
it('should add a new JavaScript file with integrity hash', function () {
|
||||
assert.deepEqual(assets.scripts, []);
|
||||
assets.addJs('../test.js', 'integrityHash');
|
||||
assert.equal(assets.scripts[0].src, 'test../test.js');
|
||||
assert.equal(assets.scripts[0].integrity, 'integrityHash');
|
||||
});
|
||||
|
||||
it('should not add a duplicate JavaScript file', function () {
|
||||
assert.deepEqual(assets.scripts, []);
|
||||
assets.addJs('../test.js');
|
||||
assets.addJs('../test.js');
|
||||
assert.equal(assets.scripts[0].src, 'test../test.js');
|
||||
assert.equal(assets.scripts.length, 1);
|
||||
});
|
||||
|
||||
it('should add a new external JavaScript file', function () {
|
||||
assert.deepEqual(assets.scripts, []);
|
||||
assets.addJs('http://www.google.com/test.js');
|
||||
assert.equal(assets.scripts[0].src, 'http://www.google.com/test.js');
|
||||
});
|
||||
|
||||
it('should add a new external JavaScript file with integrity hash', function () {
|
||||
assert.deepEqual(assets.scripts, []);
|
||||
assets.addJs('http://www.google.com/test.js', 'integrityHash');
|
||||
assert.equal(assets.scripts[0].src, 'http://www.google.com/test.js');
|
||||
assert.equal(assets.scripts[0].integrity, 'integrityHash');
|
||||
});
|
||||
|
||||
it('should not add a duplicate external JavaScript file', function () {
|
||||
assert.deepEqual(assets.scripts, []);
|
||||
assets.addJs('http://www.google.com/test.js');
|
||||
assets.addJs('http://www.google.com/test.js');
|
||||
assert.equal(assets.scripts[0].src, 'http://www.google.com/test.js');
|
||||
assert.equal(assets.scripts.length, 1);
|
||||
});
|
||||
|
||||
it('should add a new CSS file', function () {
|
||||
assets.addCss('../test.css');
|
||||
assert.equal(assets.styles[0].src, 'test../test.css');
|
||||
});
|
||||
|
||||
it('should add a new CSS file with integrity hash', function () {
|
||||
assets.addCss('../test.css', 'integrityHash');
|
||||
assert.equal(assets.styles[0].src, 'test../test.css');
|
||||
});
|
||||
|
||||
it('should not add a duplicate CSS file', function () {
|
||||
assets.addCss('../test.css');
|
||||
assets.addCss('../test.css');
|
||||
assert.equal(assets.styles[0].src, 'test../test.css');
|
||||
assert.equal(assets.styles.length, 1);
|
||||
});
|
||||
|
||||
it('should add a new external CSS file', function () {
|
||||
assets.addCss('https://www.google.com/test.css');
|
||||
assert.equal(assets.styles[0].src, 'https://www.google.com/test.css');
|
||||
});
|
||||
|
||||
it('should add a new external CSS file with integrity hash', function () {
|
||||
assets.addCss('https://www.google.com/test.css', 'integrityHash');
|
||||
assert.equal(assets.styles[0].src, 'https://www.google.com/test.css');
|
||||
assert.equal(assets.styles[0].integrity, 'integrityHash');
|
||||
});
|
||||
|
||||
it('should not add a duplicate external CSS file', function () {
|
||||
assets.addCss('https://www.google.com/test.css');
|
||||
assets.addCss('https://www.google.com/test.css');
|
||||
assert.equal(assets.styles[0].src, 'https://www.google.com/test.css');
|
||||
assert.equal(assets.styles.length, 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,306 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
var ArrayList = require('../../../../mocks/dw.util.Collection.js');
|
||||
|
||||
var mockOptions = [{
|
||||
optionId: 'option 1',
|
||||
selectedValueId: '123'
|
||||
}];
|
||||
|
||||
var availabilityModelMock = {
|
||||
inventoryRecord: {
|
||||
ATS: {
|
||||
value: 3
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var productLineItemMock = {
|
||||
productID: 'someProductID',
|
||||
quantity: {
|
||||
value: 1
|
||||
},
|
||||
setQuantityValue: function () {
|
||||
return;
|
||||
},
|
||||
quantityValue: 1,
|
||||
product: {
|
||||
availabilityModel: availabilityModelMock
|
||||
},
|
||||
optionProductLineItems: new ArrayList(mockOptions),
|
||||
bundledProductLineItems: new ArrayList([])
|
||||
};
|
||||
|
||||
var stubGetBonusLineItems = function () {
|
||||
var bonusProducts = [{
|
||||
ID: 'pid_1'
|
||||
},
|
||||
{
|
||||
ID: 'pid_2'
|
||||
}];
|
||||
var index2 = 0;
|
||||
var bonusDiscountLineItems = [
|
||||
{
|
||||
name: 'name1',
|
||||
ID: 'ID1',
|
||||
description: 'description 1',
|
||||
UUID: 'uuid_string',
|
||||
maxBonusItems: 1,
|
||||
bonusProducts: {
|
||||
iterator: function () {
|
||||
return {
|
||||
items: bonusProducts,
|
||||
hasNext: function () {
|
||||
return index2 < bonusProducts.length;
|
||||
},
|
||||
next: function () {
|
||||
return bonusProducts[index2++];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
var index = 0;
|
||||
|
||||
return {
|
||||
id: 2,
|
||||
name: '',
|
||||
iterator: function () {
|
||||
return {
|
||||
items: bonusDiscountLineItems,
|
||||
hasNext: function () {
|
||||
return index < bonusDiscountLineItems.length;
|
||||
},
|
||||
next: function () {
|
||||
return bonusDiscountLineItems[index++];
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var createApiBasket = function (productInBasket) {
|
||||
var currentBasket = {
|
||||
defaultShipment: {},
|
||||
createProductLineItem: function () {
|
||||
return {
|
||||
setQuantityValue: function () {
|
||||
return;
|
||||
}
|
||||
};
|
||||
},
|
||||
getBonusDiscountLineItems: stubGetBonusLineItems
|
||||
};
|
||||
if (productInBasket) {
|
||||
currentBasket.productLineItems = new ArrayList([productLineItemMock]);
|
||||
currentBasket.allLineItems = {};
|
||||
currentBasket.allLineItems.length = 1;
|
||||
} else {
|
||||
currentBasket.productLineItems = new ArrayList([]);
|
||||
}
|
||||
|
||||
return currentBasket;
|
||||
};
|
||||
|
||||
describe('cartHelpers', function () {
|
||||
var findStub = sinon.stub();
|
||||
findStub.withArgs([productLineItemMock]).returns(productLineItemMock);
|
||||
|
||||
var cartHelpers = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/cart/cartHelpers', {
|
||||
'dw/catalog/ProductMgr': {
|
||||
getProduct: function () {
|
||||
return {
|
||||
optionModel: {
|
||||
getOption: function () {},
|
||||
getOptionValue: function () {},
|
||||
setSelectedOptionValue: function () {}
|
||||
},
|
||||
availabilityModel: availabilityModelMock
|
||||
};
|
||||
}
|
||||
},
|
||||
'*/cartridge/scripts/util/collections': proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
}),
|
||||
'*/cartridge/scripts/checkout/shippingHelpers': {},
|
||||
'dw/system/Transaction': {
|
||||
wrap: function (item) {
|
||||
item();
|
||||
}
|
||||
},
|
||||
'*/cartridge/scripts/util/array': { find: findStub },
|
||||
'dw/web/Resource': {
|
||||
msg: function () {
|
||||
return 'someString';
|
||||
},
|
||||
msgf: function () {
|
||||
return 'someString';
|
||||
}
|
||||
},
|
||||
'*/cartridge/scripts/helpers/productHelpers': {
|
||||
getOptions: function () {},
|
||||
getCurrentOptionModel: function () {}
|
||||
},
|
||||
'dw/web/URLUtils': {
|
||||
url: function () {
|
||||
return {
|
||||
toString: function () {
|
||||
return 'string URL';
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should add a product to the cart', function () {
|
||||
var currentBasket = createApiBasket(false);
|
||||
var spy = sinon.spy(currentBasket, 'createProductLineItem');
|
||||
spy.withArgs(1);
|
||||
|
||||
cartHelpers.addProductToCart(currentBasket, 'someProductID', 1, [], mockOptions);
|
||||
assert.isTrue(spy.calledOnce);
|
||||
currentBasket.createProductLineItem.restore();
|
||||
});
|
||||
|
||||
it('should set the quantity of the product in the cart', function () {
|
||||
var currentBasket = createApiBasket(true);
|
||||
var spy = sinon.spy(currentBasket.productLineItems.toArray()[0], 'setQuantityValue');
|
||||
spy.withArgs(1);
|
||||
|
||||
cartHelpers.addProductToCart(currentBasket, 'someProductID', 1, [], mockOptions);
|
||||
assert.isTrue(spy.calledOnce);
|
||||
currentBasket.productLineItems.toArray()[0].setQuantityValue.restore();
|
||||
});
|
||||
|
||||
it('should not add a product to the cart', function () {
|
||||
var currentBasket = createApiBasket(true);
|
||||
|
||||
var result = cartHelpers.addProductToCart(currentBasket, 'someProductID', 4, [], mockOptions);
|
||||
assert.isTrue(result.error);
|
||||
assert.equal(result.message, 'someString');
|
||||
});
|
||||
|
||||
it('should not add a product to the cart when ATS is already in cart', function () {
|
||||
var currentBasket = createApiBasket(true);
|
||||
currentBasket.productLineItems.toArray()[0].quantity.value = 3;
|
||||
|
||||
var result = cartHelpers.addProductToCart(currentBasket, 'someProductID', 3, [], mockOptions);
|
||||
assert.isTrue(result.error);
|
||||
assert.equal(result.message, 'someString');
|
||||
});
|
||||
|
||||
describe('getQtyAlreadyInCart() function', function () {
|
||||
var productId1 = 'product1';
|
||||
|
||||
it('should provide the quantities of a product already in the Cart', function () {
|
||||
var lineItems = new ArrayList([{
|
||||
bundledProductLineItems: [],
|
||||
productID: productId1,
|
||||
quantityValue: 3
|
||||
}]);
|
||||
var qtyAlreadyInCart = cartHelpers.getQtyAlreadyInCart(productId1, lineItems);
|
||||
assert.equal(3, qtyAlreadyInCart);
|
||||
});
|
||||
|
||||
it('should provide the quantities of a product inside a bundle already in the Cart',
|
||||
function () {
|
||||
var lineItems = new ArrayList([{
|
||||
bundledProductLineItems: new ArrayList([{
|
||||
productID: productId1,
|
||||
quantityValue: 4
|
||||
}])
|
||||
}]);
|
||||
var qtyAlreadyInCart = cartHelpers.getQtyAlreadyInCart(productId1, lineItems);
|
||||
assert.equal(4, qtyAlreadyInCart);
|
||||
});
|
||||
|
||||
it('should not include the quantity a product matching the uuid', function () {
|
||||
var uuid = 'abc';
|
||||
var lineItems = new ArrayList([{
|
||||
bundledProductLineItems: [],
|
||||
productID: productId1,
|
||||
quantityValue: 5,
|
||||
UUID: uuid
|
||||
}]);
|
||||
var qtyAlreadyInCart = cartHelpers.getQtyAlreadyInCart(productId1, lineItems, uuid);
|
||||
assert.equal(0, qtyAlreadyInCart);
|
||||
});
|
||||
|
||||
it('should not include the quantity a product inside a bundle matching the uuid',
|
||||
function () {
|
||||
var uuid = 'abc';
|
||||
var lineItems = new ArrayList([{
|
||||
bundledProductLineItems: new ArrayList([{
|
||||
productID: productId1,
|
||||
quantityValue: 4,
|
||||
UUID: uuid
|
||||
}])
|
||||
}]);
|
||||
var qtyAlreadyInCart = cartHelpers.getQtyAlreadyInCart(productId1, lineItems, uuid);
|
||||
assert.equal(0, qtyAlreadyInCart);
|
||||
}
|
||||
);
|
||||
|
||||
it('should add a product to the cart that is eligible for bonus products', function () {
|
||||
var currentBasket = createApiBasket(false);
|
||||
var spy = sinon.spy(currentBasket, 'createProductLineItem');
|
||||
spy.withArgs(1);
|
||||
|
||||
var previousBonusDiscountLineItems = cartHelpers.addProductToCart(currentBasket, 'someProductID', 1, [], mockOptions);
|
||||
previousBonusDiscountLineItems.contains = function (x) {
|
||||
var expectedResult = {
|
||||
name: 'name1',
|
||||
ID: 'ID1',
|
||||
description: 'description 1',
|
||||
UUID: 'uuid_string',
|
||||
maxBonusItems: 1
|
||||
};
|
||||
return expectedResult === x;
|
||||
};
|
||||
var urlObject = {
|
||||
url: 'Cart-ChooseBonusProducts',
|
||||
configureProductstUrl: 'Product-ShowBonusProducts',
|
||||
addToCartUrl: 'Cart-AddBonusProducts'
|
||||
};
|
||||
|
||||
var newBonusDiscountLineItem =
|
||||
cartHelpers.getNewBonusDiscountLineItem(
|
||||
currentBasket,
|
||||
previousBonusDiscountLineItems,
|
||||
urlObject
|
||||
);
|
||||
assert.equal(newBonusDiscountLineItem.maxBonusItems, 1);
|
||||
assert.equal(newBonusDiscountLineItem.addToCartUrl, 'Cart-AddBonusProducts');
|
||||
assert.equal(newBonusDiscountLineItem.configureProductstUrl, 'string URL');
|
||||
assert.equal(newBonusDiscountLineItem.uuid, 'uuid_string');
|
||||
assert.equal(newBonusDiscountLineItem.bonuspids.length, 2);
|
||||
assert.equal(newBonusDiscountLineItem.bonuspids[0], 'pid_1');
|
||||
assert.equal(newBonusDiscountLineItem.bonuspids[1], 'pid_2');
|
||||
assert.equal(newBonusDiscountLineItem.newBonusDiscountLineItem.name, 'name1');
|
||||
assert.equal(newBonusDiscountLineItem.newBonusDiscountLineItem.ID, 'ID1');
|
||||
assert.equal(newBonusDiscountLineItem.newBonusDiscountLineItem.maxBonusItems, 1);
|
||||
assert.equal(newBonusDiscountLineItem.newBonusDiscountLineItem.description, 'description 1');
|
||||
assert.equal(newBonusDiscountLineItem.labels.close, 'someString');
|
||||
assert.equal(newBonusDiscountLineItem.labels.selectprods, 'someString');
|
||||
});
|
||||
|
||||
it('should return a url string for reporting minicart events', function () {
|
||||
var currentBasket = createApiBasket(true);
|
||||
var resultError = false;
|
||||
var result = cartHelpers.getReportingUrlAddToCart(currentBasket, resultError);
|
||||
assert.equal(result, 'string URL');
|
||||
});
|
||||
|
||||
it('should return false for reporting minicart events', function () {
|
||||
var currentBasket = createApiBasket(true);
|
||||
var resultError = true;
|
||||
var result = cartHelpers.getReportingUrlAddToCart(currentBasket, resultError);
|
||||
assert.equal(result, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,730 @@
|
||||
// checkoutHelpers.js unit tests
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var sinon = require('sinon');
|
||||
|
||||
var checkoutHelpers = require('../../../../mocks/helpers/checkoutHelpers');
|
||||
|
||||
|
||||
describe('checkoutHelpers', function () {
|
||||
describe('prepareShippingForm', function () {
|
||||
it('should return a processed shipping form object', function () {
|
||||
var shippingForm = checkoutHelpers.prepareShippingForm();
|
||||
assert.equal(shippingForm.formName, 'shipping');
|
||||
});
|
||||
});
|
||||
|
||||
describe('prepareBillingForm', function () {
|
||||
it('should return a processed billing form object', function () {
|
||||
var billingForm = checkoutHelpers.prepareBillingForm();
|
||||
assert.equal(billingForm.formName, 'billing');
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateShippingForm', function () {
|
||||
it('should return empty object when no invalid form field - with state field', function () {
|
||||
var shippingForm = {
|
||||
firstName: { valid: true, formType: 'formField' },
|
||||
lastName: { valid: true, formType: 'formField' },
|
||||
address1: { valid: true, formType: 'formField' },
|
||||
address2: { valid: true, formType: 'formField' },
|
||||
city: { valid: true, formType: 'formField' },
|
||||
states: { valid: true, formType: 'formField' },
|
||||
postalCode: { valid: true, formType: 'formField' },
|
||||
country: { valid: true, formType: 'formField' }
|
||||
};
|
||||
|
||||
var invalidFields = checkoutHelpers.validateShippingForm(shippingForm);
|
||||
assert.equal(Object.keys(invalidFields).length, 0);
|
||||
});
|
||||
|
||||
it('should return empty object when no invalid form field - without state field', function () {
|
||||
var shippingForm = {
|
||||
firstName: { valid: true, formType: 'formField' },
|
||||
lastName: { valid: true, formType: 'formField' },
|
||||
address1: { valid: true, formType: 'formField' },
|
||||
address2: { valid: true, formType: 'formField' },
|
||||
city: { valid: true, formType: 'formField' },
|
||||
postalCode: { valid: true, formType: 'formField' },
|
||||
country: { valid: true, formType: 'formField' }
|
||||
};
|
||||
|
||||
var invalidFields = checkoutHelpers.validateShippingForm(shippingForm);
|
||||
assert.equal(Object.keys(invalidFields).length, 0);
|
||||
});
|
||||
|
||||
it('should return an object containing invalid form field', function () {
|
||||
var shippingForm = {
|
||||
firstName: { valid: true, formType: 'formField' },
|
||||
lastName: { valid: true, formType: 'formField' },
|
||||
address1: { valid: true, formType: 'formField' },
|
||||
address2: {
|
||||
valid: false,
|
||||
htmlName: 'htmlNameAddress2',
|
||||
error: 'address2 is an invalid field.',
|
||||
formType: 'formField'
|
||||
},
|
||||
city: { valid: true, formType: 'formField' },
|
||||
states: { valid: true, formType: 'formField' },
|
||||
postalCode: { valid: true, formType: 'formField' },
|
||||
country: {
|
||||
valid: false,
|
||||
htmlName: 'htmlNameCountry',
|
||||
error: 'country is an invalid field.',
|
||||
formType: 'formField'
|
||||
}
|
||||
};
|
||||
|
||||
var invalidFields = checkoutHelpers.validateShippingForm(shippingForm);
|
||||
assert.equal(Object.keys(invalidFields).length, 2);
|
||||
assert.equal(invalidFields.htmlNameAddress2, shippingForm.address2.error);
|
||||
assert.equal(invalidFields.htmlNameCountry, shippingForm.country.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isShippingAddressInitialized', function () {
|
||||
it('should return true for shipment with shipping address provided', function () {
|
||||
var shipment = {
|
||||
shippingAddress: {
|
||||
stateCode: 'CA',
|
||||
postalCode: '97123'
|
||||
}
|
||||
};
|
||||
var isAddrInitialized = checkoutHelpers.isShippingAddressInitialized(shipment);
|
||||
assert.isTrue(isAddrInitialized);
|
||||
});
|
||||
|
||||
it('should return false for shipment with no shipping address provided', function () {
|
||||
var shipment = {};
|
||||
var isAddrInitialized = checkoutHelpers.isShippingAddressInitialized(shipment);
|
||||
assert.isFalse(isAddrInitialized);
|
||||
});
|
||||
|
||||
it('should return true for shipment is null and defaulShipment shippingAddress is not null', function () {
|
||||
var shipment = null;
|
||||
var isAddrInitialized = checkoutHelpers.isShippingAddressInitialized(shipment);
|
||||
assert.isTrue(isAddrInitialized);
|
||||
});
|
||||
});
|
||||
|
||||
describe('copyCustomerAddressToShipment', function () {
|
||||
var address = {
|
||||
firstName: 'James',
|
||||
lastName: 'Bond',
|
||||
address1: '10 Oxford St',
|
||||
address2: 'suite 20',
|
||||
city: 'London',
|
||||
postalCode: '02345',
|
||||
countryCode: { value: 'uk' },
|
||||
phone: '603-333-1212',
|
||||
stateCode: 'NH'
|
||||
};
|
||||
|
||||
it('should copy customer address to shipment address for non-null shipment', function () {
|
||||
var shipment = {
|
||||
shippingAddress: {
|
||||
firstName: 'David',
|
||||
lastName: 'Johnson',
|
||||
address1: '25 Quincy Rd.',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
postalCode: '01234',
|
||||
countryCode: { value: 'us' },
|
||||
phone: '617-777-1010',
|
||||
stateCode: 'MA',
|
||||
|
||||
setFirstName: function (firstNameInput) { this.firstName = firstNameInput; },
|
||||
setLastName: function (lastNameInput) { this.lastName = lastNameInput; },
|
||||
setAddress1: function (address1Input) { this.address1 = address1Input; },
|
||||
setAddress2: function (address2Input) { this.address2 = address2Input; },
|
||||
setCity: function (cityInput) { this.city = cityInput; },
|
||||
setPostalCode: function (postalCodeInput) { this.postalCode = postalCodeInput; },
|
||||
setStateCode: function (stateCodeInput) { this.stateCode = stateCodeInput; },
|
||||
setCountryCode: function (countryCodeInput) { this.countryCode.value = countryCodeInput; },
|
||||
setPhone: function (phoneInput) { this.phone = phoneInput; }
|
||||
}
|
||||
};
|
||||
|
||||
checkoutHelpers.copyCustomerAddressToShipment(address, shipment);
|
||||
|
||||
assert.equal(shipment.shippingAddress.firstName, address.firstName);
|
||||
assert.equal(shipment.shippingAddress.lastName, address.lastName);
|
||||
assert.equal(shipment.shippingAddress.address1, address.address1);
|
||||
assert.equal(shipment.shippingAddress.address2, address.address2);
|
||||
assert.equal(shipment.shippingAddress.city, address.city);
|
||||
assert.equal(shipment.shippingAddress.postalCode, address.postalCode);
|
||||
assert.equal(shipment.shippingAddress.countryCode.value, address.countryCode.value);
|
||||
assert.equal(shipment.shippingAddress.phone, address.phone);
|
||||
assert.equal(shipment.shippingAddress.stateCode, address.stateCode);
|
||||
});
|
||||
|
||||
it('should create shipment address and copy customer address to shipment address if shipment address is null', function () {
|
||||
var shipment = {
|
||||
shippingAddress: null,
|
||||
createShippingAddress: function () {
|
||||
this.shippingAddress = {
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
address1: '',
|
||||
address2: '',
|
||||
city: '',
|
||||
postalCode: '',
|
||||
countryCode: { value: '' },
|
||||
phone: '',
|
||||
stateCode: '',
|
||||
|
||||
setFirstName: function (firstNameInput) { this.firstName = firstNameInput; },
|
||||
setLastName: function (lastNameInput) { this.lastName = lastNameInput; },
|
||||
setAddress1: function (address1Input) { this.address1 = address1Input; },
|
||||
setAddress2: function (address2Input) { this.address2 = address2Input; },
|
||||
setCity: function (cityInput) { this.city = cityInput; },
|
||||
setPostalCode: function (postalCodeInput) { this.postalCode = postalCodeInput; },
|
||||
setStateCode: function (stateCodeInput) { this.stateCode = stateCodeInput; },
|
||||
setCountryCode: function (countryCodeInput) { this.countryCode.value = countryCodeInput; },
|
||||
setPhone: function (phoneInput) { this.phone = phoneInput; }
|
||||
};
|
||||
return this.shippingAddress;
|
||||
}
|
||||
};
|
||||
|
||||
checkoutHelpers.copyCustomerAddressToShipment(address, shipment);
|
||||
|
||||
assert.equal(shipment.shippingAddress.firstName, address.firstName);
|
||||
assert.equal(shipment.shippingAddress.lastName, address.lastName);
|
||||
assert.equal(shipment.shippingAddress.address1, address.address1);
|
||||
assert.equal(shipment.shippingAddress.address2, address.address2);
|
||||
assert.equal(shipment.shippingAddress.city, address.city);
|
||||
assert.equal(shipment.shippingAddress.postalCode, address.postalCode);
|
||||
assert.equal(shipment.shippingAddress.countryCode.value, address.countryCode.value);
|
||||
assert.equal(shipment.shippingAddress.phone, address.phone);
|
||||
assert.equal(shipment.shippingAddress.stateCode, address.stateCode);
|
||||
});
|
||||
});
|
||||
|
||||
describe('copyShippingAddressToShipment', function () {
|
||||
var shippingData = {
|
||||
address: {
|
||||
firstName: 'James',
|
||||
lastName: 'Bond',
|
||||
address1: '10 Oxford St',
|
||||
address2: 'suite 20',
|
||||
city: 'London',
|
||||
postalCode: '02345',
|
||||
countryCode: 'uk',
|
||||
phone: '603-333-1212',
|
||||
stateCode: 'NH'
|
||||
},
|
||||
shippingMethod: '002'
|
||||
};
|
||||
|
||||
it('should copy information from the shipping form to shipment address for non-null shipment', function () {
|
||||
var shipment = {
|
||||
shippingAddress: {
|
||||
firstName: 'David',
|
||||
lastName: 'Johnson',
|
||||
address1: '25 Quincy Rd.',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
postalCode: '01234',
|
||||
countryCode: { value: 'us' },
|
||||
phone: '617-777-1010',
|
||||
stateCode: 'MA',
|
||||
|
||||
setFirstName: function (firstNameInput) {
|
||||
this.firstName = firstNameInput;
|
||||
},
|
||||
setLastName: function (lastNameInput) {
|
||||
this.lastName = lastNameInput;
|
||||
},
|
||||
setAddress1: function (address1Input) {
|
||||
this.address1 = address1Input;
|
||||
},
|
||||
setAddress2: function (address2Input) {
|
||||
this.address2 = address2Input;
|
||||
},
|
||||
setCity: function (cityInput) {
|
||||
this.city = cityInput;
|
||||
},
|
||||
setPostalCode: function (postalCodeInput) {
|
||||
this.postalCode = postalCodeInput;
|
||||
},
|
||||
setStateCode: function (stateCodeInput) {
|
||||
this.stateCode = stateCodeInput;
|
||||
},
|
||||
setCountryCode: function (countryCodeInput) {
|
||||
this.countryCode.value = countryCodeInput;
|
||||
},
|
||||
setPhone: function (phoneInput) {
|
||||
this.phone = phoneInput;
|
||||
}
|
||||
},
|
||||
selectedShippingMethod: {},
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
this.selectedShippingMethod = shippingMethod;
|
||||
}
|
||||
};
|
||||
|
||||
checkoutHelpers.copyShippingAddressToShipment(shippingData, shipment);
|
||||
|
||||
assert.equal(shipment.shippingAddress.firstName, shippingData.address.firstName);
|
||||
assert.equal(shipment.shippingAddress.lastName, shippingData.address.lastName);
|
||||
assert.equal(shipment.shippingAddress.address1, shippingData.address.address1);
|
||||
assert.equal(shipment.shippingAddress.address2, shippingData.address.address2);
|
||||
assert.equal(shipment.shippingAddress.city, shippingData.address.city);
|
||||
assert.equal(shipment.shippingAddress.postalCode, shippingData.address.postalCode);
|
||||
assert.equal(shipment.shippingAddress.countryCode.value, shippingData.address.countryCode);
|
||||
assert.equal(shipment.shippingAddress.phone, shippingData.address.phone);
|
||||
assert.equal(shipment.shippingAddress.stateCode, shippingData.address.stateCode);
|
||||
|
||||
assert.equal(shipment.selectedShippingMethod.ID, shippingData.shippingMethod);
|
||||
});
|
||||
|
||||
it('should create shipment address and copy information from the shipping form to shipment address if shipment address is null', function () {
|
||||
var shipment = {
|
||||
shippingAddress: null,
|
||||
selectedShippingMethod: {},
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
this.selectedShippingMethod = shippingMethod;
|
||||
},
|
||||
createShippingAddress: function () {
|
||||
this.shippingAddress = {
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
address1: '',
|
||||
address2: '',
|
||||
city: '',
|
||||
postalCode: '',
|
||||
countryCode: { value: '' },
|
||||
phone: '',
|
||||
stateCode: '',
|
||||
|
||||
setFirstName: function (firstNameInput) { this.firstName = firstNameInput; },
|
||||
setLastName: function (lastNameInput) { this.lastName = lastNameInput; },
|
||||
setAddress1: function (address1Input) { this.address1 = address1Input; },
|
||||
setAddress2: function (address2Input) { this.address2 = address2Input; },
|
||||
setCity: function (cityInput) { this.city = cityInput; },
|
||||
setPostalCode: function (postalCodeInput) { this.postalCode = postalCodeInput; },
|
||||
setStateCode: function (stateCodeInput) { this.stateCode = stateCodeInput; },
|
||||
setCountryCode: function (countryCodeInput) { this.countryCode.value = countryCodeInput; },
|
||||
setPhone: function (phoneInput) { this.phone = phoneInput; }
|
||||
};
|
||||
return this.shippingAddress;
|
||||
}
|
||||
};
|
||||
|
||||
checkoutHelpers.copyShippingAddressToShipment(shippingData, shipment);
|
||||
|
||||
assert.equal(shipment.shippingAddress.firstName, shippingData.address.firstName);
|
||||
assert.equal(shipment.shippingAddress.lastName, shippingData.address.lastName);
|
||||
assert.equal(shipment.shippingAddress.address1, shippingData.address.address1);
|
||||
assert.equal(shipment.shippingAddress.address2, shippingData.address.address2);
|
||||
assert.equal(shipment.shippingAddress.city, shippingData.address.city);
|
||||
assert.equal(shipment.shippingAddress.postalCode, shippingData.address.postalCode);
|
||||
assert.equal(shipment.shippingAddress.countryCode.value, shippingData.address.countryCode);
|
||||
assert.equal(shipment.shippingAddress.phone, shippingData.address.phone);
|
||||
assert.equal(shipment.shippingAddress.stateCode, shippingData.address.stateCode);
|
||||
|
||||
assert.equal(shipment.selectedShippingMethod.ID, shippingData.shippingMethod);
|
||||
});
|
||||
|
||||
it('should copy information from the shipping form to shipment address for non-null shipment with shippingData having countryCode as an object', function () {
|
||||
shippingData.address.countryCode = {
|
||||
value: 'uk'
|
||||
};
|
||||
var shipment = {
|
||||
shippingAddress: {
|
||||
firstName: 'David',
|
||||
lastName: 'Johnson',
|
||||
address1: '25 Quincy Rd.',
|
||||
address2: '',
|
||||
city: 'Boston',
|
||||
postalCode: '01234',
|
||||
countryCode: { value: 'us' },
|
||||
phone: '617-777-1010',
|
||||
stateCode: 'MA',
|
||||
|
||||
setFirstName: function (firstNameInput) {
|
||||
this.firstName = firstNameInput;
|
||||
},
|
||||
setLastName: function (lastNameInput) {
|
||||
this.lastName = lastNameInput;
|
||||
},
|
||||
setAddress1: function (address1Input) {
|
||||
this.address1 = address1Input;
|
||||
},
|
||||
setAddress2: function (address2Input) {
|
||||
this.address2 = address2Input;
|
||||
},
|
||||
setCity: function (cityInput) {
|
||||
this.city = cityInput;
|
||||
},
|
||||
setPostalCode: function (postalCodeInput) {
|
||||
this.postalCode = postalCodeInput;
|
||||
},
|
||||
setStateCode: function (stateCodeInput) {
|
||||
this.stateCode = stateCodeInput;
|
||||
},
|
||||
setCountryCode: function (countryCodeInput) {
|
||||
this.countryCode.value = countryCodeInput;
|
||||
},
|
||||
setPhone: function (phoneInput) {
|
||||
this.phone = phoneInput;
|
||||
}
|
||||
},
|
||||
selectedShippingMethod: {},
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
this.selectedShippingMethod = shippingMethod;
|
||||
}
|
||||
};
|
||||
|
||||
checkoutHelpers.copyShippingAddressToShipment(shippingData, shipment);
|
||||
|
||||
assert.equal(shipment.shippingAddress.firstName, shippingData.address.firstName);
|
||||
assert.equal(shipment.shippingAddress.lastName, shippingData.address.lastName);
|
||||
assert.equal(shipment.shippingAddress.address1, shippingData.address.address1);
|
||||
assert.equal(shipment.shippingAddress.address2, shippingData.address.address2);
|
||||
assert.equal(shipment.shippingAddress.city, shippingData.address.city);
|
||||
assert.equal(shipment.shippingAddress.postalCode, shippingData.address.postalCode);
|
||||
assert.equal(shipment.shippingAddress.countryCode.value, shippingData.address.countryCode.value);
|
||||
assert.equal(shipment.shippingAddress.phone, shippingData.address.phone);
|
||||
assert.equal(shipment.shippingAddress.stateCode, shippingData.address.stateCode);
|
||||
|
||||
assert.equal(shipment.selectedShippingMethod.ID, shippingData.shippingMethod);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFirstNonDefaultShipmentWithProductLineItems', function () {
|
||||
it('should return the first non-default shipment with more than one product line item', function () {
|
||||
var basket = {
|
||||
shipments: [
|
||||
{
|
||||
UUID: '1111',
|
||||
shippingAddress: {
|
||||
stateCode: 'MA',
|
||||
postalCode: '01803'
|
||||
},
|
||||
default: true,
|
||||
productLineItems: [
|
||||
{ 'id': '011111' },
|
||||
{ 'id': '011112' },
|
||||
{ 'id': '011113' }
|
||||
]
|
||||
},
|
||||
{
|
||||
UUID: '1112',
|
||||
shippingAddress: {
|
||||
stateCode: 'CA',
|
||||
postalCode: '97123'
|
||||
},
|
||||
default: false,
|
||||
productLineItems: [
|
||||
{ 'id': '022221' },
|
||||
{ 'id': '022222' },
|
||||
{ 'id': '022223' }
|
||||
]
|
||||
},
|
||||
{
|
||||
UUID: '1113',
|
||||
shippingAddress: {
|
||||
stateCode: 'CO',
|
||||
postalCode: '85123'
|
||||
},
|
||||
default: false,
|
||||
productLineItems: [
|
||||
{ 'id': '033331' },
|
||||
{ 'id': '033332' },
|
||||
{ 'id': '033333' }
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var myShipment = checkoutHelpers.getFirstNonDefaultShipmentWithProductLineItems(basket);
|
||||
assert.equal(myShipment.UUID, basket.shipments[1].UUID);
|
||||
});
|
||||
});
|
||||
|
||||
describe('recalculateBasket', function () {
|
||||
it('should recalculate the basket', function () {
|
||||
var basket = {};
|
||||
checkoutHelpers.recalculateBasket(basket);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getProductLineItem', function () {
|
||||
it('should return the specified product line item', function () {
|
||||
var basket = {
|
||||
productLineItems: [
|
||||
{ 'UUID': 'pliuuid011111' },
|
||||
{ 'UUID': 'pliuuid011112' },
|
||||
{ 'UUID': 'pliuuid011113' },
|
||||
{ 'UUID': 'pliuuid011114' }
|
||||
]
|
||||
};
|
||||
|
||||
var targetPliUUID = basket.productLineItems[2].UUID;
|
||||
var myPli = checkoutHelpers.getProductLineItem(basket, targetPliUUID);
|
||||
assert.equal(myPli.UUID, targetPliUUID);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateCustomerForm', function () {
|
||||
it('should return an object with form validation result - no error', function () {
|
||||
var customerForm = {
|
||||
emailAddress: { valid: true, formType: 'formField' },
|
||||
email: {
|
||||
value: 'mary@test.com'
|
||||
}
|
||||
};
|
||||
|
||||
var result = checkoutHelpers.validateCustomerForm(customerForm);
|
||||
assert.equal(result.viewData.customer.email.value, 'mary@test.com');
|
||||
assert.equal(result.customerForm, customerForm);
|
||||
assert.equal(Object.keys(result.formFieldErrors).length, 0);
|
||||
});
|
||||
|
||||
it('should return an object with form validation result - error', function () {
|
||||
var customerForm = {
|
||||
emailAddress: { valid: false, formType: 'formField' },
|
||||
email: {
|
||||
value: 'mary@test.com'
|
||||
}
|
||||
};
|
||||
|
||||
var result = checkoutHelpers.validateCustomerForm(customerForm);
|
||||
assert.equal(Object.keys(result.viewData).length, 0);
|
||||
assert.equal(result.customerForm, customerForm);
|
||||
assert.equal(Object.keys(result.formFieldErrors).length, 1);
|
||||
});
|
||||
|
||||
it('should return null if no form', function () {
|
||||
var result = checkoutHelpers.validateCustomerForm(null);
|
||||
assert.isNull(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateBillingForm', function () {
|
||||
it('should return empty object when no invalid form field - with state field', function () {
|
||||
var billingForm = {
|
||||
firstName: { valid: true, formType: 'formField' },
|
||||
lastName: { valid: true, formType: 'formField' },
|
||||
address1: { valid: true, formType: 'formField' },
|
||||
address2: { valid: true, formType: 'formField' },
|
||||
city: { valid: true, formType: 'formField' },
|
||||
states: { valid: true, formType: 'formField' },
|
||||
postalCode: { valid: true, formType: 'formField' },
|
||||
country: { valid: true, formType: 'formField' }
|
||||
};
|
||||
|
||||
var invalidFields = checkoutHelpers.validateBillingForm(billingForm);
|
||||
assert.equal(Object.keys(invalidFields).length, 0);
|
||||
});
|
||||
|
||||
it('should return empty object when no invalid form field - without state field', function () {
|
||||
var billingForm2 = {
|
||||
firstName: { valid: true, formType: 'formField' },
|
||||
lastName: { valid: true, formType: 'formField' },
|
||||
address1: { valid: true, formType: 'formField' },
|
||||
address2: { valid: true, formType: 'formField' },
|
||||
city: { valid: true, formType: 'formField' },
|
||||
postalCode: { valid: true, formType: 'formField' },
|
||||
country: { valid: true, formType: 'formField' }
|
||||
};
|
||||
|
||||
var invalidFields = checkoutHelpers.validateBillingForm(billingForm2);
|
||||
assert.equal(Object.keys(invalidFields).length, 0);
|
||||
});
|
||||
|
||||
it('should return an object containing invalid form field', function () {
|
||||
var billingForm3 = {
|
||||
firstName: { valid: true, formType: 'formField' },
|
||||
lastName: { valid: true, formType: 'formField' },
|
||||
address1: { valid: true, formType: 'formField' },
|
||||
address2: {
|
||||
valid: false,
|
||||
htmlName: 'htmlNameAddress2',
|
||||
error: 'address2 is an invalid field.',
|
||||
formType: 'formField'
|
||||
},
|
||||
city: { valid: true, formType: 'formField' },
|
||||
states: { valid: true, formType: 'formField' },
|
||||
postalCode: { valid: true, formType: 'formField' },
|
||||
country: {
|
||||
valid: false,
|
||||
htmlName: 'htmlNameCountry',
|
||||
error: 'country is an invalid field.',
|
||||
formType: 'formField'
|
||||
}
|
||||
};
|
||||
|
||||
var invalidFields = checkoutHelpers.validateBillingForm(billingForm3);
|
||||
assert.equal(Object.keys(invalidFields).length, 2);
|
||||
assert.equal(invalidFields.htmlNameAddress2, billingForm3.address2.error);
|
||||
assert.equal(invalidFields.htmlNameCountry, billingForm3.country.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateCreditCard', function () {
|
||||
it('should return an empty object when no invalid form field', function () {
|
||||
var creditCardForm = {
|
||||
paymentMethod: {
|
||||
value: '$100.00',
|
||||
htmlName: 'htmlName payment method error'
|
||||
},
|
||||
creditCardFields: {
|
||||
cardNumber: { valid: true },
|
||||
expirationYear: { valid: true },
|
||||
expirationMonth: { valid: true },
|
||||
securityCode: { valid: true },
|
||||
email: { valid: true },
|
||||
phone: { valid: true }
|
||||
}
|
||||
};
|
||||
|
||||
var invalidFields = checkoutHelpers.validateCreditCard(creditCardForm);
|
||||
assert.equal(Object.keys(invalidFields).length, 0);
|
||||
});
|
||||
|
||||
it('should return an object containing invalid form fields when no payment method value', function () {
|
||||
var creditCardForm = {
|
||||
paymentMethod: {
|
||||
value: null,
|
||||
htmlName: 'htmlNamePaymentMethodError'
|
||||
},
|
||||
creditCardFields: {
|
||||
cardNumber: { valid: true },
|
||||
expirationYear: { valid: true },
|
||||
expirationMonth: { valid: true },
|
||||
securityCode: { valid: true },
|
||||
email: { valid: true },
|
||||
phone: { valid: true }
|
||||
}
|
||||
};
|
||||
|
||||
var invalidFields = checkoutHelpers.validateCreditCard(creditCardForm);
|
||||
assert.equal(Object.keys(invalidFields).length, 1);
|
||||
assert.equal(invalidFields.htmlNamePaymentMethodError, 'error.no.selected.payment.method');
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculatePaymentTransaction', function () {
|
||||
it('should return result with error = false when no exception', function () {
|
||||
var currentBasket = {
|
||||
totalGrossPrice: '$200.00',
|
||||
paymentInstruments: [
|
||||
{
|
||||
paymentTransaction: {
|
||||
setAmount: function (orderTotal) { // eslint-disable-line no-unused-vars
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var result = checkoutHelpers.calculatePaymentTransaction(currentBasket);
|
||||
assert.isFalse(result.error);
|
||||
});
|
||||
|
||||
it('should return result with error = true when there is an exception', function () {
|
||||
var currentBasket = {
|
||||
totalGrossPrice: '$200.00',
|
||||
paymentInstruments: [
|
||||
{
|
||||
paymentTransaction: {
|
||||
setAmount: function (value) { // eslint-disable-line no-unused-vars
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var result = checkoutHelpers.calculatePaymentTransaction(currentBasket);
|
||||
assert.isTrue(result.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createOrder', function () {
|
||||
it('should return the order object created from the current basket', function () {
|
||||
var currentBasket = {};
|
||||
|
||||
var result = checkoutHelpers.createOrder(currentBasket);
|
||||
assert.equal(result.order, 'new order');
|
||||
});
|
||||
});
|
||||
|
||||
describe('placeOrder', function () {
|
||||
var setConfirmationStatusStub = sinon.stub();
|
||||
var setExportStatusStub = sinon.stub();
|
||||
|
||||
beforeEach(function () {
|
||||
setConfirmationStatusStub.reset();
|
||||
setExportStatusStub.reset();
|
||||
});
|
||||
|
||||
var order = {
|
||||
setConfirmationStatus: setConfirmationStatusStub,
|
||||
setExportStatus: setExportStatusStub
|
||||
};
|
||||
|
||||
it('should return result with error = false when no exception ', function () {
|
||||
var mockFraudDetectionStatus = {
|
||||
status: 'success',
|
||||
errorCode: '',
|
||||
errorMessage: ''
|
||||
};
|
||||
|
||||
var result = checkoutHelpers.placeOrder(order, mockFraudDetectionStatus);
|
||||
|
||||
assert.isTrue(setConfirmationStatusStub.calledOnce);
|
||||
assert.isTrue(setConfirmationStatusStub.calledWith('CONFIRMATION_STATUS_CONFIRMED'));
|
||||
assert.isFalse(result.error);
|
||||
});
|
||||
|
||||
it('should return result with error = false when no exception and fraud status is flag', function () {
|
||||
var mockFraudDetectionStatus = {
|
||||
status: 'flag',
|
||||
errorCode: '',
|
||||
errorMessage: ''
|
||||
};
|
||||
|
||||
var result = checkoutHelpers.placeOrder(order, mockFraudDetectionStatus);
|
||||
|
||||
assert.isTrue(setConfirmationStatusStub.calledOnce);
|
||||
assert.isTrue(setConfirmationStatusStub.calledWith('ONFIRMATION_STATUS_NOTCONFIRMED'));
|
||||
assert.isFalse(result.error);
|
||||
});
|
||||
|
||||
it('should return result with error = true when exception is thrown', function () {
|
||||
var result = checkoutHelpers.placeOrder(order);
|
||||
|
||||
assert.isTrue(setConfirmationStatusStub.notCalled);
|
||||
assert.isTrue(result.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setGift', function () {
|
||||
var mockShipment = {
|
||||
setGift: function () {
|
||||
return;
|
||||
},
|
||||
setGiftMessage: function () {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
it('should return a result object with no errors', function () {
|
||||
var result = checkoutHelpers.setGift(mockShipment, true, 'gift Message');
|
||||
|
||||
assert.isFalse(result.error);
|
||||
assert.equal(result.errorMessage, null);
|
||||
});
|
||||
|
||||
it('should return a result object with errors', function () {
|
||||
var result = checkoutHelpers.setGift({}, false, 'gift Message');
|
||||
|
||||
assert.isTrue(result.error);
|
||||
assert.equal(result.errorMessage, 'error.message.could.not.be.attached');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,424 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
var ArrayList = require('../../../../mocks/dw.util.Collection');
|
||||
|
||||
var shippingHelpers = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/checkout/shippingHelpers', {
|
||||
'*/cartridge/scripts/util/collections': proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
}),
|
||||
|
||||
'dw/order/ShippingMgr': require('../../../../mocks/dw/order/ShippingMgr'),
|
||||
|
||||
'*/cartridge/models/shipping': require('../../../../mocks/models/shipping'),
|
||||
'*/cartridge/models/shipping/shippingMethod': require('../../../../mocks/models/shippingMethod')
|
||||
});
|
||||
|
||||
function MockBasket() {}
|
||||
|
||||
MockBasket.prototype.getShipments = function () {
|
||||
return new ArrayList([null, null, null]);
|
||||
};
|
||||
|
||||
describe('shippingHelpers', function () {
|
||||
describe('getShippingModels', function () {
|
||||
it('should handle a null basket', function () {
|
||||
var shippingModels = shippingHelpers.getShippingModels(null);
|
||||
assert.isNotNull(shippingModels);
|
||||
assert.equal(shippingModels.length, 0);
|
||||
});
|
||||
|
||||
it('should handle a basket with multiple shipments', function () {
|
||||
var mockBasket = new MockBasket();
|
||||
var shippingModels = shippingHelpers.getShippingModels(mockBasket);
|
||||
assert.isNotNull(shippingModels);
|
||||
assert.equal(shippingModels.length, 3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAddressFromRequest', function () {
|
||||
var request = {
|
||||
form: {
|
||||
firstName: 'Jane',
|
||||
lastName: 'Smith',
|
||||
address1: '5 Wall St.',
|
||||
address2: 'suite 10',
|
||||
city: 'Burlington',
|
||||
stateCode: 'MA',
|
||||
postalCode: '01803',
|
||||
countryCode: 'US',
|
||||
phone: '781-322-1010'
|
||||
}
|
||||
};
|
||||
|
||||
it('should return the raw address JSON object from request.form', function () {
|
||||
var address = shippingHelpers.getAddressFromRequest(request);
|
||||
assert.equal(address.firstName, request.form.firstName);
|
||||
assert.equal(address.lastName, request.form.lastName);
|
||||
assert.equal(address.address1, request.form.address1);
|
||||
assert.equal(address.address2, request.form.address2);
|
||||
assert.equal(address.city, request.form.city);
|
||||
assert.equal(address.stateCode, request.form.stateCode);
|
||||
assert.equal(address.postalCode, request.form.postalCode);
|
||||
assert.equal(address.countryCode, request.form.countryCode);
|
||||
assert.equal(address.phone, request.form.phone);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getShipmentByUUID', function () {
|
||||
var basket = {
|
||||
shipments: new ArrayList([
|
||||
{ UUID: '00001' },
|
||||
{ UUID: '00002' },
|
||||
{ UUID: '00003' }
|
||||
])
|
||||
};
|
||||
|
||||
it('should return the existing shipment object', function () {
|
||||
var shipment = shippingHelpers.getShipmentByUUID(basket, '00002');
|
||||
assert.equal(shipment.UUID, '00002');
|
||||
});
|
||||
|
||||
it('should return null when no shipment found', function () {
|
||||
var shipment = shippingHelpers.getShipmentByUUID(basket, '12345');
|
||||
assert.isNull(shipment);
|
||||
});
|
||||
});
|
||||
|
||||
describe('selectShippingMethod', function () {
|
||||
var shipment = {
|
||||
UUID: '1234-1234-1234-1234',
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
return shippingMethod;
|
||||
},
|
||||
shippingAddress: {
|
||||
stateCode: 'CA',
|
||||
postalCode: '97123'
|
||||
}
|
||||
};
|
||||
|
||||
var shippingMethods = new ArrayList([
|
||||
{
|
||||
ID: '001',
|
||||
displayName: 'Ground',
|
||||
description: 'Order received within 7-10 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '7-10 Business Days'
|
||||
}
|
||||
},
|
||||
{
|
||||
ID: '002',
|
||||
displayName: '2-Day Express',
|
||||
description: 'Order received in 2 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '2 Business Days'
|
||||
}
|
||||
},
|
||||
{
|
||||
ID: '003',
|
||||
displayName: 'Overnight',
|
||||
description: 'Order received the next business day',
|
||||
custom: {
|
||||
estimatedArrivalTime: 'Next Day'
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
var address = {
|
||||
stateCode: 'MA',
|
||||
postalCode: '01803'
|
||||
};
|
||||
|
||||
it('test 1: should replace shipment.shippingAddress with the provided address', function () {
|
||||
var shippingMethodID = '002';
|
||||
|
||||
shippingHelpers.selectShippingMethod(shipment, shippingMethodID, shippingMethods, address);
|
||||
|
||||
assert.deepEqual(shipment.shippingAddress, address);
|
||||
});
|
||||
|
||||
it('test 2: should make no change to shipment.shippingAddress when it is null', function () {
|
||||
var shippingMethodID = '002';
|
||||
|
||||
var myShipment = {
|
||||
UUID: '1234-1234-1234-1234',
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
return shippingMethod;
|
||||
},
|
||||
shippingAddress: null
|
||||
};
|
||||
|
||||
var expectedShippingAddress = null;
|
||||
|
||||
shippingHelpers.selectShippingMethod(myShipment, shippingMethodID, shippingMethods, address);
|
||||
|
||||
assert.equal(myShipment.shippingAddress, expectedShippingAddress);
|
||||
});
|
||||
|
||||
|
||||
it('test 3: should set shipping method when matching shippingMethodID is supplied', function () {
|
||||
var shippingMethodID = '002';
|
||||
var expectedShippingMethod = {
|
||||
ID: '002',
|
||||
displayName: '2-Day Express',
|
||||
description: 'Order received in 2 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '2 Business Days'
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(shipment, 'setShippingMethod');
|
||||
spy.withArgs(expectedShippingMethod);
|
||||
|
||||
shippingHelpers.selectShippingMethod(shipment, shippingMethodID, shippingMethods, address);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(spy.withArgs(expectedShippingMethod).calledOnce);
|
||||
|
||||
shipment.setShippingMethod.restore();
|
||||
});
|
||||
|
||||
it('test 4: should set default shipping method when no matching shippingMethodID found and applicable shipping methods contains default shipping method', function () {
|
||||
var shippingMethodID = 'IdNotExist';
|
||||
var expectedDefaultShipMethod = {
|
||||
ID: '001',
|
||||
displayName: 'Ground',
|
||||
description: 'Order received within 7-10 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '7-10 Business Days'
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(shipment, 'setShippingMethod');
|
||||
spy.withArgs(expectedDefaultShipMethod);
|
||||
|
||||
shippingHelpers.selectShippingMethod(shipment, shippingMethodID, shippingMethods, address);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(spy.withArgs(expectedDefaultShipMethod).calledOnce);
|
||||
shipment.setShippingMethod.restore();
|
||||
});
|
||||
|
||||
it('test 5: should set first shipping method when no matching shippingMethodID found and applicable shipping methods exist but no default shipping method', function () {
|
||||
var shippingMethodID = 'IdNotExist';
|
||||
|
||||
var shippingMethodList = new ArrayList([
|
||||
{
|
||||
ID: '003',
|
||||
displayName: 'Overnight',
|
||||
description: 'Order received the next business day',
|
||||
custom: {
|
||||
estimatedArrivalTime: 'Next Day'
|
||||
}
|
||||
},
|
||||
{
|
||||
ID: '002',
|
||||
displayName: '2-Day Express',
|
||||
description: 'Order received in 2 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '2 Business Days'
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
var expectedShippingMethod = {
|
||||
ID: '003',
|
||||
displayName: 'Overnight',
|
||||
description: 'Order received the next business day',
|
||||
custom: {
|
||||
estimatedArrivalTime: 'Next Day'
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(shipment, 'setShippingMethod');
|
||||
spy.withArgs(expectedShippingMethod);
|
||||
|
||||
shippingHelpers.selectShippingMethod(shipment, shippingMethodID, shippingMethodList, address);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(spy.withArgs(expectedShippingMethod).calledOnce);
|
||||
shipment.setShippingMethod.restore();
|
||||
});
|
||||
|
||||
it('test 6: should set shipping method to null when no matching shippingMethodID found and applicable shipping methods not exist', function () {
|
||||
var shippingMethodID = 'IdNotExist';
|
||||
|
||||
var shippingMethodList = new ArrayList([]);
|
||||
|
||||
var spy = sinon.spy(shipment, 'setShippingMethod');
|
||||
spy.withArgs(null);
|
||||
|
||||
shippingHelpers.selectShippingMethod(shipment, shippingMethodID, shippingMethodList, address);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(spy.withArgs(null).calledOnce);
|
||||
shipment.setShippingMethod.restore();
|
||||
});
|
||||
|
||||
it('test 7: should get shipping method from applicable shipping methods and given address that matched shippingMethodID', function () {
|
||||
var shippingMethodID = '002';
|
||||
|
||||
var shippingMethodList = null;
|
||||
|
||||
var expectedDefaultShipMethod = {
|
||||
ID: '002',
|
||||
displayName: '2-Day Express',
|
||||
description: 'Order received in 2 business days',
|
||||
shippingCost: '$0.00',
|
||||
custom: {
|
||||
estimatedArrivalTime: '2 Business Days'
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(shipment, 'setShippingMethod');
|
||||
spy.withArgs(expectedDefaultShipMethod);
|
||||
|
||||
shippingHelpers.selectShippingMethod(shipment, shippingMethodID, shippingMethodList, address);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(spy.withArgs(expectedDefaultShipMethod).calledOnce);
|
||||
shipment.setShippingMethod.restore();
|
||||
});
|
||||
|
||||
it('test 8: should set shipping method from applicable shipping methods when no address provided and matched shippingMethodID', function () {
|
||||
var shippingMethodID = '002';
|
||||
|
||||
var shippingMethodList = null;
|
||||
var localAddress = null;
|
||||
|
||||
var expectedDefaultShipMethod = {
|
||||
ID: '002',
|
||||
displayName: '2-Day Express',
|
||||
description: 'Order received in 2 business days',
|
||||
shippingCost: '$0.00',
|
||||
custom: {
|
||||
estimatedArrivalTime: '2 Business Days'
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(shipment, 'setShippingMethod');
|
||||
spy.withArgs(expectedDefaultShipMethod);
|
||||
|
||||
shippingHelpers.selectShippingMethod(shipment, shippingMethodID, shippingMethodList, localAddress);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(spy.withArgs(expectedDefaultShipMethod).calledOnce);
|
||||
shipment.setShippingMethod.restore();
|
||||
});
|
||||
|
||||
it('test 9: should not loop through the shipping methods to get shipping method when shipping method ID is not provided', function () {
|
||||
var shippingMethodID = null;
|
||||
var expectedDefaultShipMethod = {
|
||||
ID: '001',
|
||||
displayName: 'Ground',
|
||||
description: 'Order received within 7-10 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '7-10 Business Days'
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(shipment, 'setShippingMethod');
|
||||
spy.withArgs(expectedDefaultShipMethod);
|
||||
|
||||
shippingHelpers.selectShippingMethod(shipment, shippingMethodID, shippingMethods, address);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(spy.withArgs(expectedDefaultShipMethod).calledOnce);
|
||||
shipment.setShippingMethod.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ensureShipmentHasMethod', function () {
|
||||
it('test 1: should not set shipping method if shipment method is available in shipment', function () {
|
||||
var shipmentWithShipMethod = {
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
return shippingMethod;
|
||||
},
|
||||
shippingMethod: {
|
||||
ID: '001',
|
||||
displayName: 'Ground',
|
||||
description: 'Order received within 7-10 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '7-10 Business Days'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(shipmentWithShipMethod, 'setShippingMethod');
|
||||
|
||||
shippingHelpers.ensureShipmentHasMethod(shipmentWithShipMethod);
|
||||
|
||||
assert.isTrue(spy.notCalled);
|
||||
shipmentWithShipMethod.setShippingMethod.restore();
|
||||
});
|
||||
|
||||
it('test 2: should set default shipping method when shipment method is NOT available in shipment', function () {
|
||||
var shipmentWithNoShipMethod = {
|
||||
setShippingMethod: function (shippingMethod) {
|
||||
return shippingMethod;
|
||||
}
|
||||
};
|
||||
|
||||
var expectedDefaultShipMethod = {
|
||||
ID: '001',
|
||||
displayName: 'Ground',
|
||||
description: 'Order received within 7-10 business days',
|
||||
custom: {
|
||||
estimatedArrivalTime: '7-10 Business Days'
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(shipmentWithNoShipMethod, 'setShippingMethod');
|
||||
spy.withArgs(expectedDefaultShipMethod);
|
||||
|
||||
shippingHelpers.ensureShipmentHasMethod(shipmentWithNoShipMethod);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(spy.withArgs(expectedDefaultShipMethod).calledOnce);
|
||||
shipmentWithNoShipMethod.setShippingMethod.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getApplicableShippingMethods', function () {
|
||||
it('should return null when there is no shipment', function () {
|
||||
var shipment = null;
|
||||
var address = {};
|
||||
var shippingMethods = shippingHelpers.getApplicableShippingMethods(shipment, address);
|
||||
assert.isNull(shippingMethods);
|
||||
});
|
||||
|
||||
it('should return a list of applicable shipping methods for non null address', function () {
|
||||
var shipment = {};
|
||||
var address = {};
|
||||
var applicableShippingMethods = shippingHelpers.getApplicableShippingMethods(shipment, address);
|
||||
|
||||
assert.equal(
|
||||
applicableShippingMethods[0].description,
|
||||
'Order received within 7-10 business days'
|
||||
);
|
||||
assert.equal(applicableShippingMethods[0].displayName, 'Ground');
|
||||
assert.equal(applicableShippingMethods[0].ID, '001');
|
||||
|
||||
assert.equal(applicableShippingMethods[1].displayName, '2-Day Express');
|
||||
assert.equal(applicableShippingMethods[1].ID, '002');
|
||||
});
|
||||
|
||||
it('should return a list of applicable shipping methods for null address', function () {
|
||||
var shipment = {};
|
||||
var address = null;
|
||||
var applicableShippingMethods = shippingHelpers.getApplicableShippingMethods(shipment, address);
|
||||
|
||||
assert.equal(
|
||||
applicableShippingMethods[0].description,
|
||||
'Order received within 7-10 business days'
|
||||
);
|
||||
assert.equal(applicableShippingMethods[0].displayName, 'Ground');
|
||||
assert.equal(applicableShippingMethods[0].ID, '001');
|
||||
|
||||
assert.equal(applicableShippingMethods[1].displayName, '2-Day Express');
|
||||
assert.equal(applicableShippingMethods[1].ID, '002');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,157 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
describe('carouselBuilder', function () {
|
||||
var carouselBuilder = proxyquire('../../../../../../cartridges/app_storefront_base/cartridge/scripts/experience/utilities/carouselBuilder.js', {
|
||||
'*/cartridge/experience/utilities/PageRenderHelper.js': {
|
||||
getRegionModelRegistry: function () {
|
||||
var returnValue = {
|
||||
container: {},
|
||||
slides: {
|
||||
setClassName: function () {},
|
||||
setComponentClassName: function () {},
|
||||
region: [1, 2]
|
||||
}
|
||||
};
|
||||
returnValue.slides.region.size = 2;
|
||||
|
||||
returnValue.slides.setComponentAttribute = function () {
|
||||
|
||||
};
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should build a carousel', function () {
|
||||
var model = {};
|
||||
var context = {
|
||||
content: {
|
||||
xsCarouselSlidesToDisplay: 1,
|
||||
smCarouselSlidesToDisplay: 2,
|
||||
mdCarouselSlidesToDisplay: 3,
|
||||
xsCarouselControls: true,
|
||||
smCarouselControls: true,
|
||||
xsCarouselIndicators: true,
|
||||
smCarouselIndicators: true,
|
||||
mdCarouselIndicators: true
|
||||
},
|
||||
component: {
|
||||
typeID: 'storefront.einsteinCarouselCategory',
|
||||
getID: function () {}
|
||||
}
|
||||
};
|
||||
var result = carouselBuilder.init(model, context);
|
||||
assert.property(result, 'regions');
|
||||
assert.property(result, 'id');
|
||||
assert.property(result, 'slidesToDisplay');
|
||||
assert.property(result, 'displayIndicators');
|
||||
assert.property(result, 'displayControls');
|
||||
assert.property(result, 'insufficientNumberOfSlides');
|
||||
assert.property(result, 'numberOfSlides');
|
||||
assert.property(result, 'title');
|
||||
});
|
||||
|
||||
it('should build a carousel without slides to display properties', function () {
|
||||
var model = {};
|
||||
var context = {
|
||||
content: {
|
||||
xsCarouselSlidesToDisplay: null,
|
||||
smCarouselSlidesToDisplay: null,
|
||||
mdCarouselSlidesToDisplay: null,
|
||||
xsCarouselControls: false,
|
||||
smCarouselControls: false,
|
||||
xsCarouselIndicators: false,
|
||||
smCarouselIndicators: false,
|
||||
mdCarouselIndicators: false
|
||||
},
|
||||
component: {
|
||||
typeID: 'storefront.einsteinCarouselCategory',
|
||||
getID: function () {}
|
||||
}
|
||||
};
|
||||
var result = carouselBuilder.init(model, context);
|
||||
assert.property(result, 'regions');
|
||||
assert.property(result, 'id');
|
||||
assert.property(result, 'slidesToDisplay');
|
||||
assert.property(result, 'displayIndicators');
|
||||
assert.property(result, 'displayControls');
|
||||
assert.property(result, 'insufficientNumberOfSlides');
|
||||
assert.property(result, 'numberOfSlides');
|
||||
assert.property(result, 'title');
|
||||
});
|
||||
|
||||
it('should build a carousel with category based recs', function () {
|
||||
var model = {};
|
||||
var context = {
|
||||
content: {
|
||||
xsCarouselSlidesToDisplay: 1,
|
||||
smCarouselSlidesToDisplay: 2,
|
||||
mdCarouselSlidesToDisplay: 3
|
||||
},
|
||||
component: {
|
||||
typeID: 'storefront.einsteinCarouselCategory',
|
||||
getID: function () {}
|
||||
}
|
||||
};
|
||||
var result = carouselBuilder.init(model, context);
|
||||
assert.property(result, 'regions');
|
||||
assert.property(result, 'id');
|
||||
assert.property(result, 'slidesToDisplay');
|
||||
assert.property(result, 'displayIndicators');
|
||||
assert.property(result, 'displayControls');
|
||||
assert.property(result, 'insufficientNumberOfSlides');
|
||||
assert.property(result, 'numberOfSlides');
|
||||
assert.property(result, 'title');
|
||||
});
|
||||
|
||||
it('should build a carousel with product based recs', function () {
|
||||
var model = {};
|
||||
var context = {
|
||||
content: {
|
||||
xsCarouselSlidesToDisplay: 1,
|
||||
smCarouselSlidesToDisplay: 2,
|
||||
mdCarouselSlidesToDisplay: 3
|
||||
},
|
||||
component: {
|
||||
typeID: 'storefront.einsteinCarouselProduct',
|
||||
getID: function () {}
|
||||
}
|
||||
};
|
||||
var result = carouselBuilder.init(model, context);
|
||||
assert.property(result, 'regions');
|
||||
assert.property(result, 'id');
|
||||
assert.property(result, 'slidesToDisplay');
|
||||
assert.property(result, 'displayIndicators');
|
||||
assert.property(result, 'displayControls');
|
||||
assert.property(result, 'insufficientNumberOfSlides');
|
||||
assert.property(result, 'numberOfSlides');
|
||||
assert.property(result, 'title');
|
||||
});
|
||||
|
||||
it('should build a carousel', function () {
|
||||
var model = {};
|
||||
var context = {
|
||||
content: {
|
||||
xsCarouselSlidesToDisplay: 1,
|
||||
smCarouselSlidesToDisplay: 2,
|
||||
mdCarouselSlidesToDisplay: 3
|
||||
},
|
||||
component: {
|
||||
typeID: 'storefront.einsteinCarousel',
|
||||
getID: function () {}
|
||||
}
|
||||
};
|
||||
var result = carouselBuilder.init(model, context);
|
||||
assert.property(result, 'regions');
|
||||
assert.property(result, 'id');
|
||||
assert.property(result, 'slidesToDisplay');
|
||||
assert.property(result, 'displayIndicators');
|
||||
assert.property(result, 'displayControls');
|
||||
assert.property(result, 'insufficientNumberOfSlides');
|
||||
assert.property(result, 'numberOfSlides');
|
||||
assert.property(result, 'title');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,414 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
var mockCollections = require('../../../../mocks/util/collections');
|
||||
|
||||
|
||||
describe('priceFactory', function () {
|
||||
var price;
|
||||
var product;
|
||||
|
||||
var spyDefaultPrice = sinon.spy();
|
||||
var spyTieredPrice = sinon.spy();
|
||||
var stubRangePrice = sinon.stub();
|
||||
var stubGetPromotionPrice = sinon.stub();
|
||||
var stubGetProductPromotions = sinon.stub();
|
||||
stubGetProductPromotions.returns([]);
|
||||
|
||||
var PROMOTION_CLASS_PRODUCT = 'awesome promotion';
|
||||
|
||||
var priceFactory = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/factories/price.js', {
|
||||
'*/cartridge/scripts/util/collections': {
|
||||
find: mockCollections.find
|
||||
},
|
||||
'*/cartridge/scripts/helpers/pricing': {
|
||||
getRootPriceBook: function () { return { ID: '123' }; },
|
||||
getPromotionPrice: stubGetPromotionPrice
|
||||
},
|
||||
'dw/campaign/PromotionMgr': {
|
||||
activeCustomerPromotions: {
|
||||
getProductPromotions: stubGetProductPromotions
|
||||
}
|
||||
},
|
||||
'*/cartridge/models/price/default': spyDefaultPrice,
|
||||
'*/cartridge/models/price/range': stubRangePrice,
|
||||
'*/cartridge/models/price/tiered': spyTieredPrice,
|
||||
'dw/campaign/Promotion': {
|
||||
PROMOTION_CLASS_PRODUCT: PROMOTION_CLASS_PRODUCT
|
||||
},
|
||||
'dw/value/Money': { NOT_AVAILABLE: null }
|
||||
});
|
||||
|
||||
describe('Tiered Price', function () {
|
||||
var priceTable;
|
||||
|
||||
afterEach(function () {
|
||||
spyTieredPrice.reset();
|
||||
});
|
||||
|
||||
it('should produce a tiered price if price tables have more than 1 quantity', function () {
|
||||
priceTable = { quantities: { length: 3 } };
|
||||
product = {
|
||||
getPriceModel: function () {
|
||||
return {
|
||||
getPriceTable: function () { return priceTable; }
|
||||
};
|
||||
}
|
||||
};
|
||||
price = priceFactory.getPrice(product);
|
||||
assert.isTrue(spyTieredPrice.calledWithNew());
|
||||
});
|
||||
|
||||
it('should not produce a tiered price if a price table has only 1 quantity', function () {
|
||||
priceTable = { quantities: { length: 1 } };
|
||||
product = {
|
||||
master: false,
|
||||
priceModel: {
|
||||
priceRange: false,
|
||||
price: {
|
||||
valueOrNull: null
|
||||
},
|
||||
minPrice: '$5',
|
||||
getPriceTable: function () {
|
||||
return priceTable;
|
||||
}
|
||||
},
|
||||
getPriceModel: function () {
|
||||
return this.priceModel;
|
||||
},
|
||||
variationModel: {
|
||||
variants: [{}, {}]
|
||||
}
|
||||
};
|
||||
price = priceFactory.getPrice(product);
|
||||
assert.isFalse(spyTieredPrice.calledWithNew());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Range Price', function () {
|
||||
var rangePrice = {
|
||||
min: {
|
||||
sales: { value: '$5' }
|
||||
},
|
||||
max: {
|
||||
sales: { value: '$15' }
|
||||
}
|
||||
};
|
||||
beforeEach(function () {
|
||||
product = {
|
||||
master: true,
|
||||
priceModel: {
|
||||
price: { valueOrNull: 'value' },
|
||||
priceInfo: { priceBook: {} },
|
||||
priceRange: true,
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () {
|
||||
return { available: true };
|
||||
}
|
||||
},
|
||||
getPriceModel: function () {
|
||||
return this.priceModel;
|
||||
},
|
||||
variationModel: {
|
||||
variants: [{}, {}]
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
stubRangePrice.reset();
|
||||
});
|
||||
|
||||
it('should produce a range price', function () {
|
||||
stubRangePrice.returns(rangePrice);
|
||||
price = priceFactory.getPrice(product);
|
||||
assert.equal(price, rangePrice);
|
||||
});
|
||||
|
||||
it('should not produce a range price if min and max values are equal', function () {
|
||||
rangePrice = {
|
||||
min: {
|
||||
sales: { value: '$5' }
|
||||
},
|
||||
max: {
|
||||
sales: { value: '$5' }
|
||||
}
|
||||
};
|
||||
stubRangePrice.returns(rangePrice);
|
||||
product.variationModel = { variants: [] };
|
||||
|
||||
price = priceFactory.getPrice(product);
|
||||
assert.notEqual(price, rangePrice);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Default Price', function () {
|
||||
var priceModel = {};
|
||||
var secondSpyArg;
|
||||
var variantPriceModel = {};
|
||||
|
||||
afterEach(function () {
|
||||
spyDefaultPrice.reset();
|
||||
});
|
||||
|
||||
it('should use the first variant if product is a main', function () {
|
||||
var expectedPrice = { available: true };
|
||||
priceModel = {
|
||||
price: { valueOrNull: 'value' },
|
||||
priceInfo: { priceBook: {} },
|
||||
priceRange: false,
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return expectedPrice; }
|
||||
};
|
||||
variantPriceModel = {
|
||||
price: { valueOrNull: null },
|
||||
priceInfo: { priceBook: {} },
|
||||
priceRange: false,
|
||||
minPrice: '$8',
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return expectedPrice; }
|
||||
};
|
||||
product = {
|
||||
master: true,
|
||||
priceModel: priceModel,
|
||||
getPriceModel: function () { return priceModel; },
|
||||
variationModel: {
|
||||
variants: [{ priceModel: variantPriceModel }, {}]
|
||||
}
|
||||
};
|
||||
price = priceFactory.getPrice(product);
|
||||
assert.isTrue(spyDefaultPrice.calledWith(variantPriceModel.price));
|
||||
});
|
||||
|
||||
it('should assign list price to root pricebook price when available', function () {
|
||||
var pricebookListPrice = {
|
||||
available: true,
|
||||
value: '$20',
|
||||
valueOrNull: 20
|
||||
};
|
||||
product = {
|
||||
master: false,
|
||||
priceModel: {
|
||||
price: { valueOrNull: 'value' },
|
||||
priceInfo: { priceBook: {} },
|
||||
priceRange: false,
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return pricebookListPrice; }
|
||||
},
|
||||
getPriceModel: function () { return this.priceModel; },
|
||||
variationModel: {
|
||||
variants: [{}, {}]
|
||||
}
|
||||
};
|
||||
price = priceFactory.getPrice(product);
|
||||
secondSpyArg = spyDefaultPrice.args[0][1];
|
||||
assert.isTrue(spyDefaultPrice.calledWithNew());
|
||||
assert.equal(secondSpyArg, pricebookListPrice);
|
||||
});
|
||||
|
||||
it('should instantiate DefaultPrice with only sales price when equal to list price', function () {
|
||||
var expectedPrice = { available: false };
|
||||
product = {
|
||||
master: false,
|
||||
priceModel: {
|
||||
price: {
|
||||
available: true,
|
||||
valueOrNull: 'value',
|
||||
value: '$28'
|
||||
},
|
||||
priceInfo: { priceBook: {} },
|
||||
priceRange: false,
|
||||
minPrice: {
|
||||
value: '$2'
|
||||
},
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return expectedPrice; }
|
||||
},
|
||||
getPriceModel: function () { return this.priceModel; }
|
||||
};
|
||||
price = priceFactory.getPrice(product);
|
||||
assert.isTrue(spyDefaultPrice.calledWith(product.priceModel.price, null));
|
||||
});
|
||||
|
||||
it('should assign list price to priceModel minPrice when root pricebook and priceModel price not available', function () {
|
||||
var expectedPrice = { available: false };
|
||||
product = {
|
||||
master: false,
|
||||
priceModel: {
|
||||
price: {
|
||||
available: false,
|
||||
valueOrNull: 'value',
|
||||
value: '$28'
|
||||
},
|
||||
priceInfo: { priceBook: {} },
|
||||
priceRange: false,
|
||||
minPrice: {
|
||||
value: '$2'
|
||||
},
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return expectedPrice; }
|
||||
},
|
||||
getPriceModel: function () { return this.priceModel; }
|
||||
};
|
||||
price = priceFactory.getPrice(product);
|
||||
secondSpyArg = spyDefaultPrice.args[0][1];
|
||||
assert.isTrue(spyDefaultPrice.calledWithNew());
|
||||
assert.equal(secondSpyArg, product.priceModel.minPrice);
|
||||
});
|
||||
|
||||
describe('with promotional prices', function () {
|
||||
var listPrice = {
|
||||
available: true,
|
||||
value: 50,
|
||||
valueOrNull: 50
|
||||
};
|
||||
var salesPrice = {
|
||||
value: 30,
|
||||
valueOrNull: 'value',
|
||||
compareTo: function (otherPrice) {
|
||||
return this.value > otherPrice.value;
|
||||
}
|
||||
};
|
||||
var promotionalPrice = {
|
||||
available: true,
|
||||
value: 10,
|
||||
valueOrNull: 10
|
||||
};
|
||||
var promotions = [{
|
||||
promotionClass: {
|
||||
equals: function () { return true; }
|
||||
},
|
||||
getPromotionalPrice: function () {
|
||||
return promotionalPrice;
|
||||
}
|
||||
}];
|
||||
|
||||
beforeEach(function () {
|
||||
stubGetProductPromotions.returns(promotions);
|
||||
stubGetPromotionPrice.returns({
|
||||
available: true,
|
||||
value: 10,
|
||||
valueOrNull: 10
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
spyDefaultPrice.reset();
|
||||
});
|
||||
|
||||
it('should swap sales price for promo price', function () {
|
||||
product = {
|
||||
master: false,
|
||||
priceModel: {
|
||||
price: salesPrice,
|
||||
priceInfo: { priceBook: {} },
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return listPrice; }
|
||||
},
|
||||
getPriceModel: function () { return this.priceModel; }
|
||||
};
|
||||
price = priceFactory.getPrice(product, null, null, promotions);
|
||||
assert.isTrue(spyDefaultPrice.calledWithNew());
|
||||
assert.isTrue(spyDefaultPrice.calledWith(promotionalPrice, listPrice));
|
||||
});
|
||||
|
||||
it('should get a promotional price when an option product is provided', function () {
|
||||
product = {
|
||||
master: false,
|
||||
priceModel: {
|
||||
price: salesPrice,
|
||||
priceInfo: { priceBook: {} },
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return listPrice; }
|
||||
},
|
||||
getPriceModel: function () { return this.priceModel; }
|
||||
};
|
||||
price = priceFactory.getPrice(product, null, null, promotions, true);
|
||||
assert.isTrue(spyDefaultPrice.calledWithNew());
|
||||
assert.isTrue(spyDefaultPrice.calledWith(promotionalPrice, listPrice));
|
||||
});
|
||||
|
||||
it('should get a promotional price when an option product is not provided', function () {
|
||||
product = {
|
||||
master: false,
|
||||
priceModel: {
|
||||
price: salesPrice,
|
||||
priceInfo: { priceBook: {} },
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return listPrice; }
|
||||
},
|
||||
getPriceModel: function () { return this.priceModel; },
|
||||
optionModel: { option: 'model' }
|
||||
};
|
||||
price = priceFactory.getPrice(product, null, null, promotions, false);
|
||||
assert.isTrue(spyDefaultPrice.calledWithNew());
|
||||
assert.isTrue(spyDefaultPrice.calledWith(promotionalPrice, listPrice));
|
||||
});
|
||||
|
||||
it('should set sales price to list price if sales price is null', function () {
|
||||
product = {
|
||||
master: false,
|
||||
priceModel: {
|
||||
price: {
|
||||
value: null,
|
||||
valueOrNull: null,
|
||||
compareTo: function (otherPrice) {
|
||||
return this.value > otherPrice.value;
|
||||
}
|
||||
},
|
||||
priceInfo: { priceBook: {} },
|
||||
getPriceTable: function () {
|
||||
return {
|
||||
quantities: { length: 1 }
|
||||
};
|
||||
},
|
||||
getPriceBookPrice: function () { return listPrice; }
|
||||
},
|
||||
getPriceModel: function () { return this.priceModel; },
|
||||
optionModel: { option: 'model' }
|
||||
};
|
||||
price = priceFactory.getPrice(product, null, null, promotions, false);
|
||||
assert.isTrue(spyDefaultPrice.calledWithNew());
|
||||
assert.isTrue(spyDefaultPrice.calledWith(listPrice, {}));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,620 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var ArrayList = require('../../../../mocks/dw.util.Collection');
|
||||
var sinon = require('sinon');
|
||||
|
||||
var stubFullProduct = sinon.stub();
|
||||
stubFullProduct.returns('full product');
|
||||
|
||||
var stubProductSet = sinon.stub();
|
||||
stubProductSet.returns('product set');
|
||||
|
||||
var stubProductBundle = sinon.stub();
|
||||
stubProductBundle.returns('product bundle');
|
||||
|
||||
var stubProductTile = sinon.stub();
|
||||
stubProductTile.returns('product tile');
|
||||
|
||||
var stubProductLineItem = sinon.stub();
|
||||
stubProductLineItem.returns('product line item');
|
||||
|
||||
var stubOrderLineItem = sinon.stub();
|
||||
stubOrderLineItem.returns('product line item (order)');
|
||||
|
||||
var stubBundleLineItem = sinon.stub();
|
||||
stubBundleLineItem.returns('bundle line item');
|
||||
|
||||
var stubBundleOrderLineItem = sinon.stub();
|
||||
stubBundleOrderLineItem.returns('bundle line item (order)');
|
||||
|
||||
var stubBonusProduct = sinon.stub();
|
||||
stubBonusProduct.returns('bonus product');
|
||||
|
||||
var stubBonusProductLineItem = sinon.stub();
|
||||
stubBonusProductLineItem.returns('bonus product line item');
|
||||
|
||||
var stubBonusOrderLineItem = sinon.stub();
|
||||
stubBonusOrderLineItem.returns('bonus product line item (order)');
|
||||
|
||||
var productMock = {};
|
||||
var options = {};
|
||||
|
||||
var optionProductLineItems = new ArrayList([]);
|
||||
|
||||
describe('Product Factory', function () {
|
||||
var collections = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
});
|
||||
|
||||
var productFactory = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/factories/product', {
|
||||
'*/cartridge/scripts/util/collections': collections,
|
||||
'dw/catalog/ProductMgr': {
|
||||
getProduct: function () {
|
||||
return productMock;
|
||||
}
|
||||
},
|
||||
'dw/campaign/PromotionMgr': {
|
||||
activeCustomerPromotions: {
|
||||
getProductPromotions: function () { return 'promotions'; }
|
||||
}
|
||||
},
|
||||
'*/cartridge/scripts/helpers/productHelpers': {
|
||||
getCurrentOptionModel: function () { return 'optionModel'; },
|
||||
getProductType: function (product) {
|
||||
var result;
|
||||
if (product.master) {
|
||||
result = 'master';
|
||||
} else if (product.variant) {
|
||||
result = 'variant';
|
||||
} else if (product.variationGroup) {
|
||||
result = 'variationGroup';
|
||||
} else if (product.productSet) {
|
||||
result = 'set';
|
||||
} else if (product.bundle) {
|
||||
result = 'bundle';
|
||||
} else if (product.optionProduct) {
|
||||
result = 'optionProduct';
|
||||
} else {
|
||||
result = 'standard';
|
||||
}
|
||||
return result;
|
||||
},
|
||||
getConfig: function () {
|
||||
return options;
|
||||
},
|
||||
getVariationModel: function () {
|
||||
return productMock.variationModel;
|
||||
},
|
||||
getLineItemOptions: function () {
|
||||
return [{ productId: 'someID', optionId: 'someOptionId', selectedValueId: 'someValueId' }];
|
||||
},
|
||||
getDefaultOptions: function () {
|
||||
return ['name:value'];
|
||||
},
|
||||
getLineItemOptionNames: function () {
|
||||
return ['lineItemOptionNames'];
|
||||
}
|
||||
},
|
||||
'*/cartridge/models/product/productTile': stubProductTile,
|
||||
'*/cartridge/models/product/fullProduct': stubFullProduct,
|
||||
'*/cartridge/models/product/productSet': stubProductSet,
|
||||
'*/cartridge/models/product/productBundle': stubProductBundle,
|
||||
'*/cartridge/models/productLineItem/productLineItem': stubProductLineItem,
|
||||
'*/cartridge/models/productLineItem/orderLineItem': stubOrderLineItem,
|
||||
'*/cartridge/models/productLineItem/bundleLineItem': stubBundleLineItem,
|
||||
'*/cartridge/models/productLineItem/bundleOrderLineItem': stubBundleOrderLineItem,
|
||||
'*/cartridge/models/product/bonusProduct': stubBonusProduct,
|
||||
'*/cartridge/models/productLineItem/bonusProductLineItem': stubBonusProductLineItem,
|
||||
'*/cartridge/models/productLineItem/bonusOrderLineItem': stubBonusOrderLineItem
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
productMock = {
|
||||
optionModel: {
|
||||
options: new ArrayList([])
|
||||
},
|
||||
variationModel: {
|
||||
master: false,
|
||||
selectedVariant: false,
|
||||
productVariationAttributes: new ArrayList([{
|
||||
color: {
|
||||
ID: 'someID',
|
||||
value: 'blue'
|
||||
}
|
||||
}]),
|
||||
getAllValues: function () {
|
||||
return new ArrayList([{
|
||||
value: 'someValue'
|
||||
}]);
|
||||
},
|
||||
setSelectedAttributeValue: function () {},
|
||||
getSelectedVariant: function () {}
|
||||
},
|
||||
master: false,
|
||||
variant: false,
|
||||
variationGroup: false,
|
||||
productSet: false,
|
||||
bundle: false,
|
||||
optionProduct: false
|
||||
};
|
||||
});
|
||||
|
||||
it('should return full product model for product type master', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
productMock.master = true;
|
||||
options = {
|
||||
variationModel: null,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'master'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return full product model for product type variant', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
productMock.variant = true;
|
||||
|
||||
options = {
|
||||
variationModel: null,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'variant'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return full product model for product type variationGroup', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
productMock.variationGroup = true;
|
||||
options = {
|
||||
variationModel: null,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'variationGroup'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return full product model for product type optionProduct', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
productMock.optionProduct = true;
|
||||
options = {
|
||||
variationModel: null,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'optionProduct'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return full product model for product type standard', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
options = {
|
||||
variationModel: null,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'standard'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return set product model for product type productSet', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
productMock.productSet = true;
|
||||
options = {
|
||||
variationModel: null,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'set'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'product set');
|
||||
assert.isTrue(stubProductSet.calledWith({}, options.apiProduct, options, productFactory));
|
||||
});
|
||||
|
||||
it('should return bundle product model for product type bundle', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
productMock.bundle = true;
|
||||
options = {
|
||||
variationModel: null,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'bundle'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'product bundle');
|
||||
assert.isTrue(stubProductBundle.calledWith({}, options.apiProduct, options, productFactory));
|
||||
});
|
||||
|
||||
it('should return empty product model for invalid productid', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
options = {
|
||||
variationModel: undefined,
|
||||
options: undefined,
|
||||
optionModel: undefined,
|
||||
promotions: undefined,
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: undefined,
|
||||
productType: undefined
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return full product model for product type master with variables and variation model type master', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
variables: {
|
||||
color: {
|
||||
value: 'blue'
|
||||
}
|
||||
}
|
||||
};
|
||||
productMock.master = true;
|
||||
productMock.variationModel.master = true;
|
||||
productMock.variationModel.productVariationAttributes = new ArrayList([{ ID: 'color' }]);
|
||||
productMock.variationModel.getAllValues = function () {
|
||||
return new ArrayList([{
|
||||
ID: 'someID',
|
||||
value: 'blue'
|
||||
}]);
|
||||
};
|
||||
|
||||
options = {
|
||||
variationModel: productMock.variationModel,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: { color: { value: 'blue' } },
|
||||
apiProduct: productMock,
|
||||
productType: 'master'
|
||||
};
|
||||
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return full product model for product type master with variables', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
variables: {
|
||||
color: {
|
||||
value: null
|
||||
}
|
||||
}
|
||||
};
|
||||
productMock.master = true;
|
||||
productMock.variationModel.master = true;
|
||||
options = {
|
||||
variationModel: productMock.variationModel,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: { color: { value: null } },
|
||||
apiProduct: productMock,
|
||||
productType: 'master'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return full product model for product type master without variables', function () {
|
||||
var params = {
|
||||
pid: 'someID'
|
||||
};
|
||||
productMock.master = true;
|
||||
productMock.variationModel.master = true;
|
||||
options = {
|
||||
variationModel: productMock.variationModel,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'master'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'full product');
|
||||
assert.isTrue(stubFullProduct.calledWith({}, options.apiProduct, options));
|
||||
});
|
||||
|
||||
it('should return product tile model', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'tile'
|
||||
};
|
||||
productMock.master = true;
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'product tile');
|
||||
assert.isTrue(stubProductTile.calledWith({}, productMock, 'master'));
|
||||
});
|
||||
|
||||
it('should return product line item model', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'productLineItem',
|
||||
lineItem: {
|
||||
optionProductLineItems: new ArrayList([])
|
||||
}
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'product line item');
|
||||
});
|
||||
|
||||
it('should return product line item model for a line item that has options with multiple values', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'productLineItem',
|
||||
containerView: 'test',
|
||||
lineItem: {
|
||||
optionProductLineItems: new ArrayList([{
|
||||
productName: 'someName',
|
||||
optionID: 'someID',
|
||||
optionValueID: 'someValue'
|
||||
|
||||
}])
|
||||
}
|
||||
};
|
||||
productMock.optionModel = {
|
||||
options: new ArrayList([{ productName: 'someName',
|
||||
optionID: 'someID',
|
||||
optionValueID: 'someValue' }]),
|
||||
getSelectedOptionValue: function () {
|
||||
return { displayValue: 'someValue' };
|
||||
}
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
assert.equal(result, 'product line item');
|
||||
assert.isTrue(stubProductLineItem.calledWith({}, productMock));
|
||||
});
|
||||
|
||||
it('should return product line item model for a line item that has options', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'productLineItem',
|
||||
lineItem: {
|
||||
optionProductLineItems: new ArrayList([{
|
||||
productName: 'someName'
|
||||
}])
|
||||
}
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'product line item');
|
||||
});
|
||||
|
||||
it('should return product line item model for a line item that has options', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'productLineItem',
|
||||
lineItem: {
|
||||
optionProductLineItems: new ArrayList([])
|
||||
}
|
||||
};
|
||||
|
||||
productMock.optionModel = {
|
||||
options: new ArrayList([{ displayName: 'someName' }]),
|
||||
getSelectedOptionValue: function () {
|
||||
return { displayValue: 'someValue' };
|
||||
}
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'product line item');
|
||||
});
|
||||
|
||||
it('should return product line item model when variables are present and lineItem has no options ', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'productLineItem',
|
||||
lineItem: {
|
||||
optionProductLineItems: optionProductLineItems
|
||||
},
|
||||
variables: {
|
||||
color: {
|
||||
value: 'blue'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
productMock.variationModel.selectedVariant = true;
|
||||
productMock.optionModel = {
|
||||
options: new ArrayList([{ displayName: 'someName' }]),
|
||||
getSelectedOptionValue: function () {
|
||||
return { displayValue: 'someValue' };
|
||||
}
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'product line item');
|
||||
assert.isTrue(stubProductLineItem.calledWith({}, productMock));
|
||||
});
|
||||
|
||||
it('should return bundle line item model', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'productLineItem',
|
||||
lineItem: {}
|
||||
};
|
||||
productMock.bundle = true;
|
||||
options = {
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
lineItem: {},
|
||||
productType: 'bundle'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'bundle line item');
|
||||
assert.isTrue(stubBundleLineItem.calledWith({}, productMock, options, productFactory));
|
||||
});
|
||||
|
||||
it('should return bonus product line item model', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'bonusProductLineItem',
|
||||
lineItem: {
|
||||
optionProductLineItems: new ArrayList([])
|
||||
}
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'bonus product line item');
|
||||
});
|
||||
|
||||
it('should return bonus product line item model for a bonus line item that has options', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'bonusProductLineItem',
|
||||
lineItem: {
|
||||
optionProductLineItems: new ArrayList([{
|
||||
productName: 'someName'
|
||||
}])
|
||||
}
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'bonus product line item');
|
||||
});
|
||||
|
||||
it('should return bonus product line item model when variables are present and bonus line item has no options ', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'bonusProductLineItem',
|
||||
lineItem: {
|
||||
optionProductLineItems: optionProductLineItems
|
||||
},
|
||||
variables: {
|
||||
color: {
|
||||
value: 'blue'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
productMock.variationModel.selectedVariant = true;
|
||||
productMock.optionModel = {
|
||||
options: new ArrayList([{ displayName: 'someName' }]),
|
||||
getSelectedOptionValue: function () {
|
||||
return { displayValue: 'someValue' };
|
||||
}
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
assert.equal(result, 'bonus product line item');
|
||||
assert.isTrue(stubBonusProductLineItem.calledWith({}, productMock));
|
||||
});
|
||||
|
||||
it('should return bonus product model for product type master', function () {
|
||||
var params = {
|
||||
pid: 'someID',
|
||||
pview: 'bonus',
|
||||
lineItem: {
|
||||
optionProductLineItems: new ArrayList([])
|
||||
},
|
||||
duuid: 'duuid'
|
||||
};
|
||||
|
||||
productMock.master = true;
|
||||
options = {
|
||||
variationModel: null,
|
||||
options: undefined,
|
||||
optionModel: 'optionModel',
|
||||
promotions: 'promotions',
|
||||
quantity: undefined,
|
||||
variables: undefined,
|
||||
apiProduct: productMock,
|
||||
productType: 'master'
|
||||
};
|
||||
var result = productFactory.get(params);
|
||||
|
||||
|
||||
assert.equal(result, 'bonus product');
|
||||
assert.isTrue(stubBonusProduct.calledWith({}, options.apiProduct, options, params.duuid));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,191 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var sinon = require('sinon');
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
|
||||
var mockCollections = require('../../../../mocks/util/collections');
|
||||
var mockPriceRefinementValue = sinon.spy();
|
||||
var mockColorRefinementValue = sinon.spy();
|
||||
var mockSizeRefinementValue = sinon.spy();
|
||||
var mockBooleanRefinementValue = sinon.spy();
|
||||
var mockPromotionRefinementValue = sinon.spy();
|
||||
var mockGetCategory = sinon.stub();
|
||||
|
||||
var searchRefinements = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/factories/searchRefinements', {
|
||||
'dw/catalog/CatalogMgr': { getCategory: mockGetCategory },
|
||||
'*/cartridge/scripts/util/collections': mockCollections,
|
||||
'*/cartridge/models/search/attributeRefinementValue/price': mockPriceRefinementValue,
|
||||
'*/cartridge/models/search/attributeRefinementValue/color': mockColorRefinementValue,
|
||||
'*/cartridge/models/search/attributeRefinementValue/size': mockSizeRefinementValue,
|
||||
'*/cartridge/models/search/attributeRefinementValue/boolean': mockBooleanRefinementValue,
|
||||
'*/cartridge/models/search/attributeRefinementValue/promotion': mockPromotionRefinementValue,
|
||||
'*/cartridge/models/search/attributeRefinementValue/category': function (temp1, temp2, category) {
|
||||
return {
|
||||
online: true,
|
||||
name: category.name,
|
||||
subCategories: []
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
describe('Search Refinements Factory', function () {
|
||||
var productSearch;
|
||||
var refinementDefinition;
|
||||
var refinementValues = [{}];
|
||||
|
||||
beforeEach(function () {
|
||||
productSearch = {};
|
||||
refinementDefinition = {};
|
||||
mockPriceRefinementValue.reset();
|
||||
mockColorRefinementValue.reset();
|
||||
mockSizeRefinementValue.reset();
|
||||
mockBooleanRefinementValue.reset();
|
||||
mockPromotionRefinementValue.reset();
|
||||
});
|
||||
|
||||
it('should retrieve price refinements ', function () {
|
||||
refinementDefinition = { priceRefinement: true };
|
||||
|
||||
searchRefinements.get(productSearch, refinementDefinition, refinementValues);
|
||||
|
||||
assert.isTrue(mockPriceRefinementValue.calledWithNew());
|
||||
});
|
||||
|
||||
it('should retrieve color refinements ', function () {
|
||||
refinementDefinition = { attributeID: 'refinementColor' };
|
||||
|
||||
searchRefinements.get(productSearch, refinementDefinition, refinementValues);
|
||||
|
||||
assert.isTrue(mockColorRefinementValue.calledWithNew());
|
||||
});
|
||||
|
||||
it('should retrieve size refinements ', function () {
|
||||
refinementDefinition = { attributeID: 'size' };
|
||||
|
||||
searchRefinements.get(productSearch, refinementDefinition, refinementValues);
|
||||
|
||||
assert.isTrue(mockSizeRefinementValue.calledWithNew());
|
||||
});
|
||||
|
||||
it('should retrieve boolean refinements ', function () {
|
||||
searchRefinements.get(productSearch, refinementDefinition, refinementValues);
|
||||
|
||||
assert.isTrue(mockBooleanRefinementValue.calledWithNew());
|
||||
});
|
||||
|
||||
it('should retrieve promotion refinements ', function () {
|
||||
refinementDefinition = { promotionRefinement: true };
|
||||
|
||||
searchRefinements.get(productSearch, refinementDefinition, refinementValues);
|
||||
|
||||
assert.isTrue(mockPromotionRefinementValue.calledWithNew());
|
||||
});
|
||||
|
||||
describe('Category Refinements', function () {
|
||||
var level1Category;
|
||||
var level2Category;
|
||||
var level3Category;
|
||||
var results;
|
||||
var rootCategory;
|
||||
|
||||
beforeEach(function () {
|
||||
productSearch = { categorySearch: true };
|
||||
refinementDefinition = { categoryRefinement: true };
|
||||
rootCategory = {
|
||||
ID: 'root',
|
||||
root: true,
|
||||
parent: { ID: null },
|
||||
subCategories: []
|
||||
};
|
||||
level1Category = {
|
||||
ID: 'women',
|
||||
online: true,
|
||||
name: 'women',
|
||||
parent: rootCategory,
|
||||
subCategories: []
|
||||
};
|
||||
level2Category = {
|
||||
ID: 'women-clothing',
|
||||
online: true,
|
||||
name: 'women-clothing',
|
||||
parent: level1Category,
|
||||
subCategories: []
|
||||
};
|
||||
level3Category = {
|
||||
ID: 'women-clothing-bottoms',
|
||||
online: true,
|
||||
name: 'women-clothing-bottoms',
|
||||
parent: level2Category,
|
||||
subCategories: []
|
||||
};
|
||||
});
|
||||
|
||||
describe('createCategorySearchRefinement() function', function () {
|
||||
it('should return a hierarchical category object', function () {
|
||||
productSearch.category = level2Category;
|
||||
level2Category.subCategories.push(level3Category);
|
||||
results = searchRefinements.get(productSearch, refinementDefinition, refinementValues);
|
||||
|
||||
assert.equal(results[0].name, level1Category.name);
|
||||
assert.equal(results[0].subCategories[0].name, level2Category.name);
|
||||
assert.equal(results[0].subCategories[0].subCategories[0].name, level3Category.name);
|
||||
});
|
||||
|
||||
it('should only return a category with its immediate subCategories if it or its parent is a root', function () {
|
||||
var l2CategoryA = {
|
||||
online: true,
|
||||
name: 'l2CA',
|
||||
subCategories: []
|
||||
};
|
||||
var l2CategoryB = {
|
||||
online: true,
|
||||
name: 'l2CB',
|
||||
subCategories: []
|
||||
};
|
||||
level1Category.subCategories = [l2CategoryA, l2CategoryB];
|
||||
productSearch.category = level1Category;
|
||||
results = searchRefinements.get(productSearch, refinementDefinition, refinementValues);
|
||||
|
||||
assert.deepEqual(results[0].subCategories, [l2CategoryA, l2CategoryB]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createProductSearchRefinement() function', function () {
|
||||
beforeEach(function () {
|
||||
productSearch = { categorySearch: false };
|
||||
refinementDefinition = { categoryRefinement: true };
|
||||
});
|
||||
|
||||
afterEach(function () { mockGetCategory.reset(); });
|
||||
|
||||
it('should return a hierarchical category object', function () {
|
||||
var level1Result;
|
||||
var level2Result;
|
||||
var level3Result;
|
||||
|
||||
refinementValues = [
|
||||
{ value: 'root' },
|
||||
{ value: 'women' },
|
||||
{ value: 'women-clothing' },
|
||||
{ value: 'women-clothing-bottoms' }
|
||||
];
|
||||
|
||||
mockGetCategory.withArgs('root').returns(rootCategory);
|
||||
mockGetCategory.withArgs('women').returns(level1Category);
|
||||
mockGetCategory.withArgs('women-clothing').returns(level2Category);
|
||||
mockGetCategory.withArgs('women-clothing-bottoms').returns(level3Category);
|
||||
|
||||
results = searchRefinements.get(productSearch, refinementDefinition, refinementValues);
|
||||
level1Result = results[0];
|
||||
level2Result = level1Result.subCategories[0];
|
||||
level3Result = level2Result.subCategories[0];
|
||||
|
||||
assert.equal(level1Result.name, level1Category.name);
|
||||
assert.equal(level2Result.name, level2Category.name);
|
||||
assert.equal(level3Result.name, level3Category.name);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var formErrors = require('../../../../cartridges/app_storefront_base/cartridge/scripts/formErrors.js');
|
||||
|
||||
describe('formErrors', function () {
|
||||
it('should remove htmlValue and value from the form object', function () {
|
||||
var obj = {
|
||||
formType: 'formGroup',
|
||||
test1: {
|
||||
value: 'someValue',
|
||||
htmlValue: 'someHTMLValue',
|
||||
formType: 'formField',
|
||||
property1: 'someProperty'
|
||||
},
|
||||
test2: {
|
||||
formType: 'formGroup',
|
||||
subTest1: {
|
||||
value: 'someValue',
|
||||
htmlValue: 'someHTMLValue',
|
||||
formType: 'formField',
|
||||
property1: 'someProperty'
|
||||
},
|
||||
subTest2: {
|
||||
htmlValue: 'someHTMLValue',
|
||||
formType: 'formField',
|
||||
property1: 'someProperty'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
formErrors.removeFormValues(obj);
|
||||
|
||||
assert.equal(obj.test1.value, undefined);
|
||||
assert.equal(obj.test1.htmlValue, undefined);
|
||||
assert.equal(obj.test2.subTest1.htmlValue, undefined);
|
||||
assert.equal(obj.test2.subTest1.value, undefined);
|
||||
assert.equal(obj.test2.subTest2.htmlValue, undefined);
|
||||
assert.equal(obj.test2.subTest2.value, undefined);
|
||||
});
|
||||
|
||||
it('should return an empty object if null is passed in', function () {
|
||||
var result = formErrors.getFormErrors(null);
|
||||
|
||||
assert.deepEqual(result, {});
|
||||
});
|
||||
|
||||
it('should get form errors', function () {
|
||||
var testObject = {
|
||||
formType: 'formGroup',
|
||||
test1: {
|
||||
formType: 'formField',
|
||||
valid: true,
|
||||
error: '',
|
||||
htmlName: 'someName1'
|
||||
},
|
||||
test2: {
|
||||
formType: 'formGroup',
|
||||
subTest: {
|
||||
formType: 'formField',
|
||||
valid: false,
|
||||
error: 'someError2',
|
||||
htmlName: 'someName2'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = formErrors.getFormErrors(testObject);
|
||||
|
||||
assert.deepEqual(result, { 'someName2': 'someError2' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
var urlStub = sinon.stub();
|
||||
var getPrivacyCacheStub = sinon.stub();
|
||||
var mockedAuthStatus = 'AUTH_OK';
|
||||
var authErrorMsg = 'NOT_EMPTY_STRING';
|
||||
|
||||
describe('accountHelpers', function () {
|
||||
var accoutHelpers = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/helpers/accountHelpers', {
|
||||
'dw/web/URLUtils': {
|
||||
url: urlStub
|
||||
},
|
||||
'*/cartridge/config/oAuthRenentryRedirectEndpoints': {
|
||||
1: 'Account-Show',
|
||||
2: 'Checkout-Begin'
|
||||
},
|
||||
'dw/system/Transaction': {
|
||||
wrap: function (callback) {
|
||||
return callback();
|
||||
}
|
||||
},
|
||||
'dw/customer/CustomerMgr': {
|
||||
authenticateCustomer: function () {
|
||||
return { status: mockedAuthStatus, customer: { }, loginCustomer: function () {} };
|
||||
},
|
||||
loginCustomer: function () {}
|
||||
},
|
||||
'dw/web/Resource': {
|
||||
msg: function () {
|
||||
return authErrorMsg;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var privacyCache = {
|
||||
get: getPrivacyCacheStub
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
urlStub.reset();
|
||||
urlStub.returns({
|
||||
relative: function () {
|
||||
return {
|
||||
toString: function () {
|
||||
return 'string url';
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
getPrivacyCacheStub.reset();
|
||||
});
|
||||
|
||||
it('should return a url with no args and registration false when no redirect url is passed in', function () {
|
||||
getPrivacyCacheStub.returns(null);
|
||||
|
||||
var result = accoutHelpers.getLoginRedirectURL(null, privacyCache, false);
|
||||
|
||||
assert.isTrue(urlStub.calledOnce);
|
||||
assert.isTrue(urlStub.calledWith('Account-Show', 'registration', 'false'));
|
||||
assert.equal(result, 'string url');
|
||||
});
|
||||
|
||||
it('should return a url with no args and registration true when no redirect url is passed in', function () {
|
||||
getPrivacyCacheStub.returns(null);
|
||||
|
||||
var result = accoutHelpers.getLoginRedirectURL(null, privacyCache, true);
|
||||
|
||||
assert.isTrue(urlStub.calledOnce);
|
||||
assert.isTrue(urlStub.calledWith('Account-Show', 'registration', 'submitted'));
|
||||
assert.equal(result, 'string url');
|
||||
});
|
||||
|
||||
it('should return a url with args and registration false when no redirect url is passed in', function () {
|
||||
getPrivacyCacheStub.returns('args');
|
||||
|
||||
var result = accoutHelpers.getLoginRedirectURL(null, privacyCache, false);
|
||||
|
||||
assert.isTrue(urlStub.calledOnce);
|
||||
assert.isTrue(urlStub.calledWith('Account-Show', 'registration', 'false', 'args', 'args'));
|
||||
assert.equal(result, 'string url');
|
||||
});
|
||||
|
||||
it('should return a url with args and registration submitted when no redirect url is passed in', function () {
|
||||
getPrivacyCacheStub.returns('args');
|
||||
|
||||
var result = accoutHelpers.getLoginRedirectURL(null, privacyCache, true);
|
||||
|
||||
assert.isTrue(urlStub.calledOnce);
|
||||
assert.isTrue(urlStub.calledWith('Account-Show', 'registration', 'submitted', 'args', 'args'));
|
||||
assert.equal(result, 'string url');
|
||||
});
|
||||
|
||||
it('should return a url with args and registration submitted when redirect url is passed in', function () {
|
||||
getPrivacyCacheStub.returns('args');
|
||||
|
||||
var result = accoutHelpers.getLoginRedirectURL('1', privacyCache, true);
|
||||
|
||||
assert.isTrue(urlStub.calledOnce);
|
||||
assert.isTrue(urlStub.calledWith('Account-Show', 'registration', 'submitted', 'args', 'args'));
|
||||
assert.equal(result, 'string url');
|
||||
});
|
||||
|
||||
it('should return no error on sucessfully authenticated customer', function () {
|
||||
getPrivacyCacheStub.returns('args');
|
||||
var email = 'ok@salesforce.com';
|
||||
var password = '122345';
|
||||
var rememberMe = false;
|
||||
|
||||
var result = accoutHelpers.loginCustomer(email, password, rememberMe);
|
||||
assert.isFalse(result.error);
|
||||
});
|
||||
|
||||
it('should return an error on not-sucessfully authenticated customer and an error message', function () {
|
||||
getPrivacyCacheStub.returns('args');
|
||||
var email = 'ok@salesforce.com';
|
||||
var password = '122345';
|
||||
var rememberMe = false;
|
||||
mockedAuthStatus = 'AUTH_NOT_OK';
|
||||
|
||||
var result = accoutHelpers.loginCustomer(email, password, rememberMe);
|
||||
assert.isTrue(result.error);
|
||||
assert.equal(result.errorMessage, authErrorMsg);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,304 @@
|
||||
/* eslint-env es6 */
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
var ArrayList = require('../../../../mocks/dw.util.Collection');
|
||||
|
||||
describe('addressHelpers', function () {
|
||||
var addressHelpers = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/helpers/addressHelpers', {
|
||||
'dw/system/Transaction': {
|
||||
wrap: function (arg) { arg(); }
|
||||
},
|
||||
'*/cartridge/scripts/util/collections': proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/util/collections', {
|
||||
'dw/util/ArrayList': ArrayList
|
||||
})
|
||||
});
|
||||
|
||||
it('Should generate correct address name', function () {
|
||||
var address = {
|
||||
address1: '10 Test St.',
|
||||
city: 'Testville',
|
||||
postalCode: '12345'
|
||||
};
|
||||
|
||||
var name = addressHelpers.generateAddressName(address);
|
||||
|
||||
assert.equal(name, '10 Test St. - Testville - 12345');
|
||||
});
|
||||
|
||||
it('Should generate correct address with missing information', function () {
|
||||
var address = {
|
||||
address1: '10 Test St.',
|
||||
postalCode: '12345'
|
||||
};
|
||||
|
||||
var name = addressHelpers.generateAddressName(address);
|
||||
|
||||
assert.equal(name, '10 Test St. - - 12345');
|
||||
});
|
||||
|
||||
it('Should check if address is already stored', function () {
|
||||
var address = {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
postalCode: '12345'
|
||||
};
|
||||
|
||||
var addresses = [{
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
postalCode: '12345'
|
||||
}];
|
||||
|
||||
assert.isTrue(addressHelpers.checkIfAddressStored(address, addresses));
|
||||
});
|
||||
|
||||
it('Should report address as not stored', function () {
|
||||
var address = {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
postalCode: '12345'
|
||||
};
|
||||
|
||||
var addresses = [{
|
||||
firstName: 'Foo',
|
||||
lastName: 'Baz',
|
||||
address1: '10 Test St.',
|
||||
postalCode: '12345'
|
||||
}, {
|
||||
firstName: 'Fu',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
postalCode: '12345'
|
||||
}, {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.'
|
||||
}, {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St',
|
||||
postalCode: '12345'
|
||||
}];
|
||||
|
||||
assert.isFalse(addressHelpers.checkIfAddressStored(address, addresses));
|
||||
});
|
||||
|
||||
it('Should store an address', function () {
|
||||
var address = {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
city: 'Testville',
|
||||
postalCode: '12345',
|
||||
phone: '123456789',
|
||||
country: 'US'
|
||||
};
|
||||
|
||||
var result = {};
|
||||
|
||||
var customer = {
|
||||
raw: {
|
||||
getProfile: function () {
|
||||
return {
|
||||
getAddressBook: function () {
|
||||
return {
|
||||
createAddress: function (id) {
|
||||
result.id = id;
|
||||
return new Proxy({}, {
|
||||
get(target, name) {
|
||||
return function (value) {
|
||||
var propName = name.substr(3, name.length - 3);
|
||||
var formattedName = propName.charAt(0).toLowerCase() + propName.slice(1);
|
||||
result[formattedName] = value;
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
addressHelpers.saveAddress(address, customer, 'TestID');
|
||||
|
||||
assert.equal(result.firstName, 'Foo');
|
||||
assert.equal(result.lastName, 'Bar');
|
||||
assert.equal(result.address1, '10 Test St.');
|
||||
assert.equal(result.city, 'Testville');
|
||||
assert.equal(result.postalCode, '12345');
|
||||
assert.equal(result.phone, '123456789');
|
||||
assert.equal(result.countryCode, 'US');
|
||||
});
|
||||
|
||||
it('Should copy an address', function () {
|
||||
var address = {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
city: 'Testville',
|
||||
postalCode: '12345',
|
||||
phone: '123456789',
|
||||
countryCode: 'US'
|
||||
};
|
||||
|
||||
var result = addressHelpers.copyShippingAddress(address);
|
||||
|
||||
assert.equal(result.firstName, 'Foo');
|
||||
assert.equal(result.lastName, 'Bar');
|
||||
assert.equal(result.address1, '10 Test St.');
|
||||
assert.equal(result.city, 'Testville');
|
||||
assert.equal(result.postalCode, '12345');
|
||||
assert.equal(result.phone, '123456789');
|
||||
assert.equal(result.country, 'US');
|
||||
});
|
||||
|
||||
it('Should update an address', function () {
|
||||
var stubSetAddress1 = sinon.stub();
|
||||
var stubSetAddress2 = sinon.stub();
|
||||
var stubSetCity = sinon.stub();
|
||||
var stubSetFirstName = sinon.stub();
|
||||
var stubSetLastName = sinon.stub();
|
||||
var stubSetPhone = sinon.stub();
|
||||
var stubSetPostalCode = sinon.stub();
|
||||
var stubSetStateCode = sinon.stub();
|
||||
var stubSetCountryCode = sinon.stub();
|
||||
var stubSetJobTitle = sinon.stub();
|
||||
var stubSetPostBox = sinon.stub();
|
||||
var stubSetSalutation = sinon.stub();
|
||||
var stubSetSecondName = sinon.stub();
|
||||
var stubSetCompanyName = sinon.stub();
|
||||
var stubSetSuffix = sinon.stub();
|
||||
var stubSetSuite = sinon.stub();
|
||||
var stubSetTitle = sinon.stub();
|
||||
|
||||
var address = {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
city: 'Testville',
|
||||
postalCode: '12345',
|
||||
phone: '123456789',
|
||||
countryCode: 'US',
|
||||
setAddress1: stubSetAddress1,
|
||||
setAddress2: stubSetAddress2,
|
||||
setCity: stubSetCity,
|
||||
setFirstName: stubSetFirstName,
|
||||
setLastName: stubSetLastName,
|
||||
setPhone: stubSetPhone,
|
||||
setPostalCode: stubSetPostalCode,
|
||||
setStateCode: stubSetStateCode,
|
||||
setCountryCode: stubSetCountryCode,
|
||||
setJobTitle: stubSetJobTitle,
|
||||
setPostBox: stubSetPostBox,
|
||||
setSalutation: stubSetSalutation,
|
||||
setSecondName: stubSetSecondName,
|
||||
setCompanyName: stubSetCompanyName,
|
||||
setSuffix: stubSetSuffix,
|
||||
setSuite: stubSetSuite,
|
||||
setTitle: stubSetTitle
|
||||
};
|
||||
|
||||
var formInfo = {
|
||||
address1: '11 Test ave.',
|
||||
address2: 'apt #4',
|
||||
city: '11 Test ave.',
|
||||
firstName: 'Bar',
|
||||
lastName: 'Foo',
|
||||
phone: '987654321',
|
||||
postalCode: '54321',
|
||||
states: {
|
||||
stateCode: 'MA'
|
||||
},
|
||||
country: 'US'
|
||||
|
||||
};
|
||||
|
||||
addressHelpers.updateAddressFields(address, formInfo);
|
||||
assert.isTrue(stubSetAddress1.calledOnce);
|
||||
assert.isTrue(stubSetAddress2.calledOnce);
|
||||
assert.isTrue(stubSetCity.calledOnce);
|
||||
assert.isTrue(stubSetFirstName.calledOnce);
|
||||
assert.isTrue(stubSetLastName.calledOnce);
|
||||
assert.isTrue(stubSetPhone.calledOnce);
|
||||
assert.isTrue(stubSetPostalCode.calledOnce);
|
||||
assert.isTrue(stubSetStateCode.calledOnce);
|
||||
assert.isTrue(stubSetCountryCode.calledOnce);
|
||||
assert.isTrue(stubSetJobTitle.calledOnce);
|
||||
assert.isTrue(stubSetPostBox.calledOnce);
|
||||
assert.isTrue(stubSetStateCode.calledOnce);
|
||||
assert.isTrue(stubSetSalutation.calledOnce);
|
||||
assert.isTrue(stubSetSecondName.calledOnce);
|
||||
assert.isTrue(stubSetCompanyName.calledOnce);
|
||||
assert.isTrue(stubSetSuffix.calledOnce);
|
||||
assert.isTrue(stubSetSuite.calledOnce);
|
||||
assert.isTrue(stubSetTitle.calledOnce);
|
||||
});
|
||||
|
||||
it('Should gather all shipping addresses into one array', function () {
|
||||
var address1 = {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
city: 'Testville',
|
||||
postalCode: '12345',
|
||||
phone: '123456789',
|
||||
countryCode: 'US'
|
||||
};
|
||||
var address2 = {
|
||||
firstName: 'Foo2',
|
||||
lastName: 'Bar2',
|
||||
address1: '102 Test St.',
|
||||
city: 'Testville',
|
||||
postalCode: '12345',
|
||||
phone: '123456789',
|
||||
countryCode: 'US'
|
||||
};
|
||||
var order = {
|
||||
shipments: new ArrayList([
|
||||
{
|
||||
shippingAddress: address1
|
||||
},
|
||||
{
|
||||
shippingAddress: address2
|
||||
}
|
||||
])
|
||||
};
|
||||
var allAddresses = addressHelpers.gatherShippingAddresses(order);
|
||||
|
||||
assert.equal(allAddresses[0].firstName, address1.firstName);
|
||||
assert.equal(allAddresses[0].lastName, address1.lastName);
|
||||
assert.equal(allAddresses[0].address1, address1.address1);
|
||||
assert.equal(allAddresses[1].lastName, address2.lastName);
|
||||
assert.equal(allAddresses[1].address1, address2.address1);
|
||||
});
|
||||
|
||||
it('Should return default shipment address as an array when there are no other shipments', function () {
|
||||
var address = {
|
||||
firstName: 'Foo',
|
||||
lastName: 'Bar',
|
||||
address1: '10 Test St.',
|
||||
city: 'Testville',
|
||||
postalCode: '12345',
|
||||
phone: '123456789',
|
||||
countryCode: 'US'
|
||||
};
|
||||
var order = {
|
||||
defaultShipment: {
|
||||
shippingAddress: address
|
||||
}
|
||||
};
|
||||
var allAddresses = addressHelpers.gatherShippingAddresses(order);
|
||||
|
||||
assert.equal(allAddresses[0].firstName, address.firstName);
|
||||
assert.equal(allAddresses[0].lastName, address.lastName);
|
||||
assert.equal(allAddresses[0].address1, address.address1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
||||
var sinon = require('sinon');
|
||||
|
||||
describe('Helpers - Totals', function () {
|
||||
var hookMgrSpy = sinon.spy();
|
||||
var hookHelperSpy = sinon.spy();
|
||||
|
||||
var basketCalculationHelpers = proxyquire('../../../../../cartridges/app_storefront_base/cartridge/scripts/helpers/basketCalculationHelpers', {
|
||||
'dw/system/HookMgr': { callHook: hookMgrSpy },
|
||||
'*/cartridge/scripts/helpers/hooks': hookHelperSpy,
|
||||
'*/cartridge/scripts/hooks/taxes': { calculateTaxes: function () {} }
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
hookMgrSpy.reset();
|
||||
hookHelperSpy.reset();
|
||||
});
|
||||
|
||||
it('Should call taxes hook', function () {
|
||||
basketCalculationHelpers.calculateTaxes();
|
||||
|
||||
assert.isTrue(hookHelperSpy.calledWith('app.basket.taxes', 'calculateTaxes'));
|
||||
});
|
||||
|
||||
it('Should call totals hook', function () {
|
||||
basketCalculationHelpers.calculateTotals();
|
||||
|
||||
assert.isTrue(hookMgrSpy.calledWith('dw.order.calculate', 'calculate'));
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user