2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
|
2024-02-21 03:01:24 +01:00
|
|
|
context 'when it has multiple files' do
|
|
|
|
let(:files) do
|
|
|
|
[
|
|
|
|
fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
commentaire.piece_jointe.attach(files)
|
|
|
|
end
|
2018-09-04 18:19:29 +02:00
|
|
|
|
2024-02-21 03:01:24 +01:00
|
|
|
it 'attaches the files' do
|
2021-03-11 14:42:57 +01:00
|
|
|
expect(commentaire.piece_jointe.attached?).to be_truthy
|
2024-02-21 03:01:24 +01:00
|
|
|
expect(commentaire.piece_jointe.count).to eq(1)
|
2018-09-04 18:19:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|