@vendasta/store
Version:
Components and data for Store
311 lines (310 loc) • 15.4 kB
JavaScript
import { buildSalesPackages, addStatusesToSalesPackages, ActivationStatus } from './sales-package';
import { Product } from '../shared';
import { Package } from '../package-details';
describe('Sales Package', function () {
describe('buildSalesPackages', function () {
it('should correctly build sales package', function () {
var expectedOutput = [
{
formattedPrices: '$60.00 / Monthly',
packageId: 'PKG-123',
name: 'Get Social',
icon: 'https://media.glassdoor.com/sqll/539412/vendasta-technologies-squarelogo-1425555078161.png',
productIds: ['MP-111', 'MP-222', 'MP-333'],
products: [
{
productId: 'MP-111',
name: 'Facebook',
iconUrl: 'https://seeklogo.com/images/F/facebook-icon-logo-C61047A9E7-seeklogo.com.png',
tagline: 'Move Fast, Break Things.'
},
{
productId: 'MP-222',
name: 'Twitter',
iconUrl: 'https://image.freepik.com/free-icon/twitter-logo_318-40209.jpg',
tagline: null
},
{
productId: 'MP-333',
name: 'Instagram',
iconUrl: 'https://d1afx9quaogywf.cloudfront.net/sites/default/files/Logos/Instagram-v051916_0.png',
tagline: 'Connecting the world through photos.'
},
]
}, {
formattedPrices: '$7.50 / Daily, $30.00 / Weekly',
packageId: 'PKG-456',
name: 'Music Essentials',
icon: 'https://image.freepik.com/free-icon/itunes-logo-of-amusical-note-inside-a-circle_318-50208.jpg',
productIds: ['MP-444'],
products: [
{
'productId': 'MP-444',
'name': 'Guitar Strings',
'iconUrl': 'https://t4.rbxcdn.com/23a0bbf40bf7a18bf0abe2d2b6d09ae1',
tagline: null
}
]
}
];
var packages = [
Package.fromApi({
'pricing': {
'prices': [
{ 'price': 6000, 'frequency': 'monthly' }
],
'currency': 'USD',
},
'solution_id': 'PKG-123',
'name': 'Get Social',
'icon': 'https://media.glassdoor.com/sqll/539412/vendasta-technologies-squarelogo-1425555078161.png',
'products': ['MP-111', 'MP-222', 'MP-333']
}),
Package.fromApi({
'pricing': {
'prices': [
{ 'price': 750, 'frequency': 'daily' },
{ 'price': 3000, 'frequency': 'weekly' }
],
'currency': 'USD',
},
'solution_id': 'PKG-456',
'name': 'Music Essentials',
'icon': 'https://image.freepik.com/free-icon/itunes-logo-of-amusical-note-inside-a-circle_318-50208.jpg',
'products': ['MP-444']
})
];
var products = [
Product.fromApi({
'productId': 'MP-111',
'name': 'Facebook',
'iconUrl': 'https://seeklogo.com/images/F/facebook-icon-logo-C61047A9E7-seeklogo.com.png',
'tagline': 'Move Fast, Break Things.'
}),
Product.fromApi({
'productId': 'MP-222',
'name': 'Twitter',
'iconUrl': 'https://image.freepik.com/free-icon/twitter-logo_318-40209.jpg',
}),
Product.fromApi({
'productId': 'MP-333',
'name': 'Instagram',
'iconUrl': 'https://d1afx9quaogywf.cloudfront.net/sites/default/files/Logos/Instagram-v051916_0.png',
'tagline': 'Connecting the world through photos.'
}),
Product.fromApi({
'productId': 'MP-444',
'name': 'Guitar Strings',
'iconUrl': 'https://t4.rbxcdn.com/23a0bbf40bf7a18bf0abe2d2b6d09ae1',
})
];
var actualOutput = buildSalesPackages(packages, products);
expect(actualOutput).toEqual(expectedOutput);
});
it('should correctly handle packages when it is an empty list', function () {
var packages = [];
var products = [
Product.fromApi({
'productId': 'MP-111',
'name': 'Facebook',
'iconUrl': 'https://seeklogo.com/images/F/facebook-icon-logo-C61047A9E7-seeklogo.com.png',
'tagline': 'Move Fast, Break Things.'
})
];
var actualOutput = buildSalesPackages(packages, products);
expect(actualOutput).toEqual([]);
});
it('should correctly handle packages when it is null', function () {
var packages = null;
var products = [
Product.fromApi({
'productId': 'MP-111',
'name': 'Facebook',
'iconUrl': 'https://seeklogo.com/images/F/facebook-icon-logo-C61047A9E7-seeklogo.com.png',
'tagline': 'Move Fast, Break Things.'
})
];
var actualOutput = buildSalesPackages(packages, products);
expect(actualOutput).toEqual([]);
});
it('should correctly handle packages when it it has a null item', function () {
var packages = [null];
var products = [
Product.fromApi({
'productId': 'MP-111',
'name': 'Facebook',
'iconUrl': 'https://seeklogo.com/images/F/facebook-icon-logo-C61047A9E7-seeklogo.com.png',
'tagline': 'Move Fast, Break Things.'
})
];
var actualOutput = buildSalesPackages(packages, products);
expect(actualOutput).toEqual([null]);
});
it('should correctly handle packages when it is an empty list', function () {
var expectedOutput = [{
formattedPrices: '$60.00 / Monthly',
packageId: 'PKG-123',
name: 'Get Social',
icon: 'https://media.glassdoor.com/sqll/539412/vendasta-technologies-squarelogo-1425555078161.png',
productIds: ['MP-111', 'MP-222', 'MP-333'],
products: []
}];
var packages = [
Package.fromApi({
'pricing': {
'prices': [
{ 'price': 6000, 'frequency': 'monthly' }
],
'currency': 'USD',
},
'solution_id': 'PKG-123',
'name': 'Get Social',
'icon': 'https://media.glassdoor.com/sqll/539412/vendasta-technologies-squarelogo-1425555078161.png',
'products': ['MP-111', 'MP-222', 'MP-333']
})
];
var products = [];
var actualOutput = buildSalesPackages(packages, products);
expect(actualOutput).toEqual(expectedOutput);
});
it('should correctly handle packages when it is an empty list', function () {
var packages = [];
var products = [
Product.fromApi({
'productId': 'MP-111',
'name': 'Facebook',
'iconUrl': 'https://seeklogo.com/images/F/facebook-icon-logo-C61047A9E7-seeklogo.com.png',
'tagline': 'Move Fast, Break Things.'
}),
Product.fromApi({
'productId': 'MP-222',
'name': 'Twitter',
'iconUrl': 'https://image.freepik.com/free-icon/twitter-logo_318-40209.jpg',
}),
Product.fromApi({
'productId': 'MP-333',
'name': 'Instagram',
'iconUrl': 'https://d1afx9quaogywf.cloudfront.net/sites/default/files/Logos/Instagram-v051916_0.png',
'tagline': 'Connecting the world through photos.'
}),
Product.fromApi({
'productId': 'MP-444',
'name': 'Guitar Strings',
'iconUrl': 'https://t4.rbxcdn.com/23a0bbf40bf7a18bf0abe2d2b6d09ae1',
})
];
var actualOutput = buildSalesPackages(packages, products);
expect(actualOutput).toEqual([]);
});
it('should correctly handle products when it is null', function () {
var packages = [
Package.fromApi({
'pricing': {
'prices': [
{ 'price': 6000, 'frequency': 'monthly' }
],
'currency': 'USD',
},
'solution_id': 'PKG-123',
'name': 'Get Social',
'icon': 'https://media.glassdoor.com/sqll/539412/vendasta-technologies-squarelogo-1425555078161.png',
'products': ['MP-111', 'MP-222', 'MP-333']
})
];
var products = null;
var expected = [{
formattedPrices: '$60.00 / Monthly',
packageId: 'PKG-123',
name: 'Get Social',
icon: 'https://media.glassdoor.com/sqll/539412/vendasta-technologies-squarelogo-1425555078161.png',
productIds: ['MP-111', 'MP-222', 'MP-333'],
products: []
}];
var actualOutput = buildSalesPackages(packages, products);
expect(actualOutput).toEqual(expected);
});
});
describe('addStatusesToSalesPackages', function () {
beforeEach(function () {
inputSalesPackage.map(function (pkg) {
pkg.activationStatus = undefined;
pkg.products.map(function (product) {
product.activationStatus = undefined;
return product;
});
return pkg;
});
});
var inputSalesPackage = [
{
formattedPrices: '$60.00 / Monthly',
packageId: 'PKG-123',
name: 'Get Social',
icon: 'https://media.glassdoor.com/sqll/539412/vendasta-technologies-squarelogo-1425555078161.png',
productIds: ['MP-111', 'MP-222', 'MP-333'],
products: [
{
productId: 'MP-111',
name: 'Facebook',
iconUrl: 'https://seeklogo.com/images/F/facebook-icon-logo-C61047A9E7-seeklogo.com.png',
tagline: 'Move Fast, Break Things.'
},
{
productId: 'MP-222',
name: 'Twitter',
iconUrl: 'https://image.freepik.com/free-icon/twitter-logo_318-40209.jpg',
tagline: null
},
{
productId: 'MP-333',
name: 'Instagram',
iconUrl: 'https://d1afx9quaogywf.cloudfront.net/sites/default/files/Logos/Instagram-v051916_0.png',
tagline: 'Connecting the world through photos.'
},
]
}, {
formattedPrices: '$7.50 / Daily, $30.00 / Weekly',
packageId: 'PKG-456',
name: 'Music Essentials',
icon: 'https://image.freepik.com/free-icon/itunes-logo-of-amusical-note-inside-a-circle_318-50208.jpg',
productIds: ['MP-444'],
products: [
{
'productId': 'MP-444',
'name': 'Guitar Strings',
'iconUrl': 'https://t4.rbxcdn.com/23a0bbf40bf7a18bf0abe2d2b6d09ae1',
tagline: null
}
]
}
];
var inputStatuses = [
{ 'productId': 'MP-111', status: ActivationStatus.SUCCESS },
{ 'productId': 'MP-222', status: ActivationStatus.WARNING },
{ 'productId': 'MP-333', status: ActivationStatus.WARNING },
{ 'productId': 'MP-444', status: ActivationStatus.ERROR },
];
it('should correctly add package activation status to sales packages', function () {
var actualOutput = addStatusesToSalesPackages(inputSalesPackage, inputStatuses);
expect(actualOutput[0].activationStatus).toEqual({ icon: 'warning', text: 'Activation Warnings', status: ActivationStatus.WARNING });
expect(actualOutput[1].activationStatus).toEqual({ icon: 'error', text: 'Activation Errors Occured', status: ActivationStatus.ERROR });
});
it('should correctly add product activation statuses to sales packages', function () {
var actualOutput = addStatusesToSalesPackages(inputSalesPackage, inputStatuses);
expect(actualOutput[0].products[0].activationStatus).toEqual({ icon: 'check_circle', text: 'Activated', status: ActivationStatus.SUCCESS });
expect(actualOutput[0].products[1].activationStatus).toEqual({ icon: 'warning', text: 'Already Activated', status: ActivationStatus.WARNING });
expect(actualOutput[0].products[2].activationStatus).toEqual({ icon: 'warning', text: 'Already Activated', status: ActivationStatus.WARNING });
expect(actualOutput[1].products[0].activationStatus).toEqual({ icon: 'error', text: 'Activation Errors', status: ActivationStatus.ERROR });
});
it('should not set package activation status if input statuses is null', function () {
var actualOutput = addStatusesToSalesPackages(inputSalesPackage, null);
expect(actualOutput[0].activationStatus).toBeUndefined();
expect(actualOutput[1].activationStatus).toBeUndefined();
});
it('should not set package activation status if input statuses is a empty list', function () {
var actualOutput = addStatusesToSalesPackages(inputSalesPackage, []);
expect(actualOutput[0].activationStatus).toBeUndefined();
expect(actualOutput[1].activationStatus).toBeUndefined();
});
});
});