Fix shopping system spec

This commit is contained in:
Gaetan Craig-Riou
2024-05-22 10:44:08 +10:00
parent ca80177954
commit 6538c7adca
5 changed files with 40 additions and 22 deletions

View File

@@ -19,16 +19,16 @@ describe 'Products service', ->
beforeEach ->
product =
test: "cats"
supplier:
id: 9
price: 11
master: {}
variants: []
variants: [
id: 1000, price: 11, supplier: {id: 9}
]
productWithImage =
supplier:
id: 9
master: {}
variants: []
variants: [
id: 1000, price: 20, supplier: {id: 9}
]
image: {
large_url: 'foo.png'
}
@@ -79,7 +79,7 @@ describe 'Products service', ->
it "dereferences suppliers", ->
Shopfront.producers_by_id =
{id: 9, name: "test"}
$httpBackend.expectGET(endpoint).respond([{supplier : {id: 9}, master: {}}])
$httpBackend.expectGET(endpoint).respond([product])
$httpBackend.flush()
expect(Products.products[0].supplier).toBe Shopfront.producers_by_id["9"]
@@ -96,13 +96,16 @@ describe 'Products service', ->
expect(Products.products[0].properties[1]).toBe properties[0]
it "registers variants with Variants service", ->
product.variants = [{id: 1}]
product.variants = [{id: 1, supplier: {id: 9}}]
$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"}]
product.variants = [
{id: 1, name_to_display: "one", supplier: {id: 9}},
{id: 2, name_to_display: "two", supplier: {id: 9}}
]
$httpBackend.expectGET(endpoint).respond([product])
$httpBackend.flush()
expect(Products.products[0].variant_names).toEqual "one two "
@@ -125,7 +128,9 @@ describe 'Products service', ->
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}]
product.variants = [
{price: 22, supplier: {id: 9} }, {price: 33, supplier: {id: 9}}
]
$httpBackend.expectGET(endpoint).respond([product])
$httpBackend.flush()
expect(Products.products[0].price).toEqual 22