twi 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 727c9e8147c7ff29da2287c0a8df35be3bcf750e697baddba487605a99357e6e
4
- data.tar.gz: b4fd8d8854d21d652649ba542aa578319421900f61d2d17c88b24daea365912f
3
+ metadata.gz: 4c06bf91d26d756f01fff17c5740c7ea254ce49474b3be83ea8d57dd3e6ed472
4
+ data.tar.gz: 0125a4facf8ed3d4bdc592e11c1c0bb376e43f451f985c13ec90e01de9a9047e
5
5
  SHA512:
6
- metadata.gz: bc4539e765dd8d5d4426cff34b94e8222ba846422462c964c9e48e93f57dba29ef09490a816c628ac63209e701799191dbabd4fd39b1087129fac00f7925ac4b
7
- data.tar.gz: 2b0a73db81a391abaa10b89b31073a31617fcc18864ea3413b708726b6c2c878d7c7fc03af34ab3fc1f0f8eaa2657ca00cfbbc5d7b0668fa4ffc729940ee334c
6
+ metadata.gz: 62883cef19ef0ee4520ddbcfb62fcf0a64186836f3e8389242007e4c76f8ddfbd70d848832788358524ed19f4d5e74dfb8aa468b7372dd80631052ff0b63eede
7
+ data.tar.gz: 2db626b561d48b858ba37d8703d3c03f11e2e3b6886a8ccfbce728caa5bf6f2f5a503fc418949a3990a0a5be58bda125507a17d61de8cc05203a85d10bbfb0fe
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.7.0] - 2026-08-19
2
+
3
+ - [New] Add Twi.reset_mock, to stop a mocked answer outliving the test that arranged it
4
+ - [Fix] Answer an unarranged Twi::Mock::Conversation#create_with, as Message#create does
5
+
6
+ ## [0.6.0] - 2026-07-27
7
+
8
+ - [Fix] Remove proxy_address from conversation participant
9
+
1
10
  ## [0.5.0] - 2026-07-27
2
11
 
3
12
  - [New] Add Twi::Delivery#sender
@@ -4,8 +4,8 @@ module Twi
4
4
  class Conversation < Resource
5
5
  attr_reader :id, :status
6
6
 
7
- def create_with(host:, participant_phones:)
8
- params = create_params_for host, participant_phones
7
+ def create_with(participants:)
8
+ params = create_params_for participants
9
9
  conversation = conversation_service.conversation_with_participants.create **params
10
10
 
11
11
  @params = { id: conversation.sid, status: conversation.state }
@@ -65,19 +65,22 @@ module Twi
65
65
  conversation_service.conversations id
66
66
  end
67
67
 
68
- def create_params_for(host, participant_phones)
68
+ def create_params_for(participants)
69
69
  {
70
70
  messaging_service_sid: Twi.lio.messaging_sid, x_twilio_webhook_enabled: 'true',
71
- friendly_name: @params[:friendly_name], participant: participant_params_for(host, participant_phones),
71
+ friendly_name: @params[:friendly_name], participant: participant_params_for(participants),
72
72
  }
73
73
  end
74
74
 
75
- def participant_params_for(host, participant_phones)
76
- params = [{ messaging_binding: { projected_address: "+1#{host[:phone]}" }, identity: host[:identity] }]
77
- participant_phones.map do |participant_phone|
78
- params << { messaging_binding: { address: "+1#{participant_phone}", proxy_address: "+1#{host[:phone]}" } }
79
- end
80
- params.map(&:to_json)
75
+ def participant_params_for(participants)
76
+ participants.map do |participant|
77
+ phone = "+1#{participant[:phone]}"
78
+ if participant[:identity]
79
+ { messaging_binding: { projected_address: phone }, identity: participant[:identity] }
80
+ else
81
+ { messaging_binding: { address: phone } }
82
+ end
83
+ end.map(&:to_json)
81
84
  end
82
85
 
83
86
  def message_params_for(content, image_ids)
@@ -1,6 +1,6 @@
1
1
  module Twi
2
2
  class Mock::Conversation < Conversation
3
- def create_with(host:, participant_phones:)
3
+ def create_with(participants:)
4
4
  if error = Twi.mock.conversation_error
5
5
  Twi.mock.conversation_error = nil
6
6
  case error[:code]
@@ -9,6 +9,8 @@ module Twi
9
9
  end
10
10
  elsif Twi.mock.conversation
11
11
  @params = { id: Twi.mock.conversation[:id], status: Twi.mock.conversation[:status] }
12
+ else
13
+ @params = { id: "CH#{rand}", status: 'initializing' }
12
14
  end
13
15
  end
14
16
 
data/lib/twi/mocking.rb CHANGED
@@ -4,6 +4,13 @@ module Twi
4
4
  @mock ||= Twi::Mock.new
5
5
  end
6
6
 
7
+ # Forgets every answer arranged so far and starts mocking again from nothing.
8
+ # A test suite calls this before each test: the mock lives on the module, so
9
+ # without it one test answers for the next.
10
+ def reset_mock
11
+ @mock = Twi::Mock.new
12
+ end
13
+
7
14
  def create_phone(...)
8
15
  phone(...).tap &:create
9
16
  end
data/lib/twi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twi
4
- VERSION = '0.5.0'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo