[fix #4181] add service to procedure API (#4287)

API : le service d'une démarche est maintenant exposé
This commit is contained in:
Pierre de La Morinerie 2019-09-10 11:10:48 +02:00 committed by GitHub
commit 19e07b0cbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View file

@ -17,6 +17,7 @@ class ProcedureSerializer < ActiveModel::Serializer
has_many :types_de_champ, serializer: TypeDeChampSerializer
has_many :types_de_champ_private, serializer: TypeDeChampSerializer
has_many :types_de_piece_justificative
belongs_to :service, serializer: ServiceSerializer
def archived_at
object.archived_at&.in_time_zone('UTC')

View file

@ -0,0 +1,9 @@
class ServiceSerializer < ActiveModel::Serializer
attributes :id, :email
attribute :nom, key: :name
attribute :type_organisme, key: :type_organization
attribute :organisme, key: :organization
attribute :telephone, key: :phone
attribute :horaires, key: :schedule
attribute :adresse, key: :address
end

View file

@ -25,7 +25,7 @@ describe API::V1::ProceduresController, type: :controller do
it { is_expected.to have_http_status(200) }
describe 'body' do
let(:procedure) { create(:procedure, :with_type_de_champ, administrateur: admin) }
let(:procedure) { create(:procedure, :with_type_de_champ, :with_service, administrateur: admin) }
let(:response) { get :show, params: { id: procedure.id, token: token } }
subject { JSON.parse(response.body, symbolize_names: true)[:procedure] }
@ -51,6 +51,21 @@ describe API::V1::ProceduresController, type: :controller do
it { expect(subject[:order_place]).to eq(champ.order_place) }
it { expect(subject[:description]).to eq(champ.description) }
end
describe 'service' do
subject { super()[:service] }
let(:service) { procedure.service }
it { expect(subject[:id]).to eq(service.id) }
it { expect(subject[:email]).to eq(service.email) }
it { expect(subject[:name]).to eq(service.nom) }
it { expect(subject[:type_organization]).to eq(service.type_organisme) }
it { expect(subject[:organization]).to eq(service.organisme) }
it { expect(subject[:phone]).to eq(service.telephone) }
it { expect(subject[:schedule]).to eq(service.horaires) }
it { expect(subject[:address]).to eq(service.adresse) }
end
end
end
end