Skip to content

Commit 0fe7893

Browse files
authored
Merge pull request #2882 from DFE-Digital/AQTS-1177-dev-bug-issue-with-most-recent-work-history
[AQTS-1177] Fix issue with most recent role being miscalculated and considering other England work history
2 parents ccb43df + 4cce03c commit 0fe7893

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

app/forms/assessor_interface/select_work_histories_form.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AssessorInterface::SelectWorkHistoriesForm
1515
form
1616
.application_form
1717
&.work_histories
18+
&.teaching_role
1819
&.pluck(:id)
1920
&.map(&:to_s) || []
2021
end,
@@ -46,7 +47,7 @@ def work_history_most_recent_selected
4647
return if application_form.region.checks_available?
4748

4849
most_recent_work_history_id =
49-
application_form.work_histories.order_by_role.first.id.to_s
50+
application_form.work_histories.teaching_role.order_by_role.first.id.to_s
5051

5152
unless work_history_ids.include?(most_recent_work_history_id)
5253
errors.add(:work_history_ids, :most_recent_not_selected)

spec/forms/assessor_interface/select_work_histories_form_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,48 @@
5252

5353
it { is_expected.not_to be_valid }
5454
end
55+
56+
context "when there is a most recent other England work history" do
57+
let!(:work_history_3) do
58+
create(
59+
:work_history,
60+
:completed,
61+
:other_england_role,
62+
application_form:,
63+
start_date: Date.new(2024, 1, 1),
64+
)
65+
end
66+
67+
it do
68+
expect(subject).to validate_inclusion_of(:work_history_ids).in_array(
69+
[work_history_1.id.to_s, work_history_2.id.to_s],
70+
)
71+
end
72+
73+
context "with other England work history being submitted" do
74+
let(:work_history_ids) do
75+
[
76+
work_history_1.id.to_s,
77+
work_history_2.id.to_s,
78+
work_history_3.id.to_s,
79+
]
80+
end
81+
82+
it { is_expected.not_to be_valid }
83+
end
84+
85+
context "with latest teaching work history" do
86+
let(:work_history_ids) { [work_history_1.id.to_s] }
87+
88+
it { is_expected.to be_valid }
89+
end
90+
91+
context "without latest teaching work history" do
92+
let(:work_history_ids) { [work_history_2.id.to_s] }
93+
94+
it { is_expected.not_to be_valid }
95+
end
96+
end
5597
end
5698

5799
describe "#save" do

0 commit comments

Comments
 (0)