mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adjust API endpoint params
This commit is contained in:
@@ -12,6 +12,7 @@ describe 'Products service', ->
|
||||
properties = null
|
||||
taxons = null
|
||||
Geo = {}
|
||||
endpoint = "/api/order_cycles/1/products?distributor=1"
|
||||
|
||||
beforeEach ->
|
||||
product =
|
||||
@@ -62,60 +63,60 @@ describe 'Products service', ->
|
||||
$httpBackend = _$httpBackend_
|
||||
|
||||
it "Fetches products from the backend on init", ->
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
|
||||
$httpBackend.expectGET(endpoint).respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].test).toEqual "cats"
|
||||
|
||||
it "dereferences suppliers", ->
|
||||
Shopfront.producers_by_id =
|
||||
{id: 9, name: "test"}
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([{supplier : {id: 9}, master: {}}])
|
||||
$httpBackend.expectGET(endpoint).respond([{supplier : {id: 9}, master: {}}])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].supplier).toBe Shopfront.producers_by_id["9"]
|
||||
|
||||
it "dereferences taxons", ->
|
||||
product.taxons = [2]
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
|
||||
$httpBackend.expectGET(endpoint).respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].taxons[1]).toBe taxons[0]
|
||||
|
||||
it "dereferences properties", ->
|
||||
product.properties_with_values = [1]
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
|
||||
$httpBackend.expectGET(endpoint).respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].properties[1]).toBe properties[0]
|
||||
|
||||
it "registers variants with Variants service", ->
|
||||
product.variants = [{id: 1}]
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
|
||||
$httpBackend.expectGET(endpoint).respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].variants[0]).toBe Variants.variants[1]
|
||||
|
||||
it "stores variant names", ->
|
||||
product.variants = [{id: 1, name_to_display: "one"}, {id: 2, name_to_display: "two"}]
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
|
||||
$httpBackend.expectGET(endpoint).respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].variant_names).toEqual "one two "
|
||||
|
||||
it "sets primaryImageOrMissing when no images are provided", ->
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
|
||||
$httpBackend.expectGET(endpoint).respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].primaryImage).toBeUndefined()
|
||||
expect(Products.products[0].primaryImageOrMissing).toEqual "/assets/noimage/small.png"
|
||||
|
||||
it "sets largeImage", ->
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([productWithImage])
|
||||
$httpBackend.expectGET(endpoint).respond([productWithImage])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].largeImage).toEqual("foo.png")
|
||||
|
||||
describe "determining the price to display for a product", ->
|
||||
it "displays the product price when the product does not have variants", ->
|
||||
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
|
||||
$httpBackend.expectGET(endpoint).respond([product])
|
||||
$httpBackend.flush()
|
||||
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("/api/order_cycles/1/products").respond([product])
|
||||
$httpBackend.expectGET(endpoint).respond([product])
|
||||
$httpBackend.flush()
|
||||
expect(Products.products[0].price).toEqual 22
|
||||
|
||||
Reference in New Issue
Block a user