Class: CommandTower::Messaging::Pushover::Adapters::FakeAdapter

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb

Overview

In-memory / no-network adapter for tests and local development. Inject failures via FakeAdapter.fail_with = :invalid_user | :invalid_token | :invalid_credentials | :timeout | :provider_unavailable | :rate_limited

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.fail_withObject

Returns the value of attribute fail_with.



12
13
14
# File 'app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb', line 12

def fail_with
  @fail_with
end

.messagesObject

Returns the value of attribute messages.



12
13
14
# File 'app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb', line 12

def messages
  @messages
end

.test_notificationsObject

Returns the value of attribute test_notifications.



12
13
14
# File 'app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb', line 12

def test_notifications
  @test_notifications
end

.validationsObject

Returns the value of attribute validations.



12
13
14
# File 'app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb', line 12

def validations
  @validations
end

Class Method Details

.reset!Object



14
15
16
17
18
19
# File 'app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb', line 14

def reset!
  self.validations = []
  self.test_notifications = []
  self.messages = []
  self.fail_with = nil
end

Instance Method Details

#send_message!(user_key:, application_token:, title:, message:) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb', line 48

def send_message!(user_key:, application_token:, title:, message:)
  failure = injected_failure
  return failure if failure

  self.class.messages << {
    user_key_present: user_key.to_s.present?,
    application_token_present: application_token.to_s.present?,
    title: title.to_s,
    message: message.to_s,
  }
  Result.ok(provider_request_id: "fake-request-#{self.class.messages.size}")
end

#send_test_notification!(user_key:, application_token:, title:, message:) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb', line 35

def send_test_notification!(user_key:, application_token:, title:, message:)
  failure = injected_failure
  return failure if failure

  self.class.test_notifications << {
    user_key_present: user_key.to_s.present?,
    application_token_present: application_token.to_s.present?,
    title: title.to_s,
    message: message.to_s,
  }
  Result.ok
end

#validate_user!(user_key:, application_token:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'app/services/command_tower/messaging/pushover/adapters/fake_adapter.rb', line 24

def validate_user!(user_key:, application_token:)
  failure = injected_failure
  return failure if failure

  self.class.validations << {
    user_key_present: user_key.to_s.present?,
    application_token_present: application_token.to_s.present?,
  }
  Result.ok
end