Skip to content

Commit

Permalink
Fix the namespaces in the specs
Browse files Browse the repository at this point in the history
This moves the specs to the correct structure and flattens their
structure to apply the spec related to rubocop rules correctly.
  • Loading branch information
ahukkanen committed Sep 25, 2023
1 parent 8c7c624 commit 5bc9e37
Show file tree
Hide file tree
Showing 73 changed files with 2,197 additions and 2,285 deletions.
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
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
27 changes: 0 additions & 27 deletions spec/commands/concerns/endorse_resource_spec.rb

This file was deleted.

107 changes: 0 additions & 107 deletions spec/commands/concerns/reply_to_conversation_spec.rb

This file was deleted.

Loading

0 comments on commit 5bc9e37

Please sign in to comment.