bug(instructeurs/dossiers#update_annotations): should works if a champ_public is invalid
This commit is contained in:
parent
46c5830306
commit
b07bbfa455
1 changed files with 109 additions and 74 deletions
|
@ -940,14 +940,18 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
|
|
||||||
describe "#update_annotations" do
|
describe "#update_annotations" do
|
||||||
let(:procedure) do
|
let(:procedure) do
|
||||||
create(:procedure, :published, types_de_champ_private: [
|
create(:procedure, :published, types_de_champ_public:, types_de_champ_private:, instructeurs: instructeurs)
|
||||||
|
end
|
||||||
|
let(:types_de_champ_private) do
|
||||||
|
[
|
||||||
{ type: :multiple_drop_down_list },
|
{ type: :multiple_drop_down_list },
|
||||||
{ type: :linked_drop_down_list },
|
{ type: :linked_drop_down_list },
|
||||||
{ type: :datetime },
|
{ type: :datetime },
|
||||||
{ type: :repetition, children: [{}] },
|
{ type: :repetition, children: [{}] },
|
||||||
{ type: :drop_down_list, options: [:a, :b, :other] }
|
{ type: :drop_down_list, options: [:a, :b, :other] }
|
||||||
], instructeurs: instructeurs)
|
]
|
||||||
end
|
end
|
||||||
|
let(:types_de_champ_public) { [] }
|
||||||
let(:dossier) { create(:dossier, :en_construction, :with_populated_annotations, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_construction, :with_populated_annotations, procedure: procedure) }
|
||||||
let(:another_instructeur) { create(:instructeur) }
|
let(:another_instructeur) { create(:instructeur) }
|
||||||
let(:now) { Time.zone.parse('01/01/2100') }
|
let(:now) { Time.zone.parse('01/01/2100') }
|
||||||
|
@ -958,24 +962,105 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
let(:champ_repetition) { dossier.champs_private.fourth }
|
let(:champ_repetition) { dossier.champs_private.fourth }
|
||||||
let(:champ_drop_down_list) { dossier.champs_private.fifth }
|
let(:champ_drop_down_list) { dossier.champs_private.fifth }
|
||||||
|
|
||||||
before do
|
context 'when no invalid champs_public' do
|
||||||
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :annotations_privees)
|
context "with new values for champs_private" do
|
||||||
another_instructeur.follow(dossier)
|
before do
|
||||||
Timecop.freeze(now)
|
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :annotations_privees)
|
||||||
patch :update_annotations, params: params, format: :turbo_stream
|
another_instructeur.follow(dossier)
|
||||||
|
Timecop.freeze(now)
|
||||||
|
patch :update_annotations, params: params, format: :turbo_stream
|
||||||
|
|
||||||
champ_multiple_drop_down_list.reload
|
champ_multiple_drop_down_list.reload
|
||||||
champ_linked_drop_down_list.reload
|
champ_linked_drop_down_list.reload
|
||||||
champ_datetime.reload
|
champ_datetime.reload
|
||||||
champ_repetition.reload
|
champ_repetition.reload
|
||||||
champ_drop_down_list.reload
|
champ_drop_down_list.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
Timecop.return
|
||||||
|
end
|
||||||
|
let(:params) do
|
||||||
|
{
|
||||||
|
procedure_id: procedure.id,
|
||||||
|
dossier_id: dossier.id,
|
||||||
|
dossier: {
|
||||||
|
champs_private_attributes: {
|
||||||
|
'0': {
|
||||||
|
id: champ_multiple_drop_down_list.id,
|
||||||
|
value: ['', 'val1', 'val2']
|
||||||
|
},
|
||||||
|
'1': {
|
||||||
|
id: champ_datetime.id,
|
||||||
|
value: '2019-12-21T13:17'
|
||||||
|
},
|
||||||
|
'2': {
|
||||||
|
id: champ_linked_drop_down_list.id,
|
||||||
|
primary_value: 'primary',
|
||||||
|
secondary_value: 'secondary'
|
||||||
|
},
|
||||||
|
'3': {
|
||||||
|
id: champ_repetition.champs.first.id,
|
||||||
|
value: 'text'
|
||||||
|
},
|
||||||
|
'4': {
|
||||||
|
id: champ_drop_down_list.id,
|
||||||
|
value: '__other__',
|
||||||
|
value_other: 'other value'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(champ_multiple_drop_down_list.value).to eq('["val1","val2"]')
|
||||||
|
expect(champ_linked_drop_down_list.primary_value).to eq('primary')
|
||||||
|
expect(champ_linked_drop_down_list.secondary_value).to eq('secondary')
|
||||||
|
expect(champ_datetime.value).to eq(Time.zone.parse('2019-12-21T13:17:00').iso8601)
|
||||||
|
expect(champ_repetition.champs.first.value).to eq('text')
|
||||||
|
expect(champ_drop_down_list.value).to eq('other value')
|
||||||
|
expect(dossier.reload.last_champ_private_updated_at).to eq(now)
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
}
|
||||||
|
|
||||||
|
it 'updates the annotations' do
|
||||||
|
Timecop.travel(now + 1.hour)
|
||||||
|
expect(instructeur.followed_dossiers.with_notifications).to eq([])
|
||||||
|
expect(another_instructeur.followed_dossiers.with_notifications).to eq([dossier.reload])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "without new values for champs_private" do
|
||||||
|
let(:params) do
|
||||||
|
{
|
||||||
|
procedure_id: procedure.id,
|
||||||
|
dossier_id: dossier.id,
|
||||||
|
dossier: {
|
||||||
|
champs_private_attributes: {},
|
||||||
|
champs_public_attributes: {
|
||||||
|
'0': {
|
||||||
|
id: champ_multiple_drop_down_list.id,
|
||||||
|
value: ['', 'val1', 'val2']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(dossier.reload.last_champ_private_updated_at).to eq(nil)
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
context 'with invalid champs_public (DecimalNumberChamp)' do
|
||||||
Timecop.return
|
let(:types_de_champ_public) do
|
||||||
end
|
[
|
||||||
|
{ type: :decimal_number }
|
||||||
context "with new values for champs_private" do
|
]
|
||||||
|
end
|
||||||
let(:params) do
|
let(:params) do
|
||||||
{
|
{
|
||||||
procedure_id: procedure.id,
|
procedure_id: procedure.id,
|
||||||
|
@ -983,72 +1068,22 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
dossier: {
|
dossier: {
|
||||||
champs_private_attributes: {
|
champs_private_attributes: {
|
||||||
'0': {
|
'0': {
|
||||||
id: champ_multiple_drop_down_list.id,
|
|
||||||
value: ['', 'val1', 'val2']
|
|
||||||
},
|
|
||||||
'1': {
|
|
||||||
id: champ_datetime.id,
|
id: champ_datetime.id,
|
||||||
value: '2019-12-21T13:17'
|
value: '2024-03-30T07:03'
|
||||||
},
|
|
||||||
'2': {
|
|
||||||
id: champ_linked_drop_down_list.id,
|
|
||||||
primary_value: 'primary',
|
|
||||||
secondary_value: 'secondary'
|
|
||||||
},
|
|
||||||
'3': {
|
|
||||||
id: champ_repetition.champs.first.id,
|
|
||||||
value: 'text'
|
|
||||||
},
|
|
||||||
'4': {
|
|
||||||
id: champ_drop_down_list.id,
|
|
||||||
value: '__other__',
|
|
||||||
value_other: 'other value'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it {
|
it 'update champs_private' do
|
||||||
expect(champ_multiple_drop_down_list.value).to eq('["val1","val2"]')
|
too_long_float = '3.1415'
|
||||||
expect(champ_linked_drop_down_list.primary_value).to eq('primary')
|
dossier.champs_public.first.update_column(:value, too_long_float)
|
||||||
expect(champ_linked_drop_down_list.secondary_value).to eq('secondary')
|
patch :update_annotations, params: params, format: :turbo_stream
|
||||||
expect(champ_datetime.value).to eq(Time.zone.parse('2019-12-21T13:17:00').iso8601)
|
champ_datetime.reload
|
||||||
expect(champ_repetition.champs.first.value).to eq('text')
|
expect(champ_datetime.value).to eq(Time.zone.parse('2024-03-30T07:03:00').iso8601)
|
||||||
expect(champ_drop_down_list.value).to eq('other value')
|
|
||||||
expect(dossier.reload.last_champ_private_updated_at).to eq(now)
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
}
|
|
||||||
|
|
||||||
it 'updates the annotations' do
|
|
||||||
Timecop.travel(now + 1.hour)
|
|
||||||
expect(instructeur.followed_dossiers.with_notifications).to eq([])
|
|
||||||
expect(another_instructeur.followed_dossiers.with_notifications).to eq([dossier.reload])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "without new values for champs_private" do
|
|
||||||
let(:params) do
|
|
||||||
{
|
|
||||||
procedure_id: procedure.id,
|
|
||||||
dossier_id: dossier.id,
|
|
||||||
dossier: {
|
|
||||||
champs_private_attributes: {},
|
|
||||||
champs_public_attributes: {
|
|
||||||
'0': {
|
|
||||||
id: champ_multiple_drop_down_list.id,
|
|
||||||
value: ['', 'val1', 'val2']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it {
|
|
||||||
expect(dossier.reload.last_champ_private_updated_at).to eq(nil)
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#telecharger_pjs" do
|
describe "#telecharger_pjs" do
|
||||||
|
|
Loading…
Reference in a new issue