start api to display dossier

missing pj, fields, exercices
This commit is contained in:
Tanguy PATTE 2016-01-25 16:08:10 +01:00
parent 514918b2b8
commit dc5ac9807d
8 changed files with 160 additions and 6 deletions

View file

@ -8,7 +8,15 @@ class API::V1::DossiersController < APIController
render json: {}, status: 404
end
def pagination dossiers
def show
procedure = current_administrateur.procedures.find(params[:procedure_id])
dossier = procedure.dossiers.find(params[:id])
render json: dossier, status: 200
rescue ActiveRecord::RecordNotFound => e
render json: {}, status: 404
end
def pagination(dossiers)
{
page: dossiers.current_page,
resultats_par_page: dossiers.per_page,

View file

@ -1,5 +1,11 @@
class DossierSerializer < ActiveModel::Serializer
attributes :id,
:nom_projet,
:updated_at
:description,
:created_at,
:updated_at,
:archived
has_one :entreprise
has_one :etablissement
end

View file

@ -0,0 +1,14 @@
class EntrepriseSerializer < ActiveModel::Serializer
attributes :siren,
:capital_social,
:numero_tva_intracommunautaire,
:forme_juridique,
:forme_juridique_code,
:nom_commercial,
:raison_sociale,
:siret_siege_social,
:code_effectif_entreprise,
:date_creation,
:nom,
:prenom
end

View file

@ -0,0 +1,14 @@
class EtablissementSerializer < ActiveModel::Serializer
attributes :siret,
:siege_social,
:naf,
:libelle_naf,
:adresse,
:numero_voie,
:type_voie,
:nom_voie,
:complement_adresse,
:code_postal,
:localite,
:code_insee_localite
end

View file

@ -86,7 +86,7 @@ Rails.application.routes.draw do
namespace :api do
namespace :v1 do
resources :procedures, only: [:index, :show] do
resources :dossiers, only: [:index]
resources :dossiers, only: [:index, :show]
end
end
end

View file

@ -11,9 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160115135025) do
ActiveRecord::Schema.define(version: 20160120141602) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

View file

@ -69,4 +69,117 @@ describe API::V1::DossiersController do
end
end
end
describe 'GET show' do
let(:response) { get :show, token: admin.api_token, procedure_id: procedure_id, id: dossier_id }
subject { response }
context 'when procedure is not found' do
let(:procedure_id) { 99_999_999 }
let(:dossier_id) { 1 }
it { expect(subject.code).to eq('404') }
end
context 'when procedure exists and does not belong to current admin' do
let(:procedure_id) { wrong_procedure.id }
let(:dossier_id) { 1 }
it { expect(subject.code).to eq('404') }
end
context 'when procedure is found and belongs to current admin' do
context 'when dossier does not exist' do
let(:procedure_id) { procedure.id }
let(:dossier_id) { 99999 }
it { expect(subject.code).to eq('404') }
end
context 'when dossier exists but does not belong to procedure' do
let(:procedure_id) { procedure.id }
let(:dossier) { create(:dossier, :with_entreprise, procedure: wrong_procedure) }
let(:dossier_id) { dossier.id }
it { expect(subject.code).to eq('404') }
end
context 'when dossier exists and belongs to procedure' do
let(:procedure_id) { procedure.id }
let(:date_creation) { Time.local(2008, 9, 1, 10, 5, 0) }
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(response.body, symbolize_names: true) }
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :entreprise, :etablissement] }
subject { body[:dossier] }
it { expect(response.code).to eq('200') }
it { expect(subject[:id]).to eq(dossier.id) }
it { expect(subject[:nom_projet]).to eq(dossier.nom_projet) }
it { expect(subject[:created_at]).to eq('2008-09-01T08:05:00.000Z') }
it { expect(subject[:updated_at]).to eq('2008-09-01T08:05:00.000Z') }
it { expect(subject[:description]).to eq(dossier.description) }
it { expect(subject[:archived]).to eq(dossier.archived) }
it { expect(subject.keys).to match_array(field_list) }
describe 'entreprise' do
let(:field_list) { [
:siren,
:capital_social,
:numero_tva_intracommunautaire,
:forme_juridique,
:forme_juridique_code,
:nom_commercial,
:raison_sociale,
:siret_siege_social,
:code_effectif_entreprise,
:date_creation,
:nom,
:prenom] }
subject { super()[:entreprise]}
it { expect(subject[:siren]).to eq('440117620')}
it { expect(subject[:capital_social]).to eq(537_100_000)}
it { expect(subject[:numero_tva_intracommunautaire]).to eq('FR27440117620')}
it { expect(subject[:forme_juridique]).to eq('SA à conseil d\'administration (s.a.i.)')}
it { expect(subject[:forme_juridique_code]).to eq('5599') }
it { expect(subject[:nom_commercial]).to eq('GRTGAZ') }
it { expect(subject[:raison_sociale]).to eq('GRTGAZ') }
it { expect(subject[:siret_siege_social]).to eq('44011762001530') }
it { expect(subject[:code_effectif_entreprise]).to eq('51') }
it { expect(subject[:date_creation]).to eq(1_004_914_800) }
it { expect(subject.keys).to match_array(field_list) }
end
describe 'etablissement' do
let(:field_list) { [
:siret,
:siege_social,
:naf,
:libelle_naf,
:adresse,
:numero_voie,
:type_voie,
:nom_voie,
:complement_adresse,
:code_postal,
:localite,
:code_insee_localite
] }
subject { super()[:etablissement]}
it { expect(subject[:siret]).to eq('44011762001530') }
it { expect(subject[:siege_social]).to eq(true) }
it { expect(subject[:naf]).to eq('4950Z') }
it { expect(subject[:libelle_naf]).to eq('Transports par conduites') }
it { expect(subject[:adresse]).to eq("GRTGAZ\r IMMEUBLE BORA\r 6 RUE RAOUL NORDLING\r 92270 BOIS COLOMBES\r") }
it { expect(subject[:numero_voie]).to eq('6') }
it { expect(subject[:type_voie]).to eq('RUE') }
it { expect(subject[:nom_voie]).to eq('RAOUL NORDLING') }
it { expect(subject[:complement_adresse]).to eq('IMMEUBLE BORA') }
it { expect(subject[:code_postal]).to eq('92270') }
it { expect(subject[:localite]).to eq('BOIS COLOMBES') }
it { expect(subject[:code_insee_localite]).to eq('92009') }
it { expect(subject.keys).to match_array(field_list) }
end
end
end
end
end

View file

@ -1,6 +1,7 @@
FactoryGirl.define do
factory :dossier do
nom_projet "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger"
description "Ma super description"
state 'draft'
association :user, factory:[:user]