Browse Source
* feat: add 22/23 year validation * feat: wip commit * feat: update i18n * feat: add one year gap exchange/completion validations * tests: add tests for new validations * test: add setup validations tests * test: update factory to pass saledate validation * feat: update seeds * feat: update tests to reflect sales logs shouldn't exist in new service before 2022 * feat: merge with main, improve date behaviour * refactor: cleanup * feat: update tests * feat: enforce saledate not after 22/23 collection year endpull/1255/head
natdeanlewissoftwire
2 years ago
committed by
GitHub
9 changed files with 104 additions and 32 deletions
@ -0,0 +1,9 @@
|
||||
module Validations::Sales::SetupValidations |
||||
def validate_saledate(record) |
||||
return unless record.saledate |
||||
|
||||
unless Time.zone.local(2022, 4, 1) <= record.saledate && record.saledate < Time.zone.local(2023, 4, 1) |
||||
record.errors.add :saledate, I18n.t("validations.setup.saledate.financial_year") |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,49 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Validations::Sales::SetupValidations do |
||||
subject(:setup_validator) { validator_class.new } |
||||
|
||||
let(:validator_class) { Class.new { include Validations::Sales::SetupValidations } } |
||||
|
||||
describe "#validate_saledate" do |
||||
context "when saledate is blank" do |
||||
let(:record) { FactoryBot.build(:sales_log, saledate: nil) } |
||||
|
||||
it "does not add an error" do |
||||
setup_validator.validate_saledate(record) |
||||
|
||||
expect(record.errors).to be_empty |
||||
end |
||||
end |
||||
|
||||
context "when saledate is in the 22/23 financial year" do |
||||
let(:record) { FactoryBot.build(:sales_log, saledate: Time.zone.local(2023, 1, 1)) } |
||||
|
||||
it "does not add an error" do |
||||
setup_validator.validate_saledate(record) |
||||
|
||||
expect(record.errors).to be_empty |
||||
end |
||||
end |
||||
|
||||
context "when saledate is before the 22/23 financial year" do |
||||
let(:record) { FactoryBot.build(:sales_log, saledate: Time.zone.local(2022, 1, 1)) } |
||||
|
||||
it "adds error" do |
||||
setup_validator.validate_saledate(record) |
||||
|
||||
expect(record.errors[:saledate]).to include(I18n.t("validations.setup.saledate.financial_year")) |
||||
end |
||||
end |
||||
|
||||
context "when saledate is after the 22/23 financial year" do |
||||
let(:record) { FactoryBot.build(:sales_log, saledate: Time.zone.local(2023, 4, 1)) } |
||||
|
||||
it "adds error" do |
||||
setup_validator.validate_saledate(record) |
||||
|
||||
expect(record.errors[:saledate]).to include(I18n.t("validations.setup.saledate.financial_year")) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue