Class: CommandTower::Services::Account::Push::SendSelfTest
- Inherits:
-
CommandTower::Services::ApplicationService
- Object
- CommandTower::ServiceBase
- CommandTower::Services::ApplicationService
- CommandTower::Services::Account::Push::SendSelfTest
- Defined in:
- app/services/command_tower/services/account/push/send_self_test.rb
Overview
Me self-test: Produce a host-registered push_delivery_test communication. Does not bypass Messaging; does not talk to Expo directly.
Constant Summary collapse
- NOTIFICATION_TYPE_KEY =
"push_delivery_test"- TITLE =
"Push notifications"- BODY =
"This is a test notification from your account."
Constants inherited from CommandTower::ServiceBase
CommandTower::ServiceBase::ON_ARGUMENT_VALIDATION
Instance Method Summary collapse
Methods inherited from CommandTower::Services::ApplicationService
Methods included from Transactional
#fail_transaction!, #transaction
Methods inherited from CommandTower::ServiceBase
#command_tower_lifecycle, inherited, #internal_validate, #service_lifecycle_error_codes, #service_lifecycle_log_level, #validate!
Methods included from Logging::LifecycleDeclaration
Methods included from Execution::ContextAccess
#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event
Methods included from ArgumentValidation
Methods included from CommandTower::ServiceLogging
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/services/command_tower/services/account/push/send_self_test.rb', line 16 def call list_result = CommandTower::Services::Account::Push::List.call(user:) unless list_result.success? context.fail!(application_error: list_result.errors.first) return end if Array(list_result.data[:safe_views]).empty? context.fail!(application_error: CommandTower::Errors::Account::PushTestNoEndpointError.new) return end rate_result = CommandTower::Services::Account::Push::CheckSelfTestRateLimit.call(user:) unless rate_result.success? context.fail!(application_error: rate_result.errors.first) return end produce_result = CommandTower::Services::Messaging::Communications::Produce.call( user:, notification_type_key: NOTIFICATION_TYPE_KEY, host_event_identity: "push_delivery_test/#{user.id}/#{SecureRandom.uuid}", title: TITLE, body: BODY, metadata: {}, platform_enabled_channels: CommandTower::Services::Messaging::Preferences::PlatformEnabledChannels.call, ) unless produce_result.success? context.fail!(application_error: produce_result.errors.first) return end context.communication_id = produce_result.data[:communication_id] context.destination_plan_id = produce_result.data[:destination_plan_id] context.selected_channels = produce_result.data[:selected_channels] context.communication_status = produce_result.data[:communication_status] end |