Starting to restructure data injection

This commit is contained in:
Will Marshall
2014-07-18 11:21:51 +10:00
parent 33611ddb20
commit 562f8dbd4e
9 changed files with 61 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
describe 'Product service', ->
describe 'Products service', ->
$httpBackend = null
Product = null
Products = null
Enterprises = null
CurrentHubMock = {}
product =
@@ -15,30 +15,30 @@ describe 'Product service', ->
$provide.value "CurrentHub", CurrentHubMock
null
inject ($injector, _$httpBackend_)->
Product = $injector.get("Product")
Products = $injector.get("Products")
Enterprises = $injector.get("Enterprises")
$httpBackend = _$httpBackend_
it "Fetches products from the backend on init", ->
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.flush()
expect(Product.products[0].test).toEqual "cats"
expect(Products.products[0].test).toEqual "cats"
it "dereferences suppliers", ->
Enterprises.enterprises_by_id =
{id: 9, name: "test"}
$httpBackend.expectGET("/shop/products").respond([{supplier : {id: 9}}])
$httpBackend.flush()
expect(Product.products[0].supplier).toBe Enterprises.enterprises_by_id["9"]
expect(Products.products[0].supplier).toBe Enterprises.enterprises_by_id["9"]
describe "determining the price to display for a product", ->
it "displays the product price when the product does not have variants", ->
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.flush()
expect(Product.products[0].price).toEqual 11.00
expect(Products.products[0].price).toEqual 11.00
it "displays the minimum variant price when the product has variants", ->
product.variants = [{price: 22}, {price: 33}]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.flush()
expect(Product.products[0].price).toEqual 22
expect(Products.products[0].price).toEqual 22