-
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.
- create a notification after successfully creating a welcome message
- Loading branch information
Showing
12 changed files
with
357 additions
and
18 deletions.
There are no files selected for viewing
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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class WhatsAppTemplateCreated < Noticed::Base | ||
deliver_by :database, format: :to_database, association: :notifications_as_recipient | ||
|
||
param :organization_id | ||
|
||
def to_database | ||
{ | ||
type: self.class.name, | ||
organization_id: params[:organization_id] | ||
} | ||
end | ||
|
||
def group_key | ||
{ "#{self.class.to_s.underscore}_organization_id".to_sym => record.id } | ||
end | ||
|
||
def record_for_avatar | ||
record.organization.users.sample | ||
end | ||
|
||
def group_message(*) | ||
t('.text_html') | ||
end | ||
|
||
def url | ||
organization_settings_path(record.organization, anchor: 'onboarding-success-section') | ||
end | ||
|
||
def link_text | ||
t('.link_text') | ||
end | ||
end |
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
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
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
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
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
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
49 changes: 49 additions & 0 deletions
49
spec/jobs/whats_app_adapter/three_sixty_dialog/create_welcome_message_template_job_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,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'webmock/rspec' | ||
|
||
RSpec.describe WhatsAppAdapter::ThreeSixtyDialog::CreateWelcomeMessageTemplateJob do | ||
describe '#perform_later(organization_id:)' do | ||
subject { -> { described_class.new.perform(organization_id: organization.id) } } | ||
|
||
let!(:organization) do | ||
create(:organization, | ||
project_name: 'Test Project Name', | ||
onboarding_success_heading: 'Welcome to Test Project Name', | ||
three_sixty_dialog_client_waba_account_id: 'valid_waba_account_id') | ||
end | ||
let!(:admin) { create_list(:user, 3, admin: true) } | ||
let!(:users_of_an_organization) { create_list(:user, 2, organizations: [organization]) } | ||
let!(:user_of_another_organization) { create_list(:user, 2, organizations: [create(:organization)]) } | ||
|
||
before do | ||
allow(ENV).to receive(:fetch).with( | ||
'THREE_SIXTY_DIALOG_PARTNER_REST_API_ENDPOINT', 'https://stoplight.io/mocks/360dialog/360dialog-partner-api/24588693' | ||
).and_return('https://hub.360dialog.io/api/v2') | ||
allow(ENV).to receive(:fetch).with( | ||
'THREE_SIXTY_DIALOG_PARTNER_USERNAME', nil | ||
).and_return('valid_partner_username') | ||
allow(ENV).to receive(:fetch).with( | ||
'THREE_SIXTY_DIALOG_PARTNER_PASSWORD', nil | ||
).and_return('valid_partner_password') | ||
allow(ENV).to receive(:fetch).with( | ||
'THREE_SIXTY_DIALOG_PARTNER_ID', nil | ||
).and_return('valid_partner_id') | ||
end | ||
|
||
describe 'ActivityNotifications', vcr: { cassette_name: :three_sixty_dialog_welcome_message_created } do | ||
it 'creates a notification for all admin and users of an organizaiton' do | ||
subject.call | ||
whats_app_template_created_notifications = ActivityNotification.where(type: WhatsAppTemplateCreated.name) | ||
expect(whats_app_template_created_notifications.count).to eq(5) | ||
|
||
recipient_ids = whats_app_template_created_notifications.pluck(:recipient_id).uniq.sort | ||
user_ids = users_of_an_organization.pluck(:id).uniq | ||
admin_ids = admin.pluck(:id) | ||
all_org_user_plus_admin = (user_ids + admin_ids).sort | ||
expect(recipient_ids).to eq(all_org_user_plus_admin) | ||
end | ||
end | ||
end | ||
end |
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
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
Oops, something went wrong.