2021-12-08 11:23:03 +01:00
|
|
|
RSpec.describe Types::DossierType, type: :graphql do
|
|
|
|
let(:query) { DOSSIER_QUERY }
|
|
|
|
let(:context) { { internal_use: true } }
|
|
|
|
let(:variables) { {} }
|
|
|
|
|
|
|
|
subject { API::V2::Schema.execute(query, variables: variables, context: context) }
|
|
|
|
|
|
|
|
let(:data) { subject['data'].deep_symbolize_keys }
|
|
|
|
let(:errors) { subject['errors'].deep_symbolize_keys }
|
|
|
|
|
|
|
|
describe 'dossier with attestation' do
|
|
|
|
let(:dossier) { create(:dossier, :accepte, :with_attestation) }
|
|
|
|
let(:query) { DOSSIER_WITH_ATTESTATION_QUERY }
|
|
|
|
let(:variables) { { number: dossier.id } }
|
|
|
|
|
|
|
|
it { expect(data[:dossier][:attestation]).not_to be_nil }
|
2022-03-10 18:19:31 +01:00
|
|
|
it { expect(data[:dossier][:traitements]).to eq([{ state: 'accepte' }]) }
|
|
|
|
it { expect(data[:dossier][:dateExpiration]).not_to be_nil }
|
2021-12-08 11:23:03 +01:00
|
|
|
|
|
|
|
context 'when attestation is nil' do
|
|
|
|
before do
|
|
|
|
dossier.update(attestation: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(data[:dossier][:attestation]).to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-11 22:35:51 +02:00
|
|
|
describe 'dossier with champs' do
|
2022-08-04 11:39:07 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :communes }, { type: :address }]) }
|
2022-04-11 22:35:51 +02:00
|
|
|
let(:dossier) { create(:dossier, :accepte, :with_populated_champs, procedure: procedure) }
|
|
|
|
let(:query) { DOSSIER_WITH_CHAMPS_QUERY }
|
|
|
|
let(:variables) { { number: dossier.id } }
|
2022-04-12 19:02:59 +02:00
|
|
|
let(:address) do
|
|
|
|
{
|
|
|
|
"type" => "housenumber",
|
|
|
|
"label" => "33 Rue Rébeval 75019 Paris",
|
|
|
|
"city_code" => "75119",
|
|
|
|
"city_name" => "Paris",
|
|
|
|
"postal_code" => "75019",
|
|
|
|
"region_code" => "11",
|
|
|
|
"region_name" => "Île-de-France",
|
|
|
|
"street_name" => "Rue Rébeval",
|
|
|
|
"street_number" => "33",
|
|
|
|
"street_address" => "33 Rue Rébeval",
|
|
|
|
"department_code" => "75",
|
|
|
|
"department_name" => "Paris"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
dossier.champs.second.update(data: address)
|
|
|
|
end
|
2022-04-11 22:35:51 +02:00
|
|
|
|
|
|
|
it { expect(data[:dossier][:champs][0][:__typename]).to eq "CommuneChamp" }
|
|
|
|
it { expect(data[:dossier][:champs][1][:__typename]).to eq "AddressChamp" }
|
|
|
|
end
|
|
|
|
|
2022-10-14 10:46:09 +02:00
|
|
|
describe 'dossier with conditional champs' do
|
|
|
|
include Logic
|
|
|
|
let(:stable_id) { 1234 }
|
|
|
|
let(:condition) { ds_eq(champ_value(stable_id), constant(true)) }
|
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :checkbox, stable_id: stable_id }, { type: :text, condition: condition }]) }
|
|
|
|
let(:dossier) { create(:dossier, :accepte, :with_populated_champs, procedure: procedure) }
|
|
|
|
let(:query) { DOSSIER_WITH_CHAMPS_QUERY }
|
|
|
|
let(:variables) { { number: dossier.id } }
|
|
|
|
let(:checkbox_value) { 'on' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
dossier.champs.first.update(value: checkbox_value)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when checkbox is true' do
|
|
|
|
it { expect(data[:dossier][:champs].size).to eq 2 }
|
|
|
|
it { expect(data[:dossier][:champs][0][:__typename]).to eq "CheckboxChamp" }
|
|
|
|
it { expect(data[:dossier][:champs][1][:__typename]).to eq "TextChamp" }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when checkbox is false' do
|
|
|
|
let(:checkbox_value) { 'off' }
|
|
|
|
it { expect(data[:dossier][:champs].size).to eq 1 }
|
|
|
|
it { expect(data[:dossier][:champs][0][:__typename]).to eq "CheckboxChamp" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-04 11:34:47 +02:00
|
|
|
describe 'dossier with user' do
|
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
|
|
|
let(:query) { DOSSIER_WITH_USAGER_QUERY }
|
|
|
|
let(:variables) { { number: dossier.id } }
|
|
|
|
|
|
|
|
it { expect(data[:dossier][:usager]).not_to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'dossier with deleted user' do
|
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
|
|
|
let(:query) { DOSSIER_WITH_USAGER_QUERY }
|
|
|
|
let(:variables) { { number: dossier.id } }
|
|
|
|
let(:email) { dossier.user.email }
|
|
|
|
|
|
|
|
before do
|
|
|
|
dossier.update(user_id: nil, deleted_user_email_never_send: email)
|
|
|
|
end
|
|
|
|
|
|
|
|
it {
|
|
|
|
expect(data[:dossier][:usager]).not_to be_nil
|
|
|
|
expect(data[:dossier][:usager][:email]).to eq(email)
|
|
|
|
expect(data[:dossier][:usager][:id]).to eq('<deleted>')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-10-31 10:37:40 +01:00
|
|
|
describe 'dossier with linked dossier' do
|
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :dossier_link }]) }
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) }
|
|
|
|
let(:linked_dossier) { create(:dossier, :en_construction) }
|
|
|
|
let(:query) { DOSSIER_WITH_LINKED_DOSIER_QUERY }
|
|
|
|
let(:variables) { { number: dossier.id } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
dossier.champs.first.update(value: linked_dossier.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'en_construction' do
|
|
|
|
it {
|
|
|
|
expect(data[:dossier][:champs].first).not_to be_nil
|
|
|
|
expect(data[:dossier][:champs].first[:dossier][:id]).to eq(linked_dossier.to_typed_id)
|
|
|
|
expect(data[:dossier][:champs].first[:dossier][:state]).to eq('en_construction')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'brouillon' do
|
|
|
|
let(:linked_dossier) { create(:dossier, :brouillon) }
|
|
|
|
|
|
|
|
it {
|
|
|
|
expect(data[:dossier][:champs].first).not_to be_nil
|
|
|
|
expect(data[:dossier][:champs].first[:dossier]).to be_nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-01 14:51:34 +01:00
|
|
|
describe 'dossier with repetition' do
|
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :repetition, children: [{ libelle: 'Nom' }, { libelle: 'Age' }] }]) }
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) }
|
|
|
|
let(:linked_dossier) { create(:dossier, :en_construction) }
|
|
|
|
let(:query) { DOSSIER_WITH_REPETITION_QUERY }
|
|
|
|
let(:variables) { { number: dossier.id } }
|
|
|
|
|
|
|
|
let(:rows) do
|
|
|
|
dossier.champs.first.rows.map do |champs|
|
|
|
|
{ champs: champs.map { { id: _1.to_typed_id } } }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it {
|
|
|
|
expect(data[:dossier][:champs].first).not_to be_nil
|
|
|
|
expect(data[:dossier][:champs].first[:rows]).not_to be_nil
|
|
|
|
expect(data[:dossier][:champs].first[:rows].size).to eq(2)
|
|
|
|
expect(data[:dossier][:champs].first[:rows]).to eq(rows)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-12-08 11:23:03 +01:00
|
|
|
DOSSIER_QUERY = <<-GRAPHQL
|
|
|
|
query($number: Int!) {
|
|
|
|
dossier(number: $number) {
|
|
|
|
id
|
|
|
|
number
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
|
|
|
|
2022-05-04 11:34:47 +02:00
|
|
|
DOSSIER_WITH_USAGER_QUERY = <<-GRAPHQL
|
|
|
|
query($number: Int!) {
|
|
|
|
dossier(number: $number) {
|
|
|
|
id
|
|
|
|
number
|
|
|
|
usager {
|
|
|
|
id
|
|
|
|
email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
|
|
|
|
2021-12-08 11:23:03 +01:00
|
|
|
DOSSIER_WITH_ATTESTATION_QUERY = <<-GRAPHQL
|
|
|
|
query($number: Int!) {
|
|
|
|
dossier(number: $number) {
|
|
|
|
attestation {
|
|
|
|
url
|
|
|
|
}
|
2022-03-10 18:19:31 +01:00
|
|
|
traitements {
|
|
|
|
state
|
|
|
|
}
|
|
|
|
dateExpiration
|
2021-12-08 11:23:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
2022-04-11 22:35:51 +02:00
|
|
|
|
|
|
|
DOSSIER_WITH_CHAMPS_QUERY = <<-GRAPHQL
|
|
|
|
query($number: Int!) {
|
|
|
|
dossier(number: $number) {
|
|
|
|
id
|
|
|
|
number
|
|
|
|
champs {
|
|
|
|
id
|
|
|
|
label
|
|
|
|
__typename
|
|
|
|
...CommuneChampFragment
|
|
|
|
... on AddressChamp {
|
|
|
|
address {
|
|
|
|
...AddressFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fragment CommuneChampFragment on CommuneChamp {
|
|
|
|
commune {
|
|
|
|
...CommuneFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fragment CommuneFragment on Commune {
|
|
|
|
code
|
|
|
|
}
|
|
|
|
fragment AddressFragment on Address {
|
2022-04-12 19:02:59 +02:00
|
|
|
type
|
|
|
|
label
|
2022-04-11 22:35:51 +02:00
|
|
|
cityName
|
2022-04-12 19:02:59 +02:00
|
|
|
cityCode
|
|
|
|
streetName
|
|
|
|
streetNumber
|
2022-04-11 22:35:51 +02:00
|
|
|
}
|
|
|
|
GRAPHQL
|
2022-10-31 10:37:40 +01:00
|
|
|
|
|
|
|
DOSSIER_WITH_LINKED_DOSIER_QUERY = <<-GRAPHQL
|
|
|
|
query($number: Int!) {
|
|
|
|
dossier(number: $number) {
|
|
|
|
champs {
|
|
|
|
id
|
|
|
|
... on DossierLinkChamp {
|
|
|
|
dossier {
|
|
|
|
id
|
|
|
|
state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
2022-11-01 14:51:34 +01:00
|
|
|
|
|
|
|
DOSSIER_WITH_REPETITION_QUERY = <<-GRAPHQL
|
|
|
|
query($number: Int!) {
|
|
|
|
dossier(number: $number) {
|
|
|
|
champs {
|
|
|
|
id
|
|
|
|
... on RepetitionChamp {
|
|
|
|
rows {
|
|
|
|
champs { id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
2021-12-08 11:23:03 +01:00
|
|
|
end
|