From 9623536e1512efa547adff1371ea7c1bc62d0178 Mon Sep 17 00:00:00 2001 From: Crhistian Ramirez Date: Fri, 21 Apr 2017 07:59:56 -0500 Subject: [PATCH 1/7] include .gitignore entry for vscode folder --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ba4293a4..abaa97b4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ bower_components/ errorShots/ .idea plato/ -.publish/ \ No newline at end of file +.publish/ +.vscode/ \ No newline at end of file From 9217ece5e6366caeeec5458713773eb65fb80db7 Mon Sep 17 00:00:00 2001 From: Crhistian Ramirez Date: Fri, 21 Apr 2017 09:29:18 -0500 Subject: [PATCH 2/7] remove functionality that gets product info for li MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit product info is now a part of the line item object so we don’t need to get the product info separately --- src/app/cart/js/cart.config.js | 21 ++----------------- .../confirmation/js/confirmation.config.js | 12 ++--------- src/app/checkout/review/js/review.config.js | 21 ++----------------- 3 files changed, 6 insertions(+), 48 deletions(-) diff --git a/src/app/cart/js/cart.config.js b/src/app/cart/js/cart.config.js index 3b966071..293a6768 100644 --- a/src/app/cart/js/cart.config.js +++ b/src/app/cart/js/cart.config.js @@ -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); diff --git a/src/app/checkout/confirmation/js/confirmation.config.js b/src/app/checkout/confirmation/js/confirmation.config.js index 53cc3185..6df8a6f5 100644 --- a/src/app/checkout/confirmation/js/confirmation.config.js +++ b/src/app/checkout/confirmation/js/confirmation.config.js @@ -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}); } } }); diff --git a/src/app/checkout/review/js/review.config.js b/src/app/checkout/review/js/review.config.js index 7cc9d03e..1e665a97 100644 --- a/src/app/checkout/review/js/review.config.js +++ b/src/app/checkout/review/js/review.config.js @@ -10,25 +10,8 @@ function CheckoutReviewConfig($stateProvider) { controller: 'CheckoutReviewCtrl', controllerAs: 'checkoutReview', resolve: { - LineItemsList: function($q, $state, toastr, OrderCloudSDK, ocLineItems, CurrentOrder) { - var dfd = $q.defer(); - OrderCloudSDK.LineItems.List('outgoing', CurrentOrder.ID, {pageSize: 100}) - .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, {pageSize: 100}); }, OrderPaymentsDetail: function($q, OrderCloudSDK, CurrentOrder, $state) { return OrderCloudSDK.Payments.List('outgoing', CurrentOrder.ID) From def998b0a1471e9bfe45f3d2c451aa5fb2a7c858 Mon Sep 17 00:00:00 2001 From: Crhistian Ramirez Date: Fri, 21 Apr 2017 09:29:47 -0500 Subject: [PATCH 3/7] fix unit tests for cart --- src/app/cart/js/cart.controller.js | 44 +++++------ src/app/cart/test/cart.spec.js | 114 +++++++++++++++++++---------- 2 files changed, 99 insertions(+), 59 deletions(-) diff --git a/src/app/cart/js/cart.controller.js b/src/app/cart/js/cart.controller.js index b72f7b75..573407ad 100644 --- a/src/app/cart/js/cart.controller.js +++ b/src/app/cart/js/cart.controller.js @@ -6,7 +6,22 @@ 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 () { @@ -14,19 +29,18 @@ function CartController($rootScope, $state, toastr, OrderCloudSDK, LineItemsList 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'}) @@ -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; - } - }); - }); + } } \ No newline at end of file diff --git a/src/app/cart/test/cart.spec.js b/src/app/cart/test/cart.spec.js index cd29583f..83f0c5fd 100644 --- a/src/app/cart/test/cart.spec.js +++ b/src/app/cart/test/cart.spec.js @@ -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 = { @@ -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() { @@ -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() { @@ -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); }); }); }); From 12f9481cd23f852c0540a5a682292addf586e0e7 Mon Sep 17 00:00:00 2001 From: Crhistian Ramirez Date: Fri, 21 Apr 2017 10:49:01 -0500 Subject: [PATCH 4/7] update sdk to most recent version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 318c6326..39e282f5 100644 --- a/bower.json +++ b/bower.json @@ -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" From 68b938e6cd5ad440c55ac1ffcb9fc548793fca4f Mon Sep 17 00:00:00 2001 From: Crhistian Ramirez Date: Fri, 21 Apr 2017 10:49:41 -0500 Subject: [PATCH 5/7] clean up formatting and remove extraneous packages from gulp folders --- gulp/build/scripts.js | 2 -- gulp/build/serve-build.js | 4 ++-- gulp/build/styles.js | 1 - gulp/compile/app-js.js | 4 +--- gulp/compile/lib-js.js | 2 +- package.json | 2 +- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/gulp/build/scripts.js b/gulp/build/scripts.js index 015614af..559b39ed 100644 --- a/gulp/build/scripts.js +++ b/gulp/build/scripts.js @@ -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'); diff --git a/gulp/build/serve-build.js b/gulp/build/serve-build.js index 9259a520..bd20b4ad 100644 --- a/gulp/build/serve-build.js +++ b/gulp/build/serve-build.js @@ -8,6 +8,6 @@ var gulp = require('gulp'), gulp.task('serve-build', ['inject'], function() { serve(true /*isDev*/); - if (argv.debug) { - } + // if (argv.debug) { + // } }); diff --git a/gulp/build/styles.js b/gulp/build/styles.js index edb278ac..69cb0999 100644 --- a/gulp/build/styles.js +++ b/gulp/build/styles.js @@ -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'); diff --git a/gulp/compile/app-js.js b/gulp/compile/app-js.js index 4aa476a8..d51f17f4 100644 --- a/gulp/compile/app-js.js +++ b/gulp/compile/app-js.js @@ -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'); @@ -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) @@ -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/')); }); diff --git a/gulp/compile/lib-js.js b/gulp/compile/lib-js.js index a07493c8..2f65012e 100644 --- a/gulp/compile/lib-js.js +++ b/gulp/compile/lib-js.js @@ -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')); }); diff --git a/package.json b/package.json index e542406e..2429e2d0 100644 --- a/package.json +++ b/package.json @@ -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": { From 9a0e977d88c508592e3e7eacf6ed6273e6936bf4 Mon Sep 17 00:00:00 2001 From: Crhistian Ramirez Date: Fri, 21 Apr 2017 10:51:34 -0500 Subject: [PATCH 6/7] remove .js suffix on folder name this was causing on error on app-js task --- .../ordercloud-angular-sdk.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/app/common/config/{ordercloud-angular-sdk.js => ordercloud-angular-sdk}/ordercloud-angular-sdk.js (100%) diff --git a/src/app/common/config/ordercloud-angular-sdk.js/ordercloud-angular-sdk.js b/src/app/common/config/ordercloud-angular-sdk/ordercloud-angular-sdk.js similarity index 100% rename from src/app/common/config/ordercloud-angular-sdk.js/ordercloud-angular-sdk.js rename to src/app/common/config/ordercloud-angular-sdk/ordercloud-angular-sdk.js From 8cb5617e7fc34fa5d4fcafd74a357fcd9e1401fd Mon Sep 17 00:00:00 2001 From: Crhistian Ramirez Date: Fri, 21 Apr 2017 11:32:38 -0500 Subject: [PATCH 7/7] remove GetProductInfo method no longer necessary as product info is stored directly on line items --- .../services/oc-lineitems/oc-lineitems.js | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/app/common/services/oc-lineitems/oc-lineitems.js b/src/app/common/services/oc-lineitems/oc-lineitems.js index 522527d1..ffc34a9b 100644 --- a/src/app/common/services/oc-lineitems/oc-lineitems.js +++ b/src/app/common/services/oc-lineitems/oc-lineitems.js @@ -2,11 +2,10 @@ angular.module('orderCloud') .factory('ocLineItems', LineItemFactory) ; -function LineItemFactory($rootScope, $q, $uibModal, OrderCloudSDK, catalogid) { +function LineItemFactory($rootScope, $q, $uibModal, OrderCloudSDK) { return { SpecConvert: _specConvert, AddItem: _addItem, - GetProductInfo: _getProductInfo, CustomShipping: _customShipping, UpdateShipping: _updateShipping, ListAll: _listAll @@ -64,24 +63,6 @@ function LineItemFactory($rootScope, $q, $uibModal, OrderCloudSDK, catalogid) { return deferred.promise; } - function _getProductInfo(LineItems) { - var li = LineItems.Items || LineItems; - var productIDs = _.uniq(_.pluck(li, 'ProductID')); - var dfd = $q.defer(); - var queue = []; - angular.forEach(productIDs, function (productid) { - queue.push(OrderCloudSDK.Me.GetProduct(catalogid, productid)); - }); - $q.all(queue) - .then(function (results) { - angular.forEach(li, function (item) { - item.Product = angular.copy(_.where(results, {ID: item.ProductID})[0]); - }); - dfd.resolve(li); - }); - return dfd.promise; - } - function _customShipping(Order, LineItem) { var modalInstance = $uibModal.open({ animation: true,