mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
Starting to restructure data injection
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user