Adding tags to variant overrides

This commit is contained in:
Rob Harrington
2016-04-15 11:44:19 +10:00
parent ddc7e86e6c
commit 3f8420b0e9
18 changed files with 152 additions and 63 deletions

View File

@@ -8,36 +8,53 @@ describe "maintaining a list of dirty variant overrides", ->
beforeEach ->
module "admin.variantOverrides"
module ($provide) ->
$provide.value "variantOverrides", { 2: { 1: variantOverride } }
null
beforeEach inject (_DirtyVariantOverrides_) ->
DirtyVariantOverrides = _DirtyVariantOverrides_
it "adds new dirty variant overrides", ->
DirtyVariantOverrides.add variantOverride
expect(DirtyVariantOverrides.dirtyVariantOverrides).toEqual
2:
1:
variant_id: 1
hub_id: 2
price: 3
count_on_hand: 4
describe "adding a new dirty variant override", ->
it "adds new dirty variant overrides", ->
DirtyVariantOverrides.add(2,1,5)
expect(DirtyVariantOverrides.dirtyVariantOverrides).toEqual { 2: { 1: { id: 5, variant_id: 1, hub_id: 2 } } }
it "updates existing dirty variant overrides", ->
DirtyVariantOverrides.dirtyVariantOverrides =
2:
1:
variant_id: 5
hub_id: 6
price: 7
count_on_hand: 8
DirtyVariantOverrides.add variantOverride
expect(DirtyVariantOverrides.dirtyVariantOverrides).toEqual
2:
1:
variant_id: 1
hub_id: 2
price: 3
count_on_hand: 4
describe "setting the value of an attribute", ->
beforeEach ->
spyOn(DirtyVariantOverrides, "add").andCallThrough()
describe "when a record for the given VO does not exist", ->
beforeEach ->
DirtyVariantOverrides.dirtyVariantOverrides = {}
it "sets the specified attribute on a new dirty VO", ->
DirtyVariantOverrides.set(2,1,5,'count_on_hand', 10)
expect(DirtyVariantOverrides.add).toHaveBeenCalledWith(2,1,5)
expect(DirtyVariantOverrides.dirtyVariantOverrides).toEqual
2:
1:
id: 5
variant_id: 1
hub_id: 2
count_on_hand: 10
describe "when a record for the given VO exists", ->
beforeEach ->
DirtyVariantOverrides.dirtyVariantOverrides = { 2: { 1: { id: 5, variant_id: 1, hub_id: 2, price: 27 } } }
it "sets the specified attribute on a new dirty VO", ->
DirtyVariantOverrides.set(2,1,5,'count_on_hand', 10)
expect(DirtyVariantOverrides.add).toHaveBeenCalledWith(2,1,5)
expect(DirtyVariantOverrides.dirtyVariantOverrides).toEqual
2:
1:
id: 5
variant_id: 1
hub_id: 2
price: 27
count_on_hand: 10
describe "with a number of variant overrides", ->
beforeEach ->

View File

@@ -1,9 +1,9 @@
describe "VariantOverrides service", ->
VariantOverrides = $httpBackend = null
variantOverrides = [
{id: 1, hub_id: 10, variant_id: 100, sku: "V100", price: 1, count_on_hand: 1, on_demand: null, default_stock: null, resettable: false }
{id: 2, hub_id: 10, variant_id: 200, sku: "V200", price: 2, count_on_hand: 2, on_demand: null, default_stock: null, resettable: false}
{id: 3, hub_id: 20, variant_id: 300, sku: "V300", price: 3, count_on_hand: 3, on_demand: null, default_stock: null, resettable: false}
{id: 1, hub_id: 10, variant_id: 100, sku: "V100", price: 1, count_on_hand: 1, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
{id: 2, hub_id: 10, variant_id: 200, sku: "V200", price: 2, count_on_hand: 2, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
{id: 3, hub_id: 20, variant_id: 300, sku: "V300", price: 3, count_on_hand: 3, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
]
beforeEach ->
@@ -19,10 +19,10 @@ describe "VariantOverrides service", ->
it "indexes variant overrides by hub_id -> variant_id", ->
expect(VariantOverrides.variantOverrides).toEqual
10:
100: {id: 1, hub_id: 10, variant_id: 100, sku: "V100", price: 1, count_on_hand: 1, on_demand: null, default_stock: null, resettable: false }
200: {id: 2, hub_id: 10, variant_id: 200, sku: "V200", price: 2, count_on_hand: 2, on_demand: null, default_stock: null, resettable: false }
100: {id: 1, hub_id: 10, variant_id: 100, sku: "V100", price: 1, count_on_hand: 1, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
200: {id: 2, hub_id: 10, variant_id: 200, sku: "V200", price: 2, count_on_hand: 2, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
20:
300: {id: 3, hub_id: 20, variant_id: 300, sku: "V300", price: 3, count_on_hand: 3, on_demand: null, default_stock: null, resettable: false }
300: {id: 3, hub_id: 20, variant_id: 300, sku: "V300", price: 3, count_on_hand: 3, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
it "ensures blank data available for some products", ->
hubs = [{id: 10}, {id: 20}, {id: 30}]
@@ -34,23 +34,23 @@ describe "VariantOverrides service", ->
]
VariantOverrides.ensureDataFor hubs, products
expect(VariantOverrides.variantOverrides[10]).toEqual
100: { id: 1, hub_id: 10, variant_id: 100, sku: "V100", price: 1, count_on_hand: 1, on_demand: null, default_stock: null, resettable: false }
200: { id: 2, hub_id: 10, variant_id: 200, sku: "V200", price: 2, count_on_hand: 2, on_demand: null, default_stock: null, resettable: false }
300: { hub_id: 10, variant_id: 300, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
400: { hub_id: 10, variant_id: 400, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
500: { hub_id: 10, variant_id: 500, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
100: { id: 1, hub_id: 10, variant_id: 100, sku: "V100", price: 1, count_on_hand: 1, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
200: { id: 2, hub_id: 10, variant_id: 200, sku: "V200", price: 2, count_on_hand: 2, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
300: { hub_id: 10, variant_id: 300, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
400: { hub_id: 10, variant_id: 400, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
500: { hub_id: 10, variant_id: 500, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
expect(VariantOverrides.variantOverrides[20]).toEqual
100: { hub_id: 20, variant_id: 100, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
200: { hub_id: 20, variant_id: 200, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
300: { id: 3, hub_id: 20, variant_id: 300, sku: "V300", price: 3, count_on_hand: 3, on_demand: null, default_stock: null, resettable: false }
400: { hub_id: 20, variant_id: 400, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
500: { hub_id: 20, variant_id: 500, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
100: { hub_id: 20, variant_id: 100, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
200: { hub_id: 20, variant_id: 200, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
300: { id: 3, hub_id: 20, variant_id: 300, sku: "V300", price: 3, count_on_hand: 3, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
400: { hub_id: 20, variant_id: 400, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: []}
500: { hub_id: 20, variant_id: 500, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
expect(VariantOverrides.variantOverrides[30]).toEqual
100: { hub_id: 30, variant_id: 100, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
200: { hub_id: 30, variant_id: 200, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
300: { hub_id: 30, variant_id: 300, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
400: { hub_id: 30, variant_id: 400, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
500: { hub_id: 30, variant_id: 500, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false }
100: { hub_id: 30, variant_id: 100, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
200: { hub_id: 30, variant_id: 200, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
300: { hub_id: 30, variant_id: 300, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: []}
400: { hub_id: 30, variant_id: 400, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
500: { hub_id: 30, variant_id: 500, sku: null, price: null, count_on_hand: null, on_demand: null, default_stock: null, resettable: false, tag_list : '', tags: [] }
it "updates the IDs of variant overrides", ->
VariantOverrides.variantOverrides[2] = {}