2018-09-04 18:19:29 +02:00
|
|
|
describe CommentaireService do
|
2019-06-25 17:12:44 +02:00
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
2018-09-04 18:19:29 +02:00
|
|
|
describe '.create' do
|
2019-06-20 09:58:53 +02:00
|
|
|
let(:dossier) { create :dossier, :en_construction }
|
2018-09-04 18:19:29 +02:00
|
|
|
let(:sender) { dossier.user }
|
|
|
|
let(:body) { 'Contenu du message.' }
|
|
|
|
let(:file) { nil }
|
|
|
|
|
2019-06-25 17:12:44 +02:00
|
|
|
subject(:commentaire) { CommentaireService.build(sender, dossier, { body: body, piece_jointe: file }) }
|
2018-09-04 18:19:29 +02:00
|
|
|
|
|
|
|
it 'creates a new valid commentaire' do
|
|
|
|
expect(commentaire.email).to eq sender.email
|
|
|
|
expect(commentaire.dossier).to eq dossier
|
2018-11-29 15:00:26 +01:00
|
|
|
expect(commentaire.body).to eq 'Contenu du message.'
|
2019-06-25 17:12:44 +02:00
|
|
|
expect(commentaire.piece_jointe.attached?).to be_falsey
|
2018-09-04 18:19:29 +02:00
|
|
|
expect(commentaire).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the body is empty' do
|
|
|
|
let(:body) { nil }
|
|
|
|
|
|
|
|
it 'creates an invalid comment' do
|
|
|
|
expect(commentaire.body).to be nil
|
|
|
|
expect(commentaire.valid?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it has a file' do
|
2020-06-30 17:53:54 +02:00
|
|
|
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
|
2018-09-04 18:19:29 +02:00
|
|
|
|
2021-03-11 14:42:57 +01:00
|
|
|
it 'attaches the file' do
|
|
|
|
expect(commentaire.piece_jointe.attached?).to be_truthy
|
2018-09-04 18:19:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|