mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
Working version of the cart integration
This commit is contained in:
@@ -26,3 +26,7 @@ describe 'Cart service', ->
|
||||
expect(Cart.line_items[1].variant).toBe v2
|
||||
expect(Cart.line_items[1].variant.line_item).toBe Cart.line_items[1]
|
||||
|
||||
it "returns a list of items actually in the cart", ->
|
||||
expect(Cart.line_items_present()).toEqual []
|
||||
order.line_items[0].quantity = 1
|
||||
expect(Cart.line_items_present().length).toEqual 1
|
||||
|
||||
@@ -3,10 +3,11 @@ describe 'Products service', ->
|
||||
Products = null
|
||||
Enterprises = null
|
||||
Variants = null
|
||||
Cart = null
|
||||
CurrentHubMock = {}
|
||||
currentOrder =
|
||||
line_items: []
|
||||
currentOrder = null
|
||||
product = null
|
||||
|
||||
beforeEach ->
|
||||
product =
|
||||
test: "cats"
|
||||
@@ -14,15 +15,20 @@ describe 'Products service', ->
|
||||
id: 9
|
||||
price: 11
|
||||
variants: []
|
||||
currentOrder =
|
||||
line_items: []
|
||||
|
||||
module 'Darkswarm'
|
||||
module ($provide)->
|
||||
$provide.value "CurrentHub", CurrentHubMock
|
||||
$provide.value "currentOrder", currentOrder
|
||||
null
|
||||
|
||||
inject ($injector, _$httpBackend_)->
|
||||
Products = $injector.get("Products")
|
||||
Enterprises = $injector.get("Enterprises")
|
||||
Variants = $injector.get("Variants")
|
||||
Cart = $injector.get("Cart")
|
||||
$httpBackend = _$httpBackend_
|
||||
|
||||
it "Fetches products from the backend on init", ->
|
||||
@@ -37,12 +43,17 @@ describe 'Products service', ->
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].supplier).toBe Enterprises.enterprises_by_id["9"]
|
||||
|
||||
it "registers variants with the Variants service", ->
|
||||
spyOn(Variants, "register")
|
||||
it "registers variants with Variants service", ->
|
||||
product.variants = [{id: 1}]
|
||||
$httpBackend.expectGET("/shop/products").respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Variants.register).toHaveBeenCalledWith product.variants[0]
|
||||
expect(Products.products[0].variants[0]).toBe Variants.variants[1]
|
||||
|
||||
it "registers variants with the Cart", ->
|
||||
product.variants = [{id: 8}]
|
||||
$httpBackend.expectGET("/shop/products").respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Cart.line_items[0].variant).toBe Products.products[0].variants[0]
|
||||
|
||||
describe "determining the price to display for a product", ->
|
||||
it "displays the product price when the product does not have variants", ->
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
describe 'Variants service', ->
|
||||
Variants = null
|
||||
variant =
|
||||
id: 1
|
||||
variant = null
|
||||
|
||||
beforeEach ->
|
||||
variant =
|
||||
id: 1
|
||||
module 'Darkswarm'
|
||||
inject ($injector)->
|
||||
Variants = $injector.get("Variants")
|
||||
@@ -14,3 +15,7 @@ describe 'Variants service', ->
|
||||
it "will return an existing variant rather than duplicating", ->
|
||||
Variants.register(variant)
|
||||
expect(Variants.register({id: 1})).toBe variant
|
||||
|
||||
it "will return the same object as passed", ->
|
||||
expect(Variants.register(variant)).toBe variant
|
||||
|
||||
|
||||
Reference in New Issue
Block a user