mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Changing convention for angular resource services to generic 'byID' object and 'all' array
This commit is contained in:
@@ -26,9 +26,9 @@ describe "Enterprises service", ->
|
||||
result = Enterprises.index()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "stores returned data in @enterprisesByID, with ids as keys", ->
|
||||
it "stores returned data in @byID, with ids as keys", ->
|
||||
# EnterpriseResource returns instances of Resource rather than raw objects
|
||||
expect(Enterprises.enterprisesByID).toDeepEqual { 5: response[0] }
|
||||
expect(Enterprises.byID).toDeepEqual { 5: response[0] }
|
||||
|
||||
it "stores returned data in @pristineByID, with ids as keys", ->
|
||||
expect(Enterprises.pristineByID).toDeepEqual { 5: response[0] }
|
||||
|
||||
@@ -70,7 +70,7 @@ describe "LineItemsCtrl", ->
|
||||
expect(scope.distributors).toDeepEqual [ distributor ]
|
||||
|
||||
it "stores enterprises in an list that is accessible by id", ->
|
||||
expect(Enterprises.enterprisesByID[1]).toDeepEqual supplier
|
||||
expect(Enterprises.byID[1]).toDeepEqual supplier
|
||||
|
||||
it "gets order cycles", ->
|
||||
expect(scope.orderCycles).toDeepEqual [ orderCycle ]
|
||||
|
||||
@@ -23,9 +23,9 @@ describe "LineItems service", ->
|
||||
result = LineItems.index()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "stores returned data in @lineItemsByID, with ids as keys", ->
|
||||
it "stores returned data in @byID, with ids as keys", ->
|
||||
# LineItemResource returns instances of Resource rather than raw objects
|
||||
expect(LineItems.lineItemsByID).toDeepEqual { 5: response[0] }
|
||||
expect(LineItems.byID).toDeepEqual { 5: response[0] }
|
||||
|
||||
it "stores returned data in @pristineByID, with ids as keys", ->
|
||||
expect(LineItems.pristineByID).toDeepEqual { 5: response[0] }
|
||||
@@ -114,14 +114,14 @@ describe "LineItems service", ->
|
||||
beforeEach ->
|
||||
lineItem = new LineItemResource({ id: 15, order: { number: '12345678'} })
|
||||
LineItems.pristineByID[15] = lineItem
|
||||
LineItems.lineItemsByID[15] = lineItem
|
||||
LineItems.byID[15] = lineItem
|
||||
$httpBackend.expectDELETE('/admin/orders/12345678/line_items/15.json').respond 200, { id: 15, name: 'LineItem 1'}
|
||||
LineItems.delete(lineItem, callback).then( -> resolved = true).catch( -> rejected = true)
|
||||
$httpBackend.flush()
|
||||
|
||||
it "updates the pristine copy of the lineItem", ->
|
||||
expect(LineItems.pristineByID[15]).toBeUndefined()
|
||||
expect(LineItems.lineItemsByID[15]).toBeUndefined()
|
||||
expect(LineItems.byID[15]).toBeUndefined()
|
||||
|
||||
it "runs the callback", ->
|
||||
expect(callback).toHaveBeenCalled()
|
||||
@@ -139,14 +139,14 @@ describe "LineItems service", ->
|
||||
beforeEach ->
|
||||
lineItem = new LineItemResource({ id: 15, order: { number: '12345678'} })
|
||||
LineItems.pristineByID[15] = lineItem
|
||||
LineItems.lineItemsByID[15] = lineItem
|
||||
LineItems.byID[15] = lineItem
|
||||
$httpBackend.expectDELETE('/admin/orders/12345678/line_items/15.json').respond 422, { error: 'obj' }
|
||||
LineItems.delete(lineItem, callback).then( -> resolved = true).catch( -> rejected = true)
|
||||
$httpBackend.flush()
|
||||
|
||||
it "does not update the pristine copy of the lineItem", ->
|
||||
expect(LineItems.pristineByID[15]).toBeDefined()
|
||||
expect(LineItems.lineItemsByID[15]).toBeDefined()
|
||||
expect(LineItems.byID[15]).toBeDefined()
|
||||
|
||||
it "does not run the callback", ->
|
||||
expect(callback).not.toHaveBeenCalled()
|
||||
|
||||
@@ -26,9 +26,9 @@ describe "OrderCycles service", ->
|
||||
result = OrderCycles.index()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "stores returned data in @orderCyclesByID, with ids as keys", ->
|
||||
it "stores returned data in @byID, with ids as keys", ->
|
||||
# OrderCycleResource returns instances of Resource rather than raw objects
|
||||
expect(OrderCycles.orderCyclesByID).toDeepEqual { 5: response[0] }
|
||||
expect(OrderCycles.byID).toDeepEqual { 5: response[0] }
|
||||
|
||||
it "stores returned data in @pristineByID, with ids as keys", ->
|
||||
expect(OrderCycles.pristineByID).toDeepEqual { 5: response[0] }
|
||||
|
||||
@@ -23,9 +23,9 @@ describe "Orders service", ->
|
||||
result = Orders.index()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "stores returned data in @ordersByID, with ids as keys", ->
|
||||
it "stores returned data in @byID, with ids as keys", ->
|
||||
# OrderResource returns instances of Resource rather than raw objects
|
||||
expect(Orders.ordersByID).toDeepEqual { 5: response[0] }
|
||||
expect(Orders.byID).toDeepEqual { 5: response[0] }
|
||||
|
||||
it "stores returned data in @pristineByID, with ids as keys", ->
|
||||
expect(Orders.pristineByID).toDeepEqual { 5: response[0] }
|
||||
|
||||
Reference in New Issue
Block a user