-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This moves the specs to the correct structure and flattens their structure to apply the spec related to rubocop rules correctly.
- Loading branch information
Showing
73 changed files
with
2,197 additions
and
2,285 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
spec/commands/concerns/decidim/privacy/reply_to_conversation_extensions_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe Decidim::Privacy::ReplyToConversationExtensions do | ||
let(:organization) { create(:organization) } | ||
let!(:user) { create(:user, :admin, :confirmed, organization: organization) } | ||
let!(:receiver) { create(:user, :confirmed, organization: organization) } | ||
|
||
let(:form_params) do | ||
{ body: "Hello there receiver!" } | ||
end | ||
|
||
let(:form) do | ||
Decidim::Messaging::MessageForm.from_params( | ||
form_params | ||
).with_context( | ||
current_user: user, | ||
sender: user | ||
) | ||
end | ||
|
||
let(:conversation) do | ||
Decidim::Messaging::Conversation.start!( | ||
originator: user, | ||
interlocutors: [receiver], | ||
body: "Initial message" | ||
) | ||
end | ||
|
||
let!(:participationuser) { Decidim::Messaging::Participation.new(decidim_conversation_id: conversation.id, decidim_participant_id: user.id) } | ||
let!(:participationreceiver) { Decidim::Messaging::Participation.new(decidim_conversation_id: conversation.id, decidim_participant_id: receiver.id) } | ||
|
||
let(:command) { Decidim::Messaging::ReplyToConversation.new(conversation, form) } | ||
|
||
before do | ||
user.update(published_at: Time.current) | ||
end | ||
|
||
context "when public user with messages enabled" do | ||
it "broadcasts ok" do | ||
receiver.update(published_at: Time.current) | ||
|
||
expect do | ||
command.call | ||
end.to broadcast(:ok) | ||
end | ||
end | ||
|
||
context "when a private user" do | ||
it "broadcasts invalid" do | ||
expect do | ||
command.call | ||
end.to broadcast(:invalid) | ||
end | ||
end | ||
|
||
context "when public user with messages disabled" do | ||
it "broadcasts invalid" do | ||
receiver.update(published_at: Time.current, allow_private_messaging: false) | ||
|
||
expect do | ||
command.call | ||
end.to broadcast(:invalid) | ||
end | ||
end | ||
|
||
context "when multiple participants in a initialized conversation" do | ||
let(:participant) { create(:user, :confirmed, organization: organization) } | ||
let(:conversation) do | ||
Decidim::Messaging::Conversation.start!( | ||
originator: user, | ||
interlocutors: [receiver, participant], | ||
body: "Initial message" | ||
) | ||
end | ||
|
||
let(:form_params) do | ||
{ body: "Hello there people!" } | ||
end | ||
|
||
context "when 1 participant has private messaging disabled" do | ||
it "broadcasts ok" do | ||
receiver.update(published_at: Time.current, allow_private_messaging: false) | ||
participant.update(published_at: Time.current) | ||
|
||
expect do | ||
command.call | ||
end.to broadcast(:ok) | ||
end | ||
end | ||
|
||
context "when 1 participant is private" do | ||
it "broadcasts ok" do | ||
participant.update(published_at: Time.current) | ||
|
||
expect do | ||
command.call | ||
end.to broadcast(:ok) | ||
end | ||
end | ||
end | ||
end |
92 changes: 92 additions & 0 deletions
92
spec/commands/concerns/decidim/privacy/start_conversation_extensions_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe Decidim::Privacy::StartConversationExtensions do | ||
let(:organization) { create(:organization) } | ||
let!(:user) { create(:user, :admin, :confirmed, organization: organization) } | ||
let!(:receiver) { create(:user, :confirmed, organization: organization) } | ||
|
||
let(:form_params) do | ||
{ | ||
body: "Hello there receiver!", | ||
recipient_id: receiver.id | ||
} | ||
end | ||
|
||
let(:form) do | ||
Decidim::Messaging::ConversationForm.from_params( | ||
form_params | ||
).with_context( | ||
current_user: user, | ||
sender: user | ||
) | ||
end | ||
|
||
let(:command) { Decidim::Messaging::StartConversation.new(form) } | ||
|
||
before do | ||
user.update(published_at: Time.current) | ||
end | ||
|
||
context "when public user with messages enabled" do | ||
it "broadcasts ok" do | ||
receiver.update(published_at: Time.current) | ||
|
||
expect do | ||
command.call | ||
end.to broadcast(:ok) | ||
end | ||
end | ||
|
||
context "when a private user" do | ||
it "broadcasts invalid" do | ||
expect do | ||
command.call | ||
end.to broadcast(:invalid) | ||
end | ||
end | ||
|
||
context "when public user with messages disabled" do | ||
it "broadcasts invalid" do | ||
receiver.update(published_at: Time.current, allow_private_messaging: false) | ||
|
||
expect do | ||
command.call | ||
end.to broadcast(:invalid) | ||
end | ||
end | ||
|
||
context "when starting a conversation to multiple participants" do | ||
let(:participant) { create(:user, :confirmed, organization: organization) } | ||
|
||
let(:form_params) do | ||
{ | ||
body: "Hello there people!", | ||
recipient_id: [receiver.id, participant.id] | ||
} | ||
end | ||
|
||
context "when 1 participant has private messaging disabled" do | ||
it "broadcasts invalid" do | ||
receiver.update(published_at: Time.current, allow_private_messaging: false) | ||
participant.update(published_at: Time.current) | ||
|
||
expect do | ||
command.call | ||
end.to broadcast(:invalid) | ||
end | ||
end | ||
|
||
context "when 1 participant is private" do | ||
it "broadcasts invalid" do | ||
receiver.update(published_at: Time.current) | ||
command.call | ||
|
||
expect do | ||
command.call | ||
end.to broadcast(:invalid) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.