Add JS support for removal of enterprise images

This commit is contained in:
Kristina Lim
2018-07-28 23:44:28 +08:00
parent 9c3bb863da
commit c9370672c6
3 changed files with 94 additions and 0 deletions

View File

@@ -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);