Browse Source

CLDC-4297: test improvements

pull/3240/head
Nat Dean-Lewis 2 months ago
parent
commit
47a532017c
  1. 286
      spec/services/bulk_upload/sales/year2026/row_parser_spec.rb

286
spec/services/bulk_upload/sales/year2026/row_parser_spec.rb

@ -1944,113 +1944,233 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
end end
end end
context "when mscharge is given, but is set to 0 for shared ownership" do context "with service charges fields" do
let(:attributes) { valid_attributes.merge(field_125: "0") } context "with mscharge for shared ownership initial purchase (field_107)" do
context "when positive" do
let(:attributes) { valid_attributes.merge(field_10: "2", field_107: "100") }
it "does not override variables" do it "sets has_mscharge to yes and mscharge to the value" do
log = parser.log log = parser.log
expect(log["has_mscharge"]).to eq(0) # no expect(log["has_mscharge"]).to eq(1)
expect(log["mscharge"]).to be_nil expect(log["mscharge"]).to eq(100)
end end
end end
context "when mscharge is given, but is set to 0 for discounted ownership" do context "when set to 0" do
let(:attributes) { valid_attributes.merge(field_8: "2", field_136: "0") } let(:attributes) { valid_attributes.merge(field_10: "2", field_107: "0") }
it "does not override variables" do it "does not set mscharge and sets has_mscharge to no" do
log = parser.log log = parser.log
expect(log["has_mscharge"]).to eq(0) # no expect(log["has_mscharge"]).to eq(0)
expect(log["mscharge"]).to be_nil expect(log["mscharge"]).to be_nil
end end
end end
context "when mscharge is set to R for staircasing" do context "when set to R" do
let(:attributes) { valid_attributes.merge(field_125: "R") } let(:attributes) { valid_attributes.merge(field_10: "2", field_107: "R") }
it "does not set mscharge and sets has_mscharge to no" do it "does not set mscharge and sets has_mscharge to no" do
log = parser.log log = parser.log
expect(log["has_mscharge"]).to eq(0) expect(log["has_mscharge"]).to eq(0)
expect(log["mscharge"]).to be_nil expect(log["mscharge"]).to be_nil
end end
end end
context "when newservicecharges is set to R" do context "when an invalid string" do
let(:attributes) { valid_attributes.merge(field_126: "R") } let(:attributes) { valid_attributes.merge(field_10: "2", field_107: "X") }
it "does not set newservicecharges and sets hasservicechargeschanged to no" do it "adds a validation error" do
log = parser.log parser.valid?
expect(log["newservicecharges"]).to be_nil expect(parser.errors[:field_107]).to include(I18n.t("validations.sales.2026.bulk_upload.mscharge.invalid"))
expect(log["hasservicechargeschanged"]).to eq(2) end
end
end it "does not set mscharge or has_mscharge" do
log = parser.log
expect(log["mscharge"]).to be_nil
expect(log["has_mscharge"]).to be_nil
end
end
context "when newservicecharges is positive" do context "when blank" do
let(:attributes) { valid_attributes.merge(field_126: "150") } let(:attributes) { valid_attributes.merge(field_10: "2", field_107: nil) }
it "sets newservicecharges and hasservicechargeschanged correctly" do it "leaves mscharge and has_mscharge nil" do
log = parser.log log = parser.log
expect(log["newservicecharges"]).to eq(150) expect(log["mscharge"]).to be_nil
expect(log["hasservicechargeschanged"]).to eq(1) expect(log["has_mscharge"]).to be_nil
end
end
end end
end
context "when newservicecharges is set to 0" do context "with mscharge for staircasing (field_125)" do
let(:attributes) { valid_attributes.merge(field_126: "0") } context "when positive" do
let(:attributes) { valid_attributes.merge(field_125: "100") }
it "sets newservicecharges to 0 and hasservicechargeschanged to yes" do it "sets has_mscharge to yes and mscharge to the value" do
log = parser.log log = parser.log
expect(log["newservicecharges"]).to eq(0) expect(log["has_mscharge"]).to eq(1)
expect(log["hasservicechargeschanged"]).to eq(1) expect(log["mscharge"]).to eq(100)
end end
end end
context "when newservicecharges is blank" do context "when set to 0" do
let(:attributes) { valid_attributes.merge(field_126: nil) } let(:attributes) { valid_attributes.merge(field_125: "0") }
it "does not set newservicecharges and leaves hasservicechargeschanged nil" do it "does not set mscharge and sets has_mscharge to no" do
log = parser.log log = parser.log
expect(log["newservicecharges"]).to be_nil expect(log["has_mscharge"]).to eq(0)
expect(log["hasservicechargeschanged"]).to be_nil expect(log["mscharge"]).to be_nil
end end
end end
context "when newservicecharges is an invalid string" do context "when set to R" do
let(:attributes) { valid_attributes.merge(field_126: "S") } let(:attributes) { valid_attributes.merge(field_125: "R") }
it "adds a validation error" do it "does not set mscharge and sets has_mscharge to no" do
parser.valid? log = parser.log
expect(parser.errors[:field_126]).to include(I18n.t("validations.sales.2026.bulk_upload.newservicecharges.invalid")) expect(log["has_mscharge"]).to eq(0)
end expect(log["mscharge"]).to be_nil
end
end
it "does not set newservicecharges or hasservicechargeschanged" do context "when an invalid string" do
log = parser.log let(:attributes) { valid_attributes.merge(field_125: "X") }
expect(log["newservicecharges"]).to be_nil
expect(log["hasservicechargeschanged"]).to be_nil
end
end
context "when mscharge is an invalid string for staircasing" do it "adds a validation error" do
let(:attributes) { valid_attributes.merge(field_125: "X") } parser.valid?
expect(parser.errors[:field_125]).to include(I18n.t("validations.sales.2026.bulk_upload.mscharge.invalid"))
end
it "adds a validation error" do it "does not set mscharge or has_mscharge" do
parser.valid? log = parser.log
expect(parser.errors[:field_125]).to include(I18n.t("validations.sales.2026.bulk_upload.mscharge.invalid")) expect(log["mscharge"]).to be_nil
expect(log["has_mscharge"]).to be_nil
end
end
context "when blank" do
let(:attributes) { valid_attributes.merge(field_125: nil) }
it "leaves mscharge and has_mscharge nil" do
log = parser.log
expect(log["mscharge"]).to be_nil
expect(log["has_mscharge"]).to be_nil
end
end
end end
it "does not set mscharge or has_mscharge" do context "with mscharge for discounted ownership (field_136)" do
log = parser.log context "when positive" do
expect(log["mscharge"]).to be_nil let(:attributes) { valid_attributes.merge(field_8: "2", field_136: "100") }
expect(log["has_mscharge"]).to be_nil
it "sets has_mscharge to yes and mscharge to the value" do
log = parser.log
expect(log["has_mscharge"]).to eq(1)
expect(log["mscharge"]).to eq(100)
end
end
context "when set to 0" do
let(:attributes) { valid_attributes.merge(field_8: "2", field_136: "0") }
it "does not set mscharge and sets has_mscharge to no" do
log = parser.log
expect(log["has_mscharge"]).to eq(0)
expect(log["mscharge"]).to be_nil
end
end
context "when set to R" do
let(:attributes) { valid_attributes.merge(field_8: "2", field_136: "R") }
it "does not set mscharge and sets has_mscharge to no" do
log = parser.log
expect(log["has_mscharge"]).to eq(0)
expect(log["mscharge"]).to be_nil
end
end
context "when an invalid string" do
let(:attributes) { valid_attributes.merge(field_8: "2", field_136: "X") }
it "adds a validation error" do
parser.valid?
expect(parser.errors[:field_136]).to include(I18n.t("validations.sales.2026.bulk_upload.mscharge.invalid"))
end
it "does not set mscharge or has_mscharge" do
log = parser.log
expect(log["mscharge"]).to be_nil
expect(log["has_mscharge"]).to be_nil
end
end
context "when blank" do
let(:attributes) { valid_attributes.merge(field_8: "2", field_136: nil) }
it "leaves mscharge and has_mscharge nil" do
log = parser.log
expect(log["mscharge"]).to be_nil
expect(log["has_mscharge"]).to be_nil
end
end
end end
end
context "when mscharge is blank for staircasing" do context "with newservicecharges (field_126)" do
let(:attributes) { valid_attributes.merge(field_125: nil) } context "when positive" do
let(:attributes) { valid_attributes.merge(field_126: "150") }
it "sets newservicecharges to the value and hasservicechargeschanged to yes" do
log = parser.log
expect(log["newservicecharges"]).to eq(150)
expect(log["hasservicechargeschanged"]).to eq(1)
end
end
context "when set to 0" do
let(:attributes) { valid_attributes.merge(field_126: "0") }
it "sets newservicecharges to 0 and hasservicechargeschanged to yes" do
log = parser.log
expect(log["newservicecharges"]).to eq(0)
expect(log["hasservicechargeschanged"]).to eq(1)
end
end
context "when set to R" do
let(:attributes) { valid_attributes.merge(field_126: "R") }
it "leaves mscharge and has_mscharge nil" do it "does not set newservicecharges and sets hasservicechargeschanged to no" do
log = parser.log log = parser.log
expect(log["mscharge"]).to be_nil expect(log["newservicecharges"]).to be_nil
expect(log["has_mscharge"]).to be_nil expect(log["hasservicechargeschanged"]).to eq(2)
end
end
context "when an invalid string" do
let(:attributes) { valid_attributes.merge(field_126: "S") }
it "adds a validation error" do
parser.valid?
expect(parser.errors[:field_126]).to include(I18n.t("validations.sales.2026.bulk_upload.newservicecharges.invalid"))
end
it "does not set newservicecharges or hasservicechargeschanged" do
log = parser.log
expect(log["newservicecharges"]).to be_nil
expect(log["hasservicechargeschanged"]).to be_nil
end
end
context "when blank" do
let(:attributes) { valid_attributes.merge(field_126: nil) }
it "does not set newservicecharges and leaves hasservicechargeschanged nil" do
log = parser.log
expect(log["newservicecharges"]).to be_nil
expect(log["hasservicechargeschanged"]).to be_nil
end
end
end end
end end

Loading…
Cancel
Save