mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
Creating and then updating the new override updates the same override instead of creating a duplicate
This commit is contained in:
@@ -83,6 +83,38 @@ feature %q{
|
||||
vo.count_on_hand.should == 123
|
||||
end
|
||||
|
||||
describe "creating and then updating the new override" do
|
||||
it "updates the same override instead of creating a duplicate" do
|
||||
# When I create a new override
|
||||
fill_in "variant-overrides-#{variant.id}-price", with: '777.77'
|
||||
fill_in "variant-overrides-#{variant.id}-count-on-hand", with: '123'
|
||||
page.should have_content "Changes to one override remain unsaved."
|
||||
|
||||
expect do
|
||||
click_button 'Save Changes'
|
||||
page.should have_content "Changes saved."
|
||||
end.to change(VariantOverride, :count).by(1)
|
||||
|
||||
# And I update its settings without reloading the page
|
||||
fill_in "variant-overrides-#{variant.id}-price", with: '111.11'
|
||||
fill_in "variant-overrides-#{variant.id}-count-on-hand", with: '111'
|
||||
page.should have_content "Changes to one override remain unsaved."
|
||||
|
||||
# Then I shouldn't see a new override
|
||||
expect do
|
||||
click_button 'Save Changes'
|
||||
page.should have_content "Changes saved."
|
||||
end.to change(VariantOverride, :count).by(0)
|
||||
|
||||
# And the override should be updated
|
||||
vo = VariantOverride.last
|
||||
vo.variant_id.should == variant.id
|
||||
vo.hub_id.should == hub.id
|
||||
vo.price.should == 111.11
|
||||
vo.count_on_hand.should == 111
|
||||
end
|
||||
end
|
||||
|
||||
it "displays an error when unauthorised to access the page" do
|
||||
fill_in "variant-overrides-#{variant.id}-price", with: '777.77'
|
||||
fill_in "variant-overrides-#{variant.id}-count-on-hand", with: '123'
|
||||
|
||||
@@ -51,3 +51,18 @@ describe "VariantOverrides service", ->
|
||||
300: { hub_id: 30, variant_id: 300, price: '', count_on_hand: ''}
|
||||
400: { hub_id: 30, variant_id: 400, price: '', count_on_hand: ''}
|
||||
500: { hub_id: 30, variant_id: 500, price: '', count_on_hand: ''}
|
||||
|
||||
it "updates the IDs of variant overrides", ->
|
||||
VariantOverrides.variantOverrides[2] = {}
|
||||
VariantOverrides.variantOverrides[2][3] = {hub_id: 2, variant_id: 3, price: "4.0", count_on_hand: 5}
|
||||
VariantOverrides.variantOverrides[2][8] = {hub_id: 2, variant_id: 8, price: "9.0", count_on_hand: 10}
|
||||
|
||||
updatedVos = [
|
||||
{id: 1, hub_id: 2, variant_id: 3, price: "4.0", count_on_hand: 5}
|
||||
{id: 6, hub_id: 2, variant_id: 8, price: "9.0", count_on_hand: 10}
|
||||
]
|
||||
|
||||
VariantOverrides.updateIds updatedVos
|
||||
|
||||
expect(VariantOverrides.variantOverrides[2][3].id).toEqual 1
|
||||
expect(VariantOverrides.variantOverrides[2][8].id).toEqual 6
|
||||
|
||||
Reference in New Issue
Block a user