Skip to content

Commit

Permalink
flagged account & disable email env
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Feb 22, 2024
1 parent 3909802 commit 1901b85
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class App < ApplicationRecord
lead_editor_settings

sorted_agents

flagged
]

include InboundAddress
Expand Down
7 changes: 6 additions & 1 deletion app/models/conversation_part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ def enqueue_email_notification
end

def send_constraints?
is_from_auto_message_campaign? || private_note? || is_event_message?
is_from_auto_message_campaign? || private_note? || is_event_message? || email_send_disabled?
end

def email_send_disabled?
app = conversation.app
app.flagged || (app.plan.name == "free" && Chaskiq::Config.get("DISABLE_OUTGOING_EMAILS_FREE_PLAN"))
end

def is_from_auto_message_campaign?
Expand Down
55 changes: 55 additions & 0 deletions spec/models/conversation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@

it "add block message" do
# expect(conversation.events.count).to be == 1
allow_any_instance_of(ConversationPart).to receive(:email_send_disabled?).and_return(false)
expect(conversation.messages.count).to be == 1
expect(EventsChannel).to receive(:broadcast_to)

Expand All @@ -177,6 +178,60 @@
expect(message).to be_persisted
expect(message.message[:blocks]).to be_present
end

it "add block message, disabled emails" do
# expect(conversation.events.count).to be == 1
allow_any_instance_of(ConversationPart).to receive(:email_send_disabled?).and_return(true)
expect(conversation.messages.count).to be == 1
expect(EventsChannel).to receive(:broadcast_to)

message = conversation.messages.last

expect(MessengerEventsChannel).to receive(:broadcast_to).with(
message.broadcast_key,
hash_including(type: "conversations:conversation_part")
)

expect(MessengerEventsChannel).to receive(:broadcast_to).with(
message.broadcast_key,
hash_including(type: "conversations:unreads")
)

expect_any_instance_of(ConversationPart).to_not receive(:enqueue_email_notification)
message = conversation.add_message(
from: app_user,
controls: { a: 1 }
)
expect(message).to be_persisted
expect(message.message[:blocks]).to be_present
end

it "add block message, disabled emails account flagged" do
# expect(conversation.events.count).to be == 1
conversation.app.update(flagged: true)
expect(conversation.messages.count).to be == 1
expect(EventsChannel).to receive(:broadcast_to)

message = conversation.messages.last

expect(MessengerEventsChannel).to receive(:broadcast_to).with(
message.broadcast_key,
hash_including(type: "conversations:conversation_part")
)

expect(MessengerEventsChannel).to receive(:broadcast_to).with(
message.broadcast_key,
hash_including(type: "conversations:unreads")
)

expect_any_instance_of(ConversationPart).to_not receive(:enqueue_email_notification)
message = conversation.add_message(
from: app_user,
controls: { a: 1 }
)
expect(message).to be_persisted
expect(message.message[:blocks]).to be_present
end
end

context "add private message" do
Expand Down

0 comments on commit 1901b85

Please sign in to comment.