Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ bower_components/
errorShots/
.idea
plato/
.publish/
.publish/
.vscode/
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"jasny-bootstrap": "3.1.3",
"angular-payments": "*",
"bootswatch": "^3.3.7",
"ordercloud-angular-sdk": "v1.0.46-staging-prerelease"
"ordercloud-angular-sdk": "v1.0.47-staging-prerelease"
},
"devDependencies": {
"angular-mocks": "^1.6.0"
Expand Down
2 changes: 0 additions & 2 deletions gulp/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ var gulp = require('gulp'),
config = require('../../gulp.config'),
cache = require('gulp-cached'),
del = require('del'),
filter = require('gulp-filter'),
inject = require('gulp-inject'),
wrapper = require('gulp-wrapper'),
beautify = require('gulp-beautify'),
ngAnnotate = require('gulp-ng-annotate');
Expand Down
4 changes: 2 additions & 2 deletions gulp/build/serve-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ var gulp = require('gulp'),

gulp.task('serve-build', ['inject'], function() {
serve(true /*isDev*/);
if (argv.debug) {
}
// if (argv.debug) {
// }
});
1 change: 0 additions & 1 deletion gulp/build/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
lessImport = require('gulp-less-import'),
sourcemaps = require('gulp-sourcemaps'),
filter = require('gulp-filter'),
concatCss = require('gulp-concat-css'),
mainBowerFiles = require('main-bower-files');

Expand Down
4 changes: 1 addition & 3 deletions gulp/compile/app-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var gulp = require('gulp'),
concat = require('gulp-concat'),
filter = require('gulp-filter'),
templateCache = require('gulp-angular-templatecache'),
htmlmin = require('gulp-htmlmin'),
uglify = require('gulp-uglify'),
fileSort = require('gulp-angular-filesort'),
wrapper = require('gulp-wrapper');
Expand All @@ -31,7 +30,6 @@ gulp.task('app-js', ['clean:app-js'], function() {
.pipe(ngConstant(config.ngConstantSettings))
.pipe(jsonFilter.restore)
.pipe(htmlFilter)
//.pipe(htmlmin({collapseWhitespace: true, removeComments: true}))
.pipe(templateCache(config.templateCacheSettings))
.pipe(htmlFilter.restore)
.pipe(jsFilter)
Expand All @@ -44,5 +42,5 @@ gulp.task('app-js', ['clean:app-js'], function() {
.pipe(concat('app.controller.js'))
.pipe(rev())
.pipe(uglify({mangle:false})) //turning off mangle to fix the compile error
.pipe(gulp.dest(config.compile + 'js/'))
.pipe(gulp.dest(config.compile + 'js/'));
});
2 changes: 1 addition & 1 deletion gulp/compile/lib-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ gulp.task('lib-js', ['clean:lib-js'], function() {
.pipe(uglify())
.pipe(concat('lib.js'))
.pipe(rev())
.pipe(gulp.dest(config.compile + 'js'))
.pipe(gulp.dest(config.compile + 'js'));
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"heroku-prebuild": "npm install bower gulp --save",
"postinstall": "bower install && npm run build-all",
"start": "node server.js",
"build-all": "gulp inject index --gulpfile ./heroku.gulpfile.js",
"build-all": "gulp --gulpfile ./heroku.gulpfile.js",
"test": "gulp test:unit"
},
"repository": {
Expand Down
21 changes: 2 additions & 19 deletions src/app/cart/js/cart.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,8 @@ function CartConfig($stateProvider) {
pageTitle: 'Shopping Cart'
},
resolve: {
LineItemsList: function($q, $state, toastr, OrderCloudSDK, ocLineItems, CurrentOrder) {
var dfd = $q.defer();
OrderCloudSDK.LineItems.List('outgoing', CurrentOrder.ID)
.then(function(data) {
if (!data.Items.length) {
dfd.resolve(data);
}
else {
ocLineItems.GetProductInfo(data.Items)
.then(function() {
dfd.resolve(data);
});
}
})
.catch(function() {
toastr.warning('Your order does not contain any line items.');
dfd.reject();
});
return dfd.promise;
LineItemsList: function(OrderCloudSDK, CurrentOrder) {
return OrderCloudSDK.LineItems.List('outgoing', CurrentOrder.ID);
},
CurrentPromotions: function(CurrentOrder, OrderCloudSDK) {
return OrderCloudSDK.Orders.ListPromotions('outgoing', CurrentOrder.ID);
Expand Down
44 changes: 23 additions & 21 deletions src/app/cart/js/cart.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,41 @@ function CartController($rootScope, $state, toastr, OrderCloudSDK, LineItemsList
var vm = this;
vm.lineItems = LineItemsList;
vm.promotions = CurrentPromotions.Meta ? CurrentPromotions.Items : CurrentPromotions;
vm.removeItem = function(order, scope) {
vm.removeItem = removeItem;
vm.removePromotion = removePromotion;
vm.cancelOrder = cancelOrder;

$rootScope.$on('OC:UpdatePromotions', function(event, orderid) {
return OrderCloudSDK.Orders.ListPromotions('outgoing', orderid)
.then(function(data) {
if (data.Meta) {
vm.promotions = data.Items;
} else {
vm.promotions = data;
}
});
});

function removeItem(order, scope) {
vm.lineLoading = [];
vm.lineLoading[scope.$index] = OrderCloudSDK.LineItems.Delete('outgoing', order.ID, scope.lineItem.ID)
.then(function () {
$rootScope.$broadcast('OC:UpdateOrder', order.ID);
vm.lineItems.Items.splice(scope.$index, 1);
toastr.success(scope.lineItem.Product.Name + ' was removed from your shopping cart.');
});
};
}

//TODO: missing unit tests
vm.removePromotion = function(order, scope) {
OrderCloudSDK.Orders.RemovePromotion('outgoing', order.ID, scope.promotion.Code)
function removePromotion(order, scope) {
return OrderCloudSDK.Orders.RemovePromotion('outgoing', order.ID, scope.promotion.Code)
.then(function() {
$rootScope.$broadcast('OC:UpdateOrder', order.ID);
vm.promotions.splice(scope.$index, 1);
});
};
}

vm.cancelOrder = function(order){
ocConfirm.Confirm({
function cancelOrder(order){
return ocConfirm.Confirm({
message:'Are you sure you want to cancel this order?',
confirmText: 'Yes, cancel order',
type: 'delete'})
Expand All @@ -36,17 +50,5 @@ function CartController($rootScope, $state, toastr, OrderCloudSDK, LineItemsList
$state.go('home', {}, {reload:'base'});
});
});
};

//TODO: missing unit tests
$rootScope.$on('OC:UpdatePromotions', function(event, orderid) {
OrderCloudSDK.Orders.ListPromotions('outgoing', orderid)
.then(function(data) {
if (data.Meta) {
vm.promotions = data.Items;
} else {
vm.promotions = data;
}
});
});
}
}
114 changes: 76 additions & 38 deletions src/app/cart/test/cart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ describe('Component: Cart', function() {
currentOrder,
rootScope,
lineItemsList,
_ocLineItems,
fakeOrder,
user
promoList,
fakeOrder
;
beforeEach(module('orderCloud'));
beforeEach(module('orderCloud.sdk'));
beforeEach(module('ordercloud-angular-sdk'));
beforeEach(module(function($provide) {
$provide.value('CurrentOrder', {ID: "MockOrderID3456"});
$provide.value('CurrentOrder', {ID: 'MockOrderID3456'});
}));
beforeEach(inject(function($rootScope, $q, OrderCloud, ocLineItems, CurrentOrder) {
beforeEach(inject(function($rootScope, $q, OrderCloudSDK, CurrentOrder) {
scope = $rootScope.$new();
q = $q;
oc = OrderCloud;
_ocLineItems = ocLineItems;
oc = OrderCloudSDK;
currentOrder = CurrentOrder;
rootScope = $rootScope;
fakeOrder = {
Expand All @@ -44,15 +42,16 @@ describe('Component: Cart', function() {
"ItemRange" : [1,2]
}
};
user = {
ID: "TestUser132456789",
xp: {
defaultShippingAddressID: "TestAddress123456789",
defaultBillingAddressID: "TestAddress123456789",
defaultCreditCardID: "creditCard"
promoList = {
"Items": [{ID:"Promo1"}, {ID: "Promot2"}],
"Meta": {
"Page": 1,
"PageSize": 20,
"TotalCount":29,
"TotalPages": 3,
"ItemRange" : [1,2]
}

};
}
}));

describe('State: Cart', function() {
Expand All @@ -61,56 +60,95 @@ describe('Component: Cart', function() {
state = $state.get('cart');
var defer = q.defer();
defer.resolve(lineItemsList);
spyOn(oc.LineItems,'List').and.returnValue(defer.promise);
spyOn(_ocLineItems,'GetProductInfo').and.returnValue(defer.promise);

var promoDefer = q.defer();
defer.resolve(promoList);

spyOn(oc.LineItems, 'List').and.returnValue(defer.promise);
spyOn(oc.Orders, 'ListPromotions').and.returnValue(promoDefer.promise);

}));
it('should call LineItems.List',inject(function($injector){
it('should call LineItems.List', inject(function($injector){
$injector.invoke(state.resolve.LineItemsList);
expect(oc.LineItems.List).toHaveBeenCalledWith(currentOrder.ID);
expect(oc.LineItems.List).toHaveBeenCalledWith('outgoing', currentOrder.ID);
}));
it('should call LineItemHelper', inject(function($injector){
$injector.invoke(state.resolve.LineItemsList);
it('should call Orders.ListPromotions', inject(function($injector){
$injector.invoke(state.resolve.CurrentPromotions);
scope.$digest();
expect(_ocLineItems.GetProductInfo).toHaveBeenCalled();
expect(oc.Orders.ListPromotions).toHaveBeenCalledWith('outgoing', currentOrder.ID);
}));
});

describe('Controller : CartController',function() {
describe('Controller : CartController', function() {
var cartController;
var confirm;
beforeEach(inject(function($state, $controller, ocConfirm) {
beforeEach(inject(function($controller, ocConfirm) {
cartController = $controller('CartCtrl', {
$scope: scope,
CurrentPromotions: [],
$rootScope: rootScope,
CurrentPromotions: promoList,
LineItemsList: lineItemsList
});
confirm = ocConfirm;
var defer = q.defer();
defer.resolve(lineItemsList);
spyOn(rootScope, '$broadcast');
}));

describe('removeItem()', function() {
describe('OC:UpdatePromotions', function(){
beforeEach(function(){
var defer = q.defer();
defer.resolve({Meta:{}, Items: []});
spyOn(oc.Orders, 'ListPromotions').and.returnValue(defer.promise);
});
it('should update value of promotionsList', function(){
expect(cartController.promotions).toEqual(promoList.Items);
rootScope.$broadcast('OC:UpdatePromotions', currentOrder.ID);
scope.$digest();
expect(oc.Orders.ListPromotions).toHaveBeenCalledWith('outgoing', currentOrder.ID);
scope.$digest();
expect(cartController.promotions).toEqual([]);
});
});

describe('removeItem', function() {
beforeEach(function() {
var df = q.defer();
df.resolve();
spyOn(oc.LineItems, 'Delete').and.returnValue(df.promise);
spyOn(rootScope, '$broadcast');
});
it('should delete the line item', function() {
var lineItem = angular.copy(lineItemsList.Items[0]); //list gets mutated after deletion so save copy
cartController.removeItem(fakeOrder, {$index:0, lineItem: lineItem});
scope.$digest();
expect(oc.LineItems.Delete).toHaveBeenCalledWith('outgoing', fakeOrder.ID, lineItem.ID);
scope.$digest();
expect(rootScope.$broadcast).toHaveBeenCalledWith('OC:UpdateOrder', fakeOrder.ID);
scope.$digest();
expect(cartController.lineItems.Items).toEqual([{ID: "LI2"}]);
});
it ('should delete the line item', function() {
cartController.removeItem(fakeOrder, {$index:0, lineItem: lineItemsList.Items[0]});
expect(oc.LineItems.Delete).toHaveBeenCalledWith(fakeOrder.ID, lineItemsList.Items[0].ID);
});

describe('removePromotions', function(){
beforeEach(function(){
var d = q.defer();
d.resolve();
spyOn(oc.Orders, 'RemovePromotion').and.returnValue(d.promise);
spyOn(rootScope, '$broadcast');
});
it('should call oc.Orders.RemovePromotion', function(){
var mockScope = {$index: 0, promotion: {Code: 'Promo123'}};
cartController.removePromotion(fakeOrder, mockScope);
scope.$digest();
expect(oc.Orders.RemovePromotion).toHaveBeenCalledWith('outgoing', fakeOrder.ID, mockScope.promotion.Code);
scope.$digest();
expect(rootScope.$broadcast).toHaveBeenCalledWith('OC:UpdateOrder', fakeOrder.ID);
expect(cartController.lineItems.Items).toEqual([{ID:"LI2"}]);
})
});
});

describe('CancelOrder',function() {
describe('cancelOrder',function() {
beforeEach(function() {
var df = q.defer();
df.resolve();
spyOn(confirm,'Confirm').and.returnValue(df.promise);
spyOn(confirm, 'Confirm').and.returnValue(df.promise);
spyOn(oc.Orders, 'Delete').and.returnValue(df.promise);
});
it('should call OrderCloud Confirm modal prompt', function() {
Expand All @@ -120,7 +158,7 @@ describe('Component: Cart', function() {
it('should call OC Orders Delete Method', function(){
cartController.cancelOrder(fakeOrder);
scope.$digest();
expect(oc.Orders.Delete).toHaveBeenCalledWith(fakeOrder.ID);
expect(oc.Orders.Delete).toHaveBeenCalledWith('outgoing', fakeOrder.ID);
});
});
});
Expand Down
12 changes: 2 additions & 10 deletions src/app/checkout/confirmation/js/confirmation.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,8 @@ function CheckoutConfirmationConfig($stateProvider) {

return deferred.promise;
},
LineItemsList: function($q, $state, toastr, ocLineItems, SubmittedOrder, OrderCloudSDK) {
var dfd = $q.defer();
OrderCloudSDK.LineItems.List('outgoing', SubmittedOrder.ID, {pageSize: 100})
.then(function(data) {
ocLineItems.GetProductInfo(data.Items)
.then(function() {
dfd.resolve(data);
});
});
return dfd.promise;
LineItemsList: function(SubmittedOrder, OrderCloudSDK) {
return OrderCloudSDK.LineItems.List('outgoing', SubmittedOrder.ID, {pageSize: 100});
}
}
});
Expand Down
Loading