mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-14 23:47:48 +00:00
Add JS support for removal of enterprise images
This commit is contained in:
@@ -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("/admin/enterprises/enterprise1/images/remove_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("/admin/enterprises/enterprise1/images/remove_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("/admin/enterprises/enterprise1/images/remove_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("/admin/enterprises/enterprise1/images/remove_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