mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Merge pull request #2512 from kristinalim/feature-remove_enterprise_images
Support removal of enterprise logo and promo image
This commit is contained in:
@@ -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,72 @@ 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(window, "confirm").and.returnValue(true)
|
||||
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(window, "confirm").and.returnValue(true)
|
||||
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 ->
|
||||
|
||||
@@ -118,3 +118,73 @@ describe "Enterprises service", ->
|
||||
it "resets the specified value according to the pristine record", ->
|
||||
Enterprises.resetAttribute(enterprise, "name")
|
||||
expect(enterprise.name).toEqual "enterprise1"
|
||||
|
||||
describe "#removeLogo", ->
|
||||
enterprise = null
|
||||
|
||||
describe "success", ->
|
||||
resolved = false
|
||||
|
||||
beforeEach ->
|
||||
enterprise = new EnterpriseResource({ id: 15, permalink: "enterprise1", name: "Enterprise 1", logo: {} })
|
||||
$httpBackend.expectDELETE("/api/enterprises/enterprise1/logo.json").respond 200, { id: 15, name: "Enterprise 1"}
|
||||
Enterprises.removeLogo(enterprise).then( -> resolved = true)
|
||||
$httpBackend.flush()
|
||||
|
||||
it "updates the pristine copy of the enterprise", ->
|
||||
expect(Enterprises.pristineByID[15]).not.toBeUndefined()
|
||||
expect(Enterprises.pristineByID[15]["id"]).toEqual(15)
|
||||
expect(Enterprises.pristineByID[15]["logo"]).toBeUndefined()
|
||||
|
||||
it "resolves the promise", ->
|
||||
expect(resolved).toBe(true)
|
||||
|
||||
describe "failure", ->
|
||||
rejected = false
|
||||
|
||||
beforeEach ->
|
||||
enterprise = new EnterpriseResource( { id: 15, permalink: "enterprise1", name: "Enterprise 1" } )
|
||||
$httpBackend.expectDELETE("/api/enterprises/enterprise1/logo.json").respond 409, { error: "obj" }
|
||||
Enterprises.removeLogo(enterprise).catch( -> rejected = true)
|
||||
$httpBackend.flush()
|
||||
|
||||
it "does not update the pristine copy of the enterprise", ->
|
||||
expect(Enterprises.pristineByID[15]).toBeUndefined()
|
||||
|
||||
it "rejects the promise", ->
|
||||
expect(rejected).toBe(true)
|
||||
|
||||
describe "#removePromoImage", ->
|
||||
enterprise = null
|
||||
|
||||
describe "success", ->
|
||||
resolved = false
|
||||
|
||||
beforeEach ->
|
||||
enterprise = new EnterpriseResource({ id: 15, permalink: "enterprise1", name: "Enterprise 1", promo_image: {} })
|
||||
$httpBackend.expectDELETE("/api/enterprises/enterprise1/promo_image.json").respond 200, { id: 15, name: "Enterprise 1"}
|
||||
Enterprises.removePromoImage(enterprise).then( -> resolved = true)
|
||||
$httpBackend.flush()
|
||||
|
||||
it "updates the pristine copy of the enterprise", ->
|
||||
expect(Enterprises.pristineByID[15]).not.toBeUndefined()
|
||||
expect(Enterprises.pristineByID[15]["id"]).toEqual(15)
|
||||
expect(Enterprises.pristineByID[15]["promo_image"]).toBeUndefined()
|
||||
|
||||
it "resolves the promise", ->
|
||||
expect(resolved).toBe(true)
|
||||
|
||||
describe "failure", ->
|
||||
rejected = false
|
||||
|
||||
beforeEach ->
|
||||
enterprise = new EnterpriseResource( { id: 15, permalink: "enterprise1", name: "Enterprise 1" } )
|
||||
$httpBackend.expectDELETE("/api/enterprises/enterprise1/promo_image.json").respond 409, { error: "obj" }
|
||||
Enterprises.removePromoImage(enterprise).catch( -> rejected = true)
|
||||
$httpBackend.flush()
|
||||
|
||||
it "does not update the pristine copy of the enterprise", ->
|
||||
expect(Enterprises.pristineByID[15]).toBeUndefined()
|
||||
|
||||
it "rejects the promise", ->
|
||||
expect(rejected).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user