feat: Add an option to enable/disable email collect box (#2399)

* add email collect enabled migration

* migrations

* expose enable_email_collect field

* add select for email collect

* add enable_email condition on new conversation

* add default value true for enable_email_collect

* add specs for email collect enabled

* rereun migration

* code cleanup

* update token life span to 2 months

* revert uuid column
This commit is contained in:
Muhsin Keloth
2021-06-10 15:04:03 +05:30
committed by GitHub
parent 8ca63f0b79
commit b9e40d1452
10 changed files with 56 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ describe ::MessageTemplates::HookExecutionService do
conversation = create(:conversation, contact: contact)
# ensure greeting hook is enabled and greeting_message is present
conversation.inbox.update(greeting_enabled: true, greeting_message: 'Hi, this is a greeting message')
conversation.inbox.update(greeting_enabled: true, enable_email_collect: true, greeting_message: 'Hi, this is a greeting message')
email_collect_service = double
greeting_service = double
@@ -55,7 +55,7 @@ describe ::MessageTemplates::HookExecutionService do
contact = create(:contact, email: nil)
conversation = create(:conversation, contact: contact)
# ensure greeting hook is enabled
conversation.inbox.update(greeting_enabled: true)
conversation.inbox.update(greeting_enabled: true, enable_email_collect: true)
email_collect_service = double
@@ -70,6 +70,21 @@ describe ::MessageTemplates::HookExecutionService do
expect(::MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation)
expect(email_collect_service).to have_received(:perform)
end
it 'doesnot calls ::MessageTemplates::Template::EmailCollect when enable_email_collect form is disabled' do
contact = create(:contact, email: nil)
conversation = create(:conversation, contact: contact)
conversation.inbox.update(enable_email_collect: false)
# ensure prechat form is enabled
conversation.inbox.channel.update(pre_chat_form_enabled: true)
allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true)
# described class gets called in message after commit
message = create(:message, conversation: conversation)
expect(::MessageTemplates::Template::EmailCollect).not_to have_received(:new).with(conversation: message.conversation)
end
end
# TODO: remove this if this hook is removed