Skip to content

Commit

Permalink
AP-4664: Add remark tests to ensure that new style remarks are handled
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbruce committed Dec 1, 2023
1 parent 9d57508 commit 841e7f4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/cfe/remarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def review_transactions
def populate_review_transactions
collection = RemarkedTransactionCollection.new
@hash.each do |category, reason_hashes|
next if category.starts_with?("employment_")
next if category.starts_with?("employment_") || category.match(/.*_employment_.*/)
break if reason_hashes.is_a?(Array)

reason_hashes.each do |reason, tx_ids|
Expand Down
89 changes: 88 additions & 1 deletion spec/models/cfe/remarks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module CFE
expect(collection.transactions.keys).to match_array expected_transaction_ids
end

it "returns a collection with the expected values for a transacton" do
it "returns a collection with the expected values for a transactIon" do
tx = collection.transactions["d55743b5-c1c4-4c9a-98a3-bad709aac422"]
expect(tx).to be_instance_of(RemarkedTransaction)
expect(tx.category).to eq :state_benefit_payment
Expand All @@ -123,6 +123,39 @@ module CFE
end
end

context "with remarks in the new client/partner style" do
let(:remarks_hash) { populated_hash_specific }
let(:collection) { remarks.review_transactions }

it "returns an an instance of RemarkedTransactionCollection" do
expect(collection).to be_instance_of(RemarkedTransactionCollection)
end

it "returns an collection with the expected transaction_ids" do
expected_transaction_ids = %w[
d55743b5-c1c4-4c9a-98a3-bad709aac422
a277038a-86df-4bbd-8b87-d576ae150369
17f4bc9f-574f-4f53-a371-16db2a0197f8
28dc9ead-f8d3-498d-80f7-12087407ba22
2130cf51-5257-4818-b2be-c4629fac0803
9c7abff4-b6a9-4403-8a08-44e785724b07
]
expect(collection.transactions.keys).to match_array expected_transaction_ids
end

it "returns a collection with the expected values for a transactIon" do
tx = collection.transactions["d55743b5-c1c4-4c9a-98a3-bad709aac422"]
expect(tx).to be_instance_of(RemarkedTransaction)
expect(tx.category).to eq :partner_state_benefit_payment
expect(tx.reasons).to eq %i[amount_variation unknown_frequency]

tx = collection.transactions["28dc9ead-f8d3-498d-80f7-12087407ba22"]
expect(tx).to be_instance_of(RemarkedTransaction)
expect(tx.category).to eq :client_employment
expect(tx.reasons).to eq [:multiple_employments]
end
end

context "with duplicate reason and transaction for non-employment category remark" do
let(:duplicate_remarks) do
{
Expand Down Expand Up @@ -161,6 +194,26 @@ module CFE
expect { remarks.review_transactions }.not_to raise_error
end
end

context "with duplicate reason and transaction for client/partner employment category remark" do
let(:employment_remarks) do
{
client_employment_tax: {
refunds: %w[d55743b5-c1c4-4c9a-98a3-bad709aac422],
},
client_employment_nic: {
refunds: %w[d55743b5-c1c4-4c9a-98a3-bad709aac422],
},
}
end

# NOTE: hash key order is significant due to `break` statement
let(:remarks_hash) { employment_remarks.merge!(populated_hash) }

it "does not raise \"Category mismatch\" error" do
expect { remarks.review_transactions }.not_to raise_error
end
end
end

def empty_hash
Expand Down Expand Up @@ -190,5 +243,39 @@ def populated_hash
],
}
end

def populated_hash_specific
{
partner_state_benefit_payment: {
amount_variation: %w[
d55743b5-c1c4-4c9a-98a3-bad709aac422
a277038a-86df-4bbd-8b87-d576ae150369
],
unknown_frequency: %w[
d55743b5-c1c4-4c9a-98a3-bad709aac422
a277038a-86df-4bbd-8b87-d576ae150369
],
},
client_employment: {
multiple_employments: %w[
17f4bc9f-574f-4f53-a371-16db2a0197f8
28dc9ead-f8d3-498d-80f7-12087407ba22
2130cf51-5257-4818-b2be-c4629fac0803
9c7abff4-b6a9-4403-8a08-44e785724b07
],
},
client_employment_tax: {
refunds: %w[
5094660c-afed-4a0f-b81f-78de6a390fa8
0a0e4976-8605-44fe-b6c2-c3d72ef3e337
abc472a7-04cf-4096-9f53-8fb022dc1812
fea4f1fa-3f87-40d3-a43c-622ba4b80579
],
},
policy_disregards: %w[
england_infected_blood_support
],
}
end
end
end

0 comments on commit 841e7f4

Please sign in to comment.