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

@@ -2,11 +2,11 @@ describe 'ProductsCtrl', ->
ctrl = null
scope = null
event = null
Product = null
Products = null
beforeEach ->
module('Darkswarm')
Product =
Products =
all: ->
update: ->
products: ["testy mctest"]
@@ -15,10 +15,10 @@ describe 'ProductsCtrl', ->
inject ($controller) ->
scope = {}
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product: Product, OrderCycle: OrderCycle}
ctrl = $controller 'ProductsCtrl', {$scope: scope, Products: Products, OrderCycle: OrderCycle}
it 'fetches products from Product', ->
expect(scope.Product.products).toEqual ['testy mctest']
it 'fetches products from Products', ->
expect(scope.Products.products).toEqual ['testy mctest']
it "increments the limit up to the number of products", ->
scope.limit = 0

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