Allow removal of enterprise logo and promo image

This commit is contained in:
Kristina Lim
2018-07-30 07:42:51 +08:00
parent c9370672c6
commit 368612cad6
8 changed files with 135 additions and 31 deletions

View File

@@ -4,6 +4,8 @@ describe "enterpriseCtrl", ->
enterprise = null
PaymentMethods = null
ShippingMethods = null
Enterprises = null
StatusMessage = null
beforeEach ->
module('admin.enterprises')
@@ -18,9 +20,11 @@ describe "enterpriseCtrl", ->
shippingMethods: "shipping methods"
receivesNotifications = 99
inject ($rootScope, $controller) ->
inject ($rootScope, $controller, _Enterprises_, _StatusMessage_) ->
scope = $rootScope
ctrl = $controller 'enterpriseCtrl', {$scope: scope, enterprise: enterprise, EnterprisePaymentMethods: PaymentMethods, EnterpriseShippingMethods: ShippingMethods, receivesNotifications: receivesNotifications}
Enterprises = _Enterprises_
StatusMessage = _StatusMessage_
ctrl = $controller "enterpriseCtrl", {$scope: scope, enterprise: enterprise, EnterprisePaymentMethods: PaymentMethods, EnterpriseShippingMethods: ShippingMethods, Enterprises: Enterprises, StatusMessage: StatusMessage, receivesNotifications: receivesNotifications}
describe "initialisation", ->
it "stores enterprise", ->
@@ -32,6 +36,70 @@ describe "enterpriseCtrl", ->
it "stores shipping methods", ->
expect(scope.ShippingMethods).toBe ShippingMethods.shippingMethods
describe "removing logo", ->
deferred = null
beforeEach inject ($q) ->
spyOn(scope, "$emit")
deferred = $q.defer()
spyOn(Enterprises, "removeLogo").and.returnValue(deferred.promise)
spyOn(StatusMessage, "display").and.callThrough()
scope.removeLogo()
describe "when successful", ->
beforeEach inject ($rootScope) ->
deferred.resolve()
$rootScope.$digest()
it "emits an 'enterprise:updated' event", ->
expect(scope.$emit).toHaveBeenCalledWith("enterprise:updated", scope.Enterprise)
it "notifies user of success", ->
expect(StatusMessage.display).toHaveBeenCalledWith("success", "Logo removed successfully")
describe "when unsuccessful", ->
beforeEach inject ($rootScope) ->
deferred.reject({ data: { error: "Logo does not exist" } })
$rootScope.$digest()
it "does not emit an 'enterprise:updated' event", ->
expect(scope.$emit).not.toHaveBeenCalled()
it "notifies user of failure", ->
expect(StatusMessage.display).toHaveBeenCalledWith("failure", "Logo does not exist")
describe "removing promo image", ->
deferred = null
beforeEach inject ($q) ->
spyOn(scope, "$emit")
deferred = $q.defer()
spyOn(Enterprises, "removePromoImage").and.returnValue(deferred.promise)
spyOn(StatusMessage, "display").and.callThrough()
scope.removePromoImage()
describe "when successful", ->
beforeEach inject ($rootScope) ->
deferred.resolve()
$rootScope.$digest()
it "emits an 'enterprise:updated' event", ->
expect(scope.$emit).toHaveBeenCalledWith("enterprise:updated", scope.Enterprise)
it "notifies user of success", ->
expect(StatusMessage.display).toHaveBeenCalledWith("success", "Promo image removed successfully")
describe "when unsuccessful", ->
beforeEach inject ($rootScope) ->
deferred.reject({ data: { error: "Promo image does not exist" } })
$rootScope.$digest()
it "does not emit an 'enterprise:updated' event", ->
expect(scope.$emit).not.toHaveBeenCalled()
it "notifies user of failure", ->
expect(StatusMessage.display).toHaveBeenCalledWith("failure", "Promo image does not exist")
describe "adding managers", ->
u1 = u2 = u3 = null
beforeEach ->

View File

@@ -127,7 +127,7 @@ describe "Enterprises service", ->
beforeEach ->
enterprise = new EnterpriseResource({ id: 15, permalink: "enterprise1", name: "Enterprise 1", logo: {} })
$httpBackend.expectDELETE("/admin/enterprises/enterprise1/images/remove_logo.json").respond 200, { id: 15, name: "Enterprise 1"}
$httpBackend.expectDELETE("/api/enterprises/enterprise1/logo.json").respond 200, { id: 15, name: "Enterprise 1"}
Enterprises.removeLogo(enterprise).then( -> resolved = true)
$httpBackend.flush()
@@ -144,7 +144,7 @@ describe "Enterprises service", ->
beforeEach ->
enterprise = new EnterpriseResource( { id: 15, permalink: "enterprise1", name: "Enterprise 1" } )
$httpBackend.expectDELETE("/admin/enterprises/enterprise1/images/remove_logo.json").respond 409, { error: "obj" }
$httpBackend.expectDELETE("/api/enterprises/enterprise1/logo.json").respond 409, { error: "obj" }
Enterprises.removeLogo(enterprise).catch( -> rejected = true)
$httpBackend.flush()
@@ -162,7 +162,7 @@ describe "Enterprises service", ->
beforeEach ->
enterprise = new EnterpriseResource({ id: 15, permalink: "enterprise1", name: "Enterprise 1", promo_image: {} })
$httpBackend.expectDELETE("/admin/enterprises/enterprise1/images/remove_promo_image.json").respond 200, { id: 15, name: "Enterprise 1"}
$httpBackend.expectDELETE("/api/enterprises/enterprise1/promo_image.json").respond 200, { id: 15, name: "Enterprise 1"}
Enterprises.removePromoImage(enterprise).then( -> resolved = true)
$httpBackend.flush()
@@ -179,7 +179,7 @@ describe "Enterprises service", ->
beforeEach ->
enterprise = new EnterpriseResource( { id: 15, permalink: "enterprise1", name: "Enterprise 1" } )
$httpBackend.expectDELETE("/admin/enterprises/enterprise1/images/remove_promo_image.json").respond 409, { error: "obj" }
$httpBackend.expectDELETE("/api/enterprises/enterprise1/promo_image.json").respond 409, { error: "obj" }
Enterprises.removePromoImage(enterprise).catch( -> rejected = true)
$httpBackend.flush()