Merge branch 'notifications' into develop

This commit is contained in:
Xavier J 2016-12-27 16:03:33 +01:00
commit 12edb06a02
63 changed files with 719 additions and 72 deletions

View file

@ -36,6 +36,10 @@ describe Backoffice::CommentairesController, type: :controller do
expect { subject }.to change(Follow, :count).by(0)
end
end
it 'Internal notification is not create' do
expect { subject }.to change(Notification, :count).by (0)
end
end
context 'when document is upload whith a commentaire', vcr: {cassette_name: 'controllers_backoffice_commentaires_controller_doc_upload_with_comment'} do
@ -54,6 +58,10 @@ describe Backoffice::CommentairesController, type: :controller do
subject
end
it 'Internal notification is not create' do
expect { subject }.to change(Notification, :count).by (0)
end
describe 'piece justificative created' do
let(:pj) { PieceJustificative.last }

View file

@ -38,34 +38,40 @@ describe Backoffice::DossiersController, type: :controller do
end
describe 'GET #show' do
subject { get :show, params: {id: dossier_id} }
context 'gestionnaire is connected' do
before do
sign_in gestionnaire
end
it 'returns http success' do
get :show, params: {id: dossier_id}
expect(response).to have_http_status(200)
expect(subject).to have_http_status(200)
end
describe 'all notifications unread are changed' do
it do
expect(Notification).to receive(:where).with(dossier_id: dossier_id).and_return(Notification::ActiveRecord_Relation)
expect(Notification::ActiveRecord_Relation).to receive(:update_all).with(already_read: true).and_return(true)
subject
end
end
context ' when dossier is archived' do
before do
get :show, params: {id: dossier_archived.id}
end
it { expect(response).to redirect_to('/backoffice') }
let(:dossier_id) { dossier_archived }
it { expect(subject).to redirect_to('/backoffice') }
end
context 'when dossier id does not exist' do
before do
get :show, params: {id: bad_dossier_id}
end
it { expect(response).to redirect_to('/backoffice') }
let(:dossier_id) { bad_dossier_id }
it { expect(subject).to redirect_to('/backoffice') }
end
end
context 'gestionnaire does not connected but dossier id is correct' do
subject { get :show, params: {id: dossier_id} }
it { is_expected.to redirect_to('/gestionnaires/sign_in') }
end
end

View file

@ -28,6 +28,10 @@ describe Users::CommentairesController, type: :controller do
subject
end
it 'Notification interne is create' do
expect { subject }.to change(Notification, :count).by (1)
end
end
context 'when document is upload whith a commentaire', vcr: {cassette_name: 'controllers_sers_commentaires_controller_upload_doc'} do

View file

@ -145,6 +145,13 @@ shared_examples 'description_controller_spec' do
end
context 'Quand la procédure accepte les CERFA' do
subject { post :create, params: {dossier_id: dossier_id,
cerfa_pdf: cerfa_pdf} }
it 'Notification interne is create' do
expect { subject }.to change(Notification, :count).by (1)
end
context 'Sauvegarde du CERFA PDF', vcr: {cassette_name: 'controllers_users_description_controller_save_cerfa'} do
before do
post :create, params: {dossier_id: dossier_id,
@ -292,6 +299,10 @@ shared_examples 'description_controller_spec' do
sign_in guest
end
it 'Notification interne is create' do
expect { subject }.to change(Notification, :count).by (1)
end
context 'when PJ have no documents' do
it { expect(dossier.pieces_justificatives.size).to eq 0 }

View file

@ -7,7 +7,7 @@ describe Users::DescriptionController, type: :controller, vcr: {cassette_name: '
let(:invite_by_user) { create :user, email: 'invite@plop.com' }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true) }
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user) }
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: 'initiated') }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10000 }

View file

@ -1,4 +1,4 @@
RSpec.describe Users::Dossiers::InvitesController, type: :controller do
describe Users::Dossiers::InvitesController, type: :controller do
describe '#authenticate_user!' do
let(:user) { create :user }
let(:invite) { create :invite }

View file

@ -82,6 +82,10 @@ describe Users::RecapitulatifController, type: :controller do
dossier.validated!
post :submit, params: {dossier_id: dossier.id}
end
it 'Internal notification is created' do
expect(Notification.where(dossier_id: dossier.id, type_notif: 'submitted').first).not_to be_nil
end
end
end
end

View file

@ -50,10 +50,12 @@ describe DossiersListFacades do
it { expect(subject.first[:id]).to eq procedure.id }
it { expect(subject.first[:libelle]).to eq procedure.libelle }
it { expect(subject.first[:unread_notifications]).to eq 0 }
it { expect(subject.last[:id]).to eq procedure_2.id }
it { expect(subject.last[:libelle]).to eq procedure_2.libelle }
it { expect(subject.last[:unread_notifications]).to eq 0 }
end
describe '#active_filter?' do

View file

@ -1,5 +1,11 @@
FactoryGirl.define do
factory :commentaire do
body 'plop'
before(:create) do |commentaire, _evaluator|
unless commentaire.dossier
commentaire.dossier = create :dossier
end
end
end
end

View file

@ -1,5 +1,5 @@
FactoryGirl.define do
sequence(:gestionnaire_email) { |n| "plop#{n}@plop.com" }
sequence(:gestionnaire_email) { |n| "gest#{n}@plop.com" }
factory :gestionnaire do
email { generate(:gestionnaire_email) }
password 'password'

View file

@ -0,0 +1,12 @@
FactoryGirl.define do
factory :notification do
type_notif 'commentaire'
liste []
before(:create) do |notification, _evaluator|
unless notification.dossier
notification.dossier = create :dossier
end
end
end
end

View file

@ -5,7 +5,6 @@ describe Dossier do
describe 'database columns' do
it { is_expected.to have_db_column(:autorisation_donnees) }
it { is_expected.to have_db_column(:nom_projet) }
it { is_expected.to have_db_column(:created_at) }
it { is_expected.to have_db_column(:updated_at) }
it { is_expected.to have_db_column(:state) }
@ -27,6 +26,7 @@ describe Dossier do
it { is_expected.to belong_to(:user) }
it { is_expected.to have_many(:invites) }
it { is_expected.to have_many(:follows) }
it { is_expected.to have_many(:notifications) }
end
describe 'delegation' do

View file

@ -208,4 +208,40 @@ describe Gestionnaire, type: :model do
expect(admin.valid_password?('super secret')).to be(true)
end
end
describe '#notifications_for' do
subject { gestionnaire.notifications_for procedure }
context 'when gestionnaire follow any dossier' do
it { is_expected.to eq 0 }
it { expect(gestionnaire.follows.count).to eq 0 }
it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject)
subject }
end
context 'when gestionnaire follow any dossier into the procedure past in params' do
before do
create :follow, gestionnaire: gestionnaire, dossier: create(:dossier, procedure: procedure_2)
end
it { is_expected.to eq 0 }
it { expect(gestionnaire.follows.count).to eq 1 }
it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject)
subject }
end
context 'when gestionnaire follow a dossier with a notification into the procedure past in params' do
let(:dossier) { create(:dossier, procedure: procedure, state: 'initiated') }
before do
create :follow, gestionnaire: gestionnaire, dossier: dossier
create :notification, dossier: dossier
end
it { is_expected.to eq 1 }
it { expect(gestionnaire.follows.count).to eq 1 }
it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:inject)
subject }
end
end
end

View file

@ -0,0 +1,11 @@
require 'spec_helper'
describe Notification do
it { is_expected.to have_db_column(:already_read) }
it { is_expected.to have_db_column(:liste) }
it { is_expected.to have_db_column(:type_notif) }
it { is_expected.to have_db_column(:created_at) }
it { is_expected.to have_db_column(:updated_at) }
it { is_expected.to belong_to(:dossier) }
end

View file

@ -0,0 +1,29 @@
require 'spec_helper'
describe NotificationService do
describe '.notify' do
let(:dossier) { create :dossier }
let(:service) { described_class.new type_notif, dossier.id }
subject { service.notify }
context 'when is the first notification for dossier_id and type_notif and alread_read is false' do
let(:type_notif) { 'commentaire' }
it { expect { subject }.to change(Notification, :count).by (1) }
context 'when is not the first notification' do
before do
create :notification, dossier: dossier, type_notif: type_notif
end
it { expect { subject }.to change(Notification, :count).by (0) }
end
end
end
describe 'text_for_notif' do
pending
end
end

View file

@ -41,7 +41,7 @@ Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: true, port: 44_678 + ENV['TEST_ENV_NUMBER'].to_i, phantomjs_options: ['--proxy-type=none'], timeout: 180)
end
#ActiveSupport::Deprecation.silenced = true
ActiveSupport::Deprecation.silenced = true
Capybara.default_max_wait_time = 1

View file

@ -29,6 +29,6 @@ describe 'admin/gestionnaires/index.html.haml', type: :view do
array: true))
render
end
it { expect(rendered).to match(/plop\d+@plop.com/) }
it { expect(rendered).to match(/gest\d+@plop.com/) }
end
end