tech(clean): simplify implementation of eligibilite rules, code, enhance wording and test coverage
This commit is contained in:
parent
a011576757
commit
f819da8921
29 changed files with 161 additions and 219 deletions
|
@ -6,42 +6,6 @@ describe Logic::And do
|
|||
it { expect(and_from([true, true, false]).compute).to be false }
|
||||
end
|
||||
|
||||
describe '#computable?' do
|
||||
let(:champ_1) { create(:champ_integer_number, value: value_1) }
|
||||
let(:champ_2) { create(:champ_integer_number, value: value_2) }
|
||||
|
||||
let(:logic) do
|
||||
ds_and([
|
||||
greater_than(champ_value(champ_1.stable_id), constant(1)),
|
||||
less_than(champ_value(champ_2.stable_id), constant(10))
|
||||
])
|
||||
end
|
||||
|
||||
subject { logic.computable?([champ_1, champ_2]) }
|
||||
|
||||
context "when none of champs.value are filled, and logic can't be computed" do
|
||||
let(:value_1) { nil }
|
||||
let(:value_2) { nil }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
context "when one champs has a value (that compute to false) the other has not, and logic keeps waiting for the 2nd value" do
|
||||
let(:value_1) { 1 }
|
||||
let(:value_2) { nil }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
context 'when all champs.value are filled, and logic can be computed' do
|
||||
let(:value_1) { 1 }
|
||||
let(:value_2) { 10 }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
context 'when one champs is not visible and the other has a value, and logic can be computed' do
|
||||
let(:value_1) { 1 }
|
||||
let(:value_2) { nil }
|
||||
before { expect(champ_2).to receive(:visible?).and_return(false) }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_s' do
|
||||
it do
|
||||
expect(and_from([true, false, true]).to_s([])).to eq "(Oui && Non && Oui)"
|
||||
|
|
|
@ -28,19 +28,6 @@ describe Logic::BinaryOperator do
|
|||
it { expect(greater_than(constant(2), champ_value(champ.stable_id)).sources).to eq([champ.stable_id]) }
|
||||
it { expect(greater_than(champ_value(champ.stable_id), champ_value(champ2.stable_id)).sources).to eq([champ.stable_id, champ2.stable_id]) }
|
||||
end
|
||||
|
||||
describe '#computable?' do
|
||||
let(:champ) { create(:champ_integer_number, value: nil) }
|
||||
|
||||
it 'computable?' do
|
||||
expect(greater_than(champ_value(champ.stable_id), constant(1)).computable?([])).to be(false)
|
||||
expect(greater_than(champ_value(champ.stable_id), constant(1)).computable?([champ])).to be(false)
|
||||
allow(champ).to receive(:value).and_return(double(present?: true))
|
||||
expect(greater_than(champ_value(champ.stable_id), constant(1)).computable?([champ])).to be(true)
|
||||
allow(champ).to receive(:visible?).and_return(false)
|
||||
expect(greater_than(champ_value(champ.stable_id), constant(1)).computable?([champ])).to be(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe Logic::GreaterThan do
|
||||
|
|
|
@ -7,49 +7,6 @@ describe Logic::Or do
|
|||
it { expect(or_from([false, false, false]).compute).to be false }
|
||||
end
|
||||
|
||||
describe '#computable?' do
|
||||
let(:champ_1) { create(:champ_integer_number, value: value_1) }
|
||||
let(:champ_2) { create(:champ_integer_number, value: value_2) }
|
||||
|
||||
let(:logic) do
|
||||
ds_or([
|
||||
greater_than(champ_value(champ_1.stable_id), constant(1)),
|
||||
less_than(champ_value(champ_2.stable_id), constant(10))
|
||||
])
|
||||
end
|
||||
|
||||
context 'with all champs' do
|
||||
subject { logic.computable?([champ_1, champ_2]) }
|
||||
|
||||
context "when none of champs.value are filled, or logic can't be computed" do
|
||||
let(:value_1) { nil }
|
||||
let(:value_2) { nil }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
context "when one champs has a value (that compute to false) the other has not, or logic keeps waiting for the 2nd value" do
|
||||
let(:value_1) { 1 }
|
||||
let(:value_2) { nil }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
context 'when all champs.value are filled, or logic can be computed' do
|
||||
let(:value_1) { 1 }
|
||||
let(:value_2) { 10 }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
context 'when one champs.value and his condition is true, or logic can be computed' do
|
||||
let(:value_1) { 2 }
|
||||
let(:value_2) { nil }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
context 'when one champs is not visible and the other has a value that fails, or logic can be computed' do
|
||||
let(:value_1) { 1 }
|
||||
let(:value_2) { nil }
|
||||
before { expect(champ_2).to receive(:visible?).and_return(false) }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_s' do
|
||||
it { expect(or_from([true, false, true]).to_s).to eq "(Oui || Non || Oui)" }
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue