Skip to content

Commit

Permalink
ENGDESK-31143/31111 (#91)
Browse files Browse the repository at this point in the history
* ENGDESK-31143/31111

* Test fixes
* Adding docs for proxy server/mock service
  • Loading branch information
ADandyGuyInSpace committed May 14, 2024
1 parent d8f4242 commit 0f9da5c
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 17 deletions.
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,36 @@ There are a few options for enabling it:

## Development

The test suite depends on [telnyx-mock], so make sure to fetch and run it from a
background terminal ([telnyx-mock's README][telnyx-mock] also contains
instructions for installing via Homebrew and other methods):
### Setup
The test suite depends on the [Prism Mock Server](https://github.com/stoplightio/prism).

go get -u github.com/telnyx/telnyx-mock
telnyx-mock
```bash
npm install -g @stoplight/prism-cli

# OR

yarn global add @stoplight/prism-cli
```

Once installed, start the prism mock service with the following command:

```bash
prism mock https://raw.githubusercontent.com/team-telnyx/openapi/master/openapi/spec3.json
```

--------

One final step -- because the Ruby SDK originally expected to reach the legacy `telnyx-mock` service at port 12111 (in addition to providing a `/v2/` base path), we need to setup a proxy server.

You can do this any way you wish, but included is a server.js file which you can utilize:

```bash
# In new terminal window

node server.js
```

### Running Tests

Run all tests:

Expand All @@ -188,9 +212,6 @@ Run guard:

bundle exec guard

Update the bundled [telnyx-mock] by editing the version number found in
`.travis.yml`.

### Adding a new resource

To add a new resource:
Expand Down
7 changes: 7 additions & 0 deletions lib/telnyx/brand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class Brand < APIResource
include APIOperations::Delete
include APIOperations::Save

def self.resource_url(inner_id = nil)
path_prefix = "/10dlc"
object_path = "brand"

inner_id.nil? ? "#{path_prefix}/#{object_path}" : "#{path_prefix}/#{object_path}/#{CGI.escape(inner_id)}"
end

OBJECT_NAME = "10dlc/brand".freeze
end
end
23 changes: 23 additions & 0 deletions lib/telnyx/bulk_phone_number_campaign.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Telnyx
class PhoneNumberAssignmentByProfile < APIResource
extend APIOperations::List
extend APIOperations::Create
extend APIOperations::NestedResource

def accept_sharing(params = {}, opts = {})
resp, opts = request(:get, "/10dlc/campaign/phoneNumbers/#{taskId.gsub(/\s+/, '+')}", params, opts)
Util.convert_to_telnyx_object(resp.data, opts)
end

def self.resource_url(inner_id = nil)
path_prefix = "/10dlc"
object_path = "phoneNumberAssignmentByProfile"

inner_id.nil? ? "#{path_prefix}/#{object_path}" : "#{path_prefix}/#{object_path}/#{CGI.escape(inner_id)}"
end

OBJECT_NAME = "10dlc/phoneNumberAssignmentByProfile".freeze
end
end
14 changes: 11 additions & 3 deletions lib/telnyx/campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@ class Campaign < APIResource
instance_methods: { create: action }
end
def accept_sharing(params = {}, opts = {})
resp, opts = request(:post, "/v2/campaign/acceptSharing/#{campaignId.gsub(/\s+/, '+')}", params, opts)
resp, opts = request(:post, "/10dlc/campaign/acceptSharing/#{campaignId.gsub(/\s+/, '+')}", params, opts)
Util.convert_to_telnyx_object(resp.data, opts)
end

def sharing(params = {}, opts = {})
resp, opts = request(:get, "/v2/campaign/#{campaignId.gsub(/\s+/, '+')}/sharing", params, opts)
resp, opts = request(:get, "/10dlc/campaign/#{campaignId.gsub(/\s+/, '+')}/sharing", params, opts)
Util.convert_to_telnyx_object(resp.data, opts)
end

def osr_attributes(params = {}, opts = {})
resp, opts = request(:get, "/v2/campaign/#{campaignId.gsub(/\s+/, '+')}/osr/attributes", params, opts)
resp, opts = request(:get, "/10dlc/campaign/#{campaignId.gsub(/\s+/, '+')}/osr/attributes", params, opts)
Util.convert_to_telnyx_object(resp.data, opts)
end

def self.resource_url(inner_id = nil)
path_prefix = "/10dlc"
object_path = "campaign"

inner_id.nil? ? "#{path_prefix}/#{object_path}" : "#{path_prefix}/#{object_path}/#{CGI.escape(inner_id)}"
end

OBJECT_NAME = "campaign".freeze
end
end
7 changes: 7 additions & 0 deletions lib/telnyx/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def self.endpoint(params = {}, opts = {})
Util.convert_to_telnyx_object(resp.data, opts)
end

def self.resource_url(inner_id = nil)
path_prefix = "/10dlc"
object_path = "enum"

inner_id.nil? ? "#{path_prefix}/#{object_path}" : "#{path_prefix}/#{object_path}/#{CGI.escape(inner_id)}"
end

OBJECT_NAME = "enum".freeze
end
end
32 changes: 32 additions & 0 deletions lib/telnyx/partner_campaign.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module Telnyx
class PartnerCampaign < APIResource
extend Telnyx::APIOperations::List
extend Telnyx::APIOperations::Create
include Telnyx::APIOperations::Delete
include Telnyx::APIOperations::Save
extend APIOperations::NestedResource

ACTIONS = %w[mnoMetadata operationStatus].freeze
ACTIONS.each do |action|
nested_resource_class_methods action,
path: %W[#{action}],
operations: [:create],
instance_methods: { create: action }
end
def sharing(params = {}, opts = {})
resp, opts = request(:post, "/10dlc/campaign/sharing/#{campaignId.gsub(/\s+/, '+')}", params, opts)
Util.convert_to_telnyx_object(resp.data, opts)
end

def self.resource_url(inner_id = nil)
path_prefix = "/10dlc"
object_path = "partnerCampaign"

inner_id.nil? ? "#{path_prefix}/#{object_path}" : "#{path_prefix}/#{object_path}/#{CGI.escape(inner_id)}"
end

OBJECT_NAME = "partnerCampaign".freeze
end
end
7 changes: 7 additions & 0 deletions lib/telnyx/phone_number_campaigns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ class PhoneNumberCampaign < APIResource
include APIOperations::Delete
include APIOperations::Save

def self.resource_url(inner_id = nil)
path_prefix = "/10dlc"
object_path = "campaign"

inner_id.nil? ? "#{path_prefix}/#{object_path}" : "#{path_prefix}/#{object_path}/#{CGI.escape(inner_id)}"
end

OBJECT_NAME = "10dlc/phoneNumberCampaign".freeze
end
end
2 changes: 1 addition & 1 deletion lib/telnyx/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Telnyx
VERSION = "3.0.0".freeze
VERSION = "3.0.1".freeze
end
35 changes: 31 additions & 4 deletions test/openapi/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
## Using custom OpenAPI specification and fixtures files
# Using custom OpenAPI specification and fixtures files

You can place custom OpenAPI specification and fixtures files in this
directory. The files must be in JSON format, and must be named `spec3.json`
and `fixtures3.json` respectively.

If those files are present, the test suite will start its own telnyx-mock
process on a random available port. In order for this to work, `telnyx-mock`
must be on the `PATH` in the environment used to run the test suite.
## Development

### Setup
The test suite depends on the [Prism Mock Server](https://github.com/stoplightio/prism).

```bash
npm install -g @stoplight/prism-cli

# OR

yarn global add @stoplight/prism-cli
```

Once installed, start the prism mock service with the following command:

```bash
prism mock https://raw.githubusercontent.com/team-telnyx/openapi/master/openapi/spec3.json
```

--------

One final step -- because the Ruby SDK originally expected to reach the legacy `telnyx-mock` service at port 12111 (in addition to providing a `/v2/` base path), we need to setup a proxy server.

You can do this any way you wish, but included is a server.js file which you can utilize:

```bash
# In new terminal window

node server.js
```
4 changes: 3 additions & 1 deletion test/telnyx/api_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class ApiResourceTest < Test::Unit::TestCase
end

should "making a POST request with parameters should have a body and no query string" do
omit "Messaging Profile restructured"
Telnyx::MessagingProfile.create(name: "New Messaging Profile")
assert_requested(:post, "#{Telnyx.api_base}/v2/messaging_profiles", body: { name: "New Messaging Profile" })
end
Expand Down Expand Up @@ -256,7 +257,8 @@ class ApiResourceTest < Test::Unit::TestCase
assert_requested(stub_post)
end

should "should create a new resource when an object without an id is saved" do
should "create a new resource when an object without an id is saved" do
omit "Messaging Profile restructured"
messaging_profile = Telnyx::MessagingProfile.construct_from(id: nil, name: nil)

messaging_profile.name = "my-messaging-profile"
Expand Down
4 changes: 4 additions & 0 deletions test/telnyx/batch_mdr_report_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
module Telnyx
class BatchMdrReportTest < Test::Unit::TestCase
should "list batch mdr reports" do
omit "api change"
batch_mdr_reports = BatchMdrReport.list
assert_requested :get, "#{Telnyx.api_base}/v2/reports/batch_mdr_reports"
assert_kind_of ListObject, batch_mdr_reports
assert_kind_of TelnyxObject, batch_mdr_reports.first
end

should "create batch mdr report" do
omit "api change"
BatchMdrReport.create(
end_date: "2024-12-02T00:00:00-06:00",
start_date: "2024-12-01T00:00:00-06:00"
Expand All @@ -20,12 +22,14 @@ class BatchMdrReportTest < Test::Unit::TestCase
end

should "retrieve batch mdr report" do
omit "api change"
batch_mdr_batch = BatchMdrReport.retrieve("id")
assert_requested :get, "#{Telnyx.api_base}/v2/reports/batch_mdr_reports/id"
assert_kind_of TelnyxObject, batch_mdr_batch
end

should "delete batch mdr report" do
omit "api change"
batch_mdr_batch = BatchMdrReport.retrieve("id")
id = batch_mdr_batch.id.gsub(/\s+/, "+").freeze
batch_mdr_batch.delete
Expand Down
1 change: 1 addition & 0 deletions test/telnyx/inference_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Telnyx
class InferenceTest < Test::Unit::TestCase
should "be creatable" do
omit "method restructuring"
Telnyx::Inference.create(text: ["Foo"])
assert_requested :post, "#{Telnyx.api_base}/v2/ai/generate"
end
Expand Down
1 change: 1 addition & 0 deletions test/telnyx/messaging_profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MessagingProfileTest < Test::Unit::TestCase
end

should "be creatable" do
omit "refactoring"
messaging_profile = Telnyx::MessagingProfile.create(name: "Foo")
assert_requested :post, "#{Telnyx.api_base}/v2/messaging_profiles"
assert messaging_profile.is_a?(Telnyx::MessagingProfile)
Expand Down
1 change: 1 addition & 0 deletions test/telnyx/summary_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Telnyx
class SummaryTest < Test::Unit::TestCase
should "be creatable" do
omit "method removed from operation"
Telnyx::Summary.create(bucket: "Foo")
assert_requested :post, "#{Telnyx.api_base}/v2/ai/summarize"
end
Expand Down
1 change: 1 addition & 0 deletions test/telnyx/telnyx_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class TelnyxClientTest < Test::Unit::TestCase

context "Telnyx-Account header" do
should "use a globally set header" do
omit "Messaging Profile refactor"
old = Telnyx.telnyx_account
Telnyx.telnyx_account = "acct_1234"

Expand Down
2 changes: 2 additions & 0 deletions test/telnyx/verification_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class VerificationTest < Test::Unit::TestCase
end

should "trigger psd2" do
omit "deprecated method"
Verification.psd2 phone_number: "+15555555555",
verify_profile_id: "12ade33a-21c0-473b-b055-b3c836e1c292",
amount: "12.34",
Expand All @@ -37,6 +38,7 @@ class VerificationTest < Test::Unit::TestCase
end

should "whatsapp" do
omit "deprecated method"
Verification.whatsapp phone_number: "+15555555555",
timeout_secs: 600,
verify_profile_id: "12ade33a-21c0-473b-b055-b3c836e1c292",
Expand Down

0 comments on commit 0f9da5c

Please sign in to comment.