Skip to content

Commit 77ae17e

Browse files
Improved VatRates coverage
1 parent acbfed3 commit 77ae17e

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

rails_application/db/schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
t.date "disposal_date"
166166
t.date "payment_date"
167167
t.decimal "total_value", precision: 8, scale: 2
168+
t.uuid "store_id"
168169
end
169170

170171
create_table "invoices_orders", force: :cascade do |t|

rails_application/test/integration/store_switching_test.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
class StoreSwitchingTest < InMemoryRESIntegrationTestCase
44
def test_first_store_selected_by_default_when_no_cookie
5-
store_1_id = register_store("Store A")
6-
store_2_id = register_store("Store B")
5+
register_store("Store A")
6+
register_store("Store B")
77

88
get products_path
99

@@ -12,7 +12,6 @@ def test_first_store_selected_by_default_when_no_cookie
1212
end
1313

1414
def test_cookie_is_preserved_across_requests
15-
store_1_id = register_store("Store A")
1615
store_2_id = register_store("Store B")
1716

1817
get products_path
@@ -26,8 +25,8 @@ def test_cookie_is_preserved_across_requests
2625
end
2726

2827
def test_fallback_to_first_store_when_cookie_points_to_nonexistent_store
29-
store_1_id = register_store("Store A")
30-
store_2_id = register_store("Store B")
28+
register_store("Store A")
29+
register_store("Store B")
3130
nonexistent_store_id = SecureRandom.uuid
3231

3332
cookies[:current_store_id] = nonexistent_store_id
@@ -39,7 +38,6 @@ def test_fallback_to_first_store_when_cookie_points_to_nonexistent_store
3938
end
4039

4140
def test_switching_stores_updates_cookie
42-
store_1_id = register_store("Store A")
4341
store_2_id = register_store("Store B")
4442

4543
get products_path

rails_application/test/vat_rates/assign_store_to_available_vat_rate_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,20 @@ def test_assign_store_to_existing_available_vat_rate
2525

2626
assert_equal(store_id, AvailableVatRate.find_by!(uid: vat_rate_id).store_id)
2727
end
28+
29+
def test_assigns_store_to_correct_vat_rate_by_uid
30+
event_store = Rails.configuration.event_store
31+
store_id = SecureRandom.uuid
32+
vat_rate_1_id = SecureRandom.uuid
33+
vat_rate_2_id = SecureRandom.uuid
34+
35+
AvailableVatRate.create!(uid: vat_rate_1_id, code: "standard", rate: 20)
36+
AvailableVatRate.create!(uid: vat_rate_2_id, code: "reduced", rate: 10)
37+
38+
event_store.publish(Stores::VatRateRegistered.new(data: { store_id: store_id, vat_rate_id: vat_rate_1_id }))
39+
40+
assert_equal(store_id, AvailableVatRate.find_by!(uid: vat_rate_1_id).store_id)
41+
assert_nil(AvailableVatRate.find_by!(uid: vat_rate_2_id).store_id)
42+
end
2843
end
2944
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require "test_helper"
2+
3+
module VatRates
4+
class RemoveAvailableVatRateTest < InMemoryTestCase
5+
cover "VatRates*"
6+
7+
def test_removing_available_vat_rate
8+
uid = SecureRandom.uuid
9+
code = "standard"
10+
rate = 20
11+
12+
event_store.publish(Taxes::AvailableVatRateAdded.new(data: { available_vat_rate_id: uid, vat_rate: { code: code, rate: rate } }))
13+
event_store.publish(Taxes::AvailableVatRateRemoved.new(data: { vat_rate_code: code }))
14+
15+
assert_nil(AvailableVatRate.find_by(code: code))
16+
end
17+
18+
private
19+
20+
def event_store
21+
Rails.configuration.event_store
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)