diff --git a/.rubocop.yml b/.rubocop.yml index 06fb0407..0d34e676 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ # This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license) # Automatically generated by OpenAPI Generator (https://openapi-generator.tech) AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 3.3 # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop # to ignore them, so only the ones explicitly set in this file are enabled. DisabledByDefault: true diff --git a/Gemfile b/Gemfile index 7ac34273..9cfdd0ad 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,6 @@ gemspec group :development, :test do gem 'rake', '~> 13.2.1' gem 'pry-byebug' - gem 'rubocop', '~> 1.82.0' - gem 'simplecov', '~> 0.21.2' + gem 'rubocop', '~> 1.86.2' + gem 'simplecov', '~> 0.22.0' end diff --git a/UPDATING_MODEL_TESTS.md b/UPDATING_MODEL_TESTS.md new file mode 100644 index 00000000..f16ab155 --- /dev/null +++ b/UPDATING_MODEL_TESTS.md @@ -0,0 +1,319 @@ +# Updating Model Unit Tests + +## Context + +Model unit test files in `spec/unit/models/` are auto-generated by the `openapi-generator-cli` (`rake generate` or equivalent). The generator output is a *starting point* — every spec must be updated to match the template described here. + +This doc is the source of truth for that update step. Follow it exactly when bringing a fresh-generated spec into compliance. + +## Workflow + +1. Auto-generate the SDK (writes specs to `spec/unit/models/`). +2. For each spec under `spec/unit/models/`, pick the matching template: + - [Standard Model Template](#standard-model-template) — regular models (the model file defines a `class`) + - [Enum Model Template](#enum-model-template) — pure enum models (the model file defines a class with `all_vars` and frozen string constants only) + - [oneOf Model Template](#oneof-model-template) — discriminator-based oneOf models (the model file defines a `module`, not a `class`) +3. Run `rake unit` and confirm `0 failures`. +4. Check coverage didn't regress meaningfully (see [Coverage notes](#coverage-notes)). + +## Standard Model Template + +Apply to any spec representing a regular model (object with attributes), e.g. `message_spec.rb`, `call_state_spec.rb`, `verify_code_request_spec.rb`. + +### Required structure + +```ruby +describe Bandwidth::ModelName do + let(:model_name_default) { Bandwidth::ModelName.new } + let(:model_name_values) { Bandwidth::ModelName.new({ }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' + end + + describe '#openapi_nullable' do + # If model has nullable attrs, assert the exact Set. Otherwise assert empty Set. + it 'expects nullable attributes to be ...' + end + + describe '#build_from_hash' do + # camelCase keys in, snake_case attr reads out, instance check. + it 'validates instance of ModelName created by the build_from_hash method' + end + + describe '#to_s' do + # Use the *populated* values instance, not the empty default. + it 'returns a string representation of the object' + end + + describe '#eq? #==' do + # Assert both equality AND inequality. + it 'returns true/false when comparing objects' + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' + end + + # Only when the model has validated attrs (nil/pattern/min/max). + describe 'custom attribute writers' do + it '#attr=' do ... end + end +end +``` + +### What to drop from the auto-generated spec + +- **`#hash` block.** Asserting `obj.hash.is_a?(Integer)` is testing Ruby itself. No signal. +- **Empty `enum validation` block** (e.g. `describe 'enum validation' do; it 'works' do; end; end`). Pure noise — passes while testing nothing. +- **`EnumAttributeValidator` block.** It tests generator scaffolding with fake allow-lists (`['valid']`, `[1]`), not the model's actual enums. The customer-facing behavior — "does an invalid enum value raise when set on a model?" — belongs in custom attribute writer tests, where it actually exercises the model. + +### What to add when missing + +- **`_default` let.** Pair `_values` with a default instance so `#eq?` can assert both equal-to-equal and equal-to-different. For models with required (non-nil-validated) attrs, build `_default` with only the required attrs populated. +- **`#openapi_nullable` block.** Always include, even if the nullable set is empty. Read the model's `self.openapi_nullable` to get the exact set. +- **Custom attribute writer tests.** One `it` per validated attribute. Cover every validation the model performs: + - `nil` check → `' cannot be nil'` + - pattern → `'invalid value for "", must conform to the pattern ...'` + - min/max length → `'invalid value for "", the character length must be ...'` + - min/max value → `'invalid value for "", must be smaller/greater than or equal to ...'` + - enum allow-list → `'invalid value for "", must be one of ...'` + +### What to fix when incorrect + +- **`#to_s` using the empty `_default` instance.** Switch to `_values` so the assertion is meaningful (asserts `'{}'` proves nothing). +- **`#eq?` only checking equality.** Update to assert both `_default.eql?(equal_instance)` is true AND `_default.eql?(_values)` is false. + +## Enum Model Template + +Apply to pure enum models, e.g. `call_state_enum_spec.rb`. + +```ruby +describe Bandwidth::SomeEnum do + describe 'constants' do + it 'defines VALUE_NAME' do + expect(Bandwidth::SomeEnum::VALUE_NAME).to eq('value_string') + end + # ...one per enum constant + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::SomeEnum.all_vars).to eq([]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::SomeEnum.build_from_hash('valid_value')).to eq('valid_value') + # ...one per valid value + end + + it 'raises an error for an invalid enum value' do + expect { Bandwidth::SomeEnum.build_from_hash('invalid') }.to raise_error(RuntimeError) + end + end +end +``` + +### What to drop + +- Instance-construction tests (`Bandwidth::SomeEnum.new` then `be_instance_of`). The enum module isn't meant to be instantiated for use — only `build_from_hash` matters. + +## oneOf Model Template + +Apply to discriminator-based oneOf models, e.g. `callback_spec.rb`. These models are defined as Ruby `module`s (not classes) and act as routers — given a payload with a discriminator field, they dispatch to one of several target classes via `.build`. + +You can identify a oneOf model by inspecting `lib/bandwidth-sdk/models/.rb`: it will be a `module` exposing `openapi_one_of`, `openapi_discriminator_name`, `openapi_discriminator_mapping`, and `build` as class methods. + +```ruby +describe Bandwidth::SomeOneOf do + describe '.openapi_one_of' do + it 'lists the classes defined in oneOf' do + expect(Bandwidth::SomeOneOf.openapi_one_of).to eq([ + :'ClassA', + :'ClassB' + ]) + end + end + + describe '.openapi_discriminator_name' do + it 'returns the discriminator property name' do + expect(Bandwidth::SomeOneOf.openapi_discriminator_name).to eq(:'type') + end + end + + describe '.openapi_discriminator_mapping' do + it 'maps every discriminator value to a oneOf class' do + expect(Bandwidth::SomeOneOf.openapi_discriminator_mapping).to eq({ + :'discriminator-value-1' => :'ClassA', + :'discriminator-value-2' => :'ClassB' + }) + end + + it 'maps only to classes listed in openapi_one_of' do + mapping_targets = Bandwidth::SomeOneOf.openapi_discriminator_mapping.values.uniq.sort + expect(mapping_targets).to eq(Bandwidth::SomeOneOf.openapi_one_of.sort) + end + end + + describe '.build' do + # Stub build_from_hash on each target class so we test the routing without + # depending on the target's construction logic (which is covered by its own spec). + it 'routes discriminator values to ClassA.build_from_hash' do + Bandwidth::SomeOneOf.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'ClassA' + data = { type: discriminator.to_s } + expect(Bandwidth::ClassA).to receive(:build_from_hash).with(data).and_return(:class_a_result) + expect(Bandwidth::SomeOneOf.build(data)).to eq(:class_a_result) + end + end + + # ...one block per oneOf target class + + it 'returns nil when the discriminator value is missing' do + expect(Bandwidth::SomeOneOf.build({})).to be_nil + end + + it 'returns nil when the discriminator value does not match any mapping' do + expect(Bandwidth::SomeOneOf.build({ type: 'unknown' })).to be_nil + end + end +end +``` + +### Required structure + +- `.openapi_one_of` — assert the exact list of target class symbols +- `.openapi_discriminator_name` — assert the exact discriminator property symbol +- `.openapi_discriminator_mapping` — assert the exact mapping AND assert it only maps to classes in `openapi_one_of` +- `.build` — one block per target class verifying routing (via stubbed `build_from_hash`), plus the two nil cases (missing discriminator, unknown discriminator value) + +### What to drop from the auto-generated spec + +- **Weak `not_to be_empty` assertions.** Replace with exact equality checks against the model's actual values. +- **`mapping.values.sort == one_of.sort` assertion.** This is buggy in the generator output — `mapping.values` has duplicates when multiple discriminator values route to the same class. Use `.uniq.sort` instead. +- **Empty `.build` describe block.** Replace with the stub-based routing tests above. + +### Why stub `build_from_hash`? + +oneOf targets often have many required attributes (and nested required models), making it tedious to construct valid data for every discriminator value. Stubbing isolates the test to what `.build` is actually doing — routing based on a discriminator. The target class's `build_from_hash` is covered by that class's own spec. + +### What to skip + +- `#initialize`, `#openapi_nullable`, `#to_s`, `#eq?`, `#to_body`, custom attribute writers — these don't apply. The oneOf model is a `module`, not an instantiable class. + +### Variant: discriminator-based `openapi_any_of` + +Some modules expose `openapi_any_of` instead of `openapi_one_of` but otherwise have the identical shape (same `openapi_discriminator_name`, `openapi_discriminator_mapping`, and `build` implementation). Treat them exactly like the oneOf template above — just substitute `openapi_any_of` for `openapi_one_of` everywhere (describe block name, assertion target, the `uniq.sort` cross-check). + +Example: `multi_channel_action_spec.rb` (the model is `lib/bandwidth-sdk/models/multi_channel_action.rb`). + +### Variant: no-discriminator `openapi_one_of` + +Some `oneOf` modules expose `openapi_one_of` but **no** discriminator (no `openapi_discriminator_name`/`openapi_discriminator_mapping`). Instead, `build(data)` iterates `openapi_one_of` and uses a private `find_and_cast_into_type` helper to attempt deserialization into each target class in order, returning the first match (or `nil` if none match). + +You **cannot use the stubbed-routing pattern** for these — `find_and_cast_into_type` does a pre-flight check against the target's `acceptable_attributes` before calling `build_from_hash`, so a naked stub of `build_from_hash` is bypassed. Use real payloads instead, sized to match one target's attribute shape. + +```ruby +describe Bandwidth::SomeNoDiscriminatorOneOf do + describe '.openapi_one_of' do + it 'lists the classes defined in oneOf' do + expect(Bandwidth::SomeNoDiscriminatorOneOf.openapi_one_of).to eq([ + :'ClassA', + :'ClassB' + ]) + end + end + + describe '.build' do + it 'routes payloads matching ClassA attributes to ClassA' do + data = { someClassAAttr: 'value' } + expect(Bandwidth::SomeNoDiscriminatorOneOf.build(data)).to be_instance_of(Bandwidth::ClassA) + end + + it 'routes payloads matching ClassB attributes to ClassB' do + data = { someClassBAttr: 'value' } + expect(Bandwidth::SomeNoDiscriminatorOneOf.build(data)).to be_instance_of(Bandwidth::ClassB) + end + + it 'returns nil when the payload does not match any oneOf schema' do + expect(Bandwidth::SomeNoDiscriminatorOneOf.build({ unknown: 'value' })).to be_nil + end + end +end +``` + +Pick payload attributes that exist on only one target so `find_and_cast_into_type`'s `acceptable_attributes` check disambiguates correctly. Skip `.openapi_discriminator_name` and `.openapi_discriminator_mapping` blocks — those methods don't exist on these modules. + +Example: `rbm_message_content_rich_card_spec.rb`. + +## Gotchas + +### Writers unreachable through `Model.new` + +Some validated setters (notably `to=` and `media=` on `Bandwidth::Message`) only get invoked from `initialize` when the input is an Array. Passing `nil` to `Model.new` won't trigger the writer's nil check. + +**Fix:** call the writer directly on an instance. + +```ruby +# Wrong — won't raise: +expect { Bandwidth::Message.new({ to: nil }) }.to raise_error(ArgumentError, 'to cannot be nil') + +# Right — exercises the writer: +expect { message_values.to = nil }.to raise_error(ArgumentError, 'to cannot be nil') +``` + +When in doubt, read the model's `initialize` and check whether `self. =` is gated behind a type check. + +### `#build_from_hash` needs full required-attr data for nested models + +When a model has an attribute typed as another model (e.g., `:'business_address' => :'Address'`), `build_from_hash` recursively deserializes that nested hash into a real `Address` instance. That instance's `initialize` runs all required-attr setters, so any missing required attr raises `ArgumentError`. + +**This bites only in the `#build_from_hash` test, not `#to_s` / `#to_body` / `_values`** — when you pass a nested hash to `Model.new` directly (via `_values`), the parent's `attr_accessor` just stores the hash verbatim; no recursive deserialization happens. + +```ruby +# Wrong — raises ArgumentError: 'addr1 cannot be nil' inside Address.new: +Bandwidth::VerificationRequest.build_from_hash({ + businessAddress: { name: 'Bandwidth' }, # Address requires addr1, city, state, zip, url + # ... +}) + +# Right — full required-attr data for the nested Address: +Bandwidth::VerificationRequest.build_from_hash({ + businessAddress: { name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: 'https://www.bandwidth.com' }, + # ... +}) +``` + +Apply this recursively — if the nested model itself has nested models with required attrs, fill those too. Check the nested model's setters (`def =` blocks raising `' cannot be nil'`) to know which attrs are required. + +### `#to_s` is sensitive to attribute order + +The expected string must match the exact order of attributes as serialized by `to_hash`. Generate the expected string by running the populated instance through `to_s` in a console and pasting the result. Don't hand-craft it. + +### Nullable attribute symbols + +`openapi_nullable` returns a `Set` of `Symbol`s using snake_case attribute names with a leading colon-quote (e.g. `:'parent_call_id'`). Mirror the model's `openapi_nullable` definition exactly. + +## Coverage notes + +Dropping `EnumAttributeValidator` blocks reduces line coverage slightly, because the nested `EnumAttributeValidator` class isn't exercised elsewhere. Two options: + +1. **Accept the dip.** That code is generator scaffolding; coverage of it is low-value. +2. **Add an enum-validated writer test** for at least one attribute per model with enums (e.g. `Bandwidth::Message.new(direction: 'invalid')` should raise). This exercises `EnumAttributeValidator` through a real path and recovers the coverage. + +The coverage logic itself is being updated as part of expanding to all models — don't fight stale thresholds. + +## Verification + +```sh +rake unit +``` + +Confirm `0 failures` before considering a spec done. diff --git a/custom_templates/Gemfile.mustache b/custom_templates/Gemfile.mustache index 7ac34273..9cfdd0ad 100644 --- a/custom_templates/Gemfile.mustache +++ b/custom_templates/Gemfile.mustache @@ -5,6 +5,6 @@ gemspec group :development, :test do gem 'rake', '~> 13.2.1' gem 'pry-byebug' - gem 'rubocop', '~> 1.82.0' - gem 'simplecov', '~> 0.21.2' + gem 'rubocop', '~> 1.86.2' + gem 'simplecov', '~> 0.22.0' end diff --git a/generate-model-tests.sh b/generate-model-tests.sh new file mode 100644 index 00000000..0074b369 --- /dev/null +++ b/generate-model-tests.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Generates new test files for models. Run from the root. + +# allow generator to write test files +sed -i.bak 's|^/spec/\*\*|# /spec/**|' .openapi-generator-ignore && rm .openapi-generator-ignore.bak +# remove current test files for models +rm -f ./spec/unit/models/* +# generate new test files for models +openapi-generator-cli generate -i bandwidth.yml -o ./ -c openapi-config.yml -g ruby > /dev/null +# move generated model test files to the correct location (exclude api tests) +mv ./spec/models/* ./spec/unit/models/ +# remove remaining generated test files (api tests, etc.) +rm -rf ./spec/api ./spec/models +# discard changes to modified files only (leaves deletions and new test files intact) +modified=$(git diff --name-only --diff-filter=M) && [ -n "$modified" ] && echo "$modified" | xargs git checkout -- diff --git a/lib/bandwidth-sdk/configuration.rb b/lib/bandwidth-sdk/configuration.rb index 010085e1..751eda9a 100644 --- a/lib/bandwidth-sdk/configuration.rb +++ b/lib/bandwidth-sdk/configuration.rb @@ -217,6 +217,7 @@ def initialize body = JSON.parse(response.body) @access_token = body['access_token'] @access_token_expiration = Time.now + body['expires_in'] + @access_token } yield(self) if block_given? diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5083ef2f..7ad0c1b3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,29 +3,23 @@ SimpleCov.start do add_filter 'spec/smoke' add_filter 'spec/call_utils.rb' - add_filter do |source_file| - if !source_file.filename.include? 'bandwidth-sdk/models' then - false - else - !(['/models/call_state_enum.rb', - '/models/call_state.rb', - '/models/tfv_error.rb', - '/models/message.rb', - '/models/verify_code_request.rb', - '/models/verify_code_response.rb' - ].any? { |name| source_file.filename.include?(name) }) - end - end add_group 'Models', 'lib/bandwidth-sdk/models/' add_group 'APIs', 'lib/bandwidth-sdk/api/' - add_group 'Client', ['api_client.rb', 'api_error.rb', 'configuration.rb', 'version.rb', 'bandwidth-sdk.rb'] + add_group 'Client', [ + 'lib/bandwidth-sdk/api_client.rb', + 'lib/bandwidth-sdk/api_error.rb', + 'lib/bandwidth-sdk/api_model_base.rb', + 'lib/bandwidth-sdk/configuration.rb', + 'lib/bandwidth-sdk/version.rb', + 'lib/bandwidth-sdk.rb' + ] add_group 'Tests', 'spec' end # load the gem require 'bandwidth-sdk' -# load call utils every time. This prevents an error from occuring when running only unit tests +# load call utils every time. This prevents an error from occurring when running only unit tests require_relative './call_utils' # The following was generated by the `rspec --init` command. Conventionally, all diff --git a/spec/unit/api/phone_number_lookup_api_spec.rb b/spec/unit/api/phone_number_lookup_api_spec.rb index 2c0d1ad0..ae835397 100644 --- a/spec/unit/api/phone_number_lookup_api_spec.rb +++ b/spec/unit/api/phone_number_lookup_api_spec.rb @@ -40,6 +40,18 @@ expect(data.data.status).to eq(Bandwidth::InProgressLookupStatusEnum::IN_PROGRESS) expect(data.errors).to be_instance_of(Array) end + + it 'causes an ArgumentError for a missing account_id' do + expect { + @api_instance.create_async_bulk_lookup(nil, Bandwidth::AsyncLookupRequest.new(phone_numbers: phone_numbers)) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError for a missing async_lookup_request' do + expect { + @api_instance.create_async_bulk_lookup(BW_ACCOUNT_ID, nil) + }.to raise_error(ArgumentError) + end end # Create Synchronous Number Lookup @@ -52,7 +64,7 @@ data, status_code = @api_instance.create_sync_lookup_with_http_info(BW_ACCOUNT_ID, request) - expect(status_code).to equal_to(200) + expect(status_code).to eq(200) expect(data).to be_instance_of(Bandwidth::CreateSyncLookupResponse) expect(data.data.request_id).to be_instance_of(String) expect(data.data.status).to eq(Bandwidth::CompletedLookupStatusEnum::COMPLETE) @@ -68,6 +80,18 @@ expect(data.data.results[0].latest_message_delivery_status_date).to be_instance_of(Date) expect(data.errors).to be_instance_of(Array) end + + it 'causes an ArgumentError for a missing account_id' do + expect { + @api_instance.create_sync_lookup(nil, Bandwidth::SyncLookupRequest.new(phone_numbers: phone_numbers, rcs_agent: rcs_agent)) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError for a missing sync_lookup_request' do + expect { + @api_instance.create_sync_lookup(BW_ACCOUNT_ID, nil) + }.to raise_error(ArgumentError) + end end # Get Asynchronous Bulk Number Lookup @@ -75,7 +99,7 @@ it 'should work' do data, status_code = @api_instance.get_async_bulk_lookup_with_http_info(BW_ACCOUNT_ID, request_id) - expect(status_code).to equal_to(200) + expect(status_code).to eq(200) expect(data).to be_instance_of(Bandwidth::GetAsyncBulkLookupResponse) expect(data.data.request_id).to be_instance_of(String) expect(data.data.status).to eq(Bandwidth::InProgressLookupStatusEnum::COMPLETE) @@ -91,5 +115,17 @@ expect(data.data.results[0].latest_message_delivery_status_date).to be_instance_of(Date) expect(data.errors).to be_instance_of(Array) end + + it 'causes an ArgumentError for a missing account_id' do + expect { + @api_instance.get_async_bulk_lookup(nil, request_id) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError for a missing request_id' do + expect { + @api_instance.get_async_bulk_lookup(BW_ACCOUNT_ID, nil) + }.to raise_error(ArgumentError) + end end end diff --git a/spec/unit/api/toll_free_verification_api_spec.rb b/spec/unit/api/toll_free_verification_api_spec.rb index cebc5c0c..ccd80e26 100644 --- a/spec/unit/api/toll_free_verification_api_spec.rb +++ b/spec/unit/api/toll_free_verification_api_spec.rb @@ -150,6 +150,18 @@ _data, status_code = @tfv_api_instance.delete_verification_request_with_http_info(BW_ACCOUNT_ID, tf_phone_number) expect(status_code).to eq(204) end + + it 'causes an ArgumentError for a missing account_id' do + expect { + @tfv_api_instance.delete_verification_request(nil, tf_phone_number) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError for a missing phone_number' do + expect { + @tfv_api_instance.delete_verification_request(BW_ACCOUNT_ID, nil) + }.to raise_error(ArgumentError) + end end # List Toll-Free Use Cases diff --git a/spec/unit/client/api_client_spec.rb b/spec/unit/client/api_client_spec.rb index 89842c58..ca8fbf2e 100644 --- a/spec/unit/client/api_client_spec.rb +++ b/spec/unit/client/api_client_spec.rb @@ -258,7 +258,7 @@ end describe '#convert_to_type' do - it 'conversts data to the given return type' do + it 'converts data to the given return type' do expect(api_client_default.convert_to_type(1, 'String')).to eq('1') expect(api_client_default.convert_to_type('1', 'Integer')).to eq(1) expect(api_client_default.convert_to_type('1', 'Float')).to eq(1.0) diff --git a/spec/unit/client/configuration_spec.rb b/spec/unit/client/configuration_spec.rb index dc65ef63..0db15b46 100644 --- a/spec/unit/client/configuration_spec.rb +++ b/spec/unit/client/configuration_spec.rb @@ -113,18 +113,105 @@ end end + describe '#oauth_bearer_token' do + it 'returns the Bearer string when a static access_token is set' do + config.access_token = token + config.access_token_getter = nil + expect(config.oauth_bearer_token).to eq("Bearer #{token}") + end + + it 'returns the Bearer string using access_token_getter when defined' do + config.access_token_getter = proc { token } + expect(config.oauth_bearer_token).to eq("Bearer #{token}") + end + + it 'returns nil when no access_token is available' do + config.access_token = nil + config.access_token_getter = proc { nil } + expect(config.oauth_bearer_token).to be_nil + end + end + + describe 'default access_token_getter' do + let(:client_id) { 'test_client_id' } + let(:client_secret) { 'test_client_secret' } + let(:faraday_conn) { instance_double(Faraday::Connection) } + let(:success_response) { instance_double(Faraday::Response, status: 200, body: '{"access_token":"refreshed_token","expires_in":3600}') } + let(:error_response) { instance_double(Faraday::Response, status: 401, body: 'unauthorized') } + + before do + allow(Faraday).to receive(:new).and_return(faraday_conn) + end + + it 'returns the cached access_token when expiration is in the future' do + config.access_token = 'cached_token' + config.instance_variable_set(:@access_token_expiration, Time.now + 3600) + expect(faraday_conn).not_to receive(:post) + expect(config.access_token_getter.call).to eq('cached_token') + end + + it 'returns the cached access_token when expiration has never been set' do + config.access_token = 'cached_token' + expect(faraday_conn).not_to receive(:post) + expect(config.access_token_getter.call).to eq('cached_token') + end + + it 'returns nil when no cached token and no client credentials' do + expect(faraday_conn).not_to receive(:post) + expect(config.access_token_getter.call).to be_nil + end + + it 'fetches a new token via the token endpoint when no cached token exists' do + config.client_id = client_id + config.client_secret = client_secret + allow(faraday_conn).to receive(:post).and_return(success_response) + expect(config.access_token_getter.call).to eq('refreshed_token') + expect(config.access_token).to eq('refreshed_token') + expect(config.instance_variable_get(:@access_token_expiration)).to be_a(Time) + end + + it 'refreshes the token when the cached token is within the 60-second expiration buffer' do + config.client_id = client_id + config.client_secret = client_secret + config.access_token = 'expiring_soon' + config.instance_variable_set(:@access_token_expiration, Time.now + 30) + allow(faraday_conn).to receive(:post).and_return(success_response) + config.access_token_getter.call + expect(config.access_token).to eq('refreshed_token') + end + + it 'raises when the token endpoint returns a non-200 response' do + config.client_id = client_id + config.client_secret = client_secret + allow(faraday_conn).to receive(:post).and_return(error_response) + expect { + config.access_token_getter.call + }.to raise_error(RuntimeError, /Failed to obtain access token: 401/) + end + end + describe '#auth_settings' do - it 'returns Auth Settings hash for api client' do + it 'returns Basic auth entry for api client' do basic_auth = config.auth_settings['Basic'] expect(basic_auth[:type]).to eq('basic') expect(basic_auth[:in]).to eq('header') expect(basic_auth[:key]).to eq('Authorization') expect(basic_auth[:value]).to eq('Basic Og==') end + + it 'returns OAuth2 auth entry for api client' do + config.access_token = token + config.access_token_getter = nil + oauth2 = config.auth_settings['OAuth2'] + expect(oauth2[:type]).to eq('oauth2') + expect(oauth2[:in]).to eq('header') + expect(oauth2[:key]).to eq('Authorization') + expect(oauth2[:value]).to eq("Bearer #{token}") + end end describe '#server_url' do - it 'returns URL with enum variable substitued' do + it 'returns URL with enum variable substituted' do expect(config.server_url(0, { enum_var: 'v3' }, server)).to eq('https://voice.bandwidth.com/api/v3/default_value') end diff --git a/spec/unit/models/account_statistics_spec.rb b/spec/unit/models/account_statistics_spec.rb new file mode 100644 index 00000000..48bd3d0d --- /dev/null +++ b/spec/unit/models/account_statistics_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::AccountStatistics +describe Bandwidth::AccountStatistics do + let(:account_statistics_default) { Bandwidth::AccountStatistics.new } + let(:account_statistics_values) { Bandwidth::AccountStatistics.new({ + current_call_queue_size: 1, + max_call_queue_size: 100 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::AccountStatistics.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::AccountStatistics.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::AccountStatistics.acceptable_attributes).to eq(Bandwidth::AccountStatistics.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::AccountStatistics.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of AccountStatistics created by the build_from_hash method' do + account_statistics_from_hash = Bandwidth::AccountStatistics.build_from_hash({ + currentCallQueueSize: 1, + maxCallQueueSize: 100 + }) + expect(account_statistics_from_hash).to be_instance_of(Bandwidth::AccountStatistics) + expect(account_statistics_from_hash.current_call_queue_size).to eq(1) + expect(account_statistics_from_hash.max_call_queue_size).to eq(100) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(account_statistics_values.to_s).to eq('{:currentCallQueueSize=>1, :maxCallQueueSize=>100}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(account_statistics_default.eql?(Bandwidth::AccountStatistics.new)).to be true + expect(account_statistics_default.eql?(account_statistics_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(account_statistics_values.to_body).to eq({ + currentCallQueueSize: 1, + maxCallQueueSize: 100 + }) + end + end +end diff --git a/spec/unit/models/additional_denial_reason_spec.rb b/spec/unit/models/additional_denial_reason_spec.rb new file mode 100644 index 00000000..74d9a1cc --- /dev/null +++ b/spec/unit/models/additional_denial_reason_spec.rb @@ -0,0 +1,101 @@ +# Unit tests for Bandwidth::AdditionalDenialReason +describe Bandwidth::AdditionalDenialReason do + let(:additional_denial_reason_default) { Bandwidth::AdditionalDenialReason.new({ + status_code: 100, + reason: 'baseline', + resubmit_allowed: false + }) } + let(:additional_denial_reason_values) { Bandwidth::AdditionalDenialReason.new({ + status_code: 200, + reason: 'reason text', + resubmit_allowed: true + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::AdditionalDenialReason.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::AdditionalDenialReason.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::AdditionalDenialReason.acceptable_attributes).to eq(Bandwidth::AdditionalDenialReason.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::AdditionalDenialReason.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of AdditionalDenialReason created by the build_from_hash method' do + additional_denial_reason_from_hash = Bandwidth::AdditionalDenialReason.build_from_hash({ + statusCode: 200, + reason: 'reason text', + resubmitAllowed: true + }) + expect(additional_denial_reason_from_hash).to be_instance_of(Bandwidth::AdditionalDenialReason) + expect(additional_denial_reason_from_hash.status_code).to eq(200) + expect(additional_denial_reason_from_hash.reason).to eq('reason text') + expect(additional_denial_reason_from_hash.resubmit_allowed).to eq(true) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(additional_denial_reason_values.to_s).to eq('{:statusCode=>200, :reason=>"reason text", :resubmitAllowed=>true}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + additional_denial_reason_equal = Bandwidth::AdditionalDenialReason.new({ + status_code: 100, + reason: 'baseline', + resubmit_allowed: false + }) + expect(additional_denial_reason_default.eql?(additional_denial_reason_equal)).to be true + expect(additional_denial_reason_default.eql?(additional_denial_reason_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(additional_denial_reason_values.to_body).to eq({ + statusCode: 200, + reason: 'reason text', + resubmitAllowed: true + }) + end + end + + describe 'custom attribute writers' do + it '#status_code=' do + expect { + Bandwidth::AdditionalDenialReason.new({ status_code: nil, reason: 'a', resubmit_allowed: false }) + }.to raise_error(ArgumentError, 'status_code cannot be nil') + end + + it '#reason=' do + expect { + Bandwidth::AdditionalDenialReason.new({ status_code: 1, reason: nil, resubmit_allowed: false }) + }.to raise_error(ArgumentError, 'reason cannot be nil') + end + + it '#resubmit_allowed=' do + expect { + Bandwidth::AdditionalDenialReason.new({ status_code: 1, reason: 'a', resubmit_allowed: nil }) + }.to raise_error(ArgumentError, 'resubmit_allowed cannot be nil') + end + end +end diff --git a/spec/unit/models/address_spec.rb b/spec/unit/models/address_spec.rb new file mode 100644 index 00000000..095d1973 --- /dev/null +++ b/spec/unit/models/address_spec.rb @@ -0,0 +1,187 @@ +# Unit tests for Bandwidth::Address +describe Bandwidth::Address do + let(:address_default) { Bandwidth::Address.new({ + name: 'Bandwidth', + addr1: '900 Main Campus Dr', + city: 'Raleigh', + state: 'NC', + zip: '27606', + url: 'https://www.bandwidth.com' + }) } + let(:address_values) { Bandwidth::Address.new({ + name: 'Bandwidth', + addr1: '900 Main Campus Dr', + addr2: 'Suite 100', + city: 'Raleigh', + state: 'NC', + zip: '27606', + url: 'https://www.bandwidth.com' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Address.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Address.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Address.acceptable_attributes).to eq(Bandwidth::Address.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::Address.openapi_nullable).to eq(Set.new([:'addr2'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Address created by the build_from_hash method' do + address_from_hash = Bandwidth::Address.build_from_hash({ + name: 'Bandwidth', + addr1: '900 Main Campus Dr', + addr2: 'Suite 100', + city: 'Raleigh', + state: 'NC', + zip: '27606', + url: 'https://www.bandwidth.com' + }) + expect(address_from_hash).to be_instance_of(Bandwidth::Address) + expect(address_from_hash.name).to eq('Bandwidth') + expect(address_from_hash.addr1).to eq('900 Main Campus Dr') + expect(address_from_hash.addr2).to eq('Suite 100') + expect(address_from_hash.city).to eq('Raleigh') + expect(address_from_hash.state).to eq('NC') + expect(address_from_hash.zip).to eq('27606') + expect(address_from_hash.url).to eq('https://www.bandwidth.com') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(address_values.to_s).to eq('{:name=>"Bandwidth", :addr1=>"900 Main Campus Dr", :addr2=>"Suite 100", :city=>"Raleigh", :state=>"NC", :zip=>"27606", :url=>"https://www.bandwidth.com"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + address_equal = Bandwidth::Address.new({ + name: 'Bandwidth', + addr1: '900 Main Campus Dr', + city: 'Raleigh', + state: 'NC', + zip: '27606', + url: 'https://www.bandwidth.com' + }) + expect(address_default.eql?(address_equal)).to be true + expect(address_default.eql?(address_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(address_values.to_body).to eq({ + name: 'Bandwidth', + addr1: '900 Main Campus Dr', + addr2: 'Suite 100', + city: 'Raleigh', + state: 'NC', + zip: '27606', + url: 'https://www.bandwidth.com' + }) + end + end + + describe 'custom attribute writers' do + it '#name=' do + expect { + Bandwidth::Address.new({ name: nil }) + }.to raise_error(ArgumentError, 'name cannot be nil') + + expect { + Bandwidth::Address.new({ name: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Address.new({ name: '' }) + }.to raise_error(ArgumentError, 'invalid value for "name", the character length must be greater than or equal to 1.') + end + + it '#addr1=' do + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: nil }) + }.to raise_error(ArgumentError, 'addr1 cannot be nil') + + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "addr1", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '' }) + }.to raise_error(ArgumentError, 'invalid value for "addr1", the character length must be greater than or equal to 1.') + end + + it '#addr2=' do + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', addr2: 'a' * 501, city: 'Raleigh', state: 'NC', zip: '27606', url: 'https://www.bandwidth.com' }) + }.to raise_error(ArgumentError, 'invalid value for "addr2", the character length must be smaller than or equal to 500.') + end + + it '#city=' do + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: nil }) + }.to raise_error(ArgumentError, 'city cannot be nil') + + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "city", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: '' }) + }.to raise_error(ArgumentError, 'invalid value for "city", the character length must be greater than or equal to 1.') + end + + it '#state=' do + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: nil }) + }.to raise_error(ArgumentError, 'state cannot be nil') + + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "state", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: '' }) + }.to raise_error(ArgumentError, 'invalid value for "state", the character length must be greater than or equal to 1.') + end + + it '#zip=' do + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: nil }) + }.to raise_error(ArgumentError, 'zip cannot be nil') + end + + it '#url=' do + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: nil }) + }.to raise_error(ArgumentError, 'url cannot be nil') + + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "url", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Address.new({ name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: '' }) + }.to raise_error(ArgumentError, 'invalid value for "url", the character length must be greater than or equal to 1.') + end + end +end diff --git a/spec/unit/models/answer_callback_spec.rb b/spec/unit/models/answer_callback_spec.rb new file mode 100644 index 00000000..c775a207 --- /dev/null +++ b/spec/unit/models/answer_callback_spec.rb @@ -0,0 +1,123 @@ +# Unit tests for Bandwidth::AnswerCallback +describe Bandwidth::AnswerCallback do + let(:answer_callback_default) { Bandwidth::AnswerCallback.new } + let(:answer_callback_values) { Bandwidth::AnswerCallback.new({ + event_type: 'answer', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + machine_detection_result: { value: 'human', duration: 'PT5S' } + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::AnswerCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::AnswerCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::AnswerCallback.acceptable_attributes).to eq(Bandwidth::AnswerCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::AnswerCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag', + :'machine_detection_result' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of AnswerCallback created by the build_from_hash method' do + answer_callback_from_hash = Bandwidth::AnswerCallback.build_from_hash({ + eventType: 'answer', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + machineDetectionResult: { value: 'human', duration: 'PT5S' } + }) + expect(answer_callback_from_hash).to be_instance_of(Bandwidth::AnswerCallback) + expect(answer_callback_from_hash.event_type).to eq('answer') + expect(answer_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(answer_callback_from_hash.account_id).to eq('9900000') + expect(answer_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(answer_callback_from_hash.from).to eq('+19195554321') + expect(answer_callback_from_hash.to).to eq('+19195551234') + expect(answer_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(answer_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(answer_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(answer_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(answer_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(answer_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(answer_callback_from_hash.tag).to eq('custom tag') + expect(answer_callback_from_hash.machine_detection_result).to be_instance_of(Bandwidth::MachineDetectionResult) + expect(answer_callback_from_hash.machine_detection_result.value).to eq('human') + expect(answer_callback_from_hash.machine_detection_result.duration).to eq('PT5S') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(answer_callback_values.to_s).to eq('{:eventType=>"answer", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"inbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag", :machineDetectionResult=>{:value=>"human", :duration=>"PT5S"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(answer_callback_default.eql?(Bandwidth::AnswerCallback.new)).to be true + expect(answer_callback_default.eql?(answer_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(answer_callback_values.to_body).to eq({ + eventType: 'answer', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + machineDetectionResult: { value: 'human', duration: 'PT5S' } + }) + end + end +end diff --git a/spec/unit/models/async_lookup_request_spec.rb b/spec/unit/models/async_lookup_request_spec.rb new file mode 100644 index 00000000..a71ff605 --- /dev/null +++ b/spec/unit/models/async_lookup_request_spec.rb @@ -0,0 +1,77 @@ +# Unit tests for Bandwidth::AsyncLookupRequest +describe Bandwidth::AsyncLookupRequest do + let(:async_lookup_request_default) { Bandwidth::AsyncLookupRequest.new({ + phone_numbers: ['+19195551234'] + }) } + let(:async_lookup_request_values) { Bandwidth::AsyncLookupRequest.new({ + phone_numbers: ['+19195551234', '+19195554321'] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::AsyncLookupRequest.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::AsyncLookupRequest.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::AsyncLookupRequest.acceptable_attributes).to eq(Bandwidth::AsyncLookupRequest.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::AsyncLookupRequest.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of AsyncLookupRequest created by the build_from_hash method' do + async_lookup_request_from_hash = Bandwidth::AsyncLookupRequest.build_from_hash({ + phoneNumbers: ['+19195551234', '+19195554321'] + }) + expect(async_lookup_request_from_hash).to be_instance_of(Bandwidth::AsyncLookupRequest) + expect(async_lookup_request_from_hash.phone_numbers).to eq(['+19195551234', '+19195554321']) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(async_lookup_request_values.to_s).to eq('{:phoneNumbers=>["+19195551234", "+19195554321"]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + async_lookup_request_equal = Bandwidth::AsyncLookupRequest.new({ + phone_numbers: ['+19195551234'] + }) + expect(async_lookup_request_default.eql?(async_lookup_request_equal)).to be true + expect(async_lookup_request_default.eql?(async_lookup_request_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(async_lookup_request_values.to_body).to eq({ + phoneNumbers: ['+19195551234', '+19195554321'] + }) + end + end + + describe 'custom attribute writers' do + it '#phone_numbers=' do + expect { + async_lookup_request_values.phone_numbers = nil + }.to raise_error(ArgumentError, 'phone_numbers cannot be nil') + end + end +end diff --git a/spec/unit/models/blocked_webhook_spec.rb b/spec/unit/models/blocked_webhook_spec.rb new file mode 100644 index 00000000..7273d0f2 --- /dev/null +++ b/spec/unit/models/blocked_webhook_spec.rb @@ -0,0 +1,104 @@ +# Unit tests for Bandwidth::BlockedWebhook +describe Bandwidth::BlockedWebhook do + let(:blocked_webhook_default) { Bandwidth::BlockedWebhook.new } + let(:blocked_webhook_values) { Bandwidth::BlockedWebhook.new({ + account_id: '9900000', + phone_number: '+18005551234', + status: 'VERIFIED', + internal_ticket_number: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', + blocked: true, + blocked_reason: 'spam' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::BlockedWebhook.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::BlockedWebhook.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::BlockedWebhook.acceptable_attributes).to eq(Bandwidth::BlockedWebhook.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::BlockedWebhook.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of BlockedWebhook created by the build_from_hash method' do + blocked_webhook_from_hash = Bandwidth::BlockedWebhook.build_from_hash({ + accountId: '9900000', + phoneNumber: '+18005551234', + status: 'VERIFIED', + internalTicketNumber: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', + blocked: true, + blockedReason: 'spam' + }) + expect(blocked_webhook_from_hash).to be_instance_of(Bandwidth::BlockedWebhook) + expect(blocked_webhook_from_hash.account_id).to eq('9900000') + expect(blocked_webhook_from_hash.phone_number).to eq('+18005551234') + expect(blocked_webhook_from_hash.status).to eq('VERIFIED') + expect(blocked_webhook_from_hash.internal_ticket_number).to eq('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee') + expect(blocked_webhook_from_hash.blocked).to eq(true) + expect(blocked_webhook_from_hash.blocked_reason).to eq('spam') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(blocked_webhook_values.to_s).to eq('{:accountId=>"9900000", :phoneNumber=>"+18005551234", :status=>"VERIFIED", :internalTicketNumber=>"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", :blocked=>true, :blockedReason=>"spam"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(blocked_webhook_default.eql?(Bandwidth::BlockedWebhook.new)).to be true + expect(blocked_webhook_default.eql?(blocked_webhook_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(blocked_webhook_values.to_body).to eq({ + accountId: '9900000', + phoneNumber: '+18005551234', + status: 'VERIFIED', + internalTicketNumber: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', + blocked: true, + blockedReason: 'spam' + }) + end + end + + describe 'custom attribute writers' do + it '#phone_number=' do + expect { + Bandwidth::BlockedWebhook.new({ phone_number: nil }) + }.to raise_error(ArgumentError, 'phone_number cannot be nil') + + expect { + Bandwidth::BlockedWebhook.new({ phone_number: '+1800555123456' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be smaller than or equal to 12.') + + expect { + Bandwidth::BlockedWebhook.new({ phone_number: '+1800555' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be greater than or equal to 12.') + + expect { + Bandwidth::BlockedWebhook.new({ phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, /invalid value for "phone_number", must conform to the pattern/) + end + end +end diff --git a/spec/unit/models/bridge_complete_callback_spec.rb b/spec/unit/models/bridge_complete_callback_spec.rb new file mode 100644 index 00000000..184440b7 --- /dev/null +++ b/spec/unit/models/bridge_complete_callback_spec.rb @@ -0,0 +1,130 @@ +# Unit tests for Bandwidth::BridgeCompleteCallback +describe Bandwidth::BridgeCompleteCallback do + let(:bridge_complete_callback_default) { Bandwidth::BridgeCompleteCallback.new } + let(:bridge_complete_callback_values) { Bandwidth::BridgeCompleteCallback.new({ + event_type: 'bridgeComplete', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + cause: 'hangup', + error_message: 'call rejected', + error_id: '4642074b-7b58-478b-96e4-3a60955c6765' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::BridgeCompleteCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::BridgeCompleteCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::BridgeCompleteCallback.acceptable_attributes).to eq(Bandwidth::BridgeCompleteCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::BridgeCompleteCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag', + :'error_message', + :'error_id' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of BridgeCompleteCallback created by the build_from_hash method' do + bridge_complete_callback_from_hash = Bandwidth::BridgeCompleteCallback.build_from_hash({ + eventType: 'bridgeComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + cause: 'hangup', + errorMessage: 'call rejected', + errorId: '4642074b-7b58-478b-96e4-3a60955c6765' + }) + expect(bridge_complete_callback_from_hash).to be_instance_of(Bandwidth::BridgeCompleteCallback) + expect(bridge_complete_callback_from_hash.event_type).to eq('bridgeComplete') + expect(bridge_complete_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(bridge_complete_callback_from_hash.account_id).to eq('9900000') + expect(bridge_complete_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(bridge_complete_callback_from_hash.from).to eq('+19195554321') + expect(bridge_complete_callback_from_hash.to).to eq('+19195551234') + expect(bridge_complete_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::OUTBOUND) + expect(bridge_complete_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(bridge_complete_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(bridge_complete_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(bridge_complete_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(bridge_complete_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(bridge_complete_callback_from_hash.tag).to eq('custom tag') + expect(bridge_complete_callback_from_hash.cause).to eq('hangup') + expect(bridge_complete_callback_from_hash.error_message).to eq('call rejected') + expect(bridge_complete_callback_from_hash.error_id).to eq('4642074b-7b58-478b-96e4-3a60955c6765') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(bridge_complete_callback_values.to_s).to eq('{:eventType=>"bridgeComplete", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"outbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag", :cause=>"hangup", :errorMessage=>"call rejected", :errorId=>"4642074b-7b58-478b-96e4-3a60955c6765"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(bridge_complete_callback_default.eql?(Bandwidth::BridgeCompleteCallback.new)).to be true + expect(bridge_complete_callback_default.eql?(bridge_complete_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(bridge_complete_callback_values.to_body).to eq({ + eventType: 'bridgeComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + cause: 'hangup', + errorMessage: 'call rejected', + errorId: '4642074b-7b58-478b-96e4-3a60955c6765' + }) + end + end +end diff --git a/spec/unit/models/bridge_target_complete_callback_spec.rb b/spec/unit/models/bridge_target_complete_callback_spec.rb new file mode 100644 index 00000000..fc614e0b --- /dev/null +++ b/spec/unit/models/bridge_target_complete_callback_spec.rb @@ -0,0 +1,116 @@ +# Unit tests for Bandwidth::BridgeTargetCompleteCallback +describe Bandwidth::BridgeTargetCompleteCallback do + let(:bridge_target_complete_callback_default) { Bandwidth::BridgeTargetCompleteCallback.new } + let(:bridge_target_complete_callback_values) { Bandwidth::BridgeTargetCompleteCallback.new({ + event_type: 'bridgeTargetComplete', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::BridgeTargetCompleteCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::BridgeTargetCompleteCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::BridgeTargetCompleteCallback.acceptable_attributes).to eq(Bandwidth::BridgeTargetCompleteCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::BridgeTargetCompleteCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of BridgeTargetCompleteCallback created by the build_from_hash method' do + bridge_target_complete_callback_from_hash = Bandwidth::BridgeTargetCompleteCallback.build_from_hash({ + eventType: 'bridgeTargetComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag' + }) + expect(bridge_target_complete_callback_from_hash).to be_instance_of(Bandwidth::BridgeTargetCompleteCallback) + expect(bridge_target_complete_callback_from_hash.event_type).to eq('bridgeTargetComplete') + expect(bridge_target_complete_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(bridge_target_complete_callback_from_hash.account_id).to eq('9900000') + expect(bridge_target_complete_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(bridge_target_complete_callback_from_hash.from).to eq('+19195554321') + expect(bridge_target_complete_callback_from_hash.to).to eq('+19195551234') + expect(bridge_target_complete_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::OUTBOUND) + expect(bridge_target_complete_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(bridge_target_complete_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(bridge_target_complete_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(bridge_target_complete_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(bridge_target_complete_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(bridge_target_complete_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(bridge_target_complete_callback_values.to_s).to eq('{:eventType=>"bridgeTargetComplete", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"outbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(bridge_target_complete_callback_default.eql?(Bandwidth::BridgeTargetCompleteCallback.new)).to be true + expect(bridge_target_complete_callback_default.eql?(bridge_target_complete_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(bridge_target_complete_callback_values.to_body).to eq({ + eventType: 'bridgeTargetComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/brtc_error_response_spec.rb b/spec/unit/models/brtc_error_response_spec.rb new file mode 100644 index 00000000..f68a8586 --- /dev/null +++ b/spec/unit/models/brtc_error_response_spec.rb @@ -0,0 +1,93 @@ +# Unit tests for Bandwidth::BrtcErrorResponse +describe Bandwidth::BrtcErrorResponse do + let(:brtc_error_response_default) { Bandwidth::BrtcErrorResponse.new({ + links: [], + errors: [] + }) } + let(:brtc_error_response_values) { Bandwidth::BrtcErrorResponse.new({ + links: [Bandwidth::BrtcLink.new({ href: 'https://example.com', rel: 'self', method: 'GET' })], + data: { foo: 'bar' }, + errors: [Bandwidth::BrtcError.new({ type: 'validation', description: 'bad input' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::BrtcErrorResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::BrtcErrorResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::BrtcErrorResponse.acceptable_attributes).to eq(Bandwidth::BrtcErrorResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::BrtcErrorResponse.openapi_nullable).to eq(Set.new([:'data'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of BrtcErrorResponse created by the build_from_hash method' do + brtc_error_response_from_hash = Bandwidth::BrtcErrorResponse.build_from_hash({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { foo: 'bar' }, + errors: [{ type: 'validation', description: 'bad input' }] + }) + expect(brtc_error_response_from_hash).to be_instance_of(Bandwidth::BrtcErrorResponse) + expect(brtc_error_response_from_hash.links.first).to be_instance_of(Bandwidth::BrtcLink) + expect(brtc_error_response_from_hash.data).to eq({ foo: 'bar' }) + expect(brtc_error_response_from_hash.errors.first).to be_instance_of(Bandwidth::BrtcError) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(brtc_error_response_values.to_s).to eq('{:links=>[{:href=>"https://example.com", :rel=>"self", :method=>"GET"}], :data=>{:foo=>"bar"}, :errors=>[{:type=>"validation", :description=>"bad input"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + brtc_error_response_equal = Bandwidth::BrtcErrorResponse.new({ + links: [], + errors: [] + }) + expect(brtc_error_response_default.eql?(brtc_error_response_equal)).to be true + expect(brtc_error_response_default.eql?(brtc_error_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(brtc_error_response_values.to_body).to eq({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { foo: 'bar' }, + errors: [{ type: 'validation', description: 'bad input' }] + }) + end + end + + describe 'custom attribute writers' do + it '#links=' do + expect { + brtc_error_response_values.links = nil + }.to raise_error(ArgumentError, 'links cannot be nil') + end + + it '#errors=' do + expect { + brtc_error_response_values.errors = nil + }.to raise_error(ArgumentError, 'errors cannot be nil') + end + end +end diff --git a/spec/unit/models/brtc_error_source_spec.rb b/spec/unit/models/brtc_error_source_spec.rb new file mode 100644 index 00000000..be1b11b7 --- /dev/null +++ b/spec/unit/models/brtc_error_source_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::BrtcErrorSource +describe Bandwidth::BrtcErrorSource do + let(:brtc_error_source_default) { Bandwidth::BrtcErrorSource.new } + let(:brtc_error_source_values) { Bandwidth::BrtcErrorSource.new({ + parameter: 'limit', + field: 'phoneNumber', + header: 'Authorization', + reference: '/accounts/9900000' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::BrtcErrorSource.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::BrtcErrorSource.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::BrtcErrorSource.acceptable_attributes).to eq(Bandwidth::BrtcErrorSource.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::BrtcErrorSource.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of BrtcErrorSource created by the build_from_hash method' do + brtc_error_source_from_hash = Bandwidth::BrtcErrorSource.build_from_hash({ + parameter: 'limit', + field: 'phoneNumber', + header: 'Authorization', + reference: '/accounts/9900000' + }) + expect(brtc_error_source_from_hash).to be_instance_of(Bandwidth::BrtcErrorSource) + expect(brtc_error_source_from_hash.parameter).to eq('limit') + expect(brtc_error_source_from_hash.field).to eq('phoneNumber') + expect(brtc_error_source_from_hash.header).to eq('Authorization') + expect(brtc_error_source_from_hash.reference).to eq('/accounts/9900000') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(brtc_error_source_values.to_s).to eq('{:parameter=>"limit", :field=>"phoneNumber", :header=>"Authorization", :reference=>"/accounts/9900000"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(brtc_error_source_default.eql?(Bandwidth::BrtcErrorSource.new)).to be true + expect(brtc_error_source_default.eql?(brtc_error_source_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(brtc_error_source_values.to_body).to eq({ + parameter: 'limit', + field: 'phoneNumber', + header: 'Authorization', + reference: '/accounts/9900000' + }) + end + end +end diff --git a/spec/unit/models/brtc_error_spec.rb b/spec/unit/models/brtc_error_spec.rb new file mode 100644 index 00000000..a864f8a0 --- /dev/null +++ b/spec/unit/models/brtc_error_spec.rb @@ -0,0 +1,101 @@ +# Unit tests for Bandwidth::BrtcError +describe Bandwidth::BrtcError do + let(:brtc_error_default) { Bandwidth::BrtcError.new({ + type: 'baseline', + description: 'baseline description' + }) } + let(:brtc_error_values) { Bandwidth::BrtcError.new({ + id: 'abc-123', + type: 'validation', + description: 'bad input', + code: 'E1001', + source: Bandwidth::BrtcErrorSource.new({ field: 'phoneNumber' }) + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::BrtcError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::BrtcError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::BrtcError.acceptable_attributes).to eq(Bandwidth::BrtcError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::BrtcError.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of BrtcError created by the build_from_hash method' do + brtc_error_from_hash = Bandwidth::BrtcError.build_from_hash({ + id: 'abc-123', + type: 'validation', + description: 'bad input', + code: 'E1001', + source: { field: 'phoneNumber' } + }) + expect(brtc_error_from_hash).to be_instance_of(Bandwidth::BrtcError) + expect(brtc_error_from_hash.id).to eq('abc-123') + expect(brtc_error_from_hash.type).to eq('validation') + expect(brtc_error_from_hash.description).to eq('bad input') + expect(brtc_error_from_hash.code).to eq('E1001') + expect(brtc_error_from_hash.source).to be_instance_of(Bandwidth::BrtcErrorSource) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(brtc_error_values.to_s).to eq('{:id=>"abc-123", :type=>"validation", :description=>"bad input", :code=>"E1001", :source=>{:field=>"phoneNumber"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + brtc_error_equal = Bandwidth::BrtcError.new({ + type: 'baseline', + description: 'baseline description' + }) + expect(brtc_error_default.eql?(brtc_error_equal)).to be true + expect(brtc_error_default.eql?(brtc_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(brtc_error_values.to_body).to eq({ + id: 'abc-123', + type: 'validation', + description: 'bad input', + code: 'E1001', + source: { field: 'phoneNumber' } + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::BrtcError.new({ type: nil, description: 'a' }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#description=' do + expect { + Bandwidth::BrtcError.new({ type: 'a', description: nil }) + }.to raise_error(ArgumentError, 'description cannot be nil') + end + end +end diff --git a/spec/unit/models/brtc_link_spec.rb b/spec/unit/models/brtc_link_spec.rb new file mode 100644 index 00000000..7b4eaae6 --- /dev/null +++ b/spec/unit/models/brtc_link_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::BrtcLink +describe Bandwidth::BrtcLink do + let(:brtc_link_default) { Bandwidth::BrtcLink.new } + let(:brtc_link_values) { Bandwidth::BrtcLink.new({ + href: 'https://example.com', + rel: 'self', + method: 'GET' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::BrtcLink.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::BrtcLink.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::BrtcLink.acceptable_attributes).to eq(Bandwidth::BrtcLink.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::BrtcLink.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of BrtcLink created by the build_from_hash method' do + brtc_link_from_hash = Bandwidth::BrtcLink.build_from_hash({ + href: 'https://example.com', + rel: 'self', + method: 'GET' + }) + expect(brtc_link_from_hash).to be_instance_of(Bandwidth::BrtcLink) + expect(brtc_link_from_hash.href).to eq('https://example.com') + expect(brtc_link_from_hash.rel).to eq('self') + expect(brtc_link_from_hash.method).to eq('GET') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(brtc_link_values.to_s).to eq('{:href=>"https://example.com", :rel=>"self", :method=>"GET"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(brtc_link_default.eql?(Bandwidth::BrtcLink.new)).to be true + expect(brtc_link_default.eql?(brtc_link_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(brtc_link_values.to_body).to eq({ + href: 'https://example.com', + rel: 'self', + method: 'GET' + }) + end + end +end diff --git a/spec/unit/models/business_entity_type_enum_spec.rb b/spec/unit/models/business_entity_type_enum_spec.rb new file mode 100644 index 00000000..dccfadb7 --- /dev/null +++ b/spec/unit/models/business_entity_type_enum_spec.rb @@ -0,0 +1,52 @@ +# Unit tests for Bandwidth::BusinessEntityTypeEnum +describe Bandwidth::BusinessEntityTypeEnum do + describe 'constants' do + it 'defines SOLE_PROPRIETOR' do + expect(Bandwidth::BusinessEntityTypeEnum::SOLE_PROPRIETOR).to eq('SOLE_PROPRIETOR') + end + + it 'defines PRIVATE_PROFIT' do + expect(Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT).to eq('PRIVATE_PROFIT') + end + + it 'defines PUBLIC_PROFIT' do + expect(Bandwidth::BusinessEntityTypeEnum::PUBLIC_PROFIT).to eq('PUBLIC_PROFIT') + end + + it 'defines NON_PROFIT' do + expect(Bandwidth::BusinessEntityTypeEnum::NON_PROFIT).to eq('NON_PROFIT') + end + + it 'defines GOVERNMENT' do + expect(Bandwidth::BusinessEntityTypeEnum::GOVERNMENT).to eq('GOVERNMENT') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::BusinessEntityTypeEnum.all_vars).to eq([ + 'SOLE_PROPRIETOR', + 'PRIVATE_PROFIT', + 'PUBLIC_PROFIT', + 'NON_PROFIT', + 'GOVERNMENT' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::BusinessEntityTypeEnum.build_from_hash('SOLE_PROPRIETOR')).to eq('SOLE_PROPRIETOR') + expect(Bandwidth::BusinessEntityTypeEnum.build_from_hash('PRIVATE_PROFIT')).to eq('PRIVATE_PROFIT') + expect(Bandwidth::BusinessEntityTypeEnum.build_from_hash('PUBLIC_PROFIT')).to eq('PUBLIC_PROFIT') + expect(Bandwidth::BusinessEntityTypeEnum.build_from_hash('NON_PROFIT')).to eq('NON_PROFIT') + expect(Bandwidth::BusinessEntityTypeEnum.build_from_hash('GOVERNMENT')).to eq('GOVERNMENT') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::BusinessEntityTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/business_registration_type_enum_spec.rb b/spec/unit/models/business_registration_type_enum_spec.rb new file mode 100644 index 00000000..b44f537d --- /dev/null +++ b/spec/unit/models/business_registration_type_enum_spec.rb @@ -0,0 +1,130 @@ +# Unit tests for Bandwidth::BusinessRegistrationTypeEnum +describe Bandwidth::BusinessRegistrationTypeEnum do + describe 'constants' do + it 'defines EIN' do + expect(Bandwidth::BusinessRegistrationTypeEnum::EIN).to eq('EIN') + end + + it 'defines CBN' do + expect(Bandwidth::BusinessRegistrationTypeEnum::CBN).to eq('CBN') + end + + it 'defines NEQ' do + expect(Bandwidth::BusinessRegistrationTypeEnum::NEQ).to eq('NEQ') + end + + it 'defines PROVINCIAL_NUMBER' do + expect(Bandwidth::BusinessRegistrationTypeEnum::PROVINCIAL_NUMBER).to eq('PROVINCIAL_NUMBER') + end + + it 'defines CRN' do + expect(Bandwidth::BusinessRegistrationTypeEnum::CRN).to eq('CRN') + end + + it 'defines VAT' do + expect(Bandwidth::BusinessRegistrationTypeEnum::VAT).to eq('VAT') + end + + it 'defines ACN' do + expect(Bandwidth::BusinessRegistrationTypeEnum::ACN).to eq('ACN') + end + + it 'defines ABN' do + expect(Bandwidth::BusinessRegistrationTypeEnum::ABN).to eq('ABN') + end + + it 'defines BRN' do + expect(Bandwidth::BusinessRegistrationTypeEnum::BRN).to eq('BRN') + end + + it 'defines SIREN' do + expect(Bandwidth::BusinessRegistrationTypeEnum::SIREN).to eq('SIREN') + end + + it 'defines SIRET' do + expect(Bandwidth::BusinessRegistrationTypeEnum::SIRET).to eq('SIRET') + end + + it 'defines NZBN' do + expect(Bandwidth::BusinessRegistrationTypeEnum::NZBN).to eq('NZBN') + end + + it 'defines UST_IDNR' do + expect(Bandwidth::BusinessRegistrationTypeEnum::UST_IDNR).to eq('UST_IDNR') + end + + it 'defines CIF' do + expect(Bandwidth::BusinessRegistrationTypeEnum::CIF).to eq('CIF') + end + + it 'defines NIF' do + expect(Bandwidth::BusinessRegistrationTypeEnum::NIF).to eq('NIF') + end + + it 'defines CNPJ' do + expect(Bandwidth::BusinessRegistrationTypeEnum::CNPJ).to eq('CNPJ') + end + + it 'defines UID' do + expect(Bandwidth::BusinessRegistrationTypeEnum::UID).to eq('UID') + end + + it 'defines OTHER' do + expect(Bandwidth::BusinessRegistrationTypeEnum::OTHER).to eq('OTHER') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::BusinessRegistrationTypeEnum.all_vars).to eq([ + 'EIN', + 'CBN', + 'NEQ', + 'PROVINCIAL_NUMBER', + 'CRN', + 'VAT', + 'ACN', + 'ABN', + 'BRN', + 'SIREN', + 'SIRET', + 'NZBN', + 'UST_IDNR', + 'CIF', + 'NIF', + 'CNPJ', + 'UID', + 'OTHER' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('EIN')).to eq('EIN') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('CBN')).to eq('CBN') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('NEQ')).to eq('NEQ') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('PROVINCIAL_NUMBER')).to eq('PROVINCIAL_NUMBER') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('CRN')).to eq('CRN') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('VAT')).to eq('VAT') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('ACN')).to eq('ACN') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('ABN')).to eq('ABN') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('BRN')).to eq('BRN') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('SIREN')).to eq('SIREN') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('SIRET')).to eq('SIRET') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('NZBN')).to eq('NZBN') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('UST_IDNR')).to eq('UST_IDNR') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('CIF')).to eq('CIF') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('NIF')).to eq('NIF') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('CNPJ')).to eq('CNPJ') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('UID')).to eq('UID') + expect(Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('OTHER')).to eq('OTHER') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::BusinessRegistrationTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/call_direction_enum_spec.rb b/spec/unit/models/call_direction_enum_spec.rb new file mode 100644 index 00000000..bd901bfe --- /dev/null +++ b/spec/unit/models/call_direction_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::CallDirectionEnum +describe Bandwidth::CallDirectionEnum do + describe 'constants' do + it 'defines INBOUND' do + expect(Bandwidth::CallDirectionEnum::INBOUND).to eq('inbound') + end + + it 'defines OUTBOUND' do + expect(Bandwidth::CallDirectionEnum::OUTBOUND).to eq('outbound') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::CallDirectionEnum.all_vars).to eq([ + 'inbound', + 'outbound' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::CallDirectionEnum.build_from_hash('inbound')).to eq('inbound') + expect(Bandwidth::CallDirectionEnum.build_from_hash('outbound')).to eq('outbound') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::CallDirectionEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/call_recording_metadata_spec.rb b/spec/unit/models/call_recording_metadata_spec.rb new file mode 100644 index 00000000..be942ce5 --- /dev/null +++ b/spec/unit/models/call_recording_metadata_spec.rb @@ -0,0 +1,137 @@ +# Unit tests for Bandwidth::CallRecordingMetadata +describe Bandwidth::CallRecordingMetadata do + let(:call_recording_metadata_default) { Bandwidth::CallRecordingMetadata.new } + let(:call_recording_metadata_values) { Bandwidth::CallRecordingMetadata.new({ + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + account_id: '9900000', + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parent_call_id: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recording_id: 'r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4', + to: '+19195551234', + from: '+19195554321', + transfer_caller_id: '+19195555678', + transfer_to: '+19195558765', + duration: 'PT13.67S', + direction: Bandwidth::CallDirectionEnum::INBOUND, + channels: 1, + start_time: '2022-06-16T13:15:07.160Z', + end_time: '2022-06-16T13:15:20.830Z', + file_format: Bandwidth::FileFormatEnum::WAV, + status: 'complete', + media_url: 'https://example.com/recording.wav', + transcription: { id: 't-123', url: 'https://example.com/t-123', status: 'available', completed_time: '2022-06-16T13:15:31.000Z' }, + recording_name: 'sample-recording' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CallRecordingMetadata.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CallRecordingMetadata.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CallRecordingMetadata.acceptable_attributes).to eq(Bandwidth::CallRecordingMetadata.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::CallRecordingMetadata.openapi_nullable).to eq(Set.new([ + :'media_url', + :'transcription' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CallRecordingMetadata created by the build_from_hash method' do + call_recording_metadata_from_hash = Bandwidth::CallRecordingMetadata.build_from_hash({ + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + accountId: '9900000', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recordingId: 'r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4', + to: '+19195551234', + from: '+19195554321', + transferCallerId: '+19195555678', + transferTo: '+19195558765', + duration: 'PT13.67S', + direction: 'inbound', + channels: 1, + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:15:20.830Z', + fileFormat: 'wav', + status: 'complete', + mediaUrl: 'https://example.com/recording.wav', + recordingName: 'sample-recording' + }) + expect(call_recording_metadata_from_hash).to be_instance_of(Bandwidth::CallRecordingMetadata) + expect(call_recording_metadata_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(call_recording_metadata_from_hash.account_id).to eq('9900000') + expect(call_recording_metadata_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(call_recording_metadata_from_hash.parent_call_id).to eq('c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99') + expect(call_recording_metadata_from_hash.recording_id).to eq('r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4') + expect(call_recording_metadata_from_hash.to).to eq('+19195551234') + expect(call_recording_metadata_from_hash.from).to eq('+19195554321') + expect(call_recording_metadata_from_hash.transfer_caller_id).to eq('+19195555678') + expect(call_recording_metadata_from_hash.transfer_to).to eq('+19195558765') + expect(call_recording_metadata_from_hash.duration).to eq('PT13.67S') + expect(call_recording_metadata_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(call_recording_metadata_from_hash.channels).to eq(1) + expect(call_recording_metadata_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(call_recording_metadata_from_hash.end_time).to eq(Time.parse('2022-06-16T13:15:20.830Z')) + expect(call_recording_metadata_from_hash.file_format).to eq(Bandwidth::FileFormatEnum::WAV) + expect(call_recording_metadata_from_hash.status).to eq('complete') + expect(call_recording_metadata_from_hash.media_url).to eq('https://example.com/recording.wav') + expect(call_recording_metadata_from_hash.recording_name).to eq('sample-recording') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(call_recording_metadata_values.to_s).to eq('{:applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :accountId=>"9900000", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :parentCallId=>"c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99", :recordingId=>"r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4", :to=>"+19195551234", :from=>"+19195554321", :transferCallerId=>"+19195555678", :transferTo=>"+19195558765", :duration=>"PT13.67S", :direction=>"inbound", :channels=>1, :startTime=>"2022-06-16T13:15:07.160Z", :endTime=>"2022-06-16T13:15:20.830Z", :fileFormat=>"wav", :status=>"complete", :mediaUrl=>"https://example.com/recording.wav", :transcription=>{:id=>"t-123", :url=>"https://example.com/t-123", :status=>"available", :completed_time=>"2022-06-16T13:15:31.000Z"}, :recordingName=>"sample-recording"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(call_recording_metadata_default.eql?(Bandwidth::CallRecordingMetadata.new)).to be true + expect(call_recording_metadata_default.eql?(call_recording_metadata_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(call_recording_metadata_values.to_body).to eq({ + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + accountId: '9900000', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recordingId: 'r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4', + to: '+19195551234', + from: '+19195554321', + transferCallerId: '+19195555678', + transferTo: '+19195558765', + duration: 'PT13.67S', + direction: Bandwidth::CallDirectionEnum::INBOUND, + channels: 1, + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:15:20.830Z', + fileFormat: Bandwidth::FileFormatEnum::WAV, + status: 'complete', + mediaUrl: 'https://example.com/recording.wav', + transcription: { id: 't-123', url: 'https://example.com/t-123', status: 'available', completed_time: '2022-06-16T13:15:31.000Z' }, + recordingName: 'sample-recording' + }) + end + end +end diff --git a/spec/unit/models/call_state_enum_spec.rb b/spec/unit/models/call_state_enum_spec.rb index 4dad702d..2ef34e5d 100644 --- a/spec/unit/models/call_state_enum_spec.rb +++ b/spec/unit/models/call_state_enum_spec.rb @@ -1,10 +1,25 @@ # Unit tests for Bandwidth::CallStateEnum describe Bandwidth::CallStateEnum do - let(:instance) { Bandwidth::CallStateEnum.new } + describe 'constants' do + it 'defines ACTIVE' do + expect(Bandwidth::CallStateEnum::ACTIVE).to eq('active') + end + + it 'defines COMPLETED' do + expect(Bandwidth::CallStateEnum::COMPLETED).to eq('completed') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::CallStateEnum.all_vars).to eq(['active', 'completed']) + end + end - describe 'test an instance of CallStateEnum' do - it 'creates an instance of CallStateEnum' do - expect(instance).to be_instance_of(Bandwidth::CallStateEnum) + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::CallStateEnum.build_from_hash('active')).to eq('active') + expect(Bandwidth::CallStateEnum.build_from_hash('completed')).to eq('completed') end it 'raises an error for an invalid enum value' do diff --git a/spec/unit/models/call_state_spec.rb b/spec/unit/models/call_state_spec.rb index 41b549aa..1a9ef9f9 100644 --- a/spec/unit/models/call_state_spec.rb +++ b/spec/unit/models/call_state_spec.rb @@ -46,23 +46,20 @@ end end - describe 'EnumAttributeValidator' do - it 'validates string enum' do - validator = Bandwidth::CallState::EnumAttributeValidator.new(String, ['valid']) - expect(validator.valid?('valid')).to be true - expect(validator.valid?('invalid')).to be false - end - - it 'validates integer enum' do - validator = Bandwidth::CallState::EnumAttributeValidator.new(Integer, [1]) - expect(validator.valid?(1)).to be true - expect(validator.valid?('invalid')).to be false - end - - it 'validates float enum' do - validator = Bandwidth::CallState::EnumAttributeValidator.new(Float, [1.0]) - expect(validator.valid?(1.0)).to be true - expect(validator.valid?('invalid')).to be false + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::CallState.openapi_nullable).to eq(Set.new([ + :'parent_call_id', + :'stir_shaken', + :'identity', + :'enqueued_time', + :'start_time', + :'answer_time', + :'end_time', + :'disconnect_cause', + :'error_message', + :'error_id' + ])) end end @@ -118,15 +115,9 @@ end end - describe '#hash' do - it 'returns a hash code according to attributes' do - expect(call_state_default.hash).to be_instance_of(Integer) - end - end - describe '#to_s' do it 'returns a string representation of the object' do - expect(call_state_default.to_s).to eq('{}') + expect(call_state_values.to_s).to eq('{:applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :accountId=>"9900000", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :parentCallId=>"c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :to=>"+19195551234", :from=>"+19195554321", :direction=>"inbound", :state=>"disconnected", :stirShaken=>{:verstat=>"TN-Verification-Passed", :attestationIndicator=>"A", :originatingId=>"abc123"}, :identity=>"eyJhbGciOiJFUzI1NiI", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :endTime=>"2022-06-16T13:15:18.314Z", :disconnectCause=>"hangup", :errorMessage=>nil, :errorId=>nil, :lastUpdate=>"2022-06-16T13:15:18.314Z"}') end end diff --git a/spec/unit/models/call_transcription_detected_language_enum_spec.rb b/spec/unit/models/call_transcription_detected_language_enum_spec.rb new file mode 100644 index 00000000..ea3b3bc4 --- /dev/null +++ b/spec/unit/models/call_transcription_detected_language_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::CallTranscriptionDetectedLanguageEnum +describe Bandwidth::CallTranscriptionDetectedLanguageEnum do + describe 'constants' do + it 'defines EN_US' do + expect(Bandwidth::CallTranscriptionDetectedLanguageEnum::EN_US).to eq('en-US') + end + + it 'defines ES_US' do + expect(Bandwidth::CallTranscriptionDetectedLanguageEnum::ES_US).to eq('es-US') + end + + it 'defines FR_FR' do + expect(Bandwidth::CallTranscriptionDetectedLanguageEnum::FR_FR).to eq('fr-FR') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::CallTranscriptionDetectedLanguageEnum.all_vars).to eq([ + 'en-US', + 'es-US', + 'fr-FR' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::CallTranscriptionDetectedLanguageEnum.build_from_hash('en-US')).to eq('en-US') + expect(Bandwidth::CallTranscriptionDetectedLanguageEnum.build_from_hash('es-US')).to eq('es-US') + expect(Bandwidth::CallTranscriptionDetectedLanguageEnum.build_from_hash('fr-FR')).to eq('fr-FR') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::CallTranscriptionDetectedLanguageEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/call_transcription_metadata_spec.rb b/spec/unit/models/call_transcription_metadata_spec.rb new file mode 100644 index 00000000..cc58f5cc --- /dev/null +++ b/spec/unit/models/call_transcription_metadata_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::CallTranscriptionMetadata +describe Bandwidth::CallTranscriptionMetadata do + let(:call_transcription_metadata_default) { Bandwidth::CallTranscriptionMetadata.new } + let(:call_transcription_metadata_values) { Bandwidth::CallTranscriptionMetadata.new({ + transcription_id: 't-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + transcription_name: 'live-transcription', + transcription_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1/transcriptions/t-1' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CallTranscriptionMetadata.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CallTranscriptionMetadata.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CallTranscriptionMetadata.acceptable_attributes).to eq(Bandwidth::CallTranscriptionMetadata.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CallTranscriptionMetadata.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CallTranscriptionMetadata created by the build_from_hash method' do + call_transcription_metadata_from_hash = Bandwidth::CallTranscriptionMetadata.build_from_hash({ + transcriptionId: 't-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + transcriptionName: 'live-transcription', + transcriptionUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1/transcriptions/t-1' + }) + expect(call_transcription_metadata_from_hash).to be_instance_of(Bandwidth::CallTranscriptionMetadata) + expect(call_transcription_metadata_from_hash.transcription_id).to eq('t-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(call_transcription_metadata_from_hash.transcription_name).to eq('live-transcription') + expect(call_transcription_metadata_from_hash.transcription_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1/transcriptions/t-1') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(call_transcription_metadata_values.to_s).to eq('{:transcriptionId=>"t-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :transcriptionName=>"live-transcription", :transcriptionUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1/transcriptions/t-1"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(call_transcription_metadata_default.eql?(Bandwidth::CallTranscriptionMetadata.new)).to be true + expect(call_transcription_metadata_default.eql?(call_transcription_metadata_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(call_transcription_metadata_values.to_body).to eq({ + transcriptionId: 't-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + transcriptionName: 'live-transcription', + transcriptionUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1/transcriptions/t-1' + }) + end + end +end diff --git a/spec/unit/models/call_transcription_response_spec.rb b/spec/unit/models/call_transcription_response_spec.rb new file mode 100644 index 00000000..b152fde4 --- /dev/null +++ b/spec/unit/models/call_transcription_response_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::CallTranscriptionResponse +describe Bandwidth::CallTranscriptionResponse do + let(:call_transcription_response_default) { Bandwidth::CallTranscriptionResponse.new } + let(:call_transcription_response_values) { Bandwidth::CallTranscriptionResponse.new({ + account_id: '9900000', + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + transcription_id: 't-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tracks: [Bandwidth::CallTranscription.new({ detected_language: 'en-US', track: 'inbound', transcript: 'Hello', confidence: 0.9 })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CallTranscriptionResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CallTranscriptionResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CallTranscriptionResponse.acceptable_attributes).to eq(Bandwidth::CallTranscriptionResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CallTranscriptionResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CallTranscriptionResponse created by the build_from_hash method' do + call_transcription_response_from_hash = Bandwidth::CallTranscriptionResponse.build_from_hash({ + accountId: '9900000', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + transcriptionId: 't-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tracks: [{ detectedLanguage: 'en-US', track: 'inbound', transcript: 'Hello', confidence: 0.9 }] + }) + expect(call_transcription_response_from_hash).to be_instance_of(Bandwidth::CallTranscriptionResponse) + expect(call_transcription_response_from_hash.account_id).to eq('9900000') + expect(call_transcription_response_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(call_transcription_response_from_hash.transcription_id).to eq('t-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(call_transcription_response_from_hash.tracks.first).to be_instance_of(Bandwidth::CallTranscription) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(call_transcription_response_values.to_s).to eq('{:accountId=>"9900000", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :transcriptionId=>"t-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :tracks=>[{:detectedLanguage=>"en-US", :track=>"inbound", :transcript=>"Hello", :confidence=>0.9}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(call_transcription_response_default.eql?(Bandwidth::CallTranscriptionResponse.new)).to be true + expect(call_transcription_response_default.eql?(call_transcription_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(call_transcription_response_values.to_body).to eq({ + accountId: '9900000', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + transcriptionId: 't-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tracks: [{ detectedLanguage: 'en-US', track: 'inbound', transcript: 'Hello', confidence: 0.9 }] + }) + end + end +end diff --git a/spec/unit/models/call_transcription_spec.rb b/spec/unit/models/call_transcription_spec.rb new file mode 100644 index 00000000..50ac444d --- /dev/null +++ b/spec/unit/models/call_transcription_spec.rb @@ -0,0 +1,92 @@ +# Unit tests for Bandwidth::CallTranscription +describe Bandwidth::CallTranscription do + let(:call_transcription_default) { Bandwidth::CallTranscription.new } + let(:call_transcription_values) { Bandwidth::CallTranscription.new({ + detected_language: Bandwidth::CallTranscriptionDetectedLanguageEnum::EN_US, + track: Bandwidth::CallTranscriptionTrackEnum::INBOUND, + transcript: 'Hello world', + confidence: 0.9 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CallTranscription.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CallTranscription.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CallTranscription.acceptable_attributes).to eq(Bandwidth::CallTranscription.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CallTranscription.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CallTranscription created by the build_from_hash method' do + call_transcription_from_hash = Bandwidth::CallTranscription.build_from_hash({ + detectedLanguage: 'en-US', + track: 'inbound', + transcript: 'Hello world', + confidence: 0.9 + }) + expect(call_transcription_from_hash).to be_instance_of(Bandwidth::CallTranscription) + expect(call_transcription_from_hash.detected_language).to eq(Bandwidth::CallTranscriptionDetectedLanguageEnum::EN_US) + expect(call_transcription_from_hash.track).to eq(Bandwidth::CallTranscriptionTrackEnum::INBOUND) + expect(call_transcription_from_hash.transcript).to eq('Hello world') + expect(call_transcription_from_hash.confidence).to eq(0.9) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(call_transcription_values.to_s).to eq('{:detectedLanguage=>"en-US", :track=>"inbound", :transcript=>"Hello world", :confidence=>0.9}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(call_transcription_default.eql?(Bandwidth::CallTranscription.new)).to be true + expect(call_transcription_default.eql?(call_transcription_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(call_transcription_values.to_body).to eq({ + detectedLanguage: Bandwidth::CallTranscriptionDetectedLanguageEnum::EN_US, + track: Bandwidth::CallTranscriptionTrackEnum::INBOUND, + transcript: 'Hello world', + confidence: 0.9 + }) + end + end + + describe 'custom attribute writers' do + it '#confidence=' do + expect { + Bandwidth::CallTranscription.new({ confidence: nil }) + }.to raise_error(ArgumentError, 'confidence cannot be nil') + + expect { + Bandwidth::CallTranscription.new({ confidence: 1.5 }) + }.to raise_error(ArgumentError, 'invalid value for "confidence", must be smaller than or equal to 1.') + + expect { + Bandwidth::CallTranscription.new({ confidence: -0.5 }) + }.to raise_error(ArgumentError, 'invalid value for "confidence", must be greater than or equal to 0.') + end + end +end diff --git a/spec/unit/models/call_transcription_track_enum_spec.rb b/spec/unit/models/call_transcription_track_enum_spec.rb new file mode 100644 index 00000000..3b1b4a34 --- /dev/null +++ b/spec/unit/models/call_transcription_track_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::CallTranscriptionTrackEnum +describe Bandwidth::CallTranscriptionTrackEnum do + describe 'constants' do + it 'defines INBOUND' do + expect(Bandwidth::CallTranscriptionTrackEnum::INBOUND).to eq('inbound') + end + + it 'defines OUTBOUND' do + expect(Bandwidth::CallTranscriptionTrackEnum::OUTBOUND).to eq('outbound') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::CallTranscriptionTrackEnum.all_vars).to eq([ + 'inbound', + 'outbound' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::CallTranscriptionTrackEnum.build_from_hash('inbound')).to eq('inbound') + expect(Bandwidth::CallTranscriptionTrackEnum.build_from_hash('outbound')).to eq('outbound') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::CallTranscriptionTrackEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/callback_method_enum_spec.rb b/spec/unit/models/callback_method_enum_spec.rb new file mode 100644 index 00000000..79706d23 --- /dev/null +++ b/spec/unit/models/callback_method_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::CallbackMethodEnum +describe Bandwidth::CallbackMethodEnum do + describe 'constants' do + it 'defines GET' do + expect(Bandwidth::CallbackMethodEnum::GET).to eq('GET') + end + + it 'defines POST' do + expect(Bandwidth::CallbackMethodEnum::POST).to eq('POST') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::CallbackMethodEnum.all_vars).to eq([ + 'GET', + 'POST' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::CallbackMethodEnum.build_from_hash('GET')).to eq('GET') + expect(Bandwidth::CallbackMethodEnum.build_from_hash('POST')).to eq('POST') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::CallbackMethodEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/callback_spec.rb b/spec/unit/models/callback_spec.rb new file mode 100644 index 00000000..b3a675ee --- /dev/null +++ b/spec/unit/models/callback_spec.rb @@ -0,0 +1,65 @@ +# Unit tests for Bandwidth::Callback +describe Bandwidth::Callback do + describe '.openapi_one_of' do + it 'lists the classes defined in oneOf' do + expect(Bandwidth::Callback.openapi_one_of).to eq([ + :'InboundCallback', + :'StatusCallback' + ]) + end + end + + describe '.openapi_discriminator_name' do + it 'returns the discriminator property name' do + expect(Bandwidth::Callback.openapi_discriminator_name).to eq(:'type') + end + end + + describe '.openapi_discriminator_mapping' do + it 'maps every discriminator value to a oneOf class' do + expect(Bandwidth::Callback.openapi_discriminator_mapping).to eq({ + :'message-delivered' => :'StatusCallback', + :'message-failed' => :'StatusCallback', + :'message-read' => :'StatusCallback', + :'message-received' => :'InboundCallback', + :'message-sending' => :'StatusCallback', + :'message-sent' => :'StatusCallback', + :'request-location-response' => :'InboundCallback', + :'suggestion-response' => :'InboundCallback' + }) + end + + it 'maps only to classes listed in openapi_one_of' do + mapping_targets = Bandwidth::Callback.openapi_discriminator_mapping.values.uniq.sort + expect(mapping_targets).to eq(Bandwidth::Callback.openapi_one_of.sort) + end + end + + describe '.build' do + it 'routes inbound discriminator values to InboundCallback.build_from_hash' do + Bandwidth::Callback.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'InboundCallback' + data = { type: discriminator.to_s } + expect(Bandwidth::InboundCallback).to receive(:build_from_hash).with(data).and_return(:inbound_result) + expect(Bandwidth::Callback.build(data)).to eq(:inbound_result) + end + end + + it 'routes status discriminator values to StatusCallback.build_from_hash' do + Bandwidth::Callback.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'StatusCallback' + data = { type: discriminator.to_s } + expect(Bandwidth::StatusCallback).to receive(:build_from_hash).with(data).and_return(:status_result) + expect(Bandwidth::Callback.build(data)).to eq(:status_result) + end + end + + it 'returns nil when the discriminator value is missing' do + expect(Bandwidth::Callback.build({})).to be_nil + end + + it 'returns nil when the discriminator value does not match any mapping' do + expect(Bandwidth::Callback.build({ type: 'unknown' })).to be_nil + end + end +end diff --git a/spec/unit/models/card_width_enum_spec.rb b/spec/unit/models/card_width_enum_spec.rb new file mode 100644 index 00000000..a82bf336 --- /dev/null +++ b/spec/unit/models/card_width_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::CardWidthEnum +describe Bandwidth::CardWidthEnum do + describe 'constants' do + it 'defines SMALL' do + expect(Bandwidth::CardWidthEnum::SMALL).to eq('SMALL') + end + + it 'defines MEDIUM' do + expect(Bandwidth::CardWidthEnum::MEDIUM).to eq('MEDIUM') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::CardWidthEnum.all_vars).to eq([ + 'SMALL', + 'MEDIUM' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::CardWidthEnum.build_from_hash('SMALL')).to eq('SMALL') + expect(Bandwidth::CardWidthEnum.build_from_hash('MEDIUM')).to eq('MEDIUM') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::CardWidthEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/code_request_spec.rb b/spec/unit/models/code_request_spec.rb new file mode 100644 index 00000000..e679ba72 --- /dev/null +++ b/spec/unit/models/code_request_spec.rb @@ -0,0 +1,167 @@ +# Unit tests for Bandwidth::CodeRequest +describe Bandwidth::CodeRequest do + let(:code_request_default) { Bandwidth::CodeRequest.new({ + to: '+19195550100', + from: '+19195550101', + application_id: 'baseline-app', + message: 'Your code is {CODE}', + digits: 6 + }) } + let(:code_request_values) { Bandwidth::CodeRequest.new({ + to: '+19195551234', + from: '+19195554321', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + scope: '2FA', + message: 'Your verification code is {CODE}', + digits: 8 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CodeRequest.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CodeRequest.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CodeRequest.acceptable_attributes).to eq(Bandwidth::CodeRequest.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CodeRequest.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CodeRequest created by the build_from_hash method' do + code_request_from_hash = Bandwidth::CodeRequest.build_from_hash({ + to: '+19195551234', + from: '+19195554321', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + scope: '2FA', + message: 'Your verification code is {CODE}', + digits: 8 + }) + expect(code_request_from_hash).to be_instance_of(Bandwidth::CodeRequest) + expect(code_request_from_hash.to).to eq('+19195551234') + expect(code_request_from_hash.from).to eq('+19195554321') + expect(code_request_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(code_request_from_hash.scope).to eq('2FA') + expect(code_request_from_hash.message).to eq('Your verification code is {CODE}') + expect(code_request_from_hash.digits).to eq(8) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(code_request_values.to_s).to eq('{:to=>"+19195551234", :from=>"+19195554321", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :scope=>"2FA", :message=>"Your verification code is {CODE}", :digits=>8}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + code_request_equal = Bandwidth::CodeRequest.new({ + to: '+19195550100', + from: '+19195550101', + application_id: 'baseline-app', + message: 'Your code is {CODE}', + digits: 6 + }) + expect(code_request_default.eql?(code_request_equal)).to be true + expect(code_request_default.eql?(code_request_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(code_request_values.to_body).to eq({ + to: '+19195551234', + from: '+19195554321', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + scope: '2FA', + message: 'Your verification code is {CODE}', + digits: 8 + }) + end + end + + describe 'custom attribute writers' do + it '#to=' do + expect { + Bandwidth::CodeRequest.new({ to: nil, from: '+19195554321', application_id: 'a', message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, 'to cannot be nil') + + expect { + Bandwidth::CodeRequest.new({ to: 'invalid', from: '+19195554321', application_id: 'a', message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, /invalid value for "to", must conform to the pattern/) + end + + it '#from=' do + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: nil, application_id: 'a', message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, 'from cannot be nil') + + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+1' + '9' * 32, application_id: 'a', message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, 'invalid value for "from", the character length must be smaller than or equal to 32.') + + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: 'invalid', application_id: 'a', message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, /invalid value for "from", must conform to the pattern/) + end + + it '#application_id=' do + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: nil, message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: 'a' * 51, message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, 'invalid value for "application_id", the character length must be smaller than or equal to 50.') + end + + it '#scope=' do + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: 'a', scope: nil, message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, 'scope cannot be nil') + + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: 'a', scope: 'a' * 26, message: 'm', digits: 6 }) + }.to raise_error(ArgumentError, 'invalid value for "scope", the character length must be smaller than or equal to 25.') + end + + it '#message=' do + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: 'a', message: nil, digits: 6 }) + }.to raise_error(ArgumentError, 'message cannot be nil') + + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: 'a', message: 'a' * 2049, digits: 6 }) + }.to raise_error(ArgumentError, 'invalid value for "message", the character length must be smaller than or equal to 2048.') + end + + it '#digits=' do + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: 'a', message: 'm', digits: nil }) + }.to raise_error(ArgumentError, 'digits cannot be nil') + + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: 'a', message: 'm', digits: 9 }) + }.to raise_error(ArgumentError, 'invalid value for "digits", must be smaller than or equal to 8.') + + expect { + Bandwidth::CodeRequest.new({ to: '+19195551234', from: '+19195554321', application_id: 'a', message: 'm', digits: 3 }) + }.to raise_error(ArgumentError, 'invalid value for "digits", must be greater than or equal to 4.') + end + end +end diff --git a/spec/unit/models/completed_lookup_status_enum_spec.rb b/spec/unit/models/completed_lookup_status_enum_spec.rb new file mode 100644 index 00000000..3d401f2a --- /dev/null +++ b/spec/unit/models/completed_lookup_status_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::CompletedLookupStatusEnum +describe Bandwidth::CompletedLookupStatusEnum do + describe 'constants' do + it 'defines COMPLETE' do + expect(Bandwidth::CompletedLookupStatusEnum::COMPLETE).to eq('COMPLETE') + end + + it 'defines PARTIAL_COMPLETE' do + expect(Bandwidth::CompletedLookupStatusEnum::PARTIAL_COMPLETE).to eq('PARTIAL_COMPLETE') + end + + it 'defines FAILED' do + expect(Bandwidth::CompletedLookupStatusEnum::FAILED).to eq('FAILED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::CompletedLookupStatusEnum.all_vars).to eq([ + 'COMPLETE', + 'PARTIAL_COMPLETE', + 'FAILED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::CompletedLookupStatusEnum.build_from_hash('COMPLETE')).to eq('COMPLETE') + expect(Bandwidth::CompletedLookupStatusEnum.build_from_hash('PARTIAL_COMPLETE')).to eq('PARTIAL_COMPLETE') + expect(Bandwidth::CompletedLookupStatusEnum.build_from_hash('FAILED')).to eq('FAILED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::CompletedLookupStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/conference_completed_callback_spec.rb b/spec/unit/models/conference_completed_callback_spec.rb new file mode 100644 index 00000000..9a878b7a --- /dev/null +++ b/spec/unit/models/conference_completed_callback_spec.rb @@ -0,0 +1,82 @@ +# Unit tests for Bandwidth::ConferenceCompletedCallback +describe Bandwidth::ConferenceCompletedCallback do + let(:conference_completed_callback_default) { Bandwidth::ConferenceCompletedCallback.new } + let(:conference_completed_callback_values) { Bandwidth::ConferenceCompletedCallback.new({ + event_type: 'conferenceCompleted', + event_time: '2022-06-16T13:15:07.160Z', + conference_id: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ConferenceCompletedCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ConferenceCompletedCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ConferenceCompletedCallback.acceptable_attributes).to eq(Bandwidth::ConferenceCompletedCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ConferenceCompletedCallback.openapi_nullable).to eq(Set.new([ + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ConferenceCompletedCallback created by the build_from_hash method' do + conference_completed_callback_from_hash = Bandwidth::ConferenceCompletedCallback.build_from_hash({ + eventType: 'conferenceCompleted', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) + expect(conference_completed_callback_from_hash).to be_instance_of(Bandwidth::ConferenceCompletedCallback) + expect(conference_completed_callback_from_hash.event_type).to eq('conferenceCompleted') + expect(conference_completed_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_completed_callback_from_hash.conference_id).to eq('conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_completed_callback_from_hash.name).to eq('my-conference-name') + expect(conference_completed_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_completed_callback_values.to_s).to eq('{:eventType=>"conferenceCompleted", :eventTime=>"2022-06-16T13:15:07.160Z", :conferenceId=>"conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :name=>"my-conference-name", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_completed_callback_default.eql?(Bandwidth::ConferenceCompletedCallback.new)).to be true + expect(conference_completed_callback_default.eql?(conference_completed_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_completed_callback_values.to_body).to eq({ + eventType: 'conferenceCompleted', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/conference_created_callback_spec.rb b/spec/unit/models/conference_created_callback_spec.rb new file mode 100644 index 00000000..25ae611e --- /dev/null +++ b/spec/unit/models/conference_created_callback_spec.rb @@ -0,0 +1,82 @@ +# Unit tests for Bandwidth::ConferenceCreatedCallback +describe Bandwidth::ConferenceCreatedCallback do + let(:conference_created_callback_default) { Bandwidth::ConferenceCreatedCallback.new } + let(:conference_created_callback_values) { Bandwidth::ConferenceCreatedCallback.new({ + event_type: 'conferenceCreated', + event_time: '2022-06-16T13:15:07.160Z', + conference_id: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ConferenceCreatedCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ConferenceCreatedCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ConferenceCreatedCallback.acceptable_attributes).to eq(Bandwidth::ConferenceCreatedCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ConferenceCreatedCallback.openapi_nullable).to eq(Set.new([ + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ConferenceCreatedCallback created by the build_from_hash method' do + conference_created_callback_from_hash = Bandwidth::ConferenceCreatedCallback.build_from_hash({ + eventType: 'conferenceCreated', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) + expect(conference_created_callback_from_hash).to be_instance_of(Bandwidth::ConferenceCreatedCallback) + expect(conference_created_callback_from_hash.event_type).to eq('conferenceCreated') + expect(conference_created_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_created_callback_from_hash.conference_id).to eq('conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_created_callback_from_hash.name).to eq('my-conference-name') + expect(conference_created_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_created_callback_values.to_s).to eq('{:eventType=>"conferenceCreated", :eventTime=>"2022-06-16T13:15:07.160Z", :conferenceId=>"conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :name=>"my-conference-name", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_created_callback_default.eql?(Bandwidth::ConferenceCreatedCallback.new)).to be true + expect(conference_created_callback_default.eql?(conference_created_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_created_callback_values.to_body).to eq({ + eventType: 'conferenceCreated', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/conference_member_exit_callback_spec.rb b/spec/unit/models/conference_member_exit_callback_spec.rb new file mode 100644 index 00000000..a6865e92 --- /dev/null +++ b/spec/unit/models/conference_member_exit_callback_spec.rb @@ -0,0 +1,94 @@ +# Unit tests for Bandwidth::ConferenceMemberExitCallback +describe Bandwidth::ConferenceMemberExitCallback do + let(:conference_member_exit_callback_default) { Bandwidth::ConferenceMemberExitCallback.new } + let(:conference_member_exit_callback_values) { Bandwidth::ConferenceMemberExitCallback.new({ + event_type: 'conferenceMemberExit', + event_time: '2022-06-16T13:15:07.160Z', + conference_id: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + from: '+19195554321', + to: '+19195551234', + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ConferenceMemberExitCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ConferenceMemberExitCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ConferenceMemberExitCallback.acceptable_attributes).to eq(Bandwidth::ConferenceMemberExitCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ConferenceMemberExitCallback.openapi_nullable).to eq(Set.new([ + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ConferenceMemberExitCallback created by the build_from_hash method' do + conference_member_exit_callback_from_hash = Bandwidth::ConferenceMemberExitCallback.build_from_hash({ + eventType: 'conferenceMemberExit', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + from: '+19195554321', + to: '+19195551234', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tag: 'custom tag' + }) + expect(conference_member_exit_callback_from_hash).to be_instance_of(Bandwidth::ConferenceMemberExitCallback) + expect(conference_member_exit_callback_from_hash.event_type).to eq('conferenceMemberExit') + expect(conference_member_exit_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_member_exit_callback_from_hash.conference_id).to eq('conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_member_exit_callback_from_hash.name).to eq('my-conference-name') + expect(conference_member_exit_callback_from_hash.from).to eq('+19195554321') + expect(conference_member_exit_callback_from_hash.to).to eq('+19195551234') + expect(conference_member_exit_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_member_exit_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_member_exit_callback_values.to_s).to eq('{:eventType=>"conferenceMemberExit", :eventTime=>"2022-06-16T13:15:07.160Z", :conferenceId=>"conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :name=>"my-conference-name", :from=>"+19195554321", :to=>"+19195551234", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_member_exit_callback_default.eql?(Bandwidth::ConferenceMemberExitCallback.new)).to be true + expect(conference_member_exit_callback_default.eql?(conference_member_exit_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_member_exit_callback_values.to_body).to eq({ + eventType: 'conferenceMemberExit', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + from: '+19195554321', + to: '+19195551234', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/conference_member_join_callback_spec.rb b/spec/unit/models/conference_member_join_callback_spec.rb new file mode 100644 index 00000000..c2b31623 --- /dev/null +++ b/spec/unit/models/conference_member_join_callback_spec.rb @@ -0,0 +1,94 @@ +# Unit tests for Bandwidth::ConferenceMemberJoinCallback +describe Bandwidth::ConferenceMemberJoinCallback do + let(:conference_member_join_callback_default) { Bandwidth::ConferenceMemberJoinCallback.new } + let(:conference_member_join_callback_values) { Bandwidth::ConferenceMemberJoinCallback.new({ + event_type: 'conferenceMemberJoin', + event_time: '2022-06-16T13:15:07.160Z', + conference_id: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + from: '+19195554321', + to: '+19195551234', + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ConferenceMemberJoinCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ConferenceMemberJoinCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ConferenceMemberJoinCallback.acceptable_attributes).to eq(Bandwidth::ConferenceMemberJoinCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ConferenceMemberJoinCallback.openapi_nullable).to eq(Set.new([ + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ConferenceMemberJoinCallback created by the build_from_hash method' do + conference_member_join_callback_from_hash = Bandwidth::ConferenceMemberJoinCallback.build_from_hash({ + eventType: 'conferenceMemberJoin', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + from: '+19195554321', + to: '+19195551234', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tag: 'custom tag' + }) + expect(conference_member_join_callback_from_hash).to be_instance_of(Bandwidth::ConferenceMemberJoinCallback) + expect(conference_member_join_callback_from_hash.event_type).to eq('conferenceMemberJoin') + expect(conference_member_join_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_member_join_callback_from_hash.conference_id).to eq('conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_member_join_callback_from_hash.name).to eq('my-conference-name') + expect(conference_member_join_callback_from_hash.from).to eq('+19195554321') + expect(conference_member_join_callback_from_hash.to).to eq('+19195551234') + expect(conference_member_join_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_member_join_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_member_join_callback_values.to_s).to eq('{:eventType=>"conferenceMemberJoin", :eventTime=>"2022-06-16T13:15:07.160Z", :conferenceId=>"conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :name=>"my-conference-name", :from=>"+19195554321", :to=>"+19195551234", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_member_join_callback_default.eql?(Bandwidth::ConferenceMemberJoinCallback.new)).to be true + expect(conference_member_join_callback_default.eql?(conference_member_join_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_member_join_callback_values.to_body).to eq({ + eventType: 'conferenceMemberJoin', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + from: '+19195554321', + to: '+19195551234', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/conference_member_spec.rb b/spec/unit/models/conference_member_spec.rb new file mode 100644 index 00000000..8a18eb4f --- /dev/null +++ b/spec/unit/models/conference_member_spec.rb @@ -0,0 +1,84 @@ +# Unit tests for Bandwidth::ConferenceMember +describe Bandwidth::ConferenceMember do + let(:conference_member_default) { Bandwidth::ConferenceMember.new } + let(:conference_member_values) { Bandwidth::ConferenceMember.new({ + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + conference_id: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + member_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-1/members/c-1', + mute: false, + hold: false, + call_ids_to_coach: ['c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d86'] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ConferenceMember.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ConferenceMember.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ConferenceMember.acceptable_attributes).to eq(Bandwidth::ConferenceMember.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ConferenceMember.openapi_nullable).to eq(Set.new([:'call_ids_to_coach'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ConferenceMember created by the build_from_hash method' do + conference_member_from_hash = Bandwidth::ConferenceMember.build_from_hash({ + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + conferenceId: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + memberUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-1/members/c-1', + mute: false, + hold: false, + callIdsToCoach: ['c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d86'] + }) + expect(conference_member_from_hash).to be_instance_of(Bandwidth::ConferenceMember) + expect(conference_member_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_member_from_hash.conference_id).to eq('conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c') + expect(conference_member_from_hash.member_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-1/members/c-1') + expect(conference_member_from_hash.mute).to eq(false) + expect(conference_member_from_hash.hold).to eq(false) + expect(conference_member_from_hash.call_ids_to_coach).to eq(['c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d86']) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_member_values.to_s).to eq('{:callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :conferenceId=>"conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c", :memberUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-1/members/c-1", :mute=>false, :hold=>false, :callIdsToCoach=>["c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d86"]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_member_default.eql?(Bandwidth::ConferenceMember.new)).to be true + expect(conference_member_default.eql?(conference_member_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_member_values.to_body).to eq({ + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + conferenceId: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + memberUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-1/members/c-1', + mute: false, + hold: false, + callIdsToCoach: ['c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d86'] + }) + end + end +end diff --git a/spec/unit/models/conference_recording_available_callback_spec.rb b/spec/unit/models/conference_recording_available_callback_spec.rb new file mode 100644 index 00000000..769a1934 --- /dev/null +++ b/spec/unit/models/conference_recording_available_callback_spec.rb @@ -0,0 +1,119 @@ +# Unit tests for Bandwidth::ConferenceRecordingAvailableCallback +describe Bandwidth::ConferenceRecordingAvailableCallback do + let(:conference_recording_available_callback_default) { Bandwidth::ConferenceRecordingAvailableCallback.new } + let(:conference_recording_available_callback_values) { Bandwidth::ConferenceRecordingAvailableCallback.new({ + event_type: 'conferenceRecordingAvailable', + event_time: '2022-06-16T13:15:07.160Z', + conference_id: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + account_id: '9900000', + recording_id: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + channels: 1, + start_time: '2022-06-16T13:15:07.160Z', + end_time: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + file_format: Bandwidth::FileFormatEnum::WAV, + media_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + tag: 'custom tag', + status: 'complete' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ConferenceRecordingAvailableCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ConferenceRecordingAvailableCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ConferenceRecordingAvailableCallback.acceptable_attributes).to eq(Bandwidth::ConferenceRecordingAvailableCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ConferenceRecordingAvailableCallback.openapi_nullable).to eq(Set.new([ + :'media_url', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ConferenceRecordingAvailableCallback created by the build_from_hash method' do + conference_recording_available_callback_from_hash = Bandwidth::ConferenceRecordingAvailableCallback.build_from_hash({ + eventType: 'conferenceRecordingAvailable', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + accountId: '9900000', + recordingId: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + channels: 1, + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + fileFormat: Bandwidth::FileFormatEnum::WAV, + mediaUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + tag: 'custom tag', + status: 'complete' + }) + expect(conference_recording_available_callback_from_hash).to be_instance_of(Bandwidth::ConferenceRecordingAvailableCallback) + expect(conference_recording_available_callback_from_hash.event_type).to eq('conferenceRecordingAvailable') + expect(conference_recording_available_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_recording_available_callback_from_hash.conference_id).to eq('conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_recording_available_callback_from_hash.name).to eq('my-conference-name') + expect(conference_recording_available_callback_from_hash.account_id).to eq('9900000') + expect(conference_recording_available_callback_from_hash.recording_id).to eq('r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_recording_available_callback_from_hash.channels).to eq(1) + expect(conference_recording_available_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_recording_available_callback_from_hash.end_time).to eq(Time.parse('2022-06-16T13:17:07.160Z')) + expect(conference_recording_available_callback_from_hash.duration).to eq('PT2M') + expect(conference_recording_available_callback_from_hash.file_format).to eq(Bandwidth::FileFormatEnum::WAV) + expect(conference_recording_available_callback_from_hash.media_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media') + expect(conference_recording_available_callback_from_hash.tag).to eq('custom tag') + expect(conference_recording_available_callback_from_hash.status).to eq('complete') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_recording_available_callback_values.to_s).to eq('{:eventType=>"conferenceRecordingAvailable", :eventTime=>"2022-06-16T13:15:07.160Z", :conferenceId=>"conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :name=>"my-conference-name", :accountId=>"9900000", :recordingId=>"r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :channels=>1, :startTime=>"2022-06-16T13:15:07.160Z", :endTime=>"2022-06-16T13:17:07.160Z", :duration=>"PT2M", :fileFormat=>"wav", :mediaUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media", :tag=>"custom tag", :status=>"complete"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_recording_available_callback_default.eql?(Bandwidth::ConferenceRecordingAvailableCallback.new)).to be true + expect(conference_recording_available_callback_default.eql?(conference_recording_available_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_recording_available_callback_values.to_body).to eq({ + eventType: 'conferenceRecordingAvailable', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + accountId: '9900000', + recordingId: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + channels: 1, + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + fileFormat: Bandwidth::FileFormatEnum::WAV, + mediaUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + tag: 'custom tag', + status: 'complete' + }) + end + end +end diff --git a/spec/unit/models/conference_recording_metadata_spec.rb b/spec/unit/models/conference_recording_metadata_spec.rb new file mode 100644 index 00000000..df6923d2 --- /dev/null +++ b/spec/unit/models/conference_recording_metadata_spec.rb @@ -0,0 +1,108 @@ +# Unit tests for Bandwidth::ConferenceRecordingMetadata +describe Bandwidth::ConferenceRecordingMetadata do + let(:conference_recording_metadata_default) { Bandwidth::ConferenceRecordingMetadata.new } + let(:conference_recording_metadata_values) { Bandwidth::ConferenceRecordingMetadata.new({ + account_id: '9900000', + conference_id: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + name: 'weekly-stand-up', + recording_id: 'r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4', + duration: 'PT13.67S', + channels: 1, + start_time: '2022-06-16T13:15:07.160Z', + end_time: '2022-06-16T13:15:20.830Z', + file_format: Bandwidth::FileFormatEnum::WAV, + status: 'complete', + media_url: 'https://example.com/recording.wav', + recording_name: 'sample-recording' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ConferenceRecordingMetadata.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ConferenceRecordingMetadata.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ConferenceRecordingMetadata.acceptable_attributes).to eq(Bandwidth::ConferenceRecordingMetadata.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ConferenceRecordingMetadata.openapi_nullable).to eq(Set.new([:'media_url'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ConferenceRecordingMetadata created by the build_from_hash method' do + conference_recording_metadata_from_hash = Bandwidth::ConferenceRecordingMetadata.build_from_hash({ + accountId: '9900000', + conferenceId: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + name: 'weekly-stand-up', + recordingId: 'r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4', + duration: 'PT13.67S', + channels: 1, + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:15:20.830Z', + fileFormat: 'wav', + status: 'complete', + mediaUrl: 'https://example.com/recording.wav', + recordingName: 'sample-recording' + }) + expect(conference_recording_metadata_from_hash).to be_instance_of(Bandwidth::ConferenceRecordingMetadata) + expect(conference_recording_metadata_from_hash.account_id).to eq('9900000') + expect(conference_recording_metadata_from_hash.conference_id).to eq('conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c') + expect(conference_recording_metadata_from_hash.name).to eq('weekly-stand-up') + expect(conference_recording_metadata_from_hash.recording_id).to eq('r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4') + expect(conference_recording_metadata_from_hash.duration).to eq('PT13.67S') + expect(conference_recording_metadata_from_hash.channels).to eq(1) + expect(conference_recording_metadata_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_recording_metadata_from_hash.end_time).to eq(Time.parse('2022-06-16T13:15:20.830Z')) + expect(conference_recording_metadata_from_hash.file_format).to eq(Bandwidth::FileFormatEnum::WAV) + expect(conference_recording_metadata_from_hash.status).to eq('complete') + expect(conference_recording_metadata_from_hash.media_url).to eq('https://example.com/recording.wav') + expect(conference_recording_metadata_from_hash.recording_name).to eq('sample-recording') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_recording_metadata_values.to_s).to eq('{:accountId=>"9900000", :conferenceId=>"conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c", :name=>"weekly-stand-up", :recordingId=>"r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4", :duration=>"PT13.67S", :channels=>1, :startTime=>"2022-06-16T13:15:07.160Z", :endTime=>"2022-06-16T13:15:20.830Z", :fileFormat=>"wav", :status=>"complete", :mediaUrl=>"https://example.com/recording.wav", :recordingName=>"sample-recording"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_recording_metadata_default.eql?(Bandwidth::ConferenceRecordingMetadata.new)).to be true + expect(conference_recording_metadata_default.eql?(conference_recording_metadata_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_recording_metadata_values.to_body).to eq({ + accountId: '9900000', + conferenceId: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + name: 'weekly-stand-up', + recordingId: 'r-fbe05094-9fd2b71d-a4e6-4f43-8c3e-5b04b1d8a4b4', + duration: 'PT13.67S', + channels: 1, + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:15:20.830Z', + fileFormat: Bandwidth::FileFormatEnum::WAV, + status: 'complete', + mediaUrl: 'https://example.com/recording.wav', + recordingName: 'sample-recording' + }) + end + end +end diff --git a/spec/unit/models/conference_redirect_callback_spec.rb b/spec/unit/models/conference_redirect_callback_spec.rb new file mode 100644 index 00000000..1dd7ef73 --- /dev/null +++ b/spec/unit/models/conference_redirect_callback_spec.rb @@ -0,0 +1,82 @@ +# Unit tests for Bandwidth::ConferenceRedirectCallback +describe Bandwidth::ConferenceRedirectCallback do + let(:conference_redirect_callback_default) { Bandwidth::ConferenceRedirectCallback.new } + let(:conference_redirect_callback_values) { Bandwidth::ConferenceRedirectCallback.new({ + event_type: 'conferenceRedirect', + event_time: '2022-06-16T13:15:07.160Z', + conference_id: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ConferenceRedirectCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ConferenceRedirectCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ConferenceRedirectCallback.acceptable_attributes).to eq(Bandwidth::ConferenceRedirectCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ConferenceRedirectCallback.openapi_nullable).to eq(Set.new([ + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ConferenceRedirectCallback created by the build_from_hash method' do + conference_redirect_callback_from_hash = Bandwidth::ConferenceRedirectCallback.build_from_hash({ + eventType: 'conferenceRedirect', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) + expect(conference_redirect_callback_from_hash).to be_instance_of(Bandwidth::ConferenceRedirectCallback) + expect(conference_redirect_callback_from_hash.event_type).to eq('conferenceRedirect') + expect(conference_redirect_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_redirect_callback_from_hash.conference_id).to eq('conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(conference_redirect_callback_from_hash.name).to eq('my-conference-name') + expect(conference_redirect_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_redirect_callback_values.to_s).to eq('{:eventType=>"conferenceRedirect", :eventTime=>"2022-06-16T13:15:07.160Z", :conferenceId=>"conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :name=>"my-conference-name", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_redirect_callback_default.eql?(Bandwidth::ConferenceRedirectCallback.new)).to be true + expect(conference_redirect_callback_default.eql?(conference_redirect_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_redirect_callback_values.to_body).to eq({ + eventType: 'conferenceRedirect', + eventTime: '2022-06-16T13:15:07.160Z', + conferenceId: 'conf-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + name: 'my-conference-name', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/conference_spec.rb b/spec/unit/models/conference_spec.rb new file mode 100644 index 00000000..6a41d7ff --- /dev/null +++ b/spec/unit/models/conference_spec.rb @@ -0,0 +1,98 @@ +# Unit tests for Bandwidth::Conference +describe Bandwidth::Conference do + let(:conference_default) { Bandwidth::Conference.new } + let(:conference_values) { Bandwidth::Conference.new({ + id: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + name: 'weekly-stand-up', + created_time: '2022-06-16T13:15:07.160Z', + completed_time: '2022-06-16T13:45:07.160Z', + conference_event_url: 'https://example.com/conference-event', + conference_event_method: Bandwidth::CallbackMethodEnum::POST, + tag: 'custom tag', + active_members: [Bandwidth::ConferenceMember.new({ call_id: 'c-1', conference_id: 'conf-1' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Conference.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Conference.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Conference.acceptable_attributes).to eq(Bandwidth::Conference.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::Conference.openapi_nullable).to eq(Set.new([ + :'completed_time', + :'conference_event_url', + :'conference_event_method', + :'tag', + :'active_members' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Conference created by the build_from_hash method' do + conference_from_hash = Bandwidth::Conference.build_from_hash({ + id: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + name: 'weekly-stand-up', + createdTime: '2022-06-16T13:15:07.160Z', + completedTime: '2022-06-16T13:45:07.160Z', + conferenceEventUrl: 'https://example.com/conference-event', + conferenceEventMethod: 'POST', + tag: 'custom tag', + activeMembers: [{ callId: 'c-1', conferenceId: 'conf-1' }] + }) + expect(conference_from_hash).to be_instance_of(Bandwidth::Conference) + expect(conference_from_hash.id).to eq('conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c') + expect(conference_from_hash.name).to eq('weekly-stand-up') + expect(conference_from_hash.created_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(conference_from_hash.completed_time).to eq(Time.parse('2022-06-16T13:45:07.160Z')) + expect(conference_from_hash.conference_event_url).to eq('https://example.com/conference-event') + expect(conference_from_hash.conference_event_method).to eq(Bandwidth::CallbackMethodEnum::POST) + expect(conference_from_hash.tag).to eq('custom tag') + expect(conference_from_hash.active_members.first).to be_instance_of(Bandwidth::ConferenceMember) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(conference_values.to_s).to eq('{:id=>"conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c", :name=>"weekly-stand-up", :createdTime=>"2022-06-16T13:15:07.160Z", :completedTime=>"2022-06-16T13:45:07.160Z", :conferenceEventUrl=>"https://example.com/conference-event", :conferenceEventMethod=>"POST", :tag=>"custom tag", :activeMembers=>[{:callId=>"c-1", :conferenceId=>"conf-1"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(conference_default.eql?(Bandwidth::Conference.new)).to be true + expect(conference_default.eql?(conference_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(conference_values.to_body).to eq({ + id: 'conf-fe23a767-a75a5b77-23e8-4b5b-a973-1eb967d7d75c', + name: 'weekly-stand-up', + createdTime: '2022-06-16T13:15:07.160Z', + completedTime: '2022-06-16T13:45:07.160Z', + conferenceEventUrl: 'https://example.com/conference-event', + conferenceEventMethod: Bandwidth::CallbackMethodEnum::POST, + tag: 'custom tag', + activeMembers: [{ callId: 'c-1', conferenceId: 'conf-1' }] + }) + end + end +end diff --git a/spec/unit/models/conference_state_enum_spec.rb b/spec/unit/models/conference_state_enum_spec.rb new file mode 100644 index 00000000..9829b992 --- /dev/null +++ b/spec/unit/models/conference_state_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::ConferenceStateEnum +describe Bandwidth::ConferenceStateEnum do + describe 'constants' do + it 'defines ACTIVE' do + expect(Bandwidth::ConferenceStateEnum::ACTIVE).to eq('active') + end + + it 'defines COMPLETED' do + expect(Bandwidth::ConferenceStateEnum::COMPLETED).to eq('completed') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::ConferenceStateEnum.all_vars).to eq([ + 'active', + 'completed' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::ConferenceStateEnum.build_from_hash('active')).to eq('active') + expect(Bandwidth::ConferenceStateEnum.build_from_hash('completed')).to eq('completed') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::ConferenceStateEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/contact_spec.rb b/spec/unit/models/contact_spec.rb new file mode 100644 index 00000000..457ef608 --- /dev/null +++ b/spec/unit/models/contact_spec.rb @@ -0,0 +1,145 @@ +# Unit tests for Bandwidth::Contact +describe Bandwidth::Contact do + let(:contact_default) { Bandwidth::Contact.new({ + first_name: 'Baseline', + last_name: 'User', + email: 'baseline@example.com', + phone_number: '+19195550100' + }) } + let(:contact_values) { Bandwidth::Contact.new({ + first_name: 'John', + last_name: 'Doe', + email: 'john.doe@example.com', + phone_number: '+19195551234' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Contact.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Contact.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Contact.acceptable_attributes).to eq(Bandwidth::Contact.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Contact.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Contact created by the build_from_hash method' do + contact_from_hash = Bandwidth::Contact.build_from_hash({ + firstName: 'John', + lastName: 'Doe', + email: 'john.doe@example.com', + phoneNumber: '+19195551234' + }) + expect(contact_from_hash).to be_instance_of(Bandwidth::Contact) + expect(contact_from_hash.first_name).to eq('John') + expect(contact_from_hash.last_name).to eq('Doe') + expect(contact_from_hash.email).to eq('john.doe@example.com') + expect(contact_from_hash.phone_number).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(contact_values.to_s).to eq('{:firstName=>"John", :lastName=>"Doe", :email=>"john.doe@example.com", :phoneNumber=>"+19195551234"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + contact_equal = Bandwidth::Contact.new({ + first_name: 'Baseline', + last_name: 'User', + email: 'baseline@example.com', + phone_number: '+19195550100' + }) + expect(contact_default.eql?(contact_equal)).to be true + expect(contact_default.eql?(contact_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(contact_values.to_body).to eq({ + firstName: 'John', + lastName: 'Doe', + email: 'john.doe@example.com', + phoneNumber: '+19195551234' + }) + end + end + + describe 'custom attribute writers' do + it '#first_name=' do + expect { + Bandwidth::Contact.new({ first_name: nil, last_name: 'Doe', email: 'a@b.com', phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'first_name cannot be nil') + + expect { + Bandwidth::Contact.new({ first_name: 'a' * 501, last_name: 'Doe', email: 'a@b.com', phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'invalid value for "first_name", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Contact.new({ first_name: '', last_name: 'Doe', email: 'a@b.com', phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'invalid value for "first_name", the character length must be greater than or equal to 1.') + end + + it '#last_name=' do + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: nil, email: 'a@b.com', phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'last_name cannot be nil') + + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: 'a' * 501, email: 'a@b.com', phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'invalid value for "last_name", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: '', email: 'a@b.com', phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'invalid value for "last_name", the character length must be greater than or equal to 1.') + end + + it '#email=' do + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: 'Doe', email: nil, phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'email cannot be nil') + + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: 'Doe', email: ('a' * 495) + '@b.com', phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'invalid value for "email", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: 'Doe', email: 'not-an-email', phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, /invalid value for "email", must conform to the pattern/) + end + + it '#phone_number=' do + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: 'Doe', email: 'a@b.com', phone_number: nil }) + }.to raise_error(ArgumentError, 'phone_number cannot be nil') + + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: 'Doe', email: 'a@b.com', phone_number: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::Contact.new({ first_name: 'John', last_name: 'Doe', email: 'a@b.com', phone_number: '' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be greater than or equal to 1.') + end + end +end diff --git a/spec/unit/models/create_async_bulk_lookup_response_data_spec.rb b/spec/unit/models/create_async_bulk_lookup_response_data_spec.rb new file mode 100644 index 00000000..73b49503 --- /dev/null +++ b/spec/unit/models/create_async_bulk_lookup_response_data_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::CreateAsyncBulkLookupResponseData +describe Bandwidth::CreateAsyncBulkLookupResponseData do + let(:create_async_bulk_lookup_response_data_default) { Bandwidth::CreateAsyncBulkLookupResponseData.new } + let(:create_async_bulk_lookup_response_data_values) { Bandwidth::CreateAsyncBulkLookupResponseData.new({ + request_id: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', + status: 'IN_PROGRESS' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateAsyncBulkLookupResponseData.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateAsyncBulkLookupResponseData.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateAsyncBulkLookupResponseData.acceptable_attributes).to eq(Bandwidth::CreateAsyncBulkLookupResponseData.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateAsyncBulkLookupResponseData.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateAsyncBulkLookupResponseData created by the build_from_hash method' do + create_async_bulk_lookup_response_data_from_hash = Bandwidth::CreateAsyncBulkLookupResponseData.build_from_hash({ + requestId: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', + status: 'IN_PROGRESS' + }) + expect(create_async_bulk_lookup_response_data_from_hash).to be_instance_of(Bandwidth::CreateAsyncBulkLookupResponseData) + expect(create_async_bulk_lookup_response_data_from_hash.request_id).to eq('00b97c1b-d8b4-4a32-ad14-7d09ce04acb6') + expect(create_async_bulk_lookup_response_data_from_hash.status).to eq('IN_PROGRESS') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_async_bulk_lookup_response_data_values.to_s).to eq('{:requestId=>"00b97c1b-d8b4-4a32-ad14-7d09ce04acb6", :status=>"IN_PROGRESS"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(create_async_bulk_lookup_response_data_default.eql?(Bandwidth::CreateAsyncBulkLookupResponseData.new)).to be true + expect(create_async_bulk_lookup_response_data_default.eql?(create_async_bulk_lookup_response_data_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_async_bulk_lookup_response_data_values.to_body).to eq({ + requestId: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', + status: 'IN_PROGRESS' + }) + end + end +end diff --git a/spec/unit/models/create_async_bulk_lookup_response_spec.rb b/spec/unit/models/create_async_bulk_lookup_response_spec.rb new file mode 100644 index 00000000..2e5f74f9 --- /dev/null +++ b/spec/unit/models/create_async_bulk_lookup_response_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::CreateAsyncBulkLookupResponse +describe Bandwidth::CreateAsyncBulkLookupResponse do + let(:create_async_bulk_lookup_response_default) { Bandwidth::CreateAsyncBulkLookupResponse.new } + let(:create_async_bulk_lookup_response_values) { Bandwidth::CreateAsyncBulkLookupResponse.new({ + links: [Bandwidth::LinkSchema.new({ href: 'https://example.com', rel: 'self', method: 'GET' })], + data: Bandwidth::CreateAsyncBulkLookupResponseData.new({ request_id: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', status: 'IN_PROGRESS' }), + errors: [Bandwidth::LookupErrorSchema.new({ code: 'E1', description: 'bad', type: 'validation' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateAsyncBulkLookupResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateAsyncBulkLookupResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateAsyncBulkLookupResponse.acceptable_attributes).to eq(Bandwidth::CreateAsyncBulkLookupResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateAsyncBulkLookupResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateAsyncBulkLookupResponse created by the build_from_hash method' do + create_async_bulk_lookup_response_from_hash = Bandwidth::CreateAsyncBulkLookupResponse.build_from_hash({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { requestId: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', status: 'IN_PROGRESS' }, + errors: [{ code: 'E1', description: 'bad', type: 'validation' }] + }) + expect(create_async_bulk_lookup_response_from_hash).to be_instance_of(Bandwidth::CreateAsyncBulkLookupResponse) + expect(create_async_bulk_lookup_response_from_hash.links.first).to be_instance_of(Bandwidth::LinkSchema) + expect(create_async_bulk_lookup_response_from_hash.data).to be_instance_of(Bandwidth::CreateAsyncBulkLookupResponseData) + expect(create_async_bulk_lookup_response_from_hash.errors.first).to be_instance_of(Bandwidth::LookupErrorSchema) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_async_bulk_lookup_response_values.to_s).to eq('{:links=>[{:href=>"https://example.com", :rel=>"self", :method=>"GET"}], :data=>{:requestId=>"00b97c1b-d8b4-4a32-ad14-7d09ce04acb6", :status=>"IN_PROGRESS"}, :errors=>[{:code=>"E1", :description=>"bad", :type=>"validation"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(create_async_bulk_lookup_response_default.eql?(Bandwidth::CreateAsyncBulkLookupResponse.new)).to be true + expect(create_async_bulk_lookup_response_default.eql?(create_async_bulk_lookup_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_async_bulk_lookup_response_values.to_body).to eq({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { requestId: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', status: 'IN_PROGRESS' }, + errors: [{ code: 'E1', description: 'bad', type: 'validation' }] + }) + end + end +end diff --git a/spec/unit/models/create_call_response_spec.rb b/spec/unit/models/create_call_response_spec.rb new file mode 100644 index 00000000..a6a7ea30 --- /dev/null +++ b/spec/unit/models/create_call_response_spec.rb @@ -0,0 +1,242 @@ +# Unit tests for Bandwidth::CreateCallResponse +describe Bandwidth::CreateCallResponse do + let(:create_call_response_default) { Bandwidth::CreateCallResponse.new({ + application_id: 'baseline-app', + account_id: '9900000', + call_id: 'baseline-call', + to: '+19195550100', + from: '+19195550101', + call_url: 'https://example.com/calls/baseline', + answer_url: 'https://example.com/answer/baseline' + }) } + let(:create_call_response_values) { Bandwidth::CreateCallResponse.new({ + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + account_id: '9900000', + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + to: '+19195551234', + from: '+19195554321', + enqueued_time: '2022-06-16T13:15:07.160Z', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1', + call_timeout: 30.0, + callback_timeout: 15.0, + tag: 'custom tag', + answer_method: Bandwidth::CallbackMethodEnum::POST, + answer_url: 'https://example.com/answer', + answer_fallback_method: Bandwidth::CallbackMethodEnum::POST, + answer_fallback_url: 'https://example.com/answer-fallback', + disconnect_method: Bandwidth::CallbackMethodEnum::POST, + disconnect_url: 'https://example.com/disconnect', + username: 'user', + password: 'pass', + fallback_username: 'fallback_user', + fallback_password: 'fallback_pass', + priority: 5 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateCallResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateCallResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateCallResponse.acceptable_attributes).to eq(Bandwidth::CreateCallResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::CreateCallResponse.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'tag', + :'answer_method', + :'answer_fallback_method', + :'answer_fallback_url', + :'disconnect_method', + :'disconnect_url', + :'username', + :'password', + :'fallback_username', + :'fallback_password', + :'priority' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateCallResponse created by the build_from_hash method' do + create_call_response_from_hash = Bandwidth::CreateCallResponse.build_from_hash({ + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + accountId: '9900000', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + to: '+19195551234', + from: '+19195554321', + enqueuedTime: '2022-06-16T13:15:07.160Z', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1', + callTimeout: 30.0, + callbackTimeout: 15.0, + tag: 'custom tag', + answerMethod: 'POST', + answerUrl: 'https://example.com/answer', + answerFallbackMethod: 'POST', + answerFallbackUrl: 'https://example.com/answer-fallback', + disconnectMethod: 'POST', + disconnectUrl: 'https://example.com/disconnect', + username: 'user', + password: 'pass', + fallbackUsername: 'fallback_user', + fallbackPassword: 'fallback_pass', + priority: 5 + }) + expect(create_call_response_from_hash).to be_instance_of(Bandwidth::CreateCallResponse) + expect(create_call_response_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(create_call_response_from_hash.account_id).to eq('9900000') + expect(create_call_response_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(create_call_response_from_hash.to).to eq('+19195551234') + expect(create_call_response_from_hash.from).to eq('+19195554321') + expect(create_call_response_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(create_call_response_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1') + expect(create_call_response_from_hash.call_timeout).to eq(30.0) + expect(create_call_response_from_hash.callback_timeout).to eq(15.0) + expect(create_call_response_from_hash.tag).to eq('custom tag') + expect(create_call_response_from_hash.answer_method).to eq(Bandwidth::CallbackMethodEnum::POST) + expect(create_call_response_from_hash.answer_url).to eq('https://example.com/answer') + expect(create_call_response_from_hash.answer_fallback_method).to eq(Bandwidth::CallbackMethodEnum::POST) + expect(create_call_response_from_hash.answer_fallback_url).to eq('https://example.com/answer-fallback') + expect(create_call_response_from_hash.disconnect_method).to eq(Bandwidth::CallbackMethodEnum::POST) + expect(create_call_response_from_hash.disconnect_url).to eq('https://example.com/disconnect') + expect(create_call_response_from_hash.username).to eq('user') + expect(create_call_response_from_hash.password).to eq('pass') + expect(create_call_response_from_hash.fallback_username).to eq('fallback_user') + expect(create_call_response_from_hash.fallback_password).to eq('fallback_pass') + expect(create_call_response_from_hash.priority).to eq(5) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_call_response_values.to_s).to eq('{:applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :accountId=>"9900000", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :to=>"+19195551234", :from=>"+19195554321", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1", :callTimeout=>30.0, :callbackTimeout=>15.0, :tag=>"custom tag", :answerMethod=>"POST", :answerUrl=>"https://example.com/answer", :answerFallbackMethod=>"POST", :answerFallbackUrl=>"https://example.com/answer-fallback", :disconnectMethod=>"POST", :disconnectUrl=>"https://example.com/disconnect", :username=>"user", :password=>"pass", :fallbackUsername=>"fallback_user", :fallbackPassword=>"fallback_pass", :priority=>5}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + create_call_response_equal = Bandwidth::CreateCallResponse.new({ + application_id: 'baseline-app', + account_id: '9900000', + call_id: 'baseline-call', + to: '+19195550100', + from: '+19195550101', + call_url: 'https://example.com/calls/baseline', + answer_url: 'https://example.com/answer/baseline' + }) + expect(create_call_response_default.eql?(create_call_response_equal)).to be true + expect(create_call_response_default.eql?(create_call_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_call_response_values.to_body).to eq({ + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + accountId: '9900000', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + to: '+19195551234', + from: '+19195554321', + enqueuedTime: '2022-06-16T13:15:07.160Z', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-1', + callTimeout: 30.0, + callbackTimeout: 15.0, + tag: 'custom tag', + answerMethod: Bandwidth::CallbackMethodEnum::POST, + answerUrl: 'https://example.com/answer', + answerFallbackMethod: Bandwidth::CallbackMethodEnum::POST, + answerFallbackUrl: 'https://example.com/answer-fallback', + disconnectMethod: Bandwidth::CallbackMethodEnum::POST, + disconnectUrl: 'https://example.com/disconnect', + username: 'user', + password: 'pass', + fallbackUsername: 'fallback_user', + fallbackPassword: 'fallback_pass', + priority: 5 + }) + end + end + + describe 'custom attribute writers' do + it '#application_id=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: nil, account_id: 'a', call_id: 'a', to: 'a', from: 'a', call_url: 'a', answer_url: 'a' }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#account_id=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: nil, call_id: 'a', to: 'a', from: 'a', call_url: 'a', answer_url: 'a' }) + }.to raise_error(ArgumentError, 'account_id cannot be nil') + end + + it '#call_id=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: nil, to: 'a', from: 'a', call_url: 'a', answer_url: 'a' }) + }.to raise_error(ArgumentError, 'call_id cannot be nil') + end + + it '#to=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: 'a', to: nil, from: 'a', call_url: 'a', answer_url: 'a' }) + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#from=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: 'a', to: 'a', from: nil, call_url: 'a', answer_url: 'a' }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#call_url=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: 'a', to: 'a', from: 'a', call_url: nil, answer_url: 'a' }) + }.to raise_error(ArgumentError, 'call_url cannot be nil') + end + + it '#answer_url=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: 'a', to: 'a', from: 'a', call_url: 'a', answer_url: nil }) + }.to raise_error(ArgumentError, 'answer_url cannot be nil') + end + + it '#username=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: 'a', to: 'a', from: 'a', call_url: 'a', answer_url: 'a', username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "username", the character length must be smaller than or equal to 1024.') + end + + it '#password=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: 'a', to: 'a', from: 'a', call_url: 'a', answer_url: 'a', password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "password", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_username=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: 'a', to: 'a', from: 'a', call_url: 'a', answer_url: 'a', fallback_username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_username", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_password=' do + expect { + Bandwidth::CreateCallResponse.new({ application_id: 'a', account_id: 'a', call_id: 'a', to: 'a', from: 'a', call_url: 'a', answer_url: 'a', fallback_password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_password", the character length must be smaller than or equal to 1024.') + end + end +end diff --git a/spec/unit/models/create_call_spec.rb b/spec/unit/models/create_call_spec.rb new file mode 100644 index 00000000..aeb77d50 --- /dev/null +++ b/spec/unit/models/create_call_spec.rb @@ -0,0 +1,278 @@ +# Unit tests for Bandwidth::CreateCall +describe Bandwidth::CreateCall do + let(:create_call_default) { Bandwidth::CreateCall.new({ + to: '+19195550100', + from: '+19195550101', + application_id: 'baseline-app', + answer_url: 'https://example.com/answer/baseline' + }) } + let(:create_call_values) { Bandwidth::CreateCall.new({ + to: '+19195551234', + from: '+19195554321', + privacy: false, + display_name: 'Caller Name', + uui: 'eyJ0eXAiOiJKV1Q;encoding=jwt', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + answer_url: 'https://example.com/answer', + answer_method: Bandwidth::CallbackMethodEnum::POST, + username: 'user', + password: 'pass', + answer_fallback_url: 'https://example.com/answer-fallback', + answer_fallback_method: Bandwidth::CallbackMethodEnum::POST, + fallback_username: 'fallback_user', + fallback_password: 'fallback_pass', + disconnect_url: 'https://example.com/disconnect', + disconnect_method: Bandwidth::CallbackMethodEnum::POST, + call_timeout: 30, + callback_timeout: 15, + machine_detection: {}, + priority: 5, + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateCall.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateCall.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateCall.acceptable_attributes).to eq(Bandwidth::CreateCall.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::CreateCall.openapi_nullable).to eq(Set.new([ + :'privacy', + :'display_name', + :'uui', + :'answer_method', + :'username', + :'password', + :'answer_fallback_url', + :'answer_fallback_method', + :'fallback_username', + :'fallback_password', + :'disconnect_url', + :'disconnect_method', + :'call_timeout', + :'callback_timeout', + :'priority', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateCall created by the build_from_hash method' do + create_call_from_hash = Bandwidth::CreateCall.build_from_hash({ + to: '+19195551234', + from: '+19195554321', + privacy: false, + displayName: 'Caller Name', + uui: 'eyJ0eXAiOiJKV1Q;encoding=jwt', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + answerUrl: 'https://example.com/answer', + answerMethod: 'POST', + username: 'user', + password: 'pass', + answerFallbackUrl: 'https://example.com/answer-fallback', + answerFallbackMethod: 'POST', + fallbackUsername: 'fallback_user', + fallbackPassword: 'fallback_pass', + disconnectUrl: 'https://example.com/disconnect', + disconnectMethod: 'POST', + callTimeout: 30, + callbackTimeout: 15, + priority: 5, + tag: 'custom tag' + }) + expect(create_call_from_hash).to be_instance_of(Bandwidth::CreateCall) + expect(create_call_from_hash.to).to eq('+19195551234') + expect(create_call_from_hash.from).to eq('+19195554321') + expect(create_call_from_hash.privacy).to eq(false) + expect(create_call_from_hash.display_name).to eq('Caller Name') + expect(create_call_from_hash.uui).to eq('eyJ0eXAiOiJKV1Q;encoding=jwt') + expect(create_call_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(create_call_from_hash.answer_url).to eq('https://example.com/answer') + expect(create_call_from_hash.answer_method).to eq(Bandwidth::CallbackMethodEnum::POST) + expect(create_call_from_hash.username).to eq('user') + expect(create_call_from_hash.password).to eq('pass') + expect(create_call_from_hash.answer_fallback_url).to eq('https://example.com/answer-fallback') + expect(create_call_from_hash.answer_fallback_method).to eq(Bandwidth::CallbackMethodEnum::POST) + expect(create_call_from_hash.fallback_username).to eq('fallback_user') + expect(create_call_from_hash.fallback_password).to eq('fallback_pass') + expect(create_call_from_hash.disconnect_url).to eq('https://example.com/disconnect') + expect(create_call_from_hash.disconnect_method).to eq(Bandwidth::CallbackMethodEnum::POST) + expect(create_call_from_hash.call_timeout).to eq(30) + expect(create_call_from_hash.callback_timeout).to eq(15) + expect(create_call_from_hash.priority).to eq(5) + expect(create_call_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_call_values.to_s).to eq('{:to=>"+19195551234", :from=>"+19195554321", :privacy=>false, :displayName=>"Caller Name", :uui=>"eyJ0eXAiOiJKV1Q;encoding=jwt", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :answerUrl=>"https://example.com/answer", :answerMethod=>"POST", :username=>"user", :password=>"pass", :answerFallbackUrl=>"https://example.com/answer-fallback", :answerFallbackMethod=>"POST", :fallbackUsername=>"fallback_user", :fallbackPassword=>"fallback_pass", :disconnectUrl=>"https://example.com/disconnect", :disconnectMethod=>"POST", :callTimeout=>30, :callbackTimeout=>15, :machineDetection=>{}, :priority=>5, :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + create_call_equal = Bandwidth::CreateCall.new({ + to: '+19195550100', + from: '+19195550101', + application_id: 'baseline-app', + answer_url: 'https://example.com/answer/baseline' + }) + expect(create_call_default.eql?(create_call_equal)).to be true + expect(create_call_default.eql?(create_call_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_call_values.to_body).to eq({ + to: '+19195551234', + from: '+19195554321', + privacy: false, + displayName: 'Caller Name', + uui: 'eyJ0eXAiOiJKV1Q;encoding=jwt', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + answerUrl: 'https://example.com/answer', + answerMethod: Bandwidth::CallbackMethodEnum::POST, + username: 'user', + password: 'pass', + answerFallbackUrl: 'https://example.com/answer-fallback', + answerFallbackMethod: Bandwidth::CallbackMethodEnum::POST, + fallbackUsername: 'fallback_user', + fallbackPassword: 'fallback_pass', + disconnectUrl: 'https://example.com/disconnect', + disconnectMethod: Bandwidth::CallbackMethodEnum::POST, + callTimeout: 30, + callbackTimeout: 15, + machineDetection: {}, + priority: 5, + tag: 'custom tag' + }) + end + end + + describe 'custom attribute writers' do + it '#to=' do + expect { + Bandwidth::CreateCall.new({ to: nil, from: 'a', application_id: 'a', answer_url: 'a' }) + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#from=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: nil, application_id: 'a', answer_url: 'a' }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#display_name=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', display_name: 'a' * 257, application_id: 'a', answer_url: 'a' }) + }.to raise_error(ArgumentError, 'invalid value for "display_name", the character length must be smaller than or equal to 256.') + end + + it '#application_id=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: nil, answer_url: 'a' }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#answer_url=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: nil }) + }.to raise_error(ArgumentError, 'answer_url cannot be nil') + + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "answer_url", the character length must be smaller than or equal to 2048.') + end + + it '#username=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "username", the character length must be smaller than or equal to 1024.') + end + + it '#password=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "password", the character length must be smaller than or equal to 1024.') + end + + it '#answer_fallback_url=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', answer_fallback_url: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "answer_fallback_url", the character length must be smaller than or equal to 2048.') + end + + it '#fallback_username=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', fallback_username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_username", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_password=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', fallback_password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_password", the character length must be smaller than or equal to 1024.') + end + + it '#disconnect_url=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', disconnect_url: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "disconnect_url", the character length must be smaller than or equal to 2048.') + end + + it '#call_timeout=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', call_timeout: 301 }) + }.to raise_error(ArgumentError, 'invalid value for "call_timeout", must be smaller than or equal to 300.') + + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', call_timeout: 0 }) + }.to raise_error(ArgumentError, 'invalid value for "call_timeout", must be greater than or equal to 1.') + end + + it '#callback_timeout=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', callback_timeout: 26 }) + }.to raise_error(ArgumentError, 'invalid value for "callback_timeout", must be smaller than or equal to 25.') + + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', callback_timeout: 0 }) + }.to raise_error(ArgumentError, 'invalid value for "callback_timeout", must be greater than or equal to 1.') + end + + it '#priority=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', priority: 6 }) + }.to raise_error(ArgumentError, 'invalid value for "priority", must be smaller than or equal to 5.') + + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', priority: 0 }) + }.to raise_error(ArgumentError, 'invalid value for "priority", must be greater than or equal to 1.') + end + + it '#tag=' do + expect { + Bandwidth::CreateCall.new({ to: 'a', from: 'a', application_id: 'a', answer_url: 'a', tag: 'a' * 4097 }) + }.to raise_error(ArgumentError, 'invalid value for "tag", the character length must be smaller than or equal to 4096.') + end + end +end diff --git a/spec/unit/models/create_endpoint_request_base_spec.rb b/spec/unit/models/create_endpoint_request_base_spec.rb new file mode 100644 index 00000000..c3829200 --- /dev/null +++ b/spec/unit/models/create_endpoint_request_base_spec.rb @@ -0,0 +1,107 @@ +# Unit tests for Bandwidth::CreateEndpointRequestBase +describe Bandwidth::CreateEndpointRequestBase do + let(:create_endpoint_request_base_default) { Bandwidth::CreateEndpointRequestBase.new({ + type: 'WEBRTC', + direction: 'INBOUND' + }) } + let(:create_endpoint_request_base_values) { Bandwidth::CreateEndpointRequestBase.new({ + type: Bandwidth::EndpointTypeEnum::WEBRTC, + direction: Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL, + event_callback_url: 'https://example.com/event-callback', + event_fallback_url: 'https://example.com/event-fallback', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateEndpointRequestBase.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateEndpointRequestBase.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateEndpointRequestBase.acceptable_attributes).to eq(Bandwidth::CreateEndpointRequestBase.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateEndpointRequestBase.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateEndpointRequestBase created by the build_from_hash method' do + create_endpoint_request_base_from_hash = Bandwidth::CreateEndpointRequestBase.build_from_hash({ + type: 'WEBRTC', + direction: 'BIDIRECTIONAL', + eventCallbackUrl: 'https://example.com/event-callback', + eventFallbackUrl: 'https://example.com/event-fallback', + tag: 'custom tag' + }) + expect(create_endpoint_request_base_from_hash).to be_instance_of(Bandwidth::CreateEndpointRequestBase) + expect(create_endpoint_request_base_from_hash.type).to eq(Bandwidth::EndpointTypeEnum::WEBRTC) + expect(create_endpoint_request_base_from_hash.direction).to eq(Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL) + expect(create_endpoint_request_base_from_hash.event_callback_url).to eq('https://example.com/event-callback') + expect(create_endpoint_request_base_from_hash.event_fallback_url).to eq('https://example.com/event-fallback') + expect(create_endpoint_request_base_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_endpoint_request_base_values.to_s).to eq('{:type=>"WEBRTC", :direction=>"BIDIRECTIONAL", :eventCallbackUrl=>"https://example.com/event-callback", :eventFallbackUrl=>"https://example.com/event-fallback", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + create_endpoint_request_base_equal = Bandwidth::CreateEndpointRequestBase.new({ + type: 'WEBRTC', + direction: 'INBOUND' + }) + expect(create_endpoint_request_base_default.eql?(create_endpoint_request_base_equal)).to be true + expect(create_endpoint_request_base_default.eql?(create_endpoint_request_base_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_endpoint_request_base_values.to_body).to eq({ + type: Bandwidth::EndpointTypeEnum::WEBRTC, + direction: Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL, + eventCallbackUrl: 'https://example.com/event-callback', + eventFallbackUrl: 'https://example.com/event-fallback', + tag: 'custom tag' + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::CreateEndpointRequestBase.new({ type: nil, direction: 'INBOUND' }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#direction=' do + expect { + Bandwidth::CreateEndpointRequestBase.new({ type: 'WEBRTC', direction: nil }) + }.to raise_error(ArgumentError, 'direction cannot be nil') + end + + it '#tag=' do + expect { + Bandwidth::CreateEndpointRequestBase.new({ type: 'WEBRTC', direction: 'INBOUND', tag: nil }) + }.to raise_error(ArgumentError, 'tag cannot be nil') + end + end +end diff --git a/spec/unit/models/create_endpoint_response_data_spec.rb b/spec/unit/models/create_endpoint_response_data_spec.rb new file mode 100644 index 00000000..f7adcbb2 --- /dev/null +++ b/spec/unit/models/create_endpoint_response_data_spec.rb @@ -0,0 +1,151 @@ +# Unit tests for Bandwidth::CreateEndpointResponseData +describe Bandwidth::CreateEndpointResponseData do + let(:create_endpoint_response_data_default) { Bandwidth::CreateEndpointResponseData.new({ + endpoint_id: 'baseline-endpoint', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2022-06-16T13:15:07.160Z', + expiration_timestamp: '2022-06-17T13:15:07.160Z', + token: 'baseline-token' + }) } + let(:create_endpoint_response_data_values) { Bandwidth::CreateEndpointResponseData.new({ + endpoint_id: 'ep-abc-123', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::CONNECTED, + creation_timestamp: '2022-06-16T13:15:07.160Z', + expiration_timestamp: '2022-06-17T13:15:07.160Z', + tag: 'custom tag', + devices: [Bandwidth::Device.new({ device_id: 'd-1', status: 'CONNECTED', creation_timestamp: '2022-06-16T13:15:08.000Z' })], + token: 'eyJhbGciOiJIUzI1NiJ9' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateEndpointResponseData.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateEndpointResponseData.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateEndpointResponseData.acceptable_attributes).to eq(Bandwidth::CreateEndpointResponseData.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateEndpointResponseData.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateEndpointResponseData created by the build_from_hash method' do + create_endpoint_response_data_from_hash = Bandwidth::CreateEndpointResponseData.build_from_hash({ + endpointId: 'ep-abc-123', + type: 'WEBRTC', + status: 'CONNECTED', + creationTimestamp: '2022-06-16T13:15:07.160Z', + expirationTimestamp: '2022-06-17T13:15:07.160Z', + tag: 'custom tag', + devices: [{ deviceId: 'd-1', status: 'CONNECTED', creationTimestamp: '2022-06-16T13:15:08.000Z' }], + token: 'eyJhbGciOiJIUzI1NiJ9' + }) + expect(create_endpoint_response_data_from_hash).to be_instance_of(Bandwidth::CreateEndpointResponseData) + expect(create_endpoint_response_data_from_hash.endpoint_id).to eq('ep-abc-123') + expect(create_endpoint_response_data_from_hash.type).to eq(Bandwidth::EndpointTypeEnum::WEBRTC) + expect(create_endpoint_response_data_from_hash.status).to eq(Bandwidth::EndpointStatusEnum::CONNECTED) + expect(create_endpoint_response_data_from_hash.creation_timestamp).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(create_endpoint_response_data_from_hash.expiration_timestamp).to eq(Time.parse('2022-06-17T13:15:07.160Z')) + expect(create_endpoint_response_data_from_hash.tag).to eq('custom tag') + expect(create_endpoint_response_data_from_hash.devices.first).to be_instance_of(Bandwidth::Device) + expect(create_endpoint_response_data_from_hash.token).to eq('eyJhbGciOiJIUzI1NiJ9') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_endpoint_response_data_values.to_s).to eq('{:endpointId=>"ep-abc-123", :type=>"WEBRTC", :status=>"CONNECTED", :creationTimestamp=>"2022-06-16T13:15:07.160Z", :expirationTimestamp=>"2022-06-17T13:15:07.160Z", :tag=>"custom tag", :devices=>[{:deviceId=>"d-1", :status=>"CONNECTED", :creationTimestamp=>"2022-06-16T13:15:08.000Z"}], :token=>"eyJhbGciOiJIUzI1NiJ9"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + create_endpoint_response_data_equal = Bandwidth::CreateEndpointResponseData.new({ + endpoint_id: 'baseline-endpoint', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2022-06-16T13:15:07.160Z', + expiration_timestamp: '2022-06-17T13:15:07.160Z', + token: 'baseline-token' + }) + expect(create_endpoint_response_data_default.eql?(create_endpoint_response_data_equal)).to be true + expect(create_endpoint_response_data_default.eql?(create_endpoint_response_data_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_endpoint_response_data_values.to_body).to eq({ + endpointId: 'ep-abc-123', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::CONNECTED, + creationTimestamp: '2022-06-16T13:15:07.160Z', + expirationTimestamp: '2022-06-17T13:15:07.160Z', + tag: 'custom tag', + devices: [{ deviceId: 'd-1', status: 'CONNECTED', creationTimestamp: '2022-06-16T13:15:08.000Z' }], + token: 'eyJhbGciOiJIUzI1NiJ9' + }) + end + end + + describe 'custom attribute writers' do + it '#endpoint_id=' do + expect { + Bandwidth::CreateEndpointResponseData.new({ endpoint_id: nil, type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', token: 'a' }) + }.to raise_error(ArgumentError, 'endpoint_id cannot be nil') + end + + it '#type=' do + expect { + Bandwidth::CreateEndpointResponseData.new({ endpoint_id: 'a', type: nil, status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', token: 'a' }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#status=' do + expect { + Bandwidth::CreateEndpointResponseData.new({ endpoint_id: 'a', type: 'WEBRTC', status: nil, creation_timestamp: 'a', expiration_timestamp: 'a', token: 'a' }) + }.to raise_error(ArgumentError, 'status cannot be nil') + end + + it '#creation_timestamp=' do + expect { + Bandwidth::CreateEndpointResponseData.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: nil, expiration_timestamp: 'a', token: 'a' }) + }.to raise_error(ArgumentError, 'creation_timestamp cannot be nil') + end + + it '#expiration_timestamp=' do + expect { + Bandwidth::CreateEndpointResponseData.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: nil, token: 'a' }) + }.to raise_error(ArgumentError, 'expiration_timestamp cannot be nil') + end + + it '#tag=' do + expect { + Bandwidth::CreateEndpointResponseData.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', token: 'a', tag: nil }) + }.to raise_error(ArgumentError, 'tag cannot be nil') + end + + it '#token=' do + expect { + Bandwidth::CreateEndpointResponseData.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', token: nil }) + }.to raise_error(ArgumentError, 'token cannot be nil') + end + end +end diff --git a/spec/unit/models/create_endpoint_response_spec.rb b/spec/unit/models/create_endpoint_response_spec.rb new file mode 100644 index 00000000..a827d7a3 --- /dev/null +++ b/spec/unit/models/create_endpoint_response_spec.rb @@ -0,0 +1,122 @@ +# Unit tests for Bandwidth::CreateEndpointResponse +describe Bandwidth::CreateEndpointResponse do + let(:create_endpoint_response_default) { Bandwidth::CreateEndpointResponse.new({ + links: [], + data: {}, + errors: [] + }) } + let(:create_endpoint_response_values) { Bandwidth::CreateEndpointResponse.new({ + links: [Bandwidth::BrtcLink.new({ href: 'https://example.com', rel: 'self', method: 'GET' })], + data: Bandwidth::CreateEndpointResponseData.new({ + endpoint_id: 'ep-abc-123', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2022-06-16T13:15:07.160Z', + expiration_timestamp: '2022-06-17T13:15:07.160Z', + token: 'eyJhbGciOiJIUzI1NiJ9' + }), + errors: [Bandwidth::BrtcError.new({ type: 'validation', description: 'bad input' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateEndpointResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateEndpointResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateEndpointResponse.acceptable_attributes).to eq(Bandwidth::CreateEndpointResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateEndpointResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateEndpointResponse created by the build_from_hash method' do + create_endpoint_response_from_hash = Bandwidth::CreateEndpointResponse.build_from_hash({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { + endpointId: 'ep-abc-123', + type: 'WEBRTC', + status: 'CONNECTED', + creationTimestamp: '2022-06-16T13:15:07.160Z', + expirationTimestamp: '2022-06-17T13:15:07.160Z', + token: 'eyJhbGciOiJIUzI1NiJ9' + }, + errors: [{ type: 'validation', description: 'bad input' }] + }) + expect(create_endpoint_response_from_hash).to be_instance_of(Bandwidth::CreateEndpointResponse) + expect(create_endpoint_response_from_hash.links.first).to be_instance_of(Bandwidth::BrtcLink) + expect(create_endpoint_response_from_hash.data).to be_instance_of(Bandwidth::CreateEndpointResponseData) + expect(create_endpoint_response_from_hash.errors.first).to be_instance_of(Bandwidth::BrtcError) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_endpoint_response_values.to_s).to eq('{:links=>[{:href=>"https://example.com", :rel=>"self", :method=>"GET"}], :data=>{:endpointId=>"ep-abc-123", :type=>"WEBRTC", :status=>"CONNECTED", :creationTimestamp=>"2022-06-16T13:15:07.160Z", :expirationTimestamp=>"2022-06-17T13:15:07.160Z", :token=>"eyJhbGciOiJIUzI1NiJ9"}, :errors=>[{:type=>"validation", :description=>"bad input"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + create_endpoint_response_equal = Bandwidth::CreateEndpointResponse.new({ + links: [], + data: {}, + errors: [] + }) + expect(create_endpoint_response_default.eql?(create_endpoint_response_equal)).to be true + expect(create_endpoint_response_default.eql?(create_endpoint_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_endpoint_response_values.to_body).to eq({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { + endpointId: 'ep-abc-123', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::CONNECTED, + creationTimestamp: '2022-06-16T13:15:07.160Z', + expirationTimestamp: '2022-06-17T13:15:07.160Z', + token: 'eyJhbGciOiJIUzI1NiJ9' + }, + errors: [{ type: 'validation', description: 'bad input' }] + }) + end + end + + describe 'custom attribute writers' do + it '#links=' do + expect { + create_endpoint_response_values.links = nil + }.to raise_error(ArgumentError, 'links cannot be nil') + end + + it '#data=' do + expect { + create_endpoint_response_values.data = nil + }.to raise_error(ArgumentError, 'data cannot be nil') + end + + it '#errors=' do + expect { + create_endpoint_response_values.errors = nil + }.to raise_error(ArgumentError, 'errors cannot be nil') + end + end +end diff --git a/spec/unit/models/create_message_request_error_spec.rb b/spec/unit/models/create_message_request_error_spec.rb new file mode 100644 index 00000000..3d92c38b --- /dev/null +++ b/spec/unit/models/create_message_request_error_spec.rb @@ -0,0 +1,93 @@ +# Unit tests for Bandwidth::CreateMessageRequestError +describe Bandwidth::CreateMessageRequestError do + let(:create_message_request_error_default) { Bandwidth::CreateMessageRequestError.new({ + type: 'baseline-type', + description: 'baseline description' + }) } + let(:create_message_request_error_values) { Bandwidth::CreateMessageRequestError.new({ + type: 'request-validation', + description: 'Your request could not be processed.', + field_errors: [Bandwidth::FieldError.new({ field_name: 'to', description: 'must be present' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateMessageRequestError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateMessageRequestError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateMessageRequestError.acceptable_attributes).to eq(Bandwidth::CreateMessageRequestError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateMessageRequestError.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateMessageRequestError created by the build_from_hash method' do + create_message_request_error_from_hash = Bandwidth::CreateMessageRequestError.build_from_hash({ + type: 'request-validation', + description: 'Your request could not be processed.', + fieldErrors: [{ fieldName: 'to', description: 'must be present' }] + }) + expect(create_message_request_error_from_hash).to be_instance_of(Bandwidth::CreateMessageRequestError) + expect(create_message_request_error_from_hash.type).to eq('request-validation') + expect(create_message_request_error_from_hash.description).to eq('Your request could not be processed.') + expect(create_message_request_error_from_hash.field_errors.first).to be_instance_of(Bandwidth::FieldError) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_message_request_error_values.to_s).to eq('{:type=>"request-validation", :description=>"Your request could not be processed.", :fieldErrors=>[{:fieldName=>"to", :description=>"must be present"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + create_message_request_error_equal = Bandwidth::CreateMessageRequestError.new({ + type: 'baseline-type', + description: 'baseline description' + }) + expect(create_message_request_error_default.eql?(create_message_request_error_equal)).to be true + expect(create_message_request_error_default.eql?(create_message_request_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_message_request_error_values.to_body).to eq({ + type: 'request-validation', + description: 'Your request could not be processed.', + fieldErrors: [{ fieldName: 'to', description: 'must be present' }] + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::CreateMessageRequestError.new({ type: nil, description: 'a' }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#description=' do + expect { + Bandwidth::CreateMessageRequestError.new({ type: 'a', description: nil }) + }.to raise_error(ArgumentError, 'description cannot be nil') + end + end +end diff --git a/spec/unit/models/create_multi_channel_message_response_spec.rb b/spec/unit/models/create_multi_channel_message_response_spec.rb new file mode 100644 index 00000000..989f5969 --- /dev/null +++ b/spec/unit/models/create_multi_channel_message_response_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::CreateMultiChannelMessageResponse +describe Bandwidth::CreateMultiChannelMessageResponse do + let(:create_multi_channel_message_response_default) { Bandwidth::CreateMultiChannelMessageResponse.new } + let(:create_multi_channel_message_response_values) { Bandwidth::CreateMultiChannelMessageResponse.new({ + links: [Bandwidth::Link.new({ rel: 'self', href: 'https://example.com' })], + errors: [Bandwidth::ErrorObject.new({ type: 'validation', description: 'bad input', source: Bandwidth::ErrorSource.new })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateMultiChannelMessageResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateMultiChannelMessageResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateMultiChannelMessageResponse.acceptable_attributes).to eq(Bandwidth::CreateMultiChannelMessageResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateMultiChannelMessageResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateMultiChannelMessageResponse created by the build_from_hash method' do + create_multi_channel_message_response_from_hash = Bandwidth::CreateMultiChannelMessageResponse.build_from_hash({ + links: [{ rel: 'self', href: 'https://example.com' }], + errors: [{ type: 'validation', description: 'bad input', source: {} }] + }) + expect(create_multi_channel_message_response_from_hash).to be_instance_of(Bandwidth::CreateMultiChannelMessageResponse) + expect(create_multi_channel_message_response_from_hash.links.first).to be_instance_of(Bandwidth::Link) + expect(create_multi_channel_message_response_from_hash.errors.first).to be_instance_of(Bandwidth::ErrorObject) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_multi_channel_message_response_values.to_s).to eq('{:links=>[{:rel=>"self", :href=>"https://example.com"}], :errors=>[{:type=>"validation", :description=>"bad input", :source=>{}}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(create_multi_channel_message_response_default.eql?(Bandwidth::CreateMultiChannelMessageResponse.new)).to be true + expect(create_multi_channel_message_response_default.eql?(create_multi_channel_message_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_multi_channel_message_response_values.to_body).to eq({ + links: [{ rel: 'self', href: 'https://example.com' }], + errors: [{ type: 'validation', description: 'bad input', source: {} }] + }) + end + end +end diff --git a/spec/unit/models/create_sync_lookup_response_data_spec.rb b/spec/unit/models/create_sync_lookup_response_data_spec.rb new file mode 100644 index 00000000..289eafa1 --- /dev/null +++ b/spec/unit/models/create_sync_lookup_response_data_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::CreateSyncLookupResponseData +describe Bandwidth::CreateSyncLookupResponseData do + let(:create_sync_lookup_response_data_default) { Bandwidth::CreateSyncLookupResponseData.new } + let(:create_sync_lookup_response_data_values) { Bandwidth::CreateSyncLookupResponseData.new({ + request_id: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', + status: Bandwidth::CompletedLookupStatusEnum::COMPLETE, + results: [Bandwidth::LookupResult.new({ phone_number: '+19195551234' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateSyncLookupResponseData.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateSyncLookupResponseData.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateSyncLookupResponseData.acceptable_attributes).to eq(Bandwidth::CreateSyncLookupResponseData.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateSyncLookupResponseData.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateSyncLookupResponseData created by the build_from_hash method' do + create_sync_lookup_response_data_from_hash = Bandwidth::CreateSyncLookupResponseData.build_from_hash({ + requestId: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', + status: 'COMPLETE', + results: [{ phoneNumber: '+19195551234' }] + }) + expect(create_sync_lookup_response_data_from_hash).to be_instance_of(Bandwidth::CreateSyncLookupResponseData) + expect(create_sync_lookup_response_data_from_hash.request_id).to eq('00b97c1b-d8b4-4a32-ad14-7d09ce04acb6') + expect(create_sync_lookup_response_data_from_hash.status).to eq(Bandwidth::CompletedLookupStatusEnum::COMPLETE) + expect(create_sync_lookup_response_data_from_hash.results.first).to be_instance_of(Bandwidth::LookupResult) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_sync_lookup_response_data_values.to_s).to eq('{:requestId=>"00b97c1b-d8b4-4a32-ad14-7d09ce04acb6", :status=>"COMPLETE", :results=>[{:phoneNumber=>"+19195551234"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(create_sync_lookup_response_data_default.eql?(Bandwidth::CreateSyncLookupResponseData.new)).to be true + expect(create_sync_lookup_response_data_default.eql?(create_sync_lookup_response_data_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_sync_lookup_response_data_values.to_body).to eq({ + requestId: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', + status: Bandwidth::CompletedLookupStatusEnum::COMPLETE, + results: [{ phoneNumber: '+19195551234' }] + }) + end + end +end diff --git a/spec/unit/models/create_sync_lookup_response_spec.rb b/spec/unit/models/create_sync_lookup_response_spec.rb new file mode 100644 index 00000000..5da32fcc --- /dev/null +++ b/spec/unit/models/create_sync_lookup_response_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::CreateSyncLookupResponse +describe Bandwidth::CreateSyncLookupResponse do + let(:create_sync_lookup_response_default) { Bandwidth::CreateSyncLookupResponse.new } + let(:create_sync_lookup_response_values) { Bandwidth::CreateSyncLookupResponse.new({ + links: [Bandwidth::LinkSchema.new({ href: 'https://example.com', rel: 'self', method: 'GET' })], + data: Bandwidth::CreateSyncLookupResponseData.new({ request_id: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', status: 'COMPLETE' }), + errors: [Bandwidth::LookupErrorSchema.new({ code: 'E1', description: 'bad', type: 'validation' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateSyncLookupResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateSyncLookupResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateSyncLookupResponse.acceptable_attributes).to eq(Bandwidth::CreateSyncLookupResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateSyncLookupResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateSyncLookupResponse created by the build_from_hash method' do + create_sync_lookup_response_from_hash = Bandwidth::CreateSyncLookupResponse.build_from_hash({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { requestId: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', status: 'COMPLETE' }, + errors: [{ code: 'E1', description: 'bad', type: 'validation' }] + }) + expect(create_sync_lookup_response_from_hash).to be_instance_of(Bandwidth::CreateSyncLookupResponse) + expect(create_sync_lookup_response_from_hash.links.first).to be_instance_of(Bandwidth::LinkSchema) + expect(create_sync_lookup_response_from_hash.data).to be_instance_of(Bandwidth::CreateSyncLookupResponseData) + expect(create_sync_lookup_response_from_hash.errors.first).to be_instance_of(Bandwidth::LookupErrorSchema) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_sync_lookup_response_values.to_s).to eq('{:links=>[{:href=>"https://example.com", :rel=>"self", :method=>"GET"}], :data=>{:requestId=>"00b97c1b-d8b4-4a32-ad14-7d09ce04acb6", :status=>"COMPLETE"}, :errors=>[{:code=>"E1", :description=>"bad", :type=>"validation"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(create_sync_lookup_response_default.eql?(Bandwidth::CreateSyncLookupResponse.new)).to be true + expect(create_sync_lookup_response_default.eql?(create_sync_lookup_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_sync_lookup_response_values.to_body).to eq({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { requestId: '00b97c1b-d8b4-4a32-ad14-7d09ce04acb6', status: 'COMPLETE' }, + errors: [{ code: 'E1', description: 'bad', type: 'validation' }] + }) + end + end +end diff --git a/spec/unit/models/create_web_rtc_connection_request_spec.rb b/spec/unit/models/create_web_rtc_connection_request_spec.rb new file mode 100644 index 00000000..cb03ee40 --- /dev/null +++ b/spec/unit/models/create_web_rtc_connection_request_spec.rb @@ -0,0 +1,111 @@ +# Unit tests for Bandwidth::CreateWebRtcConnectionRequest +describe Bandwidth::CreateWebRtcConnectionRequest do + let(:create_web_rtc_connection_request_default) { Bandwidth::CreateWebRtcConnectionRequest.new({ + type: 'WEBRTC', + direction: 'INBOUND' + }) } + let(:create_web_rtc_connection_request_values) { Bandwidth::CreateWebRtcConnectionRequest.new({ + type: Bandwidth::EndpointTypeEnum::WEBRTC, + direction: Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL, + event_callback_url: 'https://example.com/event-callback', + event_fallback_url: 'https://example.com/event-fallback', + tag: 'custom tag', + connection_metadata: { sessionId: 'session-1' } + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::CreateWebRtcConnectionRequest.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::CreateWebRtcConnectionRequest.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::CreateWebRtcConnectionRequest.acceptable_attributes).to eq(Bandwidth::CreateWebRtcConnectionRequest.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::CreateWebRtcConnectionRequest.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of CreateWebRtcConnectionRequest created by the build_from_hash method' do + create_web_rtc_connection_request_from_hash = Bandwidth::CreateWebRtcConnectionRequest.build_from_hash({ + type: 'WEBRTC', + direction: 'BIDIRECTIONAL', + eventCallbackUrl: 'https://example.com/event-callback', + eventFallbackUrl: 'https://example.com/event-fallback', + tag: 'custom tag', + connectionMetadata: { sessionId: 'session-1' } + }) + expect(create_web_rtc_connection_request_from_hash).to be_instance_of(Bandwidth::CreateWebRtcConnectionRequest) + expect(create_web_rtc_connection_request_from_hash.type).to eq(Bandwidth::EndpointTypeEnum::WEBRTC) + expect(create_web_rtc_connection_request_from_hash.direction).to eq(Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL) + expect(create_web_rtc_connection_request_from_hash.event_callback_url).to eq('https://example.com/event-callback') + expect(create_web_rtc_connection_request_from_hash.event_fallback_url).to eq('https://example.com/event-fallback') + expect(create_web_rtc_connection_request_from_hash.tag).to eq('custom tag') + expect(create_web_rtc_connection_request_from_hash.connection_metadata).to eq({ sessionId: 'session-1' }) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(create_web_rtc_connection_request_values.to_s).to eq('{:type=>"WEBRTC", :direction=>"BIDIRECTIONAL", :eventCallbackUrl=>"https://example.com/event-callback", :eventFallbackUrl=>"https://example.com/event-fallback", :tag=>"custom tag", :connectionMetadata=>{:sessionId=>"session-1"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + create_web_rtc_connection_request_equal = Bandwidth::CreateWebRtcConnectionRequest.new({ + type: 'WEBRTC', + direction: 'INBOUND' + }) + expect(create_web_rtc_connection_request_default.eql?(create_web_rtc_connection_request_equal)).to be true + expect(create_web_rtc_connection_request_default.eql?(create_web_rtc_connection_request_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(create_web_rtc_connection_request_values.to_body).to eq({ + type: Bandwidth::EndpointTypeEnum::WEBRTC, + direction: Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL, + eventCallbackUrl: 'https://example.com/event-callback', + eventFallbackUrl: 'https://example.com/event-fallback', + tag: 'custom tag', + connectionMetadata: { sessionId: 'session-1' } + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::CreateWebRtcConnectionRequest.new({ type: nil, direction: 'INBOUND' }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#direction=' do + expect { + Bandwidth::CreateWebRtcConnectionRequest.new({ type: 'WEBRTC', direction: nil }) + }.to raise_error(ArgumentError, 'direction cannot be nil') + end + + it '#tag=' do + expect { + Bandwidth::CreateWebRtcConnectionRequest.new({ type: 'WEBRTC', direction: 'INBOUND', tag: nil }) + }.to raise_error(ArgumentError, 'tag cannot be nil') + end + end +end diff --git a/spec/unit/models/deactivation_event_enum_spec.rb b/spec/unit/models/deactivation_event_enum_spec.rb new file mode 100644 index 00000000..0e8127aa --- /dev/null +++ b/spec/unit/models/deactivation_event_enum_spec.rb @@ -0,0 +1,28 @@ +# Unit tests for Bandwidth::DeactivationEventEnum +describe Bandwidth::DeactivationEventEnum do + describe 'constants' do + it 'defines DEACTIVATED' do + expect(Bandwidth::DeactivationEventEnum::DEACTIVATED).to eq('DEACTIVATED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::DeactivationEventEnum.all_vars).to eq([ + 'DEACTIVATED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::DeactivationEventEnum.build_from_hash('DEACTIVATED')).to eq('DEACTIVATED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::DeactivationEventEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/device_spec.rb b/spec/unit/models/device_spec.rb new file mode 100644 index 00000000..3c9786e8 --- /dev/null +++ b/spec/unit/models/device_spec.rb @@ -0,0 +1,111 @@ +# Unit tests for Bandwidth::Device +describe Bandwidth::Device do + let(:device_default) { Bandwidth::Device.new({ + device_id: 'baseline-device', + status: 'CONNECTED', + creation_timestamp: '2022-06-16T13:15:07.160Z' + }) } + let(:device_values) { Bandwidth::Device.new({ + device_id: 'd-abc-123', + device_name: 'Chrome on macOS', + status: Bandwidth::DeviceStatusEnum::CONNECTED, + creation_timestamp: '2022-06-16T13:15:07.160Z' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Device.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Device.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Device.acceptable_attributes).to eq(Bandwidth::Device.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Device.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Device created by the build_from_hash method' do + device_from_hash = Bandwidth::Device.build_from_hash({ + deviceId: 'd-abc-123', + deviceName: 'Chrome on macOS', + status: 'CONNECTED', + creationTimestamp: '2022-06-16T13:15:07.160Z' + }) + expect(device_from_hash).to be_instance_of(Bandwidth::Device) + expect(device_from_hash.device_id).to eq('d-abc-123') + expect(device_from_hash.device_name).to eq('Chrome on macOS') + expect(device_from_hash.status).to eq(Bandwidth::DeviceStatusEnum::CONNECTED) + expect(device_from_hash.creation_timestamp).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(device_values.to_s).to eq('{:deviceId=>"d-abc-123", :deviceName=>"Chrome on macOS", :status=>"CONNECTED", :creationTimestamp=>"2022-06-16T13:15:07.160Z"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + device_equal = Bandwidth::Device.new({ + device_id: 'baseline-device', + status: 'CONNECTED', + creation_timestamp: '2022-06-16T13:15:07.160Z' + }) + expect(device_default.eql?(device_equal)).to be true + expect(device_default.eql?(device_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(device_values.to_body).to eq({ + deviceId: 'd-abc-123', + deviceName: 'Chrome on macOS', + status: Bandwidth::DeviceStatusEnum::CONNECTED, + creationTimestamp: '2022-06-16T13:15:07.160Z' + }) + end + end + + describe 'custom attribute writers' do + it '#device_id=' do + expect { + Bandwidth::Device.new({ device_id: nil, status: 'CONNECTED', creation_timestamp: 'a' }) + }.to raise_error(ArgumentError, 'device_id cannot be nil') + end + + it '#device_name=' do + expect { + Bandwidth::Device.new({ device_id: 'a', device_name: nil, status: 'CONNECTED', creation_timestamp: 'a' }) + }.to raise_error(ArgumentError, 'device_name cannot be nil') + end + + it '#status=' do + expect { + Bandwidth::Device.new({ device_id: 'a', status: nil, creation_timestamp: 'a' }) + }.to raise_error(ArgumentError, 'status cannot be nil') + end + + it '#creation_timestamp=' do + expect { + Bandwidth::Device.new({ device_id: 'a', status: 'CONNECTED', creation_timestamp: nil }) + }.to raise_error(ArgumentError, 'creation_timestamp cannot be nil') + end + end +end diff --git a/spec/unit/models/device_status_enum_spec.rb b/spec/unit/models/device_status_enum_spec.rb new file mode 100644 index 00000000..7036bdc9 --- /dev/null +++ b/spec/unit/models/device_status_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::DeviceStatusEnum +describe Bandwidth::DeviceStatusEnum do + describe 'constants' do + it 'defines CONNECTED' do + expect(Bandwidth::DeviceStatusEnum::CONNECTED).to eq('CONNECTED') + end + + it 'defines DISCONNECTED' do + expect(Bandwidth::DeviceStatusEnum::DISCONNECTED).to eq('DISCONNECTED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::DeviceStatusEnum.all_vars).to eq([ + 'CONNECTED', + 'DISCONNECTED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::DeviceStatusEnum.build_from_hash('CONNECTED')).to eq('CONNECTED') + expect(Bandwidth::DeviceStatusEnum.build_from_hash('DISCONNECTED')).to eq('DISCONNECTED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::DeviceStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/disconnect_callback_spec.rb b/spec/unit/models/disconnect_callback_spec.rb new file mode 100644 index 00000000..20457aae --- /dev/null +++ b/spec/unit/models/disconnect_callback_spec.rb @@ -0,0 +1,134 @@ +# Unit tests for Bandwidth::DisconnectCallback +describe Bandwidth::DisconnectCallback do + let(:disconnect_callback_default) { Bandwidth::DisconnectCallback.new } + let(:disconnect_callback_values) { Bandwidth::DisconnectCallback.new({ + event_type: 'disconnect', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + end_time: '2022-06-16T13:16:18.126Z', + cause: 'hangup', + error_message: 'call rejected', + error_id: '4642074b-7b58-478b-96e4-3a60955c6765', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::DisconnectCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::DisconnectCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::DisconnectCallback.acceptable_attributes).to eq(Bandwidth::DisconnectCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::DisconnectCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'error_message', + :'error_id', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of DisconnectCallback created by the build_from_hash method' do + disconnect_callback_from_hash = Bandwidth::DisconnectCallback.build_from_hash({ + eventType: 'disconnect', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + endTime: '2022-06-16T13:16:18.126Z', + cause: 'hangup', + errorMessage: 'call rejected', + errorId: '4642074b-7b58-478b-96e4-3a60955c6765', + tag: 'custom tag' + }) + expect(disconnect_callback_from_hash).to be_instance_of(Bandwidth::DisconnectCallback) + expect(disconnect_callback_from_hash.event_type).to eq('disconnect') + expect(disconnect_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(disconnect_callback_from_hash.account_id).to eq('9900000') + expect(disconnect_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(disconnect_callback_from_hash.from).to eq('+19195554321') + expect(disconnect_callback_from_hash.to).to eq('+19195551234') + expect(disconnect_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(disconnect_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(disconnect_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(disconnect_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(disconnect_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(disconnect_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(disconnect_callback_from_hash.end_time).to eq(Time.parse('2022-06-16T13:16:18.126Z')) + expect(disconnect_callback_from_hash.cause).to eq('hangup') + expect(disconnect_callback_from_hash.error_message).to eq('call rejected') + expect(disconnect_callback_from_hash.error_id).to eq('4642074b-7b58-478b-96e4-3a60955c6765') + expect(disconnect_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(disconnect_callback_values.to_s).to eq('{:eventType=>"disconnect", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :direction=>"inbound", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :endTime=>"2022-06-16T13:16:18.126Z", :cause=>"hangup", :errorMessage=>"call rejected", :errorId=>"4642074b-7b58-478b-96e4-3a60955c6765", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(disconnect_callback_default.eql?(Bandwidth::DisconnectCallback.new)).to be true + expect(disconnect_callback_default.eql?(disconnect_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(disconnect_callback_values.to_body).to eq({ + eventType: 'disconnect', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + endTime: '2022-06-16T13:16:18.126Z', + cause: 'hangup', + errorMessage: 'call rejected', + errorId: '4642074b-7b58-478b-96e4-3a60955c6765', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/diversion_spec.rb b/spec/unit/models/diversion_spec.rb new file mode 100644 index 00000000..7c636dce --- /dev/null +++ b/spec/unit/models/diversion_spec.rb @@ -0,0 +1,88 @@ +# Unit tests for Bandwidth::Diversion +describe Bandwidth::Diversion do + let(:diversion_default) { Bandwidth::Diversion.new } + let(:diversion_values) { Bandwidth::Diversion.new({ + reason: 'unconditional', + privacy: 'off', + screen: 'no', + counter: '2', + limit: '5', + unknown: 'some-value', + orig_to: '+19195551234' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Diversion.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Diversion.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Diversion.acceptable_attributes).to eq(Bandwidth::Diversion.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Diversion.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Diversion created by the build_from_hash method' do + diversion_from_hash = Bandwidth::Diversion.build_from_hash({ + reason: 'unconditional', + privacy: 'off', + screen: 'no', + counter: '2', + limit: '5', + unknown: 'some-value', + origTo: '+19195551234' + }) + expect(diversion_from_hash).to be_instance_of(Bandwidth::Diversion) + expect(diversion_from_hash.reason).to eq('unconditional') + expect(diversion_from_hash.privacy).to eq('off') + expect(diversion_from_hash.screen).to eq('no') + expect(diversion_from_hash.counter).to eq('2') + expect(diversion_from_hash.limit).to eq('5') + expect(diversion_from_hash.unknown).to eq('some-value') + expect(diversion_from_hash.orig_to).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(diversion_values.to_s).to eq('{:reason=>"unconditional", :privacy=>"off", :screen=>"no", :counter=>"2", :limit=>"5", :unknown=>"some-value", :origTo=>"+19195551234"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(diversion_default.eql?(Bandwidth::Diversion.new)).to be true + expect(diversion_default.eql?(diversion_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(diversion_values.to_body).to eq({ + reason: 'unconditional', + privacy: 'off', + screen: 'no', + counter: '2', + limit: '5', + unknown: 'some-value', + origTo: '+19195551234' + }) + end + end +end diff --git a/spec/unit/models/dtmf_callback_spec.rb b/spec/unit/models/dtmf_callback_spec.rb new file mode 100644 index 00000000..67fe1eca --- /dev/null +++ b/spec/unit/models/dtmf_callback_spec.rb @@ -0,0 +1,132 @@ +# Unit tests for Bandwidth::DtmfCallback +describe Bandwidth::DtmfCallback do + let(:dtmf_callback_default) { Bandwidth::DtmfCallback.new } + let(:dtmf_callback_values) { Bandwidth::DtmfCallback.new({ + event_type: 'dtmf', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + direction: Bandwidth::CallDirectionEnum::INBOUND, + digit: '1', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + parent_call_id: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::DtmfCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::DtmfCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::DtmfCallback.acceptable_attributes).to eq(Bandwidth::DtmfCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::DtmfCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of DtmfCallback created by the build_from_hash method' do + dtmf_callback_from_hash = Bandwidth::DtmfCallback.build_from_hash({ + eventType: 'dtmf', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + direction: Bandwidth::CallDirectionEnum::INBOUND, + digit: '1', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + transferCallerId: '+19195554321', + transferTo: '+19195551234', + tag: 'custom tag' + }) + expect(dtmf_callback_from_hash).to be_instance_of(Bandwidth::DtmfCallback) + expect(dtmf_callback_from_hash.event_type).to eq('dtmf') + expect(dtmf_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(dtmf_callback_from_hash.account_id).to eq('9900000') + expect(dtmf_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(dtmf_callback_from_hash.from).to eq('+19195554321') + expect(dtmf_callback_from_hash.to).to eq('+19195551234') + expect(dtmf_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(dtmf_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(dtmf_callback_from_hash.digit).to eq('1') + expect(dtmf_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(dtmf_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(dtmf_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(dtmf_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(dtmf_callback_from_hash.parent_call_id).to eq('c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99') + expect(dtmf_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(dtmf_callback_from_hash.transfer_to).to eq('+19195551234') + expect(dtmf_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(dtmf_callback_values.to_s).to eq('{:eventType=>"dtmf", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :direction=>"inbound", :digit=>"1", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :parentCallId=>"c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99", :transferCallerId=>"+19195554321", :transferTo=>"+19195551234", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(dtmf_callback_default.eql?(Bandwidth::DtmfCallback.new)).to be true + expect(dtmf_callback_default.eql?(dtmf_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(dtmf_callback_values.to_body).to eq({ + eventType: 'dtmf', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + direction: Bandwidth::CallDirectionEnum::INBOUND, + digit: '1', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + transferCallerId: '+19195554321', + transferTo: '+19195551234', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/endpoint_direction_enum_spec.rb b/spec/unit/models/endpoint_direction_enum_spec.rb new file mode 100644 index 00000000..a21bc99a --- /dev/null +++ b/spec/unit/models/endpoint_direction_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::EndpointDirectionEnum +describe Bandwidth::EndpointDirectionEnum do + describe 'constants' do + it 'defines INBOUND' do + expect(Bandwidth::EndpointDirectionEnum::INBOUND).to eq('INBOUND') + end + + it 'defines OUTBOUND' do + expect(Bandwidth::EndpointDirectionEnum::OUTBOUND).to eq('OUTBOUND') + end + + it 'defines BIDIRECTIONAL' do + expect(Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL).to eq('BIDIRECTIONAL') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::EndpointDirectionEnum.all_vars).to eq([ + 'INBOUND', + 'OUTBOUND', + 'BIDIRECTIONAL' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::EndpointDirectionEnum.build_from_hash('INBOUND')).to eq('INBOUND') + expect(Bandwidth::EndpointDirectionEnum.build_from_hash('OUTBOUND')).to eq('OUTBOUND') + expect(Bandwidth::EndpointDirectionEnum.build_from_hash('BIDIRECTIONAL')).to eq('BIDIRECTIONAL') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::EndpointDirectionEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/endpoint_event_spec.rb b/spec/unit/models/endpoint_event_spec.rb new file mode 100644 index 00000000..eb17e562 --- /dev/null +++ b/spec/unit/models/endpoint_event_spec.rb @@ -0,0 +1,163 @@ +# Unit tests for Bandwidth::EndpointEvent +describe Bandwidth::EndpointEvent do + let(:endpoint_event_default) { Bandwidth::EndpointEvent.new({ + endpoint_id: 'baseline-endpoint', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2022-06-16T13:15:07.160Z', + expiration_timestamp: '2022-06-17T13:15:07.160Z', + event_time: '2022-06-16T13:15:08.000Z', + event_type: 'DEVICE_CONNECTED' + }) } + let(:endpoint_event_values) { Bandwidth::EndpointEvent.new({ + endpoint_id: 'ep-abc-123', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::CONNECTED, + creation_timestamp: '2022-06-16T13:15:07.160Z', + expiration_timestamp: '2022-06-17T13:15:07.160Z', + tag: 'custom tag', + event_time: '2022-06-16T13:15:08.000Z', + event_type: Bandwidth::EndpointEventTypeEnum::DEVICE_CONNECTED, + device: Bandwidth::Device.new({ device_id: 'd-1', status: 'CONNECTED', creation_timestamp: '2022-06-16T13:15:08.000Z' }) + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::EndpointEvent.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::EndpointEvent.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::EndpointEvent.acceptable_attributes).to eq(Bandwidth::EndpointEvent.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::EndpointEvent.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of EndpointEvent created by the build_from_hash method' do + endpoint_event_from_hash = Bandwidth::EndpointEvent.build_from_hash({ + endpointId: 'ep-abc-123', + type: 'WEBRTC', + status: 'CONNECTED', + creationTimestamp: '2022-06-16T13:15:07.160Z', + expirationTimestamp: '2022-06-17T13:15:07.160Z', + tag: 'custom tag', + eventTime: '2022-06-16T13:15:08.000Z', + eventType: 'DEVICE_CONNECTED', + device: { deviceId: 'd-1', status: 'CONNECTED', creationTimestamp: '2022-06-16T13:15:08.000Z' } + }) + expect(endpoint_event_from_hash).to be_instance_of(Bandwidth::EndpointEvent) + expect(endpoint_event_from_hash.endpoint_id).to eq('ep-abc-123') + expect(endpoint_event_from_hash.type).to eq(Bandwidth::EndpointTypeEnum::WEBRTC) + expect(endpoint_event_from_hash.status).to eq(Bandwidth::EndpointStatusEnum::CONNECTED) + expect(endpoint_event_from_hash.creation_timestamp).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(endpoint_event_from_hash.expiration_timestamp).to eq(Time.parse('2022-06-17T13:15:07.160Z')) + expect(endpoint_event_from_hash.tag).to eq('custom tag') + expect(endpoint_event_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:08.000Z')) + expect(endpoint_event_from_hash.event_type).to eq(Bandwidth::EndpointEventTypeEnum::DEVICE_CONNECTED) + expect(endpoint_event_from_hash.device).to be_instance_of(Bandwidth::Device) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(endpoint_event_values.to_s).to eq('{:endpointId=>"ep-abc-123", :type=>"WEBRTC", :status=>"CONNECTED", :creationTimestamp=>"2022-06-16T13:15:07.160Z", :expirationTimestamp=>"2022-06-17T13:15:07.160Z", :tag=>"custom tag", :eventTime=>"2022-06-16T13:15:08.000Z", :eventType=>"DEVICE_CONNECTED", :device=>{:deviceId=>"d-1", :status=>"CONNECTED", :creationTimestamp=>"2022-06-16T13:15:08.000Z"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + endpoint_event_equal = Bandwidth::EndpointEvent.new({ + endpoint_id: 'baseline-endpoint', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2022-06-16T13:15:07.160Z', + expiration_timestamp: '2022-06-17T13:15:07.160Z', + event_time: '2022-06-16T13:15:08.000Z', + event_type: 'DEVICE_CONNECTED' + }) + expect(endpoint_event_default.eql?(endpoint_event_equal)).to be true + expect(endpoint_event_default.eql?(endpoint_event_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(endpoint_event_values.to_body).to eq({ + endpointId: 'ep-abc-123', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::CONNECTED, + creationTimestamp: '2022-06-16T13:15:07.160Z', + expirationTimestamp: '2022-06-17T13:15:07.160Z', + tag: 'custom tag', + eventTime: '2022-06-16T13:15:08.000Z', + eventType: Bandwidth::EndpointEventTypeEnum::DEVICE_CONNECTED, + device: { deviceId: 'd-1', status: 'CONNECTED', creationTimestamp: '2022-06-16T13:15:08.000Z' } + }) + end + end + + describe 'custom attribute writers' do + it '#endpoint_id=' do + expect { + Bandwidth::EndpointEvent.new({ endpoint_id: nil, type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', event_time: 'a', event_type: 'DEVICE_CONNECTED' }) + }.to raise_error(ArgumentError, 'endpoint_id cannot be nil') + end + + it '#type=' do + expect { + Bandwidth::EndpointEvent.new({ endpoint_id: 'a', type: nil, status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', event_time: 'a', event_type: 'DEVICE_CONNECTED' }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#status=' do + expect { + Bandwidth::EndpointEvent.new({ endpoint_id: 'a', type: 'WEBRTC', status: nil, creation_timestamp: 'a', expiration_timestamp: 'a', event_time: 'a', event_type: 'DEVICE_CONNECTED' }) + }.to raise_error(ArgumentError, 'status cannot be nil') + end + + it '#creation_timestamp=' do + expect { + Bandwidth::EndpointEvent.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: nil, expiration_timestamp: 'a', event_time: 'a', event_type: 'DEVICE_CONNECTED' }) + }.to raise_error(ArgumentError, 'creation_timestamp cannot be nil') + end + + it '#expiration_timestamp=' do + expect { + Bandwidth::EndpointEvent.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: nil, event_time: 'a', event_type: 'DEVICE_CONNECTED' }) + }.to raise_error(ArgumentError, 'expiration_timestamp cannot be nil') + end + + it '#tag=' do + expect { + Bandwidth::EndpointEvent.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', event_time: 'a', event_type: 'DEVICE_CONNECTED', tag: nil }) + }.to raise_error(ArgumentError, 'tag cannot be nil') + end + + it '#event_time=' do + expect { + Bandwidth::EndpointEvent.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', event_time: nil, event_type: 'DEVICE_CONNECTED' }) + }.to raise_error(ArgumentError, 'event_time cannot be nil') + end + + it '#event_type=' do + expect { + Bandwidth::EndpointEvent.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: 'a', expiration_timestamp: 'a', event_time: 'a', event_type: nil }) + }.to raise_error(ArgumentError, 'event_type cannot be nil') + end + end +end diff --git a/spec/unit/models/endpoint_event_type_enum_spec.rb b/spec/unit/models/endpoint_event_type_enum_spec.rb new file mode 100644 index 00000000..1f8474bd --- /dev/null +++ b/spec/unit/models/endpoint_event_type_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::EndpointEventTypeEnum +describe Bandwidth::EndpointEventTypeEnum do + describe 'constants' do + it 'defines DEVICE_CONNECTED' do + expect(Bandwidth::EndpointEventTypeEnum::DEVICE_CONNECTED).to eq('DEVICE_CONNECTED') + end + + it 'defines DEVICE_DISCONNECTED' do + expect(Bandwidth::EndpointEventTypeEnum::DEVICE_DISCONNECTED).to eq('DEVICE_DISCONNECTED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::EndpointEventTypeEnum.all_vars).to eq([ + 'DEVICE_CONNECTED', + 'DEVICE_DISCONNECTED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::EndpointEventTypeEnum.build_from_hash('DEVICE_CONNECTED')).to eq('DEVICE_CONNECTED') + expect(Bandwidth::EndpointEventTypeEnum.build_from_hash('DEVICE_DISCONNECTED')).to eq('DEVICE_DISCONNECTED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::EndpointEventTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/endpoint_response_spec.rb b/spec/unit/models/endpoint_response_spec.rb new file mode 100644 index 00000000..5f947d27 --- /dev/null +++ b/spec/unit/models/endpoint_response_spec.rb @@ -0,0 +1,108 @@ +# Unit tests for Bandwidth::EndpointResponse +describe Bandwidth::EndpointResponse do + let(:endpoint_data) { Bandwidth::Endpoint.new({ + endpoint_id: 'abc123', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2024-01-01T00:00:00Z', + expiration_timestamp: '2024-01-02T00:00:00Z' + }) } + let(:endpoint_response_default) { Bandwidth::EndpointResponse.new({ + links: [], + data: endpoint_data, + errors: [] + }) } + let(:endpoint_response_values) { Bandwidth::EndpointResponse.new({ + links: [Bandwidth::BrtcLink.new({ href: 'https://example.com', rel: 'self', method: 'GET' })], + data: endpoint_data, + errors: [Bandwidth::BrtcError.new({ type: 'validation', description: 'bad input' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::EndpointResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::EndpointResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::EndpointResponse.acceptable_attributes).to eq(Bandwidth::EndpointResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::EndpointResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of EndpointResponse created by the build_from_hash method' do + endpoint_response_from_hash = Bandwidth::EndpointResponse.build_from_hash({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { endpointId: 'abc123', type: 'WEBRTC', status: 'CONNECTED', creationTimestamp: '2024-01-01T00:00:00Z', expirationTimestamp: '2024-01-02T00:00:00Z' }, + errors: [{ type: 'validation', description: 'bad input' }] + }) + expect(endpoint_response_from_hash).to be_instance_of(Bandwidth::EndpointResponse) + expect(endpoint_response_from_hash.links.first).to be_instance_of(Bandwidth::BrtcLink) + expect(endpoint_response_from_hash.data).to be_instance_of(Bandwidth::Endpoint) + expect(endpoint_response_from_hash.errors.first).to be_instance_of(Bandwidth::BrtcError) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(endpoint_response_values.to_s).to eq('{:links=>[{:href=>"https://example.com", :rel=>"self", :method=>"GET"}], :data=>{:endpointId=>"abc123", :type=>"WEBRTC", :status=>"CONNECTED", :creationTimestamp=>"2024-01-01T00:00:00Z", :expirationTimestamp=>"2024-01-02T00:00:00Z"}, :errors=>[{:type=>"validation", :description=>"bad input"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + endpoint_response_equal = Bandwidth::EndpointResponse.new({ + links: [], + data: endpoint_data, + errors: [] + }) + expect(endpoint_response_default.eql?(endpoint_response_equal)).to be true + expect(endpoint_response_default.eql?(endpoint_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(endpoint_response_values.to_body).to eq({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { endpointId: 'abc123', type: 'WEBRTC', status: 'CONNECTED', creationTimestamp: '2024-01-01T00:00:00Z', expirationTimestamp: '2024-01-02T00:00:00Z' }, + errors: [{ type: 'validation', description: 'bad input' }] + }) + end + end + + describe 'custom attribute writers' do + it '#links=' do + expect { + endpoint_response_values.links = nil + }.to raise_error(ArgumentError, 'links cannot be nil') + end + + it '#data=' do + expect { + endpoint_response_values.data = nil + }.to raise_error(ArgumentError, 'data cannot be nil') + end + + it '#errors=' do + expect { + endpoint_response_values.errors = nil + }.to raise_error(ArgumentError, 'errors cannot be nil') + end + end +end diff --git a/spec/unit/models/endpoint_spec.rb b/spec/unit/models/endpoint_spec.rb new file mode 100644 index 00000000..8ea24817 --- /dev/null +++ b/spec/unit/models/endpoint_spec.rb @@ -0,0 +1,140 @@ +# Unit tests for Bandwidth::Endpoint +describe Bandwidth::Endpoint do + let(:endpoint_default) { Bandwidth::Endpoint.new({ + endpoint_id: 'endpoint-1', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::CONNECTED, + creation_timestamp: '2024-01-01T00:00:00Z', + expiration_timestamp: '2024-01-02T00:00:00Z' + }) } + let(:endpoint_values) { Bandwidth::Endpoint.new({ + endpoint_id: 'endpoint-2', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::DISCONNECTED, + creation_timestamp: '2024-02-01T00:00:00Z', + expiration_timestamp: '2024-02-02T00:00:00Z', + tag: 'custom tag', + devices: [{ device_id: 'device-1', device_name: 'Phone', status: 'CONNECTED', creation_timestamp: '2024-02-01T00:00:00Z' }] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Endpoint.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Endpoint.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Endpoint.acceptable_attributes).to eq(Bandwidth::Endpoint.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Endpoint.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Endpoint created by the build_from_hash method' do + endpoint_from_hash = Bandwidth::Endpoint.build_from_hash({ + endpointId: 'endpoint-2', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::DISCONNECTED, + creationTimestamp: '2024-02-01T00:00:00Z', + expirationTimestamp: '2024-02-02T00:00:00Z', + tag: 'custom tag', + devices: [{ deviceId: 'device-1', deviceName: 'Phone', status: 'CONNECTED', creationTimestamp: '2024-02-01T00:00:00Z' }] + }) + expect(endpoint_from_hash).to be_instance_of(Bandwidth::Endpoint) + expect(endpoint_from_hash.endpoint_id).to eq('endpoint-2') + expect(endpoint_from_hash.type).to eq(Bandwidth::EndpointTypeEnum::WEBRTC) + expect(endpoint_from_hash.status).to eq(Bandwidth::EndpointStatusEnum::DISCONNECTED) + expect(endpoint_from_hash.creation_timestamp).to eq(Time.parse('2024-02-01T00:00:00Z')) + expect(endpoint_from_hash.expiration_timestamp).to eq(Time.parse('2024-02-02T00:00:00Z')) + expect(endpoint_from_hash.tag).to eq('custom tag') + expect(endpoint_from_hash.devices).to be_instance_of(Array) + expect(endpoint_from_hash.devices.first).to be_instance_of(Bandwidth::Device) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(endpoint_values.to_s).to eq('{:endpointId=>"endpoint-2", :type=>"WEBRTC", :status=>"DISCONNECTED", :creationTimestamp=>"2024-02-01T00:00:00Z", :expirationTimestamp=>"2024-02-02T00:00:00Z", :tag=>"custom tag", :devices=>[{:device_id=>"device-1", :device_name=>"Phone", :status=>"CONNECTED", :creation_timestamp=>"2024-02-01T00:00:00Z"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + endpoint_equal = Bandwidth::Endpoint.new({ + endpoint_id: 'endpoint-1', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::CONNECTED, + creation_timestamp: '2024-01-01T00:00:00Z', + expiration_timestamp: '2024-01-02T00:00:00Z' + }) + expect(endpoint_default.eql?(endpoint_equal)).to be true + expect(endpoint_default.eql?(endpoint_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(endpoint_values.to_body).to eq({ + endpointId: 'endpoint-2', + type: Bandwidth::EndpointTypeEnum::WEBRTC, + status: Bandwidth::EndpointStatusEnum::DISCONNECTED, + creationTimestamp: '2024-02-01T00:00:00Z', + expirationTimestamp: '2024-02-02T00:00:00Z', + tag: 'custom tag', + devices: [{ device_id: 'device-1', device_name: 'Phone', status: 'CONNECTED', creation_timestamp: '2024-02-01T00:00:00Z' }] + }) + end + end + + describe 'custom attribute writers' do + it '#endpoint_id=' do + expect { + Bandwidth::Endpoint.new({ endpoint_id: nil }) + }.to raise_error(ArgumentError, 'endpoint_id cannot be nil') + end + + it '#type=' do + expect { + Bandwidth::Endpoint.new({ endpoint_id: 'endpoint-1', type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#status=' do + expect { + Bandwidth::Endpoint.new({ endpoint_id: 'endpoint-1', type: Bandwidth::EndpointTypeEnum::WEBRTC, status: nil }) + }.to raise_error(ArgumentError, 'status cannot be nil') + end + + it '#creation_timestamp=' do + expect { + Bandwidth::Endpoint.new({ endpoint_id: 'endpoint-1', type: Bandwidth::EndpointTypeEnum::WEBRTC, status: Bandwidth::EndpointStatusEnum::CONNECTED, creation_timestamp: nil }) + }.to raise_error(ArgumentError, 'creation_timestamp cannot be nil') + end + + it '#expiration_timestamp=' do + expect { + Bandwidth::Endpoint.new({ endpoint_id: 'endpoint-1', type: Bandwidth::EndpointTypeEnum::WEBRTC, status: Bandwidth::EndpointStatusEnum::CONNECTED, creation_timestamp: '2024-01-01T00:00:00Z', expiration_timestamp: nil }) + }.to raise_error(ArgumentError, 'expiration_timestamp cannot be nil') + end + + it '#tag=' do + expect { + endpoint_values.tag = nil + }.to raise_error(ArgumentError, 'tag cannot be nil') + end + end +end diff --git a/spec/unit/models/endpoint_status_enum_spec.rb b/spec/unit/models/endpoint_status_enum_spec.rb new file mode 100644 index 00000000..76b16eb8 --- /dev/null +++ b/spec/unit/models/endpoint_status_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::EndpointStatusEnum +describe Bandwidth::EndpointStatusEnum do + describe 'constants' do + it 'defines CONNECTED' do + expect(Bandwidth::EndpointStatusEnum::CONNECTED).to eq('CONNECTED') + end + + it 'defines DISCONNECTED' do + expect(Bandwidth::EndpointStatusEnum::DISCONNECTED).to eq('DISCONNECTED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::EndpointStatusEnum.all_vars).to eq([ + 'CONNECTED', + 'DISCONNECTED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::EndpointStatusEnum.build_from_hash('CONNECTED')).to eq('CONNECTED') + expect(Bandwidth::EndpointStatusEnum.build_from_hash('DISCONNECTED')).to eq('DISCONNECTED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::EndpointStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/endpoint_type_enum_spec.rb b/spec/unit/models/endpoint_type_enum_spec.rb new file mode 100644 index 00000000..b1767bce --- /dev/null +++ b/spec/unit/models/endpoint_type_enum_spec.rb @@ -0,0 +1,28 @@ +# Unit tests for Bandwidth::EndpointTypeEnum +describe Bandwidth::EndpointTypeEnum do + describe 'constants' do + it 'defines WEBRTC' do + expect(Bandwidth::EndpointTypeEnum::WEBRTC).to eq('WEBRTC') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::EndpointTypeEnum.all_vars).to eq([ + 'WEBRTC' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::EndpointTypeEnum.build_from_hash('WEBRTC')).to eq('WEBRTC') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::EndpointTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/endpoints_spec.rb b/spec/unit/models/endpoints_spec.rb new file mode 100644 index 00000000..11db75e6 --- /dev/null +++ b/spec/unit/models/endpoints_spec.rb @@ -0,0 +1,135 @@ +# Unit tests for Bandwidth::Endpoints +describe Bandwidth::Endpoints do + let(:endpoints_default) { Bandwidth::Endpoints.new({ + endpoint_id: 'baseline', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2024-01-01T00:00:00Z', + expiration_timestamp: '2024-01-02T00:00:00Z' + }) } + let(:endpoints_values) { Bandwidth::Endpoints.new({ + endpoint_id: 'abc123', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2024-01-01T00:00:00Z', + expiration_timestamp: '2024-01-02T00:00:00Z', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Endpoints.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Endpoints.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Endpoints.acceptable_attributes).to eq(Bandwidth::Endpoints.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Endpoints.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Endpoints created by the build_from_hash method' do + endpoints_from_hash = Bandwidth::Endpoints.build_from_hash({ + endpointId: 'abc123', + type: 'WEBRTC', + status: 'CONNECTED', + creationTimestamp: '2024-01-01T00:00:00Z', + expirationTimestamp: '2024-01-02T00:00:00Z', + tag: 'custom tag' + }) + expect(endpoints_from_hash).to be_instance_of(Bandwidth::Endpoints) + expect(endpoints_from_hash.endpoint_id).to eq('abc123') + expect(endpoints_from_hash.type).to eq('WEBRTC') + expect(endpoints_from_hash.status).to eq('CONNECTED') + expect(endpoints_from_hash.creation_timestamp).to eq(Time.parse('2024-01-01T00:00:00Z')) + expect(endpoints_from_hash.expiration_timestamp).to eq(Time.parse('2024-01-02T00:00:00Z')) + expect(endpoints_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(endpoints_values.to_s).to eq('{:endpointId=>"abc123", :type=>"WEBRTC", :status=>"CONNECTED", :creationTimestamp=>"2024-01-01T00:00:00Z", :expirationTimestamp=>"2024-01-02T00:00:00Z", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + endpoints_equal = Bandwidth::Endpoints.new({ + endpoint_id: 'baseline', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2024-01-01T00:00:00Z', + expiration_timestamp: '2024-01-02T00:00:00Z' + }) + expect(endpoints_default.eql?(endpoints_equal)).to be true + expect(endpoints_default.eql?(endpoints_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(endpoints_values.to_body).to eq({ + endpointId: 'abc123', + type: 'WEBRTC', + status: 'CONNECTED', + creationTimestamp: '2024-01-01T00:00:00Z', + expirationTimestamp: '2024-01-02T00:00:00Z', + tag: 'custom tag' + }) + end + end + + describe 'custom attribute writers' do + it '#endpoint_id=' do + expect { + Bandwidth::Endpoints.new({ endpoint_id: nil }) + }.to raise_error(ArgumentError, 'endpoint_id cannot be nil') + end + + it '#type=' do + expect { + Bandwidth::Endpoints.new({ endpoint_id: 'a', type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#status=' do + expect { + Bandwidth::Endpoints.new({ endpoint_id: 'a', type: 'WEBRTC', status: nil }) + }.to raise_error(ArgumentError, 'status cannot be nil') + end + + it '#creation_timestamp=' do + expect { + Bandwidth::Endpoints.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: nil }) + }.to raise_error(ArgumentError, 'creation_timestamp cannot be nil') + end + + it '#expiration_timestamp=' do + expect { + Bandwidth::Endpoints.new({ endpoint_id: 'a', type: 'WEBRTC', status: 'CONNECTED', creation_timestamp: '2024-01-01T00:00:00Z', expiration_timestamp: nil }) + }.to raise_error(ArgumentError, 'expiration_timestamp cannot be nil') + end + + it '#tag=' do + expect { + endpoints_values.tag = nil + }.to raise_error(ArgumentError, 'tag cannot be nil') + end + end +end diff --git a/spec/unit/models/error_object_spec.rb b/spec/unit/models/error_object_spec.rb new file mode 100644 index 00000000..ce6bbd35 --- /dev/null +++ b/spec/unit/models/error_object_spec.rb @@ -0,0 +1,103 @@ +# Unit tests for Bandwidth::ErrorObject +describe Bandwidth::ErrorObject do + let(:error_source) { Bandwidth::ErrorSource.new({ field: 'phoneNumber' }) } + let(:error_object_default) { Bandwidth::ErrorObject.new({ + type: 'baseline', + description: 'baseline description', + source: error_source + }) } + let(:error_object_values) { Bandwidth::ErrorObject.new({ + type: 'validation', + description: 'bad input', + source: error_source + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ErrorObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ErrorObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ErrorObject.acceptable_attributes).to eq(Bandwidth::ErrorObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::ErrorObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ErrorObject created by the build_from_hash method' do + error_object_from_hash = Bandwidth::ErrorObject.build_from_hash({ + type: 'validation', + description: 'bad input', + source: { field: 'phoneNumber' } + }) + expect(error_object_from_hash).to be_instance_of(Bandwidth::ErrorObject) + expect(error_object_from_hash.type).to eq('validation') + expect(error_object_from_hash.description).to eq('bad input') + expect(error_object_from_hash.source).to be_instance_of(Bandwidth::ErrorSource) + expect(error_object_from_hash.source.field).to eq('phoneNumber') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(error_object_values.to_s).to eq('{:type=>"validation", :description=>"bad input", :source=>{:field=>"phoneNumber"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + error_object_equal = Bandwidth::ErrorObject.new({ + type: 'baseline', + description: 'baseline description', + source: error_source + }) + expect(error_object_default.eql?(error_object_equal)).to be true + expect(error_object_default.eql?(error_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(error_object_values.to_body).to eq({ + type: 'validation', + description: 'bad input', + source: { field: 'phoneNumber' } + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::ErrorObject.new({ type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#description=' do + expect { + Bandwidth::ErrorObject.new({ type: 'a', description: nil }) + }.to raise_error(ArgumentError, 'description cannot be nil') + end + + it '#source=' do + expect { + Bandwidth::ErrorObject.new({ type: 'a', description: 'b', source: nil }) + }.to raise_error(ArgumentError, 'source cannot be nil') + end + end +end diff --git a/spec/unit/models/error_source_spec.rb b/spec/unit/models/error_source_spec.rb new file mode 100644 index 00000000..d8c73237 --- /dev/null +++ b/spec/unit/models/error_source_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::ErrorSource +describe Bandwidth::ErrorSource do + let(:error_source_default) { Bandwidth::ErrorSource.new } + let(:error_source_values) { Bandwidth::ErrorSource.new({ + parameter: 'phoneNumber', + field: 'to', + header: 'X-Request-Id', + reference: '/messages/123' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ErrorSource.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ErrorSource.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ErrorSource.acceptable_attributes).to eq(Bandwidth::ErrorSource.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::ErrorSource.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ErrorSource created by the build_from_hash method' do + error_source_from_hash = Bandwidth::ErrorSource.build_from_hash({ + parameter: 'phoneNumber', + field: 'to', + header: 'X-Request-Id', + reference: '/messages/123' + }) + expect(error_source_from_hash).to be_instance_of(Bandwidth::ErrorSource) + expect(error_source_from_hash.parameter).to eq('phoneNumber') + expect(error_source_from_hash.field).to eq('to') + expect(error_source_from_hash.header).to eq('X-Request-Id') + expect(error_source_from_hash.reference).to eq('/messages/123') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(error_source_values.to_s).to eq('{:parameter=>"phoneNumber", :field=>"to", :header=>"X-Request-Id", :reference=>"/messages/123"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(error_source_default.eql?(Bandwidth::ErrorSource.new)).to be true + expect(error_source_default.eql?(error_source_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(error_source_values.to_body).to eq({ + parameter: 'phoneNumber', + field: 'to', + header: 'X-Request-Id', + reference: '/messages/123' + }) + end + end +end diff --git a/spec/unit/models/failure_webhook_spec.rb b/spec/unit/models/failure_webhook_spec.rb new file mode 100644 index 00000000..e9ab4aed --- /dev/null +++ b/spec/unit/models/failure_webhook_spec.rb @@ -0,0 +1,104 @@ +# Unit tests for Bandwidth::FailureWebhook +describe Bandwidth::FailureWebhook do + let(:failure_webhook_default) { Bandwidth::FailureWebhook.new } + let(:failure_webhook_values) { Bandwidth::FailureWebhook.new({ + account_id: '9900000', + phone_number: '+18005551234', + error_code: '400', + error_message: 'bad request', + errors: ['missing field'], + internal_ticket_number: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::FailureWebhook.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::FailureWebhook.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::FailureWebhook.acceptable_attributes).to eq(Bandwidth::FailureWebhook.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::FailureWebhook.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of FailureWebhook created by the build_from_hash method' do + failure_webhook_from_hash = Bandwidth::FailureWebhook.build_from_hash({ + accountId: '9900000', + phoneNumber: '+18005551234', + errorCode: '400', + errorMessage: 'bad request', + errors: ['missing field'], + internalTicketNumber: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' + }) + expect(failure_webhook_from_hash).to be_instance_of(Bandwidth::FailureWebhook) + expect(failure_webhook_from_hash.account_id).to eq('9900000') + expect(failure_webhook_from_hash.phone_number).to eq('+18005551234') + expect(failure_webhook_from_hash.error_code).to eq('400') + expect(failure_webhook_from_hash.error_message).to eq('bad request') + expect(failure_webhook_from_hash.errors).to eq(['missing field']) + expect(failure_webhook_from_hash.internal_ticket_number).to eq('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(failure_webhook_values.to_s).to eq('{:accountId=>"9900000", :phoneNumber=>"+18005551234", :errorCode=>"400", :errorMessage=>"bad request", :errors=>["missing field"], :internalTicketNumber=>"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(failure_webhook_default.eql?(Bandwidth::FailureWebhook.new)).to be true + expect(failure_webhook_default.eql?(failure_webhook_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(failure_webhook_values.to_body).to eq({ + accountId: '9900000', + phoneNumber: '+18005551234', + errorCode: '400', + errorMessage: 'bad request', + errors: ['missing field'], + internalTicketNumber: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' + }) + end + end + + describe 'custom attribute writers' do + it '#phone_number=' do + expect { + Bandwidth::FailureWebhook.new({ phone_number: nil }) + }.to raise_error(ArgumentError, 'phone_number cannot be nil') + + expect { + Bandwidth::FailureWebhook.new({ phone_number: '+1800555123456' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be smaller than or equal to 12.') + + expect { + Bandwidth::FailureWebhook.new({ phone_number: '+1800555' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be greater than or equal to 12.') + + expect { + Bandwidth::FailureWebhook.new({ phone_number: '+19195551234' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", must conform to the pattern (?-mix:^\+1(800|833|844|855|866|877|888)[2-9]\d{6}$).') + end + end +end diff --git a/spec/unit/models/field_error_spec.rb b/spec/unit/models/field_error_spec.rb new file mode 100644 index 00000000..8c6e16e2 --- /dev/null +++ b/spec/unit/models/field_error_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::FieldError +describe Bandwidth::FieldError do + let(:field_error_default) { Bandwidth::FieldError.new } + let(:field_error_values) { Bandwidth::FieldError.new({ + field_name: 'to', + description: 'invalid phone number' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::FieldError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::FieldError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::FieldError.acceptable_attributes).to eq(Bandwidth::FieldError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::FieldError.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of FieldError created by the build_from_hash method' do + field_error_from_hash = Bandwidth::FieldError.build_from_hash({ + fieldName: 'to', + description: 'invalid phone number' + }) + expect(field_error_from_hash).to be_instance_of(Bandwidth::FieldError) + expect(field_error_from_hash.field_name).to eq('to') + expect(field_error_from_hash.description).to eq('invalid phone number') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(field_error_values.to_s).to eq('{:fieldName=>"to", :description=>"invalid phone number"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(field_error_default.eql?(Bandwidth::FieldError.new)).to be true + expect(field_error_default.eql?(field_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(field_error_values.to_body).to eq({ + fieldName: 'to', + description: 'invalid phone number' + }) + end + end +end diff --git a/spec/unit/models/file_format_enum_spec.rb b/spec/unit/models/file_format_enum_spec.rb new file mode 100644 index 00000000..8ed78228 --- /dev/null +++ b/spec/unit/models/file_format_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::FileFormatEnum +describe Bandwidth::FileFormatEnum do + describe 'constants' do + it 'defines MP3' do + expect(Bandwidth::FileFormatEnum::MP3).to eq('mp3') + end + + it 'defines WAV' do + expect(Bandwidth::FileFormatEnum::WAV).to eq('wav') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::FileFormatEnum.all_vars).to eq([ + 'mp3', + 'wav' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::FileFormatEnum.build_from_hash('mp3')).to eq('mp3') + expect(Bandwidth::FileFormatEnum.build_from_hash('wav')).to eq('wav') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::FileFormatEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/gather_callback_spec.rb b/spec/unit/models/gather_callback_spec.rb new file mode 100644 index 00000000..276754a6 --- /dev/null +++ b/spec/unit/models/gather_callback_spec.rb @@ -0,0 +1,136 @@ +# Unit tests for Bandwidth::GatherCallback +describe Bandwidth::GatherCallback do + let(:gather_callback_default) { Bandwidth::GatherCallback.new } + let(:gather_callback_values) { Bandwidth::GatherCallback.new({ + event_type: 'gather', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + digits: '123', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + parent_call_id: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + terminating_digit: '#', + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::GatherCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::GatherCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::GatherCallback.acceptable_attributes).to eq(Bandwidth::GatherCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::GatherCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of GatherCallback created by the build_from_hash method' do + gather_callback_from_hash = Bandwidth::GatherCallback.build_from_hash({ + eventType: 'gather', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + digits: '123', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + terminatingDigit: '#', + transferCallerId: '+19195554321', + transferTo: '+19195551234', + tag: 'custom tag' + }) + expect(gather_callback_from_hash).to be_instance_of(Bandwidth::GatherCallback) + expect(gather_callback_from_hash.event_type).to eq('gather') + expect(gather_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(gather_callback_from_hash.account_id).to eq('9900000') + expect(gather_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(gather_callback_from_hash.from).to eq('+19195554321') + expect(gather_callback_from_hash.to).to eq('+19195551234') + expect(gather_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(gather_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(gather_callback_from_hash.digits).to eq('123') + expect(gather_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(gather_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(gather_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(gather_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(gather_callback_from_hash.parent_call_id).to eq('c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99') + expect(gather_callback_from_hash.terminating_digit).to eq('#') + expect(gather_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(gather_callback_from_hash.transfer_to).to eq('+19195551234') + expect(gather_callback_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(gather_callback_values.to_s).to eq('{:eventType=>"gather", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"inbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :digits=>"123", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :parentCallId=>"c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99", :terminatingDigit=>"#", :transferCallerId=>"+19195554321", :transferTo=>"+19195551234", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(gather_callback_default.eql?(Bandwidth::GatherCallback.new)).to be true + expect(gather_callback_default.eql?(gather_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(gather_callback_values.to_body).to eq({ + eventType: 'gather', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + digits: '123', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + terminatingDigit: '#', + transferCallerId: '+19195554321', + transferTo: '+19195551234', + tag: 'custom tag' + }) + end + end +end diff --git a/spec/unit/models/get_async_bulk_lookup_response_data_spec.rb b/spec/unit/models/get_async_bulk_lookup_response_data_spec.rb new file mode 100644 index 00000000..39e0e878 --- /dev/null +++ b/spec/unit/models/get_async_bulk_lookup_response_data_spec.rb @@ -0,0 +1,74 @@ +# Unit tests for Bandwidth::GetAsyncBulkLookupResponseData +describe Bandwidth::GetAsyncBulkLookupResponseData do + let(:lookup_result) { Bandwidth::LookupResult.new({ phone_number: '+19195551234' }) } + let(:get_async_bulk_lookup_response_data_default) { Bandwidth::GetAsyncBulkLookupResponseData.new } + let(:get_async_bulk_lookup_response_data_values) { Bandwidth::GetAsyncBulkLookupResponseData.new({ + request_id: 'abc-123', + status: Bandwidth::InProgressLookupStatusEnum::COMPLETE, + results: [lookup_result] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::GetAsyncBulkLookupResponseData.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::GetAsyncBulkLookupResponseData.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::GetAsyncBulkLookupResponseData.acceptable_attributes).to eq(Bandwidth::GetAsyncBulkLookupResponseData.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::GetAsyncBulkLookupResponseData.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of GetAsyncBulkLookupResponseData created by the build_from_hash method' do + get_async_bulk_lookup_response_data_from_hash = Bandwidth::GetAsyncBulkLookupResponseData.build_from_hash({ + requestId: 'abc-123', + status: 'COMPLETE', + results: [{ phoneNumber: '+19195551234' }] + }) + expect(get_async_bulk_lookup_response_data_from_hash).to be_instance_of(Bandwidth::GetAsyncBulkLookupResponseData) + expect(get_async_bulk_lookup_response_data_from_hash.request_id).to eq('abc-123') + expect(get_async_bulk_lookup_response_data_from_hash.status).to eq('COMPLETE') + expect(get_async_bulk_lookup_response_data_from_hash.results.first).to be_instance_of(Bandwidth::LookupResult) + expect(get_async_bulk_lookup_response_data_from_hash.results.first.phone_number).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(get_async_bulk_lookup_response_data_values.to_s).to eq('{:requestId=>"abc-123", :status=>"COMPLETE", :results=>[{:phoneNumber=>"+19195551234"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(get_async_bulk_lookup_response_data_default.eql?(Bandwidth::GetAsyncBulkLookupResponseData.new)).to be true + expect(get_async_bulk_lookup_response_data_default.eql?(get_async_bulk_lookup_response_data_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(get_async_bulk_lookup_response_data_values.to_body).to eq({ + requestId: 'abc-123', + status: Bandwidth::InProgressLookupStatusEnum::COMPLETE, + results: [{ phoneNumber: '+19195551234' }] + }) + end + end +end diff --git a/spec/unit/models/get_async_bulk_lookup_response_spec.rb b/spec/unit/models/get_async_bulk_lookup_response_spec.rb new file mode 100644 index 00000000..4c8a302b --- /dev/null +++ b/spec/unit/models/get_async_bulk_lookup_response_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::GetAsyncBulkLookupResponse +describe Bandwidth::GetAsyncBulkLookupResponse do + let(:get_async_bulk_lookup_response_default) { Bandwidth::GetAsyncBulkLookupResponse.new } + let(:get_async_bulk_lookup_response_values) { Bandwidth::GetAsyncBulkLookupResponse.new({ + links: [Bandwidth::LinkSchema.new({ href: 'https://example.com', rel: 'self', method: 'GET' })], + data: Bandwidth::GetAsyncBulkLookupResponseData.new({ request_id: 'abc-123' }), + errors: [Bandwidth::LookupErrorSchema.new({ code: '400', description: 'bad request', type: 'validation' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::GetAsyncBulkLookupResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::GetAsyncBulkLookupResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::GetAsyncBulkLookupResponse.acceptable_attributes).to eq(Bandwidth::GetAsyncBulkLookupResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::GetAsyncBulkLookupResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of GetAsyncBulkLookupResponse created by the build_from_hash method' do + get_async_bulk_lookup_response_from_hash = Bandwidth::GetAsyncBulkLookupResponse.build_from_hash({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { requestId: 'abc-123' }, + errors: [{ code: '400', description: 'bad request', type: 'validation' }] + }) + expect(get_async_bulk_lookup_response_from_hash).to be_instance_of(Bandwidth::GetAsyncBulkLookupResponse) + expect(get_async_bulk_lookup_response_from_hash.links.first).to be_instance_of(Bandwidth::LinkSchema) + expect(get_async_bulk_lookup_response_from_hash.data).to be_instance_of(Bandwidth::GetAsyncBulkLookupResponseData) + expect(get_async_bulk_lookup_response_from_hash.errors.first).to be_instance_of(Bandwidth::LookupErrorSchema) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(get_async_bulk_lookup_response_values.to_s).to eq('{:links=>[{:href=>"https://example.com", :rel=>"self", :method=>"GET"}], :data=>{:requestId=>"abc-123"}, :errors=>[{:code=>"400", :description=>"bad request", :type=>"validation"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(get_async_bulk_lookup_response_default.eql?(Bandwidth::GetAsyncBulkLookupResponse.new)).to be true + expect(get_async_bulk_lookup_response_default.eql?(get_async_bulk_lookup_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(get_async_bulk_lookup_response_values.to_body).to eq({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { requestId: 'abc-123' }, + errors: [{ code: '400', description: 'bad request', type: 'validation' }] + }) + end + end +end diff --git a/spec/unit/models/in_progress_lookup_status_enum_spec.rb b/spec/unit/models/in_progress_lookup_status_enum_spec.rb new file mode 100644 index 00000000..dce92d25 --- /dev/null +++ b/spec/unit/models/in_progress_lookup_status_enum_spec.rb @@ -0,0 +1,46 @@ +# Unit tests for Bandwidth::InProgressLookupStatusEnum +describe Bandwidth::InProgressLookupStatusEnum do + describe 'constants' do + it 'defines IN_PROGRESS' do + expect(Bandwidth::InProgressLookupStatusEnum::IN_PROGRESS).to eq('IN_PROGRESS') + end + + it 'defines COMPLETE' do + expect(Bandwidth::InProgressLookupStatusEnum::COMPLETE).to eq('COMPLETE') + end + + it 'defines PARTIAL_COMPLETE' do + expect(Bandwidth::InProgressLookupStatusEnum::PARTIAL_COMPLETE).to eq('PARTIAL_COMPLETE') + end + + it 'defines FAILED' do + expect(Bandwidth::InProgressLookupStatusEnum::FAILED).to eq('FAILED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::InProgressLookupStatusEnum.all_vars).to eq([ + 'IN_PROGRESS', + 'COMPLETE', + 'PARTIAL_COMPLETE', + 'FAILED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::InProgressLookupStatusEnum.build_from_hash('IN_PROGRESS')).to eq('IN_PROGRESS') + expect(Bandwidth::InProgressLookupStatusEnum.build_from_hash('COMPLETE')).to eq('COMPLETE') + expect(Bandwidth::InProgressLookupStatusEnum.build_from_hash('PARTIAL_COMPLETE')).to eq('PARTIAL_COMPLETE') + expect(Bandwidth::InProgressLookupStatusEnum.build_from_hash('FAILED')).to eq('FAILED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::InProgressLookupStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/inbound_callback_message_spec.rb b/spec/unit/models/inbound_callback_message_spec.rb new file mode 100644 index 00000000..a53ee7e9 --- /dev/null +++ b/spec/unit/models/inbound_callback_message_spec.rb @@ -0,0 +1,181 @@ +# Unit tests for Bandwidth::InboundCallbackMessage +describe Bandwidth::InboundCallbackMessage do + let(:inbound_callback_message_default) { Bandwidth::InboundCallbackMessage.new({ + id: 'baseline-id', + owner: '+19195554321', + application_id: 'baseline-app', + time: '2022-06-16T13:15:07.160Z', + segment_count: 1, + direction: Bandwidth::MessageDirectionEnum::IN, + to: ['+19195551234'], + from: '+19195554321' + }) } + let(:inbound_callback_message_values) { Bandwidth::InboundCallbackMessage.new({ + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segment_count: 2, + direction: Bandwidth::MessageDirectionEnum::IN, + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + tag: 'custom tag', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + priority: Bandwidth::PriorityEnum::DEFAULT, + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::InboundCallbackMessage.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::InboundCallbackMessage.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::InboundCallbackMessage.acceptable_attributes).to eq(Bandwidth::InboundCallbackMessage.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::InboundCallbackMessage.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of InboundCallbackMessage created by the build_from_hash method' do + inbound_callback_message_from_hash = Bandwidth::InboundCallbackMessage.build_from_hash({ + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 2, + direction: Bandwidth::MessageDirectionEnum::IN, + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + tag: 'custom tag', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + priority: Bandwidth::PriorityEnum::DEFAULT, + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS + }) + expect(inbound_callback_message_from_hash).to be_instance_of(Bandwidth::InboundCallbackMessage) + expect(inbound_callback_message_from_hash.id).to eq('1589228074636lm4k2je7j7jklbn2') + expect(inbound_callback_message_from_hash.owner).to eq('+19195554321') + expect(inbound_callback_message_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(inbound_callback_message_from_hash.time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(inbound_callback_message_from_hash.segment_count).to eq(2) + expect(inbound_callback_message_from_hash.direction).to eq(Bandwidth::MessageDirectionEnum::IN) + expect(inbound_callback_message_from_hash.to).to eq(['+19195551234']) + expect(inbound_callback_message_from_hash.from).to eq('+19195554321') + expect(inbound_callback_message_from_hash.text).to eq('Hello world') + expect(inbound_callback_message_from_hash.tag).to eq('custom tag') + expect(inbound_callback_message_from_hash.media).to eq(['https://dev.bandwidth.com/images/bandwidth-logo.png']) + expect(inbound_callback_message_from_hash.priority).to eq(Bandwidth::PriorityEnum::DEFAULT) + expect(inbound_callback_message_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::SMS) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(inbound_callback_message_values.to_s).to eq('{:id=>"1589228074636lm4k2je7j7jklbn2", :owner=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :time=>"2022-06-16T13:15:07.160Z", :segmentCount=>2, :direction=>"in", :to=>["+19195551234"], :from=>"+19195554321", :text=>"Hello world", :tag=>"custom tag", :media=>["https://dev.bandwidth.com/images/bandwidth-logo.png"], :priority=>"default", :channel=>"SMS"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + inbound_callback_message_equal = Bandwidth::InboundCallbackMessage.new({ + id: 'baseline-id', + owner: '+19195554321', + application_id: 'baseline-app', + time: '2022-06-16T13:15:07.160Z', + segment_count: 1, + direction: Bandwidth::MessageDirectionEnum::IN, + to: ['+19195551234'], + from: '+19195554321' + }) + expect(inbound_callback_message_default.eql?(inbound_callback_message_equal)).to be true + expect(inbound_callback_message_default.eql?(inbound_callback_message_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(inbound_callback_message_values.to_body).to eq({ + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 2, + direction: Bandwidth::MessageDirectionEnum::IN, + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + tag: 'custom tag', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + priority: Bandwidth::PriorityEnum::DEFAULT, + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS + }) + end + end + + describe 'custom attribute writers' do + it '#id=' do + expect { + inbound_callback_message_values.id = nil + }.to raise_error(ArgumentError, 'id cannot be nil') + end + + it '#owner=' do + expect { + inbound_callback_message_values.owner = nil + }.to raise_error(ArgumentError, 'owner cannot be nil') + end + + it '#application_id=' do + expect { + inbound_callback_message_values.application_id = nil + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#time=' do + expect { + inbound_callback_message_values.time = nil + }.to raise_error(ArgumentError, 'time cannot be nil') + end + + it '#segment_count=' do + expect { + inbound_callback_message_values.segment_count = nil + }.to raise_error(ArgumentError, 'segment_count cannot be nil') + end + + it '#direction=' do + expect { + inbound_callback_message_values.direction = nil + }.to raise_error(ArgumentError, 'direction cannot be nil') + end + + it '#to=' do + expect { + inbound_callback_message_values.to = nil + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#from=' do + expect { + inbound_callback_message_values.from = nil + }.to raise_error(ArgumentError, 'from cannot be nil') + end + end +end diff --git a/spec/unit/models/inbound_callback_spec.rb b/spec/unit/models/inbound_callback_spec.rb new file mode 100644 index 00000000..fabc33b9 --- /dev/null +++ b/spec/unit/models/inbound_callback_spec.rb @@ -0,0 +1,161 @@ +# Unit tests for Bandwidth::InboundCallback +describe Bandwidth::InboundCallback do + let(:inbound_callback_default) { Bandwidth::InboundCallback.new({ + time: '2022-06-16T13:15:07.160Z', + type: Bandwidth::InboundCallbackTypeEnum::MESSAGE_RECEIVED, + to: '+19195551234', + description: 'baseline description', + message: { id: 'baseline' } + }) } + let(:inbound_callback_values) { Bandwidth::InboundCallback.new({ + time: '2022-06-16T13:15:07.160Z', + type: Bandwidth::InboundCallbackTypeEnum::MESSAGE_RECEIVED, + to: '+19195551234', + description: 'Incoming message received', + message: { + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 1, + direction: 'in', + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world' + }, + carrier_name: 'Verizon' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::InboundCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::InboundCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::InboundCallback.acceptable_attributes).to eq(Bandwidth::InboundCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::InboundCallback.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of InboundCallback created by the build_from_hash method' do + inbound_callback_from_hash = Bandwidth::InboundCallback.build_from_hash({ + time: '2022-06-16T13:15:07.160Z', + type: Bandwidth::InboundCallbackTypeEnum::MESSAGE_RECEIVED, + to: '+19195551234', + description: 'Incoming message received', + message: { + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 1, + direction: Bandwidth::MessageDirectionEnum::IN, + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world' + }, + carrierName: 'Verizon' + }) + expect(inbound_callback_from_hash).to be_instance_of(Bandwidth::InboundCallback) + expect(inbound_callback_from_hash.time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(inbound_callback_from_hash.type).to eq(Bandwidth::InboundCallbackTypeEnum::MESSAGE_RECEIVED) + expect(inbound_callback_from_hash.to).to eq('+19195551234') + expect(inbound_callback_from_hash.description).to eq('Incoming message received') + expect(inbound_callback_from_hash.message).to be_instance_of(Bandwidth::InboundCallbackMessage) + expect(inbound_callback_from_hash.message.id).to eq('1589228074636lm4k2je7j7jklbn2') + expect(inbound_callback_from_hash.message.text).to eq('Hello world') + expect(inbound_callback_from_hash.carrier_name).to eq('Verizon') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(inbound_callback_values.to_s).to eq('{:time=>"2022-06-16T13:15:07.160Z", :type=>"message-received", :to=>"+19195551234", :description=>"Incoming message received", :message=>{:id=>"1589228074636lm4k2je7j7jklbn2", :owner=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :time=>"2022-06-16T13:15:07.160Z", :segmentCount=>1, :direction=>"in", :to=>["+19195551234"], :from=>"+19195554321", :text=>"Hello world"}, :carrierName=>"Verizon"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + inbound_callback_equal = Bandwidth::InboundCallback.new({ + time: '2022-06-16T13:15:07.160Z', + type: Bandwidth::InboundCallbackTypeEnum::MESSAGE_RECEIVED, + to: '+19195551234', + description: 'baseline description', + message: { id: 'baseline' } + }) + expect(inbound_callback_default.eql?(inbound_callback_equal)).to be true + expect(inbound_callback_default.eql?(inbound_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(inbound_callback_values.to_body).to eq({ + time: '2022-06-16T13:15:07.160Z', + type: Bandwidth::InboundCallbackTypeEnum::MESSAGE_RECEIVED, + to: '+19195551234', + description: 'Incoming message received', + message: { + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 1, + direction: 'in', + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world' + }, + carrierName: 'Verizon' + }) + end + end + + describe 'custom attribute writers' do + it '#time=' do + expect { + inbound_callback_values.time = nil + }.to raise_error(ArgumentError, 'time cannot be nil') + end + + it '#type=' do + expect { + inbound_callback_values.type = nil + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#to=' do + expect { + inbound_callback_values.to = nil + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#description=' do + expect { + inbound_callback_values.description = nil + }.to raise_error(ArgumentError, 'description cannot be nil') + end + + it '#message=' do + expect { + inbound_callback_values.message = nil + }.to raise_error(ArgumentError, 'message cannot be nil') + end + end +end diff --git a/spec/unit/models/inbound_callback_type_enum_spec.rb b/spec/unit/models/inbound_callback_type_enum_spec.rb new file mode 100644 index 00000000..5cbeb78e --- /dev/null +++ b/spec/unit/models/inbound_callback_type_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::InboundCallbackTypeEnum +describe Bandwidth::InboundCallbackTypeEnum do + describe 'constants' do + it 'defines MESSAGE_RECEIVED' do + expect(Bandwidth::InboundCallbackTypeEnum::MESSAGE_RECEIVED).to eq('message-received') + end + + it 'defines REQUEST_LOCATION_RESPONSE' do + expect(Bandwidth::InboundCallbackTypeEnum::REQUEST_LOCATION_RESPONSE).to eq('request-location-response') + end + + it 'defines SUGGESTION_RESPONSE' do + expect(Bandwidth::InboundCallbackTypeEnum::SUGGESTION_RESPONSE).to eq('suggestion-response') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::InboundCallbackTypeEnum.all_vars).to eq([ + 'message-received', + 'request-location-response', + 'suggestion-response' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::InboundCallbackTypeEnum.build_from_hash('message-received')).to eq('message-received') + expect(Bandwidth::InboundCallbackTypeEnum.build_from_hash('request-location-response')).to eq('request-location-response') + expect(Bandwidth::InboundCallbackTypeEnum.build_from_hash('suggestion-response')).to eq('suggestion-response') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::InboundCallbackTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/initiate_callback_spec.rb b/spec/unit/models/initiate_callback_spec.rb new file mode 100644 index 00000000..5f5dd51d --- /dev/null +++ b/spec/unit/models/initiate_callback_spec.rb @@ -0,0 +1,114 @@ +# Unit tests for Bandwidth::InitiateCallback +describe Bandwidth::InitiateCallback do + let(:initiate_callback_default) { Bandwidth::InitiateCallback.new } + let(:initiate_callback_values) { Bandwidth::InitiateCallback.new({ + event_type: 'initiate', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + start_time: '2022-06-16T13:15:07.160Z', + diversion: { reason: 'unconditional', privacy: 'off' }, + stir_shaken: { verstat: 'TN-Validation-Passed', attestationIndicator: 'A', originatingId: '527c7d1f-22a4-4ec1-ad19-1a4ec9466cdb' }, + uui: 'aGVsbG8sIHdvcmxkIQ==;encoding=base64' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::InitiateCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::InitiateCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::InitiateCallback.acceptable_attributes).to eq(Bandwidth::InitiateCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::InitiateCallback.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of InitiateCallback created by the build_from_hash method' do + initiate_callback_from_hash = Bandwidth::InitiateCallback.build_from_hash({ + eventType: 'initiate', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + startTime: '2022-06-16T13:15:07.160Z', + diversion: { reason: 'unconditional', privacy: 'off' }, + stirShaken: { verstat: 'TN-Validation-Passed', attestationIndicator: 'A', originatingId: '527c7d1f-22a4-4ec1-ad19-1a4ec9466cdb' }, + uui: 'aGVsbG8sIHdvcmxkIQ==;encoding=base64' + }) + expect(initiate_callback_from_hash).to be_instance_of(Bandwidth::InitiateCallback) + expect(initiate_callback_from_hash.event_type).to eq('initiate') + expect(initiate_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(initiate_callback_from_hash.account_id).to eq('9900000') + expect(initiate_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(initiate_callback_from_hash.from).to eq('+19195554321') + expect(initiate_callback_from_hash.to).to eq('+19195551234') + expect(initiate_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(initiate_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(initiate_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(initiate_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(initiate_callback_from_hash.diversion).to be_instance_of(Bandwidth::Diversion) + expect(initiate_callback_from_hash.diversion.reason).to eq('unconditional') + expect(initiate_callback_from_hash.stir_shaken).to be_instance_of(Bandwidth::StirShaken) + expect(initiate_callback_from_hash.stir_shaken.verstat).to eq('TN-Validation-Passed') + expect(initiate_callback_from_hash.uui).to eq('aGVsbG8sIHdvcmxkIQ==;encoding=base64') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(initiate_callback_values.to_s).to eq('{:eventType=>"initiate", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"inbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :startTime=>"2022-06-16T13:15:07.160Z", :diversion=>{:reason=>"unconditional", :privacy=>"off"}, :stirShaken=>{:verstat=>"TN-Validation-Passed", :attestationIndicator=>"A", :originatingId=>"527c7d1f-22a4-4ec1-ad19-1a4ec9466cdb"}, :uui=>"aGVsbG8sIHdvcmxkIQ==;encoding=base64"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(initiate_callback_default.eql?(Bandwidth::InitiateCallback.new)).to be true + expect(initiate_callback_default.eql?(initiate_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(initiate_callback_values.to_body).to eq({ + eventType: 'initiate', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + startTime: '2022-06-16T13:15:07.160Z', + diversion: { reason: 'unconditional', privacy: 'off' }, + stirShaken: { verstat: 'TN-Validation-Passed', attestationIndicator: 'A', originatingId: '527c7d1f-22a4-4ec1-ad19-1a4ec9466cdb' }, + uui: 'aGVsbG8sIHdvcmxkIQ==;encoding=base64' + }) + end + end +end diff --git a/spec/unit/models/latest_message_delivery_status_enum_spec.rb b/spec/unit/models/latest_message_delivery_status_enum_spec.rb new file mode 100644 index 00000000..4a9b0483 --- /dev/null +++ b/spec/unit/models/latest_message_delivery_status_enum_spec.rb @@ -0,0 +1,46 @@ +# Unit tests for Bandwidth::LatestMessageDeliveryStatusEnum +describe Bandwidth::LatestMessageDeliveryStatusEnum do + describe 'constants' do + it 'defines ACTIVE' do + expect(Bandwidth::LatestMessageDeliveryStatusEnum::ACTIVE).to eq('ACTIVE') + end + + it 'defines DEACTIVATED' do + expect(Bandwidth::LatestMessageDeliveryStatusEnum::DEACTIVATED).to eq('DEACTIVATED') + end + + it 'defines UNKNOWN' do + expect(Bandwidth::LatestMessageDeliveryStatusEnum::UNKNOWN).to eq('UNKNOWN') + end + + it 'defines NOT_ENABLED' do + expect(Bandwidth::LatestMessageDeliveryStatusEnum::NOT_ENABLED).to eq('NOT_ENABLED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::LatestMessageDeliveryStatusEnum.all_vars).to eq([ + 'ACTIVE', + 'DEACTIVATED', + 'UNKNOWN', + 'NOT_ENABLED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::LatestMessageDeliveryStatusEnum.build_from_hash('ACTIVE')).to eq('ACTIVE') + expect(Bandwidth::LatestMessageDeliveryStatusEnum.build_from_hash('DEACTIVATED')).to eq('DEACTIVATED') + expect(Bandwidth::LatestMessageDeliveryStatusEnum.build_from_hash('UNKNOWN')).to eq('UNKNOWN') + expect(Bandwidth::LatestMessageDeliveryStatusEnum.build_from_hash('NOT_ENABLED')).to eq('NOT_ENABLED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::LatestMessageDeliveryStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/line_type_enum_spec.rb b/spec/unit/models/line_type_enum_spec.rb new file mode 100644 index 00000000..dcdef2d3 --- /dev/null +++ b/spec/unit/models/line_type_enum_spec.rb @@ -0,0 +1,46 @@ +# Unit tests for Bandwidth::LineTypeEnum +describe Bandwidth::LineTypeEnum do + describe 'constants' do + it 'defines FIXED' do + expect(Bandwidth::LineTypeEnum::FIXED).to eq('FIXED') + end + + it 'defines VOIP_FIXED' do + expect(Bandwidth::LineTypeEnum::VOIP_FIXED).to eq('VOIP-FIXED') + end + + it 'defines MOBILE' do + expect(Bandwidth::LineTypeEnum::MOBILE).to eq('MOBILE') + end + + it 'defines VOIP' do + expect(Bandwidth::LineTypeEnum::VOIP).to eq('VOIP') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::LineTypeEnum.all_vars).to eq([ + 'FIXED', + 'VOIP-FIXED', + 'MOBILE', + 'VOIP' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::LineTypeEnum.build_from_hash('FIXED')).to eq('FIXED') + expect(Bandwidth::LineTypeEnum.build_from_hash('VOIP-FIXED')).to eq('VOIP-FIXED') + expect(Bandwidth::LineTypeEnum.build_from_hash('MOBILE')).to eq('MOBILE') + expect(Bandwidth::LineTypeEnum.build_from_hash('VOIP')).to eq('VOIP') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::LineTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/link_schema_spec.rb b/spec/unit/models/link_schema_spec.rb new file mode 100644 index 00000000..aa6c8528 --- /dev/null +++ b/spec/unit/models/link_schema_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::LinkSchema +describe Bandwidth::LinkSchema do + let(:link_schema_default) { Bandwidth::LinkSchema.new } + let(:link_schema_values) { Bandwidth::LinkSchema.new({ + href: 'https://example.com', + rel: 'self', + method: 'GET' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::LinkSchema.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::LinkSchema.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::LinkSchema.acceptable_attributes).to eq(Bandwidth::LinkSchema.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::LinkSchema.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of LinkSchema created by the build_from_hash method' do + link_schema_from_hash = Bandwidth::LinkSchema.build_from_hash({ + href: 'https://example.com', + rel: 'self', + method: 'GET' + }) + expect(link_schema_from_hash).to be_instance_of(Bandwidth::LinkSchema) + expect(link_schema_from_hash.href).to eq('https://example.com') + expect(link_schema_from_hash.rel).to eq('self') + expect(link_schema_from_hash.method).to eq('GET') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(link_schema_values.to_s).to eq('{:href=>"https://example.com", :rel=>"self", :method=>"GET"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(link_schema_default.eql?(Bandwidth::LinkSchema.new)).to be true + expect(link_schema_default.eql?(link_schema_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(link_schema_values.to_body).to eq({ + href: 'https://example.com', + rel: 'self', + method: 'GET' + }) + end + end +end diff --git a/spec/unit/models/link_spec.rb b/spec/unit/models/link_spec.rb new file mode 100644 index 00000000..e051891b --- /dev/null +++ b/spec/unit/models/link_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::Link +describe Bandwidth::Link do + let(:link_default) { Bandwidth::Link.new } + let(:link_values) { Bandwidth::Link.new({ + rel: 'next', + href: 'https://example.com/page/2' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Link.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Link.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Link.acceptable_attributes).to eq(Bandwidth::Link.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Link.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Link created by the build_from_hash method' do + link_from_hash = Bandwidth::Link.build_from_hash({ + rel: 'next', + href: 'https://example.com/page/2' + }) + expect(link_from_hash).to be_instance_of(Bandwidth::Link) + expect(link_from_hash.rel).to eq('next') + expect(link_from_hash.href).to eq('https://example.com/page/2') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(link_values.to_s).to eq('{:rel=>"next", :href=>"https://example.com/page/2"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(link_default.eql?(Bandwidth::Link.new)).to be true + expect(link_default.eql?(link_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(link_values.to_body).to eq({ + rel: 'next', + href: 'https://example.com/page/2' + }) + end + end +end diff --git a/spec/unit/models/links_object_spec.rb b/spec/unit/models/links_object_spec.rb new file mode 100644 index 00000000..aeb52552 --- /dev/null +++ b/spec/unit/models/links_object_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::LinksObject +describe Bandwidth::LinksObject do + let(:links_object_default) { Bandwidth::LinksObject.new } + let(:links_object_values) { Bandwidth::LinksObject.new({ + first: 'https://example.com/page/1', + _next: 'https://example.com/page/2', + previous: 'https://example.com/page/0', + last: 'https://example.com/page/9' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::LinksObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::LinksObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::LinksObject.acceptable_attributes).to eq(Bandwidth::LinksObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::LinksObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of LinksObject created by the build_from_hash method' do + links_object_from_hash = Bandwidth::LinksObject.build_from_hash({ + first: 'https://example.com/page/1', + next: 'https://example.com/page/2', + previous: 'https://example.com/page/0', + last: 'https://example.com/page/9' + }) + expect(links_object_from_hash).to be_instance_of(Bandwidth::LinksObject) + expect(links_object_from_hash.first).to eq('https://example.com/page/1') + expect(links_object_from_hash._next).to eq('https://example.com/page/2') + expect(links_object_from_hash.previous).to eq('https://example.com/page/0') + expect(links_object_from_hash.last).to eq('https://example.com/page/9') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(links_object_values.to_s).to eq('{:first=>"https://example.com/page/1", :next=>"https://example.com/page/2", :previous=>"https://example.com/page/0", :last=>"https://example.com/page/9"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(links_object_default.eql?(Bandwidth::LinksObject.new)).to be true + expect(links_object_default.eql?(links_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(links_object_values.to_body).to eq({ + first: 'https://example.com/page/1', + next: 'https://example.com/page/2', + previous: 'https://example.com/page/0', + last: 'https://example.com/page/9' + }) + end + end +end diff --git a/spec/unit/models/list_endpoints_response_spec.rb b/spec/unit/models/list_endpoints_response_spec.rb new file mode 100644 index 00000000..da468f7d --- /dev/null +++ b/spec/unit/models/list_endpoints_response_spec.rb @@ -0,0 +1,113 @@ +# Unit tests for Bandwidth::ListEndpointsResponse +describe Bandwidth::ListEndpointsResponse do + let(:page) { Bandwidth::Page.new({ page_size: 25, total_elements: 100, total_pages: 4, page_number: 1 }) } + let(:endpoint) { Bandwidth::Endpoints.new({ + endpoint_id: 'abc123', + type: 'WEBRTC', + status: 'CONNECTED', + creation_timestamp: '2024-01-01T00:00:00Z', + expiration_timestamp: '2024-01-02T00:00:00Z' + }) } + let(:list_endpoints_response_default) { Bandwidth::ListEndpointsResponse.new({ + links: [], + data: [], + errors: [] + }) } + let(:list_endpoints_response_values) { Bandwidth::ListEndpointsResponse.new({ + links: [Bandwidth::BrtcLink.new({ href: 'https://example.com', rel: 'self', method: 'GET' })], + page: page, + data: [endpoint], + errors: [Bandwidth::BrtcError.new({ type: 'validation', description: 'bad input' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ListEndpointsResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ListEndpointsResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ListEndpointsResponse.acceptable_attributes).to eq(Bandwidth::ListEndpointsResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::ListEndpointsResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ListEndpointsResponse created by the build_from_hash method' do + list_endpoints_response_from_hash = Bandwidth::ListEndpointsResponse.build_from_hash({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + page: { pageSize: 25, totalElements: 100, totalPages: 4, pageNumber: 1 }, + data: [{ endpointId: 'abc123', type: 'WEBRTC', status: 'CONNECTED', creationTimestamp: '2024-01-01T00:00:00Z', expirationTimestamp: '2024-01-02T00:00:00Z' }], + errors: [{ type: 'validation', description: 'bad input' }] + }) + expect(list_endpoints_response_from_hash).to be_instance_of(Bandwidth::ListEndpointsResponse) + expect(list_endpoints_response_from_hash.links.first).to be_instance_of(Bandwidth::BrtcLink) + expect(list_endpoints_response_from_hash.page).to be_instance_of(Bandwidth::Page) + expect(list_endpoints_response_from_hash.data.first).to be_instance_of(Bandwidth::Endpoints) + expect(list_endpoints_response_from_hash.errors.first).to be_instance_of(Bandwidth::BrtcError) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(list_endpoints_response_values.to_s).to eq('{:links=>[{:href=>"https://example.com", :rel=>"self", :method=>"GET"}], :page=>{:pageSize=>25, :totalElements=>100, :totalPages=>4, :pageNumber=>1}, :data=>[{:endpointId=>"abc123", :type=>"WEBRTC", :status=>"CONNECTED", :creationTimestamp=>"2024-01-01T00:00:00Z", :expirationTimestamp=>"2024-01-02T00:00:00Z"}], :errors=>[{:type=>"validation", :description=>"bad input"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + list_endpoints_response_equal = Bandwidth::ListEndpointsResponse.new({ + links: [], + data: [], + errors: [] + }) + expect(list_endpoints_response_default.eql?(list_endpoints_response_equal)).to be true + expect(list_endpoints_response_default.eql?(list_endpoints_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(list_endpoints_response_values.to_body).to eq({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + page: { pageSize: 25, totalElements: 100, totalPages: 4, pageNumber: 1 }, + data: [{ endpointId: 'abc123', type: 'WEBRTC', status: 'CONNECTED', creationTimestamp: '2024-01-01T00:00:00Z', expirationTimestamp: '2024-01-02T00:00:00Z' }], + errors: [{ type: 'validation', description: 'bad input' }] + }) + end + end + + describe 'custom attribute writers' do + it '#links=' do + expect { + list_endpoints_response_values.links = nil + }.to raise_error(ArgumentError, 'links cannot be nil') + end + + it '#data=' do + expect { + list_endpoints_response_values.data = nil + }.to raise_error(ArgumentError, 'data cannot be nil') + end + + it '#errors=' do + expect { + list_endpoints_response_values.errors = nil + }.to raise_error(ArgumentError, 'errors cannot be nil') + end + end +end diff --git a/spec/unit/models/list_message_direction_enum_spec.rb b/spec/unit/models/list_message_direction_enum_spec.rb new file mode 100644 index 00000000..e3264bbb --- /dev/null +++ b/spec/unit/models/list_message_direction_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::ListMessageDirectionEnum +describe Bandwidth::ListMessageDirectionEnum do + describe 'constants' do + it 'defines INBOUND' do + expect(Bandwidth::ListMessageDirectionEnum::INBOUND).to eq('INBOUND') + end + + it 'defines OUTBOUND' do + expect(Bandwidth::ListMessageDirectionEnum::OUTBOUND).to eq('OUTBOUND') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::ListMessageDirectionEnum.all_vars).to eq([ + 'INBOUND', + 'OUTBOUND' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::ListMessageDirectionEnum.build_from_hash('INBOUND')).to eq('INBOUND') + expect(Bandwidth::ListMessageDirectionEnum.build_from_hash('OUTBOUND')).to eq('OUTBOUND') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::ListMessageDirectionEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/list_message_item_spec.rb b/spec/unit/models/list_message_item_spec.rb new file mode 100644 index 00000000..ad55d2a1 --- /dev/null +++ b/spec/unit/models/list_message_item_spec.rb @@ -0,0 +1,165 @@ +# Unit tests for Bandwidth::ListMessageItem +describe Bandwidth::ListMessageItem do + let(:list_message_item_default) { Bandwidth::ListMessageItem.new } + let(:list_message_item_values) { Bandwidth::ListMessageItem.new({ + message_id: '1589228074636lm4k2je7j7jklbn2', + account_id: '9900000', + source_tn: '+19195554321', + destination_tn: '+19195551234', + message_status: Bandwidth::MessageStatusEnum::DELIVERED, + message_direction: Bandwidth::ListMessageDirectionEnum::OUTBOUND, + message_type: Bandwidth::MessageTypeEnum::SMS, + segment_count: 1, + error_code: 0, + receive_time: '2022-06-16T13:15:07.160Z', + carrier_name: 'verizon', + message_size: 27, + message_length: 18, + attachment_count: 0, + recipient_count: 1, + campaign_class: 'T', + campaign_id: 'CABC123', + bw_latency: 1, + carrier_latency: 2, + calling_number_country_a3: 'USA', + called_number_country_a3: 'USA', + product: 'MESSAGING-V2', + location: 'loc-1' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ListMessageItem.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ListMessageItem.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::ListMessageItem.acceptable_attributes).to eq(Bandwidth::ListMessageItem.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ListMessageItem.openapi_nullable).to eq(Set.new([ + :'carrier_name', + :'message_size', + :'attachment_count', + :'recipient_count', + :'campaign_class', + :'campaign_id', + :'bw_latency', + :'carrier_latency', + :'calling_number_country_a3', + :'called_number_country_a3', + :'product', + :'location' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ListMessageItem created by the build_from_hash method' do + list_message_item_from_hash = Bandwidth::ListMessageItem.build_from_hash({ + messageId: '1589228074636lm4k2je7j7jklbn2', + accountId: '9900000', + sourceTn: '+19195554321', + destinationTn: '+19195551234', + messageStatus: 'DELIVERED', + messageDirection: 'OUTBOUND', + messageType: 'sms', + segmentCount: 1, + errorCode: 0, + receiveTime: '2022-06-16T13:15:07.160Z', + carrierName: 'verizon', + messageSize: 27, + messageLength: 18, + attachmentCount: 0, + recipientCount: 1, + campaignClass: 'T', + campaignId: 'CABC123', + bwLatency: 1, + carrierLatency: 2, + callingNumberCountryA3: 'USA', + calledNumberCountryA3: 'USA', + product: 'MESSAGING-V2', + location: 'loc-1' + }) + expect(list_message_item_from_hash).to be_instance_of(Bandwidth::ListMessageItem) + expect(list_message_item_from_hash.message_id).to eq('1589228074636lm4k2je7j7jklbn2') + expect(list_message_item_from_hash.account_id).to eq('9900000') + expect(list_message_item_from_hash.source_tn).to eq('+19195554321') + expect(list_message_item_from_hash.destination_tn).to eq('+19195551234') + expect(list_message_item_from_hash.message_status).to eq('DELIVERED') + expect(list_message_item_from_hash.message_direction).to eq('OUTBOUND') + expect(list_message_item_from_hash.message_type).to eq('sms') + expect(list_message_item_from_hash.segment_count).to eq(1) + expect(list_message_item_from_hash.error_code).to eq(0) + expect(list_message_item_from_hash.receive_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(list_message_item_from_hash.carrier_name).to eq('verizon') + expect(list_message_item_from_hash.message_size).to eq(27) + expect(list_message_item_from_hash.message_length).to eq(18) + expect(list_message_item_from_hash.attachment_count).to eq(0) + expect(list_message_item_from_hash.recipient_count).to eq(1) + expect(list_message_item_from_hash.campaign_class).to eq('T') + expect(list_message_item_from_hash.campaign_id).to eq('CABC123') + expect(list_message_item_from_hash.bw_latency).to eq(1) + expect(list_message_item_from_hash.carrier_latency).to eq(2) + expect(list_message_item_from_hash.calling_number_country_a3).to eq('USA') + expect(list_message_item_from_hash.called_number_country_a3).to eq('USA') + expect(list_message_item_from_hash.product).to eq('MESSAGING-V2') + expect(list_message_item_from_hash.location).to eq('loc-1') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(list_message_item_values.to_s).to eq('{:messageId=>"1589228074636lm4k2je7j7jklbn2", :accountId=>"9900000", :sourceTn=>"+19195554321", :destinationTn=>"+19195551234", :messageStatus=>"DELIVERED", :messageDirection=>"OUTBOUND", :messageType=>"sms", :segmentCount=>1, :errorCode=>0, :receiveTime=>"2022-06-16T13:15:07.160Z", :carrierName=>"verizon", :messageSize=>27, :messageLength=>18, :attachmentCount=>0, :recipientCount=>1, :campaignClass=>"T", :campaignId=>"CABC123", :bwLatency=>1, :carrierLatency=>2, :callingNumberCountryA3=>"USA", :calledNumberCountryA3=>"USA", :product=>"MESSAGING-V2", :location=>"loc-1"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(list_message_item_default.eql?(Bandwidth::ListMessageItem.new)).to be true + expect(list_message_item_default.eql?(list_message_item_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(list_message_item_values.to_body).to eq({ + messageId: '1589228074636lm4k2je7j7jklbn2', + accountId: '9900000', + sourceTn: '+19195554321', + destinationTn: '+19195551234', + messageStatus: Bandwidth::MessageStatusEnum::DELIVERED, + messageDirection: Bandwidth::ListMessageDirectionEnum::OUTBOUND, + messageType: Bandwidth::MessageTypeEnum::SMS, + segmentCount: 1, + errorCode: 0, + receiveTime: '2022-06-16T13:15:07.160Z', + carrierName: 'verizon', + messageSize: 27, + messageLength: 18, + attachmentCount: 0, + recipientCount: 1, + campaignClass: 'T', + campaignId: 'CABC123', + bwLatency: 1, + carrierLatency: 2, + callingNumberCountryA3: 'USA', + calledNumberCountryA3: 'USA', + product: 'MESSAGING-V2', + location: 'loc-1' + }) + end + end +end diff --git a/spec/unit/models/lookup_error_response_spec.rb b/spec/unit/models/lookup_error_response_spec.rb new file mode 100644 index 00000000..df8ab780 --- /dev/null +++ b/spec/unit/models/lookup_error_response_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::LookupErrorResponse +describe Bandwidth::LookupErrorResponse do + let(:lookup_error_response_default) { Bandwidth::LookupErrorResponse.new } + let(:lookup_error_response_values) { Bandwidth::LookupErrorResponse.new({ + links: [Bandwidth::LinkSchema.new({ href: 'https://example.com', rel: 'self', method: 'GET' })], + data: { foo: 'bar' }, + errors: [Bandwidth::LookupErrorSchema.new({ code: '400', description: 'bad request', type: 'validation' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::LookupErrorResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::LookupErrorResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::LookupErrorResponse.acceptable_attributes).to eq(Bandwidth::LookupErrorResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::LookupErrorResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of LookupErrorResponse created by the build_from_hash method' do + lookup_error_response_from_hash = Bandwidth::LookupErrorResponse.build_from_hash({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { foo: 'bar' }, + errors: [{ code: '400', description: 'bad request', type: 'validation' }] + }) + expect(lookup_error_response_from_hash).to be_instance_of(Bandwidth::LookupErrorResponse) + expect(lookup_error_response_from_hash.links.first).to be_instance_of(Bandwidth::LinkSchema) + expect(lookup_error_response_from_hash.data).to eq({ foo: 'bar' }) + expect(lookup_error_response_from_hash.errors.first).to be_instance_of(Bandwidth::LookupErrorSchema) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(lookup_error_response_values.to_s).to eq('{:links=>[{:href=>"https://example.com", :rel=>"self", :method=>"GET"}], :data=>{:foo=>"bar"}, :errors=>[{:code=>"400", :description=>"bad request", :type=>"validation"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(lookup_error_response_default.eql?(Bandwidth::LookupErrorResponse.new)).to be true + expect(lookup_error_response_default.eql?(lookup_error_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(lookup_error_response_values.to_body).to eq({ + links: [{ href: 'https://example.com', rel: 'self', method: 'GET' }], + data: { foo: 'bar' }, + errors: [{ code: '400', description: 'bad request', type: 'validation' }] + }) + end + end +end diff --git a/spec/unit/models/lookup_error_schema_meta_spec.rb b/spec/unit/models/lookup_error_schema_meta_spec.rb new file mode 100644 index 00000000..39e531dc --- /dev/null +++ b/spec/unit/models/lookup_error_schema_meta_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::LookupErrorSchemaMeta +describe Bandwidth::LookupErrorSchemaMeta do + let(:lookup_error_schema_meta_default) { Bandwidth::LookupErrorSchemaMeta.new } + let(:lookup_error_schema_meta_values) { Bandwidth::LookupErrorSchemaMeta.new({ + phone_numbers: ['+19195551234'], + message: 'invalid phone number', + code: 400 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::LookupErrorSchemaMeta.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::LookupErrorSchemaMeta.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::LookupErrorSchemaMeta.acceptable_attributes).to eq(Bandwidth::LookupErrorSchemaMeta.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::LookupErrorSchemaMeta.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of LookupErrorSchemaMeta created by the build_from_hash method' do + lookup_error_schema_meta_from_hash = Bandwidth::LookupErrorSchemaMeta.build_from_hash({ + phoneNumbers: ['+19195551234'], + message: 'invalid phone number', + code: 400 + }) + expect(lookup_error_schema_meta_from_hash).to be_instance_of(Bandwidth::LookupErrorSchemaMeta) + expect(lookup_error_schema_meta_from_hash.phone_numbers).to eq(['+19195551234']) + expect(lookup_error_schema_meta_from_hash.message).to eq('invalid phone number') + expect(lookup_error_schema_meta_from_hash.code).to eq(400) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(lookup_error_schema_meta_values.to_s).to eq('{:phoneNumbers=>["+19195551234"], :message=>"invalid phone number", :code=>400}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(lookup_error_schema_meta_default.eql?(Bandwidth::LookupErrorSchemaMeta.new)).to be true + expect(lookup_error_schema_meta_default.eql?(lookup_error_schema_meta_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(lookup_error_schema_meta_values.to_body).to eq({ + phoneNumbers: ['+19195551234'], + message: 'invalid phone number', + code: 400 + }) + end + end +end diff --git a/spec/unit/models/lookup_error_schema_spec.rb b/spec/unit/models/lookup_error_schema_spec.rb new file mode 100644 index 00000000..6a965c7a --- /dev/null +++ b/spec/unit/models/lookup_error_schema_spec.rb @@ -0,0 +1,105 @@ +# Unit tests for Bandwidth::LookupErrorSchema +describe Bandwidth::LookupErrorSchema do + let(:lookup_error_schema_default) { Bandwidth::LookupErrorSchema.new({ + code: '400', + description: 'baseline description', + type: 'baseline' + }) } + let(:lookup_error_schema_values) { Bandwidth::LookupErrorSchema.new({ + code: '404', + description: 'not found', + type: 'validation', + meta: Bandwidth::LookupErrorSchemaMeta.new({ phone_numbers: ['+19195551234'], message: 'invalid', code: 404 }) + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::LookupErrorSchema.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::LookupErrorSchema.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::LookupErrorSchema.acceptable_attributes).to eq(Bandwidth::LookupErrorSchema.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::LookupErrorSchema.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of LookupErrorSchema created by the build_from_hash method' do + lookup_error_schema_from_hash = Bandwidth::LookupErrorSchema.build_from_hash({ + code: '404', + description: 'not found', + type: 'validation', + meta: { phoneNumbers: ['+19195551234'], message: 'invalid', code: 404 } + }) + expect(lookup_error_schema_from_hash).to be_instance_of(Bandwidth::LookupErrorSchema) + expect(lookup_error_schema_from_hash.code).to eq('404') + expect(lookup_error_schema_from_hash.description).to eq('not found') + expect(lookup_error_schema_from_hash.type).to eq('validation') + expect(lookup_error_schema_from_hash.meta).to be_instance_of(Bandwidth::LookupErrorSchemaMeta) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(lookup_error_schema_values.to_s).to eq('{:code=>"404", :description=>"not found", :type=>"validation", :meta=>{:phoneNumbers=>["+19195551234"], :message=>"invalid", :code=>404}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + lookup_error_schema_equal = Bandwidth::LookupErrorSchema.new({ + code: '400', + description: 'baseline description', + type: 'baseline' + }) + expect(lookup_error_schema_default.eql?(lookup_error_schema_equal)).to be true + expect(lookup_error_schema_default.eql?(lookup_error_schema_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(lookup_error_schema_values.to_body).to eq({ + code: '404', + description: 'not found', + type: 'validation', + meta: { phoneNumbers: ['+19195551234'], message: 'invalid', code: 404 } + }) + end + end + + describe 'custom attribute writers' do + it '#code=' do + expect { + Bandwidth::LookupErrorSchema.new({ code: nil }) + }.to raise_error(ArgumentError, 'code cannot be nil') + end + + it '#description=' do + expect { + Bandwidth::LookupErrorSchema.new({ code: '400', description: nil }) + }.to raise_error(ArgumentError, 'description cannot be nil') + end + + it '#type=' do + expect { + Bandwidth::LookupErrorSchema.new({ code: '400', description: 'a', type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + end +end diff --git a/spec/unit/models/lookup_result_spec.rb b/spec/unit/models/lookup_result_spec.rb new file mode 100644 index 00000000..6054108e --- /dev/null +++ b/spec/unit/models/lookup_result_spec.rb @@ -0,0 +1,108 @@ +# Unit tests for Bandwidth::LookupResult +describe Bandwidth::LookupResult do + let(:lookup_result_default) { Bandwidth::LookupResult.new } + let(:lookup_result_values) { Bandwidth::LookupResult.new({ + phone_number: '+19195551234', + line_type: Bandwidth::LineTypeEnum::MOBILE, + messaging_provider: 'Bandwidth', + voice_provider: 'Bandwidth', + country_code_a3: 'USA', + deactivation_reporter: 'verizon', + deactivation_date: '2024-01-01', + deactivation_event: Bandwidth::DeactivationEventEnum::DEACTIVATED, + latest_message_delivery_status: Bandwidth::LatestMessageDeliveryStatusEnum::ACTIVE, + initial_message_delivery_status_date: '2024-01-01', + latest_message_delivery_status_date: '2024-01-02', + rcs_enabled: true + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::LookupResult.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::LookupResult.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::LookupResult.acceptable_attributes).to eq(Bandwidth::LookupResult.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::LookupResult.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of LookupResult created by the build_from_hash method' do + lookup_result_from_hash = Bandwidth::LookupResult.build_from_hash({ + phoneNumber: '+19195551234', + lineType: 'MOBILE', + messagingProvider: 'Bandwidth', + voiceProvider: 'Bandwidth', + countryCodeA3: 'USA', + deactivationReporter: 'verizon', + deactivationDate: '2024-01-01', + deactivationEvent: 'DEACTIVATED', + latestMessageDeliveryStatus: 'ACTIVE', + initialMessageDeliveryStatusDate: '2024-01-01', + latestMessageDeliveryStatusDate: '2024-01-02', + rcsEnabled: true + }) + expect(lookup_result_from_hash).to be_instance_of(Bandwidth::LookupResult) + expect(lookup_result_from_hash.phone_number).to eq('+19195551234') + expect(lookup_result_from_hash.line_type).to eq('MOBILE') + expect(lookup_result_from_hash.messaging_provider).to eq('Bandwidth') + expect(lookup_result_from_hash.voice_provider).to eq('Bandwidth') + expect(lookup_result_from_hash.country_code_a3).to eq('USA') + expect(lookup_result_from_hash.deactivation_reporter).to eq('verizon') + expect(lookup_result_from_hash.deactivation_date).to eq('2024-01-01') + expect(lookup_result_from_hash.deactivation_event).to eq('DEACTIVATED') + expect(lookup_result_from_hash.latest_message_delivery_status).to eq('ACTIVE') + expect(lookup_result_from_hash.initial_message_delivery_status_date).to eq(Date.parse('2024-01-01')) + expect(lookup_result_from_hash.latest_message_delivery_status_date).to eq(Date.parse('2024-01-02')) + expect(lookup_result_from_hash.rcs_enabled).to eq(true) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(lookup_result_values.to_s).to eq('{:phoneNumber=>"+19195551234", :lineType=>"MOBILE", :messagingProvider=>"Bandwidth", :voiceProvider=>"Bandwidth", :countryCodeA3=>"USA", :deactivationReporter=>"verizon", :deactivationDate=>"2024-01-01", :deactivationEvent=>"DEACTIVATED", :latestMessageDeliveryStatus=>"ACTIVE", :initialMessageDeliveryStatusDate=>"2024-01-01", :latestMessageDeliveryStatusDate=>"2024-01-02", :rcsEnabled=>true}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(lookup_result_default.eql?(Bandwidth::LookupResult.new)).to be true + expect(lookup_result_default.eql?(lookup_result_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(lookup_result_values.to_body).to eq({ + phoneNumber: '+19195551234', + lineType: Bandwidth::LineTypeEnum::MOBILE, + messagingProvider: 'Bandwidth', + voiceProvider: 'Bandwidth', + countryCodeA3: 'USA', + deactivationReporter: 'verizon', + deactivationDate: '2024-01-01', + deactivationEvent: Bandwidth::DeactivationEventEnum::DEACTIVATED, + latestMessageDeliveryStatus: Bandwidth::LatestMessageDeliveryStatusEnum::ACTIVE, + initialMessageDeliveryStatusDate: '2024-01-01', + latestMessageDeliveryStatusDate: '2024-01-02', + rcsEnabled: true + }) + end + end +end diff --git a/spec/unit/models/machine_detection_complete_callback_spec.rb b/spec/unit/models/machine_detection_complete_callback_spec.rb new file mode 100644 index 00000000..492bb199 --- /dev/null +++ b/spec/unit/models/machine_detection_complete_callback_spec.rb @@ -0,0 +1,123 @@ +# Unit tests for Bandwidth::MachineDetectionCompleteCallback +describe Bandwidth::MachineDetectionCompleteCallback do + let(:machine_detection_complete_callback_default) { Bandwidth::MachineDetectionCompleteCallback.new } + let(:machine_detection_complete_callback_values) { Bandwidth::MachineDetectionCompleteCallback.new({ + event_type: 'machineDetectionComplete', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + machine_detection_result: { value: 'human', duration: 'PT5S' } + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MachineDetectionCompleteCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MachineDetectionCompleteCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MachineDetectionCompleteCallback.acceptable_attributes).to eq(Bandwidth::MachineDetectionCompleteCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::MachineDetectionCompleteCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag', + :'machine_detection_result' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MachineDetectionCompleteCallback created by the build_from_hash method' do + machine_detection_complete_callback_from_hash = Bandwidth::MachineDetectionCompleteCallback.build_from_hash({ + eventType: 'machineDetectionComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + machineDetectionResult: { value: 'human', duration: 'PT5S' } + }) + expect(machine_detection_complete_callback_from_hash).to be_instance_of(Bandwidth::MachineDetectionCompleteCallback) + expect(machine_detection_complete_callback_from_hash.event_type).to eq('machineDetectionComplete') + expect(machine_detection_complete_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(machine_detection_complete_callback_from_hash.account_id).to eq('9900000') + expect(machine_detection_complete_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(machine_detection_complete_callback_from_hash.from).to eq('+19195554321') + expect(machine_detection_complete_callback_from_hash.to).to eq('+19195551234') + expect(machine_detection_complete_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::OUTBOUND) + expect(machine_detection_complete_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(machine_detection_complete_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(machine_detection_complete_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(machine_detection_complete_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(machine_detection_complete_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(machine_detection_complete_callback_from_hash.tag).to eq('custom tag') + expect(machine_detection_complete_callback_from_hash.machine_detection_result).to be_instance_of(Bandwidth::MachineDetectionResult) + expect(machine_detection_complete_callback_from_hash.machine_detection_result.value).to eq('human') + expect(machine_detection_complete_callback_from_hash.machine_detection_result.duration).to eq('PT5S') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(machine_detection_complete_callback_values.to_s).to eq('{:eventType=>"machineDetectionComplete", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"outbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag", :machineDetectionResult=>{:value=>"human", :duration=>"PT5S"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(machine_detection_complete_callback_default.eql?(Bandwidth::MachineDetectionCompleteCallback.new)).to be true + expect(machine_detection_complete_callback_default.eql?(machine_detection_complete_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(machine_detection_complete_callback_values.to_body).to eq({ + eventType: 'machineDetectionComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + machineDetectionResult: { value: 'human', duration: 'PT5S' } + }) + end + end +end diff --git a/spec/unit/models/machine_detection_configuration_spec.rb b/spec/unit/models/machine_detection_configuration_spec.rb new file mode 100644 index 00000000..a7c302f8 --- /dev/null +++ b/spec/unit/models/machine_detection_configuration_spec.rb @@ -0,0 +1,173 @@ +# Unit tests for Bandwidth::MachineDetectionConfiguration +describe Bandwidth::MachineDetectionConfiguration do + let(:machine_detection_configuration_default) { Bandwidth::MachineDetectionConfiguration.new } + let(:machine_detection_configuration_values) { Bandwidth::MachineDetectionConfiguration.new({ + mode: Bandwidth::MachineDetectionModeEnum::SYNC, + detection_timeout: 20, + silence_timeout: 12, + speech_threshold: 8, + speech_end_threshold: 4, + machine_speech_end_threshold: 7, + delay_result: true, + callback_url: 'https://example.com/callback', + callback_method: Bandwidth::CallbackMethodEnum::GET, + username: 'user', + password: 'pass', + fallback_url: 'https://example.com/fallback', + fallback_method: Bandwidth::CallbackMethodEnum::GET, + fallback_username: 'fallback-user', + fallback_password: 'fallback-pass' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MachineDetectionConfiguration.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MachineDetectionConfiguration.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MachineDetectionConfiguration.acceptable_attributes).to eq(Bandwidth::MachineDetectionConfiguration.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::MachineDetectionConfiguration.openapi_nullable).to eq(Set.new([ + :'detection_timeout', + :'silence_timeout', + :'speech_threshold', + :'speech_end_threshold', + :'machine_speech_end_threshold', + :'delay_result', + :'callback_url', + :'callback_method', + :'username', + :'password', + :'fallback_url', + :'fallback_method', + :'fallback_username', + :'fallback_password' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MachineDetectionConfiguration created by the build_from_hash method' do + machine_detection_configuration_from_hash = Bandwidth::MachineDetectionConfiguration.build_from_hash({ + mode: 'sync', + detectionTimeout: 20, + silenceTimeout: 12, + speechThreshold: 8, + speechEndThreshold: 4, + machineSpeechEndThreshold: 7, + delayResult: true, + callbackUrl: 'https://example.com/callback', + callbackMethod: 'GET', + username: 'user', + password: 'pass', + fallbackUrl: 'https://example.com/fallback', + fallbackMethod: 'GET', + fallbackUsername: 'fallback-user', + fallbackPassword: 'fallback-pass' + }) + expect(machine_detection_configuration_from_hash).to be_instance_of(Bandwidth::MachineDetectionConfiguration) + expect(machine_detection_configuration_from_hash.mode).to eq('sync') + expect(machine_detection_configuration_from_hash.detection_timeout).to eq(20.0) + expect(machine_detection_configuration_from_hash.silence_timeout).to eq(12.0) + expect(machine_detection_configuration_from_hash.speech_threshold).to eq(8.0) + expect(machine_detection_configuration_from_hash.speech_end_threshold).to eq(4.0) + expect(machine_detection_configuration_from_hash.machine_speech_end_threshold).to eq(7.0) + expect(machine_detection_configuration_from_hash.delay_result).to eq(true) + expect(machine_detection_configuration_from_hash.callback_url).to eq('https://example.com/callback') + expect(machine_detection_configuration_from_hash.callback_method).to eq('GET') + expect(machine_detection_configuration_from_hash.username).to eq('user') + expect(machine_detection_configuration_from_hash.password).to eq('pass') + expect(machine_detection_configuration_from_hash.fallback_url).to eq('https://example.com/fallback') + expect(machine_detection_configuration_from_hash.fallback_method).to eq('GET') + expect(machine_detection_configuration_from_hash.fallback_username).to eq('fallback-user') + expect(machine_detection_configuration_from_hash.fallback_password).to eq('fallback-pass') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(machine_detection_configuration_values.to_s).to eq('{:mode=>"sync", :detectionTimeout=>20, :silenceTimeout=>12, :speechThreshold=>8, :speechEndThreshold=>4, :machineSpeechEndThreshold=>7, :delayResult=>true, :callbackUrl=>"https://example.com/callback", :callbackMethod=>"GET", :username=>"user", :password=>"pass", :fallbackUrl=>"https://example.com/fallback", :fallbackMethod=>"GET", :fallbackUsername=>"fallback-user", :fallbackPassword=>"fallback-pass"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(machine_detection_configuration_default.eql?(Bandwidth::MachineDetectionConfiguration.new)).to be true + expect(machine_detection_configuration_default.eql?(machine_detection_configuration_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(machine_detection_configuration_values.to_body).to eq({ + mode: Bandwidth::MachineDetectionModeEnum::SYNC, + detectionTimeout: 20, + silenceTimeout: 12, + speechThreshold: 8, + speechEndThreshold: 4, + machineSpeechEndThreshold: 7, + delayResult: true, + callbackUrl: 'https://example.com/callback', + callbackMethod: Bandwidth::CallbackMethodEnum::GET, + username: 'user', + password: 'pass', + fallbackUrl: 'https://example.com/fallback', + fallbackMethod: Bandwidth::CallbackMethodEnum::GET, + fallbackUsername: 'fallback-user', + fallbackPassword: 'fallback-pass' + }) + end + end + + describe 'custom attribute writers' do + it '#callback_url=' do + expect { + Bandwidth::MachineDetectionConfiguration.new({ callback_url: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "callback_url", the character length must be smaller than or equal to 2048.') + end + + it '#username=' do + expect { + Bandwidth::MachineDetectionConfiguration.new({ username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "username", the character length must be smaller than or equal to 1024.') + end + + it '#password=' do + expect { + Bandwidth::MachineDetectionConfiguration.new({ password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "password", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_url=' do + expect { + Bandwidth::MachineDetectionConfiguration.new({ fallback_url: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_url", the character length must be smaller than or equal to 2048.') + end + + it '#fallback_username=' do + expect { + Bandwidth::MachineDetectionConfiguration.new({ fallback_username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_username", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_password=' do + expect { + Bandwidth::MachineDetectionConfiguration.new({ fallback_password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_password", the character length must be smaller than or equal to 1024.') + end + end +end diff --git a/spec/unit/models/machine_detection_mode_enum_spec.rb b/spec/unit/models/machine_detection_mode_enum_spec.rb new file mode 100644 index 00000000..9b24a8cc --- /dev/null +++ b/spec/unit/models/machine_detection_mode_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::MachineDetectionModeEnum +describe Bandwidth::MachineDetectionModeEnum do + describe 'constants' do + it 'defines SYNC' do + expect(Bandwidth::MachineDetectionModeEnum::SYNC).to eq('sync') + end + + it 'defines ASYNC' do + expect(Bandwidth::MachineDetectionModeEnum::ASYNC).to eq('async') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::MachineDetectionModeEnum.all_vars).to eq([ + 'sync', + 'async' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::MachineDetectionModeEnum.build_from_hash('sync')).to eq('sync') + expect(Bandwidth::MachineDetectionModeEnum.build_from_hash('async')).to eq('async') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::MachineDetectionModeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/machine_detection_result_spec.rb b/spec/unit/models/machine_detection_result_spec.rb new file mode 100644 index 00000000..91dd7017 --- /dev/null +++ b/spec/unit/models/machine_detection_result_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::MachineDetectionResult +describe Bandwidth::MachineDetectionResult do + let(:machine_detection_result_default) { Bandwidth::MachineDetectionResult.new } + let(:machine_detection_result_values) { Bandwidth::MachineDetectionResult.new({ + value: 'human', + duration: 'PT5S' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MachineDetectionResult.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MachineDetectionResult.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MachineDetectionResult.acceptable_attributes).to eq(Bandwidth::MachineDetectionResult.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MachineDetectionResult.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MachineDetectionResult created by the build_from_hash method' do + machine_detection_result_from_hash = Bandwidth::MachineDetectionResult.build_from_hash({ + value: 'human', + duration: 'PT5S' + }) + expect(machine_detection_result_from_hash).to be_instance_of(Bandwidth::MachineDetectionResult) + expect(machine_detection_result_from_hash.value).to eq('human') + expect(machine_detection_result_from_hash.duration).to eq('PT5S') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(machine_detection_result_values.to_s).to eq('{:value=>"human", :duration=>"PT5S"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(machine_detection_result_default.eql?(Bandwidth::MachineDetectionResult.new)).to be true + expect(machine_detection_result_default.eql?(machine_detection_result_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(machine_detection_result_values.to_body).to eq({ + value: 'human', + duration: 'PT5S' + }) + end + end +end diff --git a/spec/unit/models/media_spec.rb b/spec/unit/models/media_spec.rb new file mode 100644 index 00000000..21785d74 --- /dev/null +++ b/spec/unit/models/media_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::Media +describe Bandwidth::Media do + let(:media_default) { Bandwidth::Media.new } + let(:media_values) { Bandwidth::Media.new({ + content: 'https://example.com/media/1.jpg', + content_length: 12345, + media_name: 'image.jpg' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Media.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Media.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Media.acceptable_attributes).to eq(Bandwidth::Media.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Media.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Media created by the build_from_hash method' do + media_from_hash = Bandwidth::Media.build_from_hash({ + content: 'https://example.com/media/1.jpg', + contentLength: 12345, + mediaName: 'image.jpg' + }) + expect(media_from_hash).to be_instance_of(Bandwidth::Media) + expect(media_from_hash.content).to eq('https://example.com/media/1.jpg') + expect(media_from_hash.content_length).to eq(12345) + expect(media_from_hash.media_name).to eq('image.jpg') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(media_values.to_s).to eq('{:content=>"https://example.com/media/1.jpg", :contentLength=>12345, :mediaName=>"image.jpg"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(media_default.eql?(Bandwidth::Media.new)).to be true + expect(media_default.eql?(media_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(media_values.to_body).to eq({ + content: 'https://example.com/media/1.jpg', + contentLength: 12345, + mediaName: 'image.jpg' + }) + end + end +end diff --git a/spec/unit/models/message_direction_enum_spec.rb b/spec/unit/models/message_direction_enum_spec.rb new file mode 100644 index 00000000..6fbc61d7 --- /dev/null +++ b/spec/unit/models/message_direction_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::MessageDirectionEnum +describe Bandwidth::MessageDirectionEnum do + describe 'constants' do + it 'defines IN' do + expect(Bandwidth::MessageDirectionEnum::IN).to eq('in') + end + + it 'defines OUT' do + expect(Bandwidth::MessageDirectionEnum::OUT).to eq('out') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::MessageDirectionEnum.all_vars).to eq([ + 'in', + 'out' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::MessageDirectionEnum.build_from_hash('in')).to eq('in') + expect(Bandwidth::MessageDirectionEnum.build_from_hash('out')).to eq('out') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::MessageDirectionEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/message_request_spec.rb b/spec/unit/models/message_request_spec.rb new file mode 100644 index 00000000..a60bddb6 --- /dev/null +++ b/spec/unit/models/message_request_spec.rb @@ -0,0 +1,131 @@ +# Unit tests for Bandwidth::MessageRequest +describe Bandwidth::MessageRequest do + let(:message_request_default) { Bandwidth::MessageRequest.new({ + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + to: ['+19195551234'], + from: '+19195554321' + }) } + let(:message_request_values) { Bandwidth::MessageRequest.new({ + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + tag: 'custom tag', + priority: Bandwidth::PriorityEnum::DEFAULT, + expiration: '2022-06-16T13:45:07.160Z' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MessageRequest.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MessageRequest.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MessageRequest.acceptable_attributes).to eq(Bandwidth::MessageRequest.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MessageRequest.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MessageRequest created by the build_from_hash method' do + message_request_from_hash = Bandwidth::MessageRequest.build_from_hash({ + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + tag: 'custom tag', + priority: 'default', + expiration: '2022-06-16T13:45:07.160Z' + }) + expect(message_request_from_hash).to be_instance_of(Bandwidth::MessageRequest) + expect(message_request_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(message_request_from_hash.to).to eq(['+19195551234']) + expect(message_request_from_hash.from).to eq('+19195554321') + expect(message_request_from_hash.text).to eq('Hello world') + expect(message_request_from_hash.media).to eq(['https://dev.bandwidth.com/images/bandwidth-logo.png']) + expect(message_request_from_hash.tag).to eq('custom tag') + expect(message_request_from_hash.priority).to eq('default') + expect(message_request_from_hash.expiration).to eq(Time.parse('2022-06-16T13:45:07.160Z')) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(message_request_values.to_s).to eq('{:applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :to=>["+19195551234"], :from=>"+19195554321", :text=>"Hello world", :media=>["https://dev.bandwidth.com/images/bandwidth-logo.png"], :tag=>"custom tag", :priority=>"default", :expiration=>"2022-06-16T13:45:07.160Z"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + message_request_equal = Bandwidth::MessageRequest.new({ + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + to: ['+19195551234'], + from: '+19195554321' + }) + expect(message_request_default.eql?(message_request_equal)).to be true + expect(message_request_default.eql?(message_request_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(message_request_values.to_body).to eq({ + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + tag: 'custom tag', + priority: Bandwidth::PriorityEnum::DEFAULT, + expiration: '2022-06-16T13:45:07.160Z' + }) + end + end + + describe 'custom attribute writers' do + it '#application_id=' do + expect { + Bandwidth::MessageRequest.new({ application_id: nil }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#to=' do + expect { + message_request_values.to = nil + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#from=' do + expect { + Bandwidth::MessageRequest.new({ application_id: 'a', to: ['+19195551234'], from: nil }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#text=' do + expect { + message_request_values.text = nil + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + message_request_values.text = 'a' * 2049 + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 2048.') + end + end +end diff --git a/spec/unit/models/message_spec.rb b/spec/unit/models/message_spec.rb index c2c745b6..669e650d 100644 --- a/spec/unit/models/message_spec.rb +++ b/spec/unit/models/message_spec.rb @@ -37,29 +37,9 @@ end end - describe 'enum validation' do - it 'works' do - - end - end - - describe 'EnumAttributeValidator' do - it 'validates string enum' do - validator = Bandwidth::Message::EnumAttributeValidator.new(String, ['valid']) - expect(validator.valid?('valid')).to be true - expect(validator.valid?('invalid')).to be false - end - - it 'validates integer enum' do - validator = Bandwidth::Message::EnumAttributeValidator.new(Integer, [1]) - expect(validator.valid?(1)).to be true - expect(validator.valid?('invalid')).to be false - end - - it 'validates float enum' do - validator = Bandwidth::Message::EnumAttributeValidator.new(Float, [1.0]) - expect(validator.valid?(1.0)).to be true - expect(validator.valid?('invalid')).to be false + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Message.openapi_nullable).to eq(Set.new([])) end end @@ -97,15 +77,9 @@ end end - describe '#hash' do - it 'returns a hash code according to attributes' do - expect(message_default.hash).to be_instance_of(Integer) - end - end - describe '#to_s' do it 'returns a string representation of the object' do - expect(message_default.to_s).to eq('{}') + expect(message_values.to_s).to eq('{:id=>"1589228074636lm4k2je7j7jklbn2", :owner=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :time=>"2022-06-16T13:15:07.160Z", :segmentCount=>2, :direction=>"in", :to=>["+19195551234"], :from=>"+19195554321", :media=>["https://dev.bandwidth.com/images/bandwidth-logo.png"], :text=>"Hello world", :tag=>"custom tag", :priority=>"default", :expiration=>"2022-06-16T13:45:07.160Z"}') end end @@ -135,4 +109,18 @@ }) end end + + describe 'custom attribute writers' do + it '#to=' do + expect { + message_values.to = nil + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#media=' do + expect { + message_values.media = nil + }.to raise_error(ArgumentError, 'media cannot be nil') + end + end end diff --git a/spec/unit/models/message_status_enum_spec.rb b/spec/unit/models/message_status_enum_spec.rb new file mode 100644 index 00000000..6eea6ede --- /dev/null +++ b/spec/unit/models/message_status_enum_spec.rb @@ -0,0 +1,70 @@ +# Unit tests for Bandwidth::MessageStatusEnum +describe Bandwidth::MessageStatusEnum do + describe 'constants' do + it 'defines RECEIVED' do + expect(Bandwidth::MessageStatusEnum::RECEIVED).to eq('RECEIVED') + end + + it 'defines QUEUED' do + expect(Bandwidth::MessageStatusEnum::QUEUED).to eq('QUEUED') + end + + it 'defines SENDING' do + expect(Bandwidth::MessageStatusEnum::SENDING).to eq('SENDING') + end + + it 'defines SENT' do + expect(Bandwidth::MessageStatusEnum::SENT).to eq('SENT') + end + + it 'defines FAILED' do + expect(Bandwidth::MessageStatusEnum::FAILED).to eq('FAILED') + end + + it 'defines DELIVERED' do + expect(Bandwidth::MessageStatusEnum::DELIVERED).to eq('DELIVERED') + end + + it 'defines ACCEPTED' do + expect(Bandwidth::MessageStatusEnum::ACCEPTED).to eq('ACCEPTED') + end + + it 'defines UNDELIVERED' do + expect(Bandwidth::MessageStatusEnum::UNDELIVERED).to eq('UNDELIVERED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::MessageStatusEnum.all_vars).to eq([ + 'RECEIVED', + 'QUEUED', + 'SENDING', + 'SENT', + 'FAILED', + 'DELIVERED', + 'ACCEPTED', + 'UNDELIVERED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::MessageStatusEnum.build_from_hash('RECEIVED')).to eq('RECEIVED') + expect(Bandwidth::MessageStatusEnum.build_from_hash('QUEUED')).to eq('QUEUED') + expect(Bandwidth::MessageStatusEnum.build_from_hash('SENDING')).to eq('SENDING') + expect(Bandwidth::MessageStatusEnum.build_from_hash('SENT')).to eq('SENT') + expect(Bandwidth::MessageStatusEnum.build_from_hash('FAILED')).to eq('FAILED') + expect(Bandwidth::MessageStatusEnum.build_from_hash('DELIVERED')).to eq('DELIVERED') + expect(Bandwidth::MessageStatusEnum.build_from_hash('ACCEPTED')).to eq('ACCEPTED') + expect(Bandwidth::MessageStatusEnum.build_from_hash('UNDELIVERED')).to eq('UNDELIVERED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::MessageStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/message_type_enum_spec.rb b/spec/unit/models/message_type_enum_spec.rb new file mode 100644 index 00000000..6d593767 --- /dev/null +++ b/spec/unit/models/message_type_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::MessageTypeEnum +describe Bandwidth::MessageTypeEnum do + describe 'constants' do + it 'defines SMS' do + expect(Bandwidth::MessageTypeEnum::SMS).to eq('sms') + end + + it 'defines MMS' do + expect(Bandwidth::MessageTypeEnum::MMS).to eq('mms') + end + + it 'defines RCS' do + expect(Bandwidth::MessageTypeEnum::RCS).to eq('rcs') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::MessageTypeEnum.all_vars).to eq([ + 'sms', + 'mms', + 'rcs' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::MessageTypeEnum.build_from_hash('sms')).to eq('sms') + expect(Bandwidth::MessageTypeEnum.build_from_hash('mms')).to eq('mms') + expect(Bandwidth::MessageTypeEnum.build_from_hash('rcs')).to eq('rcs') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::MessageTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/messages_list_spec.rb b/spec/unit/models/messages_list_spec.rb new file mode 100644 index 00000000..837ab4b3 --- /dev/null +++ b/spec/unit/models/messages_list_spec.rb @@ -0,0 +1,79 @@ +# Unit tests for Bandwidth::MessagesList +describe Bandwidth::MessagesList do + let(:page_info) { Bandwidth::PageInfo.new({ + prev_page: 'https://example.com/prev', + next_page: 'https://example.com/next', + prev_page_token: 'prev-token', + next_page_token: 'next-token' + }) } + let(:list_message_item) { Bandwidth::ListMessageItem.new({ message_id: 'abc-123', message_length: 10 }) } + let(:messages_list_default) { Bandwidth::MessagesList.new } + let(:messages_list_values) { Bandwidth::MessagesList.new({ + total_count: 1, + page_info: page_info, + messages: [list_message_item] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MessagesList.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MessagesList.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MessagesList.acceptable_attributes).to eq(Bandwidth::MessagesList.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MessagesList.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MessagesList created by the build_from_hash method' do + messages_list_from_hash = Bandwidth::MessagesList.build_from_hash({ + totalCount: 1, + pageInfo: { prevPage: 'https://example.com/prev', nextPage: 'https://example.com/next', prevPageToken: 'prev-token', nextPageToken: 'next-token' }, + messages: [{ messageId: 'abc-123', messageLength: 10 }] + }) + expect(messages_list_from_hash).to be_instance_of(Bandwidth::MessagesList) + expect(messages_list_from_hash.total_count).to eq(1) + expect(messages_list_from_hash.page_info).to be_instance_of(Bandwidth::PageInfo) + expect(messages_list_from_hash.messages.first).to be_instance_of(Bandwidth::ListMessageItem) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(messages_list_values.to_s).to eq('{:totalCount=>1, :pageInfo=>{:prevPage=>"https://example.com/prev", :nextPage=>"https://example.com/next", :prevPageToken=>"prev-token", :nextPageToken=>"next-token"}, :messages=>[{:messageId=>"abc-123", :messageLength=>10}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(messages_list_default.eql?(Bandwidth::MessagesList.new)).to be true + expect(messages_list_default.eql?(messages_list_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(messages_list_values.to_body).to eq({ + totalCount: 1, + pageInfo: { prevPage: 'https://example.com/prev', nextPage: 'https://example.com/next', prevPageToken: 'prev-token', nextPageToken: 'next-token' }, + messages: [{ messageId: 'abc-123', messageLength: 10 }] + }) + end + end +end diff --git a/spec/unit/models/messaging_code_response_spec.rb b/spec/unit/models/messaging_code_response_spec.rb new file mode 100644 index 00000000..40da4dae --- /dev/null +++ b/spec/unit/models/messaging_code_response_spec.rb @@ -0,0 +1,64 @@ +# Unit tests for Bandwidth::MessagingCodeResponse +describe Bandwidth::MessagingCodeResponse do + let(:messaging_code_response_default) { Bandwidth::MessagingCodeResponse.new } + let(:messaging_code_response_values) { Bandwidth::MessagingCodeResponse.new({ + message_id: '1589228074636lm4k2je7j7jklbn2' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MessagingCodeResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MessagingCodeResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MessagingCodeResponse.acceptable_attributes).to eq(Bandwidth::MessagingCodeResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MessagingCodeResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MessagingCodeResponse created by the build_from_hash method' do + messaging_code_response_from_hash = Bandwidth::MessagingCodeResponse.build_from_hash({ + messageId: '1589228074636lm4k2je7j7jklbn2' + }) + expect(messaging_code_response_from_hash).to be_instance_of(Bandwidth::MessagingCodeResponse) + expect(messaging_code_response_from_hash.message_id).to eq('1589228074636lm4k2je7j7jklbn2') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(messaging_code_response_values.to_s).to eq('{:messageId=>"1589228074636lm4k2je7j7jklbn2"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(messaging_code_response_default.eql?(Bandwidth::MessagingCodeResponse.new)).to be true + expect(messaging_code_response_default.eql?(messaging_code_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(messaging_code_response_values.to_body).to eq({ + messageId: '1589228074636lm4k2je7j7jklbn2' + }) + end + end +end diff --git a/spec/unit/models/messaging_request_error_spec.rb b/spec/unit/models/messaging_request_error_spec.rb new file mode 100644 index 00000000..a5a04823 --- /dev/null +++ b/spec/unit/models/messaging_request_error_spec.rb @@ -0,0 +1,89 @@ +# Unit tests for Bandwidth::MessagingRequestError +describe Bandwidth::MessagingRequestError do + let(:messaging_request_error_default) { Bandwidth::MessagingRequestError.new({ + type: 'baseline', + description: 'baseline description' + }) } + let(:messaging_request_error_values) { Bandwidth::MessagingRequestError.new({ + type: 'validation', + description: 'bad input' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MessagingRequestError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MessagingRequestError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MessagingRequestError.acceptable_attributes).to eq(Bandwidth::MessagingRequestError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MessagingRequestError.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MessagingRequestError created by the build_from_hash method' do + messaging_request_error_from_hash = Bandwidth::MessagingRequestError.build_from_hash({ + type: 'validation', + description: 'bad input' + }) + expect(messaging_request_error_from_hash).to be_instance_of(Bandwidth::MessagingRequestError) + expect(messaging_request_error_from_hash.type).to eq('validation') + expect(messaging_request_error_from_hash.description).to eq('bad input') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(messaging_request_error_values.to_s).to eq('{:type=>"validation", :description=>"bad input"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + messaging_request_error_equal = Bandwidth::MessagingRequestError.new({ + type: 'baseline', + description: 'baseline description' + }) + expect(messaging_request_error_default.eql?(messaging_request_error_equal)).to be true + expect(messaging_request_error_default.eql?(messaging_request_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(messaging_request_error_values.to_body).to eq({ + type: 'validation', + description: 'bad input' + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::MessagingRequestError.new({ type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#description=' do + expect { + Bandwidth::MessagingRequestError.new({ type: 'a', description: nil }) + }.to raise_error(ArgumentError, 'description cannot be nil') + end + end +end diff --git a/spec/unit/models/mfa_forbidden_request_error_spec.rb b/spec/unit/models/mfa_forbidden_request_error_spec.rb new file mode 100644 index 00000000..8073eccf --- /dev/null +++ b/spec/unit/models/mfa_forbidden_request_error_spec.rb @@ -0,0 +1,64 @@ +# Unit tests for Bandwidth::MfaForbiddenRequestError +describe Bandwidth::MfaForbiddenRequestError do + let(:mfa_forbidden_request_error_default) { Bandwidth::MfaForbiddenRequestError.new } + let(:mfa_forbidden_request_error_values) { Bandwidth::MfaForbiddenRequestError.new({ + message: 'Forbidden request' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MfaForbiddenRequestError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MfaForbiddenRequestError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MfaForbiddenRequestError.acceptable_attributes).to eq(Bandwidth::MfaForbiddenRequestError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MfaForbiddenRequestError.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MfaForbiddenRequestError created by the build_from_hash method' do + mfa_forbidden_request_error_from_hash = Bandwidth::MfaForbiddenRequestError.build_from_hash({ + message: 'Forbidden request' + }) + expect(mfa_forbidden_request_error_from_hash).to be_instance_of(Bandwidth::MfaForbiddenRequestError) + expect(mfa_forbidden_request_error_from_hash.message).to eq('Forbidden request') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(mfa_forbidden_request_error_values.to_s).to eq('{:message=>"Forbidden request"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(mfa_forbidden_request_error_default.eql?(Bandwidth::MfaForbiddenRequestError.new)).to be true + expect(mfa_forbidden_request_error_default.eql?(mfa_forbidden_request_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(mfa_forbidden_request_error_values.to_body).to eq({ + message: 'Forbidden request' + }) + end + end +end diff --git a/spec/unit/models/mfa_request_error_spec.rb b/spec/unit/models/mfa_request_error_spec.rb new file mode 100644 index 00000000..de2d376c --- /dev/null +++ b/spec/unit/models/mfa_request_error_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::MfaRequestError +describe Bandwidth::MfaRequestError do + let(:mfa_request_error_default) { Bandwidth::MfaRequestError.new } + let(:mfa_request_error_values) { Bandwidth::MfaRequestError.new({ + error: 'Invalid request', + request_id: 'req-abc-123' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MfaRequestError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MfaRequestError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MfaRequestError.acceptable_attributes).to eq(Bandwidth::MfaRequestError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MfaRequestError.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MfaRequestError created by the build_from_hash method' do + mfa_request_error_from_hash = Bandwidth::MfaRequestError.build_from_hash({ + error: 'Invalid request', + requestId: 'req-abc-123' + }) + expect(mfa_request_error_from_hash).to be_instance_of(Bandwidth::MfaRequestError) + expect(mfa_request_error_from_hash.error).to eq('Invalid request') + expect(mfa_request_error_from_hash.request_id).to eq('req-abc-123') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(mfa_request_error_values.to_s).to eq('{:error=>"Invalid request", :requestId=>"req-abc-123"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(mfa_request_error_default.eql?(Bandwidth::MfaRequestError.new)).to be true + expect(mfa_request_error_default.eql?(mfa_request_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(mfa_request_error_values.to_body).to eq({ + error: 'Invalid request', + requestId: 'req-abc-123' + }) + end + end +end diff --git a/spec/unit/models/mfa_unauthorized_request_error_spec.rb b/spec/unit/models/mfa_unauthorized_request_error_spec.rb new file mode 100644 index 00000000..361f11f5 --- /dev/null +++ b/spec/unit/models/mfa_unauthorized_request_error_spec.rb @@ -0,0 +1,64 @@ +# Unit tests for Bandwidth::MfaUnauthorizedRequestError +describe Bandwidth::MfaUnauthorizedRequestError do + let(:mfa_unauthorized_request_error_default) { Bandwidth::MfaUnauthorizedRequestError.new } + let(:mfa_unauthorized_request_error_values) { Bandwidth::MfaUnauthorizedRequestError.new({ + message: 'Unauthorized' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MfaUnauthorizedRequestError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MfaUnauthorizedRequestError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MfaUnauthorizedRequestError.acceptable_attributes).to eq(Bandwidth::MfaUnauthorizedRequestError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MfaUnauthorizedRequestError.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MfaUnauthorizedRequestError created by the build_from_hash method' do + mfa_unauthorized_request_error_from_hash = Bandwidth::MfaUnauthorizedRequestError.build_from_hash({ + message: 'Unauthorized' + }) + expect(mfa_unauthorized_request_error_from_hash).to be_instance_of(Bandwidth::MfaUnauthorizedRequestError) + expect(mfa_unauthorized_request_error_from_hash.message).to eq('Unauthorized') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(mfa_unauthorized_request_error_values.to_s).to eq('{:message=>"Unauthorized"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(mfa_unauthorized_request_error_default.eql?(Bandwidth::MfaUnauthorizedRequestError.new)).to be true + expect(mfa_unauthorized_request_error_default.eql?(mfa_unauthorized_request_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(mfa_unauthorized_request_error_values.to_body).to eq({ + message: 'Unauthorized' + }) + end + end +end diff --git a/spec/unit/models/mms_message_content_file_spec.rb b/spec/unit/models/mms_message_content_file_spec.rb new file mode 100644 index 00000000..98f359c5 --- /dev/null +++ b/spec/unit/models/mms_message_content_file_spec.rb @@ -0,0 +1,81 @@ +# Unit tests for Bandwidth::MmsMessageContentFile +describe Bandwidth::MmsMessageContentFile do + let(:mms_message_content_file_default) { Bandwidth::MmsMessageContentFile.new({ + file_url: 'https://example.com/baseline.jpg' + }) } + let(:mms_message_content_file_values) { Bandwidth::MmsMessageContentFile.new({ + file_url: 'https://example.com/image.jpg' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MmsMessageContentFile.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MmsMessageContentFile.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MmsMessageContentFile.acceptable_attributes).to eq(Bandwidth::MmsMessageContentFile.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MmsMessageContentFile.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MmsMessageContentFile created by the build_from_hash method' do + mms_message_content_file_from_hash = Bandwidth::MmsMessageContentFile.build_from_hash({ + fileUrl: 'https://example.com/image.jpg' + }) + expect(mms_message_content_file_from_hash).to be_instance_of(Bandwidth::MmsMessageContentFile) + expect(mms_message_content_file_from_hash.file_url).to eq('https://example.com/image.jpg') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(mms_message_content_file_values.to_s).to eq('{:fileUrl=>"https://example.com/image.jpg"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + mms_message_content_file_equal = Bandwidth::MmsMessageContentFile.new({ + file_url: 'https://example.com/baseline.jpg' + }) + expect(mms_message_content_file_default.eql?(mms_message_content_file_equal)).to be true + expect(mms_message_content_file_default.eql?(mms_message_content_file_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(mms_message_content_file_values.to_body).to eq({ + fileUrl: 'https://example.com/image.jpg' + }) + end + end + + describe 'custom attribute writers' do + it '#file_url=' do + expect { + Bandwidth::MmsMessageContentFile.new({ file_url: nil }) + }.to raise_error(ArgumentError, 'file_url cannot be nil') + + expect { + Bandwidth::MmsMessageContentFile.new({ file_url: 'a' * 1001 }) + }.to raise_error(ArgumentError, 'invalid value for "file_url", the character length must be smaller than or equal to 1000.') + end + end +end diff --git a/spec/unit/models/mms_message_content_spec.rb b/spec/unit/models/mms_message_content_spec.rb new file mode 100644 index 00000000..85fcf198 --- /dev/null +++ b/spec/unit/models/mms_message_content_spec.rb @@ -0,0 +1,82 @@ +# Unit tests for Bandwidth::MmsMessageContent +describe Bandwidth::MmsMessageContent do + let(:mms_message_content_default) { Bandwidth::MmsMessageContent.new } + let(:mms_message_content_values) { Bandwidth::MmsMessageContent.new({ + text: 'Hello world', + media: [Bandwidth::MmsMessageContentFile.new({ file_url: 'https://dev.bandwidth.com/images/bandwidth-logo.png' })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MmsMessageContent.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MmsMessageContent.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MmsMessageContent.acceptable_attributes).to eq(Bandwidth::MmsMessageContent.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MmsMessageContent.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MmsMessageContent created by the build_from_hash method' do + mms_message_content_from_hash = Bandwidth::MmsMessageContent.build_from_hash({ + text: 'Hello world', + media: [{ fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png' }] + }) + expect(mms_message_content_from_hash).to be_instance_of(Bandwidth::MmsMessageContent) + expect(mms_message_content_from_hash.text).to eq('Hello world') + expect(mms_message_content_from_hash.media).to be_instance_of(Array) + expect(mms_message_content_from_hash.media.first).to be_instance_of(Bandwidth::MmsMessageContentFile) + expect(mms_message_content_from_hash.media.first.file_url).to eq('https://dev.bandwidth.com/images/bandwidth-logo.png') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(mms_message_content_values.to_s).to eq('{:text=>"Hello world", :media=>[{:fileUrl=>"https://dev.bandwidth.com/images/bandwidth-logo.png"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(mms_message_content_default.eql?(Bandwidth::MmsMessageContent.new)).to be true + expect(mms_message_content_default.eql?(mms_message_content_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(mms_message_content_values.to_body).to eq({ + text: 'Hello world', + media: [{ fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png' }] + }) + end + end + + describe 'custom attribute writers' do + it '#text=' do + expect { + Bandwidth::MmsMessageContent.new({ text: nil }) + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + Bandwidth::MmsMessageContent.new({ text: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 2048.') + end + end +end diff --git a/spec/unit/models/multi_channel_action_calendar_event_spec.rb b/spec/unit/models/multi_channel_action_calendar_event_spec.rb new file mode 100644 index 00000000..f279ff8f --- /dev/null +++ b/spec/unit/models/multi_channel_action_calendar_event_spec.rb @@ -0,0 +1,163 @@ +# Unit tests for Bandwidth::MultiChannelActionCalendarEvent +describe Bandwidth::MultiChannelActionCalendarEvent do + let(:multi_channel_action_calendar_event_default) { Bandwidth::MultiChannelActionCalendarEvent.new({ + type: Bandwidth::RbmActionTypeEnum::CREATE_CALENDAR_EVENT, + text: 'baseline', + postback_data: 'baseline_postback', + title: 'Baseline Event', + start_time: '2024-01-01T00:00:00Z', + end_time: '2024-01-01T01:00:00Z' + }) } + let(:multi_channel_action_calendar_event_values) { Bandwidth::MultiChannelActionCalendarEvent.new({ + type: Bandwidth::RbmActionTypeEnum::CREATE_CALENDAR_EVENT, + text: 'Add to calendar', + postback_data: 'calendar_postback', + title: 'Bandwidth Demo', + start_time: '2024-06-16T13:15:07.160Z', + end_time: '2024-06-16T14:15:07.160Z', + description: 'A demo of the Bandwidth API' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelActionCalendarEvent.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelActionCalendarEvent.acceptable_attributes).to eq(Bandwidth::MultiChannelActionCalendarEvent.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelActionCalendarEvent.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelActionCalendarEvent created by the build_from_hash method' do + multi_channel_action_calendar_event_from_hash = Bandwidth::MultiChannelActionCalendarEvent.build_from_hash({ + type: Bandwidth::RbmActionTypeEnum::CREATE_CALENDAR_EVENT, + text: 'Add to calendar', + postbackData: 'calendar_postback', + title: 'Bandwidth Demo', + startTime: '2024-06-16T13:15:07.160Z', + endTime: '2024-06-16T14:15:07.160Z', + description: 'A demo of the Bandwidth API' + }) + expect(multi_channel_action_calendar_event_from_hash).to be_instance_of(Bandwidth::MultiChannelActionCalendarEvent) + expect(multi_channel_action_calendar_event_from_hash.type).to eq(Bandwidth::RbmActionTypeEnum::CREATE_CALENDAR_EVENT) + expect(multi_channel_action_calendar_event_from_hash.text).to eq('Add to calendar') + expect(multi_channel_action_calendar_event_from_hash.postback_data).to eq('calendar_postback') + expect(multi_channel_action_calendar_event_from_hash.title).to eq('Bandwidth Demo') + expect(multi_channel_action_calendar_event_from_hash.start_time).to eq(Time.parse('2024-06-16T13:15:07.160Z')) + expect(multi_channel_action_calendar_event_from_hash.end_time).to eq(Time.parse('2024-06-16T14:15:07.160Z')) + expect(multi_channel_action_calendar_event_from_hash.description).to eq('A demo of the Bandwidth API') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_action_calendar_event_values.to_s).to eq('{:type=>"CREATE_CALENDAR_EVENT", :text=>"Add to calendar", :postbackData=>"calendar_postback", :title=>"Bandwidth Demo", :startTime=>"2024-06-16T13:15:07.160Z", :endTime=>"2024-06-16T14:15:07.160Z", :description=>"A demo of the Bandwidth API"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_action_calendar_event_equal = Bandwidth::MultiChannelActionCalendarEvent.new({ + type: Bandwidth::RbmActionTypeEnum::CREATE_CALENDAR_EVENT, + text: 'baseline', + postback_data: 'baseline_postback', + title: 'Baseline Event', + start_time: '2024-01-01T00:00:00Z', + end_time: '2024-01-01T01:00:00Z' + }) + expect(multi_channel_action_calendar_event_default.eql?(multi_channel_action_calendar_event_equal)).to be true + expect(multi_channel_action_calendar_event_default.eql?(multi_channel_action_calendar_event_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_action_calendar_event_values.to_body).to eq({ + type: Bandwidth::RbmActionTypeEnum::CREATE_CALENDAR_EVENT, + text: 'Add to calendar', + postbackData: 'calendar_postback', + title: 'Bandwidth Demo', + startTime: '2024-06-16T13:15:07.160Z', + endTime: '2024-06-16T14:15:07.160Z', + description: 'A demo of the Bandwidth API' + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#text=' do + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: 'CREATE_CALENDAR_EVENT', text: nil }) + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: 'CREATE_CALENDAR_EVENT', text: 'a' * 26 }) + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 25.') + end + + it '#postback_data=' do + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: 'CREATE_CALENDAR_EVENT', text: 'a', postback_data: nil }) + }.to raise_error(ArgumentError, 'postback_data cannot be nil') + + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: 'CREATE_CALENDAR_EVENT', text: 'a', postback_data: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "postback_data", the character length must be smaller than or equal to 2048.') + end + + it '#title=' do + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: 'CREATE_CALENDAR_EVENT', text: 'a', postback_data: 'a', title: nil }) + }.to raise_error(ArgumentError, 'title cannot be nil') + + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: 'CREATE_CALENDAR_EVENT', text: 'a', postback_data: 'a', title: 'a' * 101 }) + }.to raise_error(ArgumentError, 'invalid value for "title", the character length must be smaller than or equal to 100.') + end + + it '#start_time=' do + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: 'CREATE_CALENDAR_EVENT', text: 'a', postback_data: 'a', title: 'a', start_time: nil }) + }.to raise_error(ArgumentError, 'start_time cannot be nil') + end + + it '#end_time=' do + expect { + Bandwidth::MultiChannelActionCalendarEvent.new({ type: 'CREATE_CALENDAR_EVENT', text: 'a', postback_data: 'a', title: 'a', start_time: '2024-01-01T00:00:00Z', end_time: nil }) + }.to raise_error(ArgumentError, 'end_time cannot be nil') + end + + it '#description=' do + expect { + multi_channel_action_calendar_event_values.description = nil + }.to raise_error(ArgumentError, 'description cannot be nil') + + expect { + multi_channel_action_calendar_event_values.description = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 500.') + end + end +end diff --git a/spec/unit/models/multi_channel_action_spec.rb b/spec/unit/models/multi_channel_action_spec.rb new file mode 100644 index 00000000..f6036104 --- /dev/null +++ b/spec/unit/models/multi_channel_action_spec.rb @@ -0,0 +1,93 @@ +# Unit tests for Bandwidth::MultiChannelAction +describe Bandwidth::MultiChannelAction do + describe '.openapi_any_of' do + it 'lists the classes defined in anyOf' do + expect(Bandwidth::MultiChannelAction.openapi_any_of).to eq([ + :'MultiChannelActionCalendarEvent', + :'RbmActionBase', + :'RbmActionDial', + :'RbmActionOpenUrl', + :'RbmActionViewLocation' + ]) + end + end + + describe '.openapi_discriminator_name' do + it 'returns the discriminator property name' do + expect(Bandwidth::MultiChannelAction.openapi_discriminator_name).to eq(:'type') + end + end + + describe '.openapi_discriminator_mapping' do + it 'maps every discriminator value to an anyOf class' do + expect(Bandwidth::MultiChannelAction.openapi_discriminator_mapping).to eq({ + :'CREATE_CALENDAR_EVENT' => :'MultiChannelActionCalendarEvent', + :'DIAL_PHONE' => :'RbmActionDial', + :'OPEN_URL' => :'RbmActionOpenUrl', + :'REPLY' => :'RbmActionBase', + :'REQUEST_LOCATION' => :'RbmActionBase', + :'SHOW_LOCATION' => :'RbmActionViewLocation' + }) + end + + it 'maps only to classes listed in openapi_any_of' do + mapping_targets = Bandwidth::MultiChannelAction.openapi_discriminator_mapping.values.uniq.sort + expect(mapping_targets).to eq(Bandwidth::MultiChannelAction.openapi_any_of.sort) + end + end + + describe '.build' do + it 'routes MultiChannelActionCalendarEvent discriminator values to MultiChannelActionCalendarEvent.build_from_hash' do + Bandwidth::MultiChannelAction.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'MultiChannelActionCalendarEvent' + data = { type: discriminator.to_s } + expect(Bandwidth::MultiChannelActionCalendarEvent).to receive(:build_from_hash).with(data).and_return(:calendar_event_result) + expect(Bandwidth::MultiChannelAction.build(data)).to eq(:calendar_event_result) + end + end + + it 'routes RbmActionBase discriminator values to RbmActionBase.build_from_hash' do + Bandwidth::MultiChannelAction.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'RbmActionBase' + data = { type: discriminator.to_s } + expect(Bandwidth::RbmActionBase).to receive(:build_from_hash).with(data).and_return(:base_result) + expect(Bandwidth::MultiChannelAction.build(data)).to eq(:base_result) + end + end + + it 'routes RbmActionDial discriminator values to RbmActionDial.build_from_hash' do + Bandwidth::MultiChannelAction.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'RbmActionDial' + data = { type: discriminator.to_s } + expect(Bandwidth::RbmActionDial).to receive(:build_from_hash).with(data).and_return(:dial_result) + expect(Bandwidth::MultiChannelAction.build(data)).to eq(:dial_result) + end + end + + it 'routes RbmActionOpenUrl discriminator values to RbmActionOpenUrl.build_from_hash' do + Bandwidth::MultiChannelAction.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'RbmActionOpenUrl' + data = { type: discriminator.to_s } + expect(Bandwidth::RbmActionOpenUrl).to receive(:build_from_hash).with(data).and_return(:open_url_result) + expect(Bandwidth::MultiChannelAction.build(data)).to eq(:open_url_result) + end + end + + it 'routes RbmActionViewLocation discriminator values to RbmActionViewLocation.build_from_hash' do + Bandwidth::MultiChannelAction.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'RbmActionViewLocation' + data = { type: discriminator.to_s } + expect(Bandwidth::RbmActionViewLocation).to receive(:build_from_hash).with(data).and_return(:view_location_result) + expect(Bandwidth::MultiChannelAction.build(data)).to eq(:view_location_result) + end + end + + it 'returns nil when the discriminator value is missing' do + expect(Bandwidth::MultiChannelAction.build({})).to be_nil + end + + it 'returns nil when the discriminator value does not match any mapping' do + expect(Bandwidth::MultiChannelAction.build({ type: 'unknown' })).to be_nil + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_mms_object_spec.rb b/spec/unit/models/multi_channel_channel_list_mms_object_spec.rb new file mode 100644 index 00000000..234b1754 --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_mms_object_spec.rb @@ -0,0 +1,114 @@ +# Unit tests for Bandwidth::MultiChannelChannelListMMSObject +describe Bandwidth::MultiChannelChannelListMMSObject do + let(:multi_channel_channel_list_mms_object_default) { Bandwidth::MultiChannelChannelListMMSObject.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: Bandwidth::MmsMessageContent.new({ text: 'baseline' }) + }) } + let(:multi_channel_channel_list_mms_object_values) { Bandwidth::MultiChannelChannelListMMSObject.new({ + from: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: Bandwidth::MmsMessageContent.new({ text: 'Hello world' }) + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListMMSObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListMMSObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelChannelListMMSObject.acceptable_attributes).to eq(Bandwidth::MultiChannelChannelListMMSObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelChannelListMMSObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelChannelListMMSObject created by the build_from_hash method' do + multi_channel_channel_list_mms_object_from_hash = Bandwidth::MultiChannelChannelListMMSObject.build_from_hash({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: { text: 'Hello world' } + }) + expect(multi_channel_channel_list_mms_object_from_hash).to be_instance_of(Bandwidth::MultiChannelChannelListMMSObject) + expect(multi_channel_channel_list_mms_object_from_hash.from).to eq('+19195554321') + expect(multi_channel_channel_list_mms_object_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(multi_channel_channel_list_mms_object_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::MMS) + expect(multi_channel_channel_list_mms_object_from_hash.content).to be_instance_of(Bandwidth::MmsMessageContent) + expect(multi_channel_channel_list_mms_object_from_hash.content.text).to eq('Hello world') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_channel_list_mms_object_values.to_s).to eq('{:from=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"MMS", :content=>{:text=>"Hello world"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_channel_list_mms_object_equal = Bandwidth::MultiChannelChannelListMMSObject.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: Bandwidth::MmsMessageContent.new({ text: 'baseline' }) + }) + expect(multi_channel_channel_list_mms_object_default.eql?(multi_channel_channel_list_mms_object_equal)).to be true + expect(multi_channel_channel_list_mms_object_default.eql?(multi_channel_channel_list_mms_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_channel_list_mms_object_values.to_body).to eq({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: { text: 'Hello world' } + }) + end + end + + describe 'custom attribute writers' do + it '#from=' do + expect { + Bandwidth::MultiChannelChannelListMMSObject.new({ from: nil }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#application_id=' do + expect { + Bandwidth::MultiChannelChannelListMMSObject.new({ from: '+15554443333', application_id: nil }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#channel=' do + expect { + Bandwidth::MultiChannelChannelListMMSObject.new({ from: '+15554443333', application_id: 'a', channel: nil }) + }.to raise_error(ArgumentError, 'channel cannot be nil') + end + + it '#content=' do + expect { + Bandwidth::MultiChannelChannelListMMSObject.new({ from: '+15554443333', application_id: 'a', channel: 'MMS', content: nil }) + }.to raise_error(ArgumentError, 'content cannot be nil') + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_mms_response_object_spec.rb b/spec/unit/models/multi_channel_channel_list_mms_response_object_spec.rb new file mode 100644 index 00000000..3a99f894 --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_mms_response_object_spec.rb @@ -0,0 +1,126 @@ +# Unit tests for Bandwidth::MultiChannelChannelListMMSResponseObject +describe Bandwidth::MultiChannelChannelListMMSResponseObject do + let(:multi_channel_channel_list_mms_response_object_default) { Bandwidth::MultiChannelChannelListMMSResponseObject.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: Bandwidth::MmsMessageContent.new({ text: 'baseline' }), + owner: '+15554443333' + }) } + let(:multi_channel_channel_list_mms_response_object_values) { Bandwidth::MultiChannelChannelListMMSResponseObject.new({ + from: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: Bandwidth::MmsMessageContent.new({ text: 'Hello world' }), + owner: '+19195554321' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListMMSResponseObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListMMSResponseObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelChannelListMMSResponseObject.acceptable_attributes).to eq(Bandwidth::MultiChannelChannelListMMSResponseObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelChannelListMMSResponseObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelChannelListMMSResponseObject created by the build_from_hash method' do + multi_channel_channel_list_mms_response_object_from_hash = Bandwidth::MultiChannelChannelListMMSResponseObject.build_from_hash({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: { text: 'Hello world' }, + owner: '+19195554321' + }) + expect(multi_channel_channel_list_mms_response_object_from_hash).to be_instance_of(Bandwidth::MultiChannelChannelListMMSResponseObject) + expect(multi_channel_channel_list_mms_response_object_from_hash.from).to eq('+19195554321') + expect(multi_channel_channel_list_mms_response_object_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(multi_channel_channel_list_mms_response_object_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::MMS) + expect(multi_channel_channel_list_mms_response_object_from_hash.content).to be_instance_of(Bandwidth::MmsMessageContent) + expect(multi_channel_channel_list_mms_response_object_from_hash.content.text).to eq('Hello world') + expect(multi_channel_channel_list_mms_response_object_from_hash.owner).to eq('+19195554321') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_channel_list_mms_response_object_values.to_s).to eq('{:from=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"MMS", :content=>{:text=>"Hello world"}, :owner=>"+19195554321"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_channel_list_mms_response_object_equal = Bandwidth::MultiChannelChannelListMMSResponseObject.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: Bandwidth::MmsMessageContent.new({ text: 'baseline' }), + owner: '+15554443333' + }) + expect(multi_channel_channel_list_mms_response_object_default.eql?(multi_channel_channel_list_mms_response_object_equal)).to be true + expect(multi_channel_channel_list_mms_response_object_default.eql?(multi_channel_channel_list_mms_response_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_channel_list_mms_response_object_values.to_body).to eq({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS, + content: { text: 'Hello world' }, + owner: '+19195554321' + }) + end + end + + describe 'custom attribute writers' do + it '#from=' do + expect { + Bandwidth::MultiChannelChannelListMMSResponseObject.new({ from: nil }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#application_id=' do + expect { + Bandwidth::MultiChannelChannelListMMSResponseObject.new({ from: '+15554443333', application_id: nil }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#channel=' do + expect { + Bandwidth::MultiChannelChannelListMMSResponseObject.new({ from: '+15554443333', application_id: 'a', channel: nil }) + }.to raise_error(ArgumentError, 'channel cannot be nil') + end + + it '#content=' do + expect { + Bandwidth::MultiChannelChannelListMMSResponseObject.new({ from: '+15554443333', application_id: 'a', channel: 'MMS', content: nil }) + }.to raise_error(ArgumentError, 'content cannot be nil') + end + + it '#owner=' do + expect { + Bandwidth::MultiChannelChannelListMMSResponseObject.new({ from: '+15554443333', application_id: 'a', channel: 'MMS', content: 'c', owner: nil }) + }.to raise_error(ArgumentError, 'owner cannot be nil') + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_object_base_spec.rb b/spec/unit/models/multi_channel_channel_list_object_base_spec.rb new file mode 100644 index 00000000..97621d66 --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_object_base_spec.rb @@ -0,0 +1,101 @@ +# Unit tests for Bandwidth::MultiChannelChannelListObjectBase +describe Bandwidth::MultiChannelChannelListObjectBase do + let(:multi_channel_channel_list_object_base_default) { Bandwidth::MultiChannelChannelListObjectBase.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS + }) } + let(:multi_channel_channel_list_object_base_values) { Bandwidth::MultiChannelChannelListObjectBase.new({ + from: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListObjectBase.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListObjectBase.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelChannelListObjectBase.acceptable_attributes).to eq(Bandwidth::MultiChannelChannelListObjectBase.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelChannelListObjectBase.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelChannelListObjectBase created by the build_from_hash method' do + multi_channel_channel_list_object_base_from_hash = Bandwidth::MultiChannelChannelListObjectBase.build_from_hash({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS + }) + expect(multi_channel_channel_list_object_base_from_hash).to be_instance_of(Bandwidth::MultiChannelChannelListObjectBase) + expect(multi_channel_channel_list_object_base_from_hash.from).to eq('+19195554321') + expect(multi_channel_channel_list_object_base_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(multi_channel_channel_list_object_base_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::MMS) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_channel_list_object_base_values.to_s).to eq('{:from=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"MMS"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_channel_list_object_base_equal = Bandwidth::MultiChannelChannelListObjectBase.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS + }) + expect(multi_channel_channel_list_object_base_default.eql?(multi_channel_channel_list_object_base_equal)).to be true + expect(multi_channel_channel_list_object_base_default.eql?(multi_channel_channel_list_object_base_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_channel_list_object_base_values.to_body).to eq({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::MMS + }) + end + end + + describe 'custom attribute writers' do + it '#from=' do + expect { + Bandwidth::MultiChannelChannelListObjectBase.new({ from: nil }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#application_id=' do + expect { + Bandwidth::MultiChannelChannelListObjectBase.new({ from: '+15554443333', application_id: nil }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#channel=' do + expect { + Bandwidth::MultiChannelChannelListObjectBase.new({ from: '+15554443333', application_id: 'a', channel: nil }) + }.to raise_error(ArgumentError, 'channel cannot be nil') + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_owner_object_spec.rb b/spec/unit/models/multi_channel_channel_list_owner_object_spec.rb new file mode 100644 index 00000000..cb33eb67 --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_owner_object_spec.rb @@ -0,0 +1,77 @@ +# Unit tests for Bandwidth::MultiChannelChannelListOwnerObject +describe Bandwidth::MultiChannelChannelListOwnerObject do + let(:multi_channel_channel_list_owner_object_default) { Bandwidth::MultiChannelChannelListOwnerObject.new({ + owner: '+15554443333' + }) } + let(:multi_channel_channel_list_owner_object_values) { Bandwidth::MultiChannelChannelListOwnerObject.new({ + owner: '+19195554321' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListOwnerObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListOwnerObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelChannelListOwnerObject.acceptable_attributes).to eq(Bandwidth::MultiChannelChannelListOwnerObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelChannelListOwnerObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelChannelListOwnerObject created by the build_from_hash method' do + multi_channel_channel_list_owner_object_from_hash = Bandwidth::MultiChannelChannelListOwnerObject.build_from_hash({ + owner: '+19195554321' + }) + expect(multi_channel_channel_list_owner_object_from_hash).to be_instance_of(Bandwidth::MultiChannelChannelListOwnerObject) + expect(multi_channel_channel_list_owner_object_from_hash.owner).to eq('+19195554321') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_channel_list_owner_object_values.to_s).to eq('{:owner=>"+19195554321"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_channel_list_owner_object_equal = Bandwidth::MultiChannelChannelListOwnerObject.new({ + owner: '+15554443333' + }) + expect(multi_channel_channel_list_owner_object_default.eql?(multi_channel_channel_list_owner_object_equal)).to be true + expect(multi_channel_channel_list_owner_object_default.eql?(multi_channel_channel_list_owner_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_channel_list_owner_object_values.to_body).to eq({ + owner: '+19195554321' + }) + end + end + + describe 'custom attribute writers' do + it '#owner=' do + expect { + Bandwidth::MultiChannelChannelListOwnerObject.new({ owner: nil }) + }.to raise_error(ArgumentError, 'owner cannot be nil') + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_rbm_object_all_of_content_spec.rb b/spec/unit/models/multi_channel_channel_list_rbm_object_all_of_content_spec.rb new file mode 100644 index 00000000..133db3fa --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_rbm_object_all_of_content_spec.rb @@ -0,0 +1,28 @@ +# Unit tests for Bandwidth::MultiChannelChannelListRBMObjectAllOfContent +describe Bandwidth::MultiChannelChannelListRBMObjectAllOfContent do + describe '.openapi_one_of' do + it 'lists the classes defined in oneOf' do + expect(Bandwidth::MultiChannelChannelListRBMObjectAllOfContent.openapi_one_of).to eq([ + :'RbmMessageContentRichCard', + :'RbmMessageContentText', + :'RbmMessageMedia' + ]) + end + end + + describe '.build' do + it 'routes payloads matching RbmMessageContentText attributes to RbmMessageContentText.build_from_hash' do + data = { text: 'Hello world' } + expect(Bandwidth::MultiChannelChannelListRBMObjectAllOfContent.build(data)).to be_instance_of(Bandwidth::RbmMessageContentText) + end + + it 'routes payloads matching RbmMessageMedia attributes to RbmMessageMedia.build_from_hash' do + data = { media: [{ fileUrl: 'https://example.com/image.png' }] } + expect(Bandwidth::MultiChannelChannelListRBMObjectAllOfContent.build(data)).to be_instance_of(Bandwidth::RbmMessageMedia) + end + + it 'returns nil when the payload does not match any oneOf schema' do + expect(Bandwidth::MultiChannelChannelListRBMObjectAllOfContent.build({ unknown: 'value' })).to be_nil + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_rbm_object_spec.rb b/spec/unit/models/multi_channel_channel_list_rbm_object_spec.rb new file mode 100644 index 00000000..960fae69 --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_rbm_object_spec.rb @@ -0,0 +1,114 @@ +# Unit tests for Bandwidth::MultiChannelChannelListRBMObject +describe Bandwidth::MultiChannelChannelListRBMObject do + let(:multi_channel_channel_list_rbm_object_default) { Bandwidth::MultiChannelChannelListRBMObject.new({ + from: 'BANDWIDTH', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: Bandwidth::RbmMessageContentText.new({ text: 'baseline' }) + }) } + let(:multi_channel_channel_list_rbm_object_values) { Bandwidth::MultiChannelChannelListRBMObject.new({ + from: 'BANDWIDTH', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: Bandwidth::RbmMessageContentText.new({ text: 'Hello world' }) + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListRBMObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListRBMObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelChannelListRBMObject.acceptable_attributes).to eq(Bandwidth::MultiChannelChannelListRBMObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelChannelListRBMObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelChannelListRBMObject created by the build_from_hash method' do + multi_channel_channel_list_rbm_object_from_hash = Bandwidth::MultiChannelChannelListRBMObject.build_from_hash({ + from: 'BANDWIDTH', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: { text: 'Hello world' } + }) + expect(multi_channel_channel_list_rbm_object_from_hash).to be_instance_of(Bandwidth::MultiChannelChannelListRBMObject) + expect(multi_channel_channel_list_rbm_object_from_hash.from).to eq('BANDWIDTH') + expect(multi_channel_channel_list_rbm_object_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(multi_channel_channel_list_rbm_object_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::RBM) + expect(multi_channel_channel_list_rbm_object_from_hash.content).to be_instance_of(Bandwidth::RbmMessageContentText) + expect(multi_channel_channel_list_rbm_object_from_hash.content.text).to eq('Hello world') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_channel_list_rbm_object_values.to_s).to eq('{:from=>"BANDWIDTH", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"RBM", :content=>{:text=>"Hello world"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_channel_list_rbm_object_equal = Bandwidth::MultiChannelChannelListRBMObject.new({ + from: 'BANDWIDTH', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: Bandwidth::RbmMessageContentText.new({ text: 'baseline' }) + }) + expect(multi_channel_channel_list_rbm_object_default.eql?(multi_channel_channel_list_rbm_object_equal)).to be true + expect(multi_channel_channel_list_rbm_object_default.eql?(multi_channel_channel_list_rbm_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_channel_list_rbm_object_values.to_body).to eq({ + from: 'BANDWIDTH', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: { text: 'Hello world' } + }) + end + end + + describe 'custom attribute writers' do + it '#from=' do + expect { + Bandwidth::MultiChannelChannelListRBMObject.new({ from: nil }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#application_id=' do + expect { + Bandwidth::MultiChannelChannelListRBMObject.new({ from: 'BANDWIDTH', application_id: nil }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#channel=' do + expect { + Bandwidth::MultiChannelChannelListRBMObject.new({ from: 'BANDWIDTH', application_id: 'a', channel: nil }) + }.to raise_error(ArgumentError, 'channel cannot be nil') + end + + it '#content=' do + expect { + Bandwidth::MultiChannelChannelListRBMObject.new({ from: 'BANDWIDTH', application_id: 'a', channel: 'RBM', content: nil }) + }.to raise_error(ArgumentError, 'content cannot be nil') + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_rbm_response_object_spec.rb b/spec/unit/models/multi_channel_channel_list_rbm_response_object_spec.rb new file mode 100644 index 00000000..d5982ffc --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_rbm_response_object_spec.rb @@ -0,0 +1,126 @@ +# Unit tests for Bandwidth::MultiChannelChannelListRBMResponseObject +describe Bandwidth::MultiChannelChannelListRBMResponseObject do + let(:multi_channel_channel_list_rbm_response_object_default) { Bandwidth::MultiChannelChannelListRBMResponseObject.new({ + from: 'BANDWIDTH', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: Bandwidth::RbmMessageContentText.new({ text: 'baseline' }), + owner: 'BANDWIDTH' + }) } + let(:multi_channel_channel_list_rbm_response_object_values) { Bandwidth::MultiChannelChannelListRBMResponseObject.new({ + from: 'BANDWIDTH', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: Bandwidth::RbmMessageContentText.new({ text: 'Hello world' }), + owner: 'BANDWIDTH' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListRBMResponseObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListRBMResponseObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelChannelListRBMResponseObject.acceptable_attributes).to eq(Bandwidth::MultiChannelChannelListRBMResponseObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelChannelListRBMResponseObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelChannelListRBMResponseObject created by the build_from_hash method' do + multi_channel_channel_list_rbm_response_object_from_hash = Bandwidth::MultiChannelChannelListRBMResponseObject.build_from_hash({ + from: 'BANDWIDTH', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: { text: 'Hello world' }, + owner: 'BANDWIDTH' + }) + expect(multi_channel_channel_list_rbm_response_object_from_hash).to be_instance_of(Bandwidth::MultiChannelChannelListRBMResponseObject) + expect(multi_channel_channel_list_rbm_response_object_from_hash.from).to eq('BANDWIDTH') + expect(multi_channel_channel_list_rbm_response_object_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(multi_channel_channel_list_rbm_response_object_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::RBM) + expect(multi_channel_channel_list_rbm_response_object_from_hash.content).to be_instance_of(Bandwidth::RbmMessageContentText) + expect(multi_channel_channel_list_rbm_response_object_from_hash.content.text).to eq('Hello world') + expect(multi_channel_channel_list_rbm_response_object_from_hash.owner).to eq('BANDWIDTH') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_channel_list_rbm_response_object_values.to_s).to eq('{:from=>"BANDWIDTH", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"RBM", :content=>{:text=>"Hello world"}, :owner=>"BANDWIDTH"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_channel_list_rbm_response_object_equal = Bandwidth::MultiChannelChannelListRBMResponseObject.new({ + from: 'BANDWIDTH', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: Bandwidth::RbmMessageContentText.new({ text: 'baseline' }), + owner: 'BANDWIDTH' + }) + expect(multi_channel_channel_list_rbm_response_object_default.eql?(multi_channel_channel_list_rbm_response_object_equal)).to be true + expect(multi_channel_channel_list_rbm_response_object_default.eql?(multi_channel_channel_list_rbm_response_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_channel_list_rbm_response_object_values.to_body).to eq({ + from: 'BANDWIDTH', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::RBM, + content: { text: 'Hello world' }, + owner: 'BANDWIDTH' + }) + end + end + + describe 'custom attribute writers' do + it '#from=' do + expect { + Bandwidth::MultiChannelChannelListRBMResponseObject.new({ from: nil }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#application_id=' do + expect { + Bandwidth::MultiChannelChannelListRBMResponseObject.new({ from: 'BANDWIDTH', application_id: nil }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#channel=' do + expect { + Bandwidth::MultiChannelChannelListRBMResponseObject.new({ from: 'BANDWIDTH', application_id: 'a', channel: nil }) + }.to raise_error(ArgumentError, 'channel cannot be nil') + end + + it '#content=' do + expect { + Bandwidth::MultiChannelChannelListRBMResponseObject.new({ from: 'BANDWIDTH', application_id: 'a', channel: 'RBM', content: nil }) + }.to raise_error(ArgumentError, 'content cannot be nil') + end + + it '#owner=' do + expect { + Bandwidth::MultiChannelChannelListRBMResponseObject.new({ from: 'BANDWIDTH', application_id: 'a', channel: 'RBM', content: 'c', owner: nil }) + }.to raise_error(ArgumentError, 'owner cannot be nil') + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_request_object_spec.rb b/spec/unit/models/multi_channel_channel_list_request_object_spec.rb new file mode 100644 index 00000000..d4ab9479 --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_request_object_spec.rb @@ -0,0 +1,70 @@ +# Unit tests for Bandwidth::MultiChannelChannelListRequestObject +describe Bandwidth::MultiChannelChannelListRequestObject do + describe '.openapi_any_of' do + it 'lists the classes defined in anyOf' do + expect(Bandwidth::MultiChannelChannelListRequestObject.openapi_any_of).to eq([ + :'MultiChannelChannelListMMSObject', + :'MultiChannelChannelListRBMObject', + :'MultiChannelChannelListSMSObject' + ]) + end + end + + describe '.openapi_discriminator_name' do + it 'returns the discriminator property name' do + expect(Bandwidth::MultiChannelChannelListRequestObject.openapi_discriminator_name).to eq(:'channel') + end + end + + describe '.openapi_discriminator_mapping' do + it 'maps every discriminator value to an anyOf class' do + expect(Bandwidth::MultiChannelChannelListRequestObject.openapi_discriminator_mapping).to eq({ + :'MMS' => :'MultiChannelChannelListMMSObject', + :'RBM' => :'MultiChannelChannelListRBMObject', + :'SMS' => :'MultiChannelChannelListSMSObject' + }) + end + + it 'maps only to classes listed in openapi_any_of' do + mapping_targets = Bandwidth::MultiChannelChannelListRequestObject.openapi_discriminator_mapping.values.uniq.sort + expect(mapping_targets).to eq(Bandwidth::MultiChannelChannelListRequestObject.openapi_any_of.sort) + end + end + + describe '.build' do + it 'routes MultiChannelChannelListMMSObject discriminator values to MultiChannelChannelListMMSObject.build_from_hash' do + Bandwidth::MultiChannelChannelListRequestObject.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'MultiChannelChannelListMMSObject' + data = { channel: discriminator.to_s } + expect(Bandwidth::MultiChannelChannelListMMSObject).to receive(:build_from_hash).with(data).and_return(:mms_result) + expect(Bandwidth::MultiChannelChannelListRequestObject.build(data)).to eq(:mms_result) + end + end + + it 'routes MultiChannelChannelListRBMObject discriminator values to MultiChannelChannelListRBMObject.build_from_hash' do + Bandwidth::MultiChannelChannelListRequestObject.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'MultiChannelChannelListRBMObject' + data = { channel: discriminator.to_s } + expect(Bandwidth::MultiChannelChannelListRBMObject).to receive(:build_from_hash).with(data).and_return(:rbm_result) + expect(Bandwidth::MultiChannelChannelListRequestObject.build(data)).to eq(:rbm_result) + end + end + + it 'routes MultiChannelChannelListSMSObject discriminator values to MultiChannelChannelListSMSObject.build_from_hash' do + Bandwidth::MultiChannelChannelListRequestObject.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'MultiChannelChannelListSMSObject' + data = { channel: discriminator.to_s } + expect(Bandwidth::MultiChannelChannelListSMSObject).to receive(:build_from_hash).with(data).and_return(:sms_result) + expect(Bandwidth::MultiChannelChannelListRequestObject.build(data)).to eq(:sms_result) + end + end + + it 'returns nil when the discriminator value is missing' do + expect(Bandwidth::MultiChannelChannelListRequestObject.build({})).to be_nil + end + + it 'returns nil when the discriminator value does not match any mapping' do + expect(Bandwidth::MultiChannelChannelListRequestObject.build({ channel: 'unknown' })).to be_nil + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_response_object_spec.rb b/spec/unit/models/multi_channel_channel_list_response_object_spec.rb new file mode 100644 index 00000000..1379861f --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_response_object_spec.rb @@ -0,0 +1,70 @@ +# Unit tests for Bandwidth::MultiChannelChannelListResponseObject +describe Bandwidth::MultiChannelChannelListResponseObject do + describe '.openapi_any_of' do + it 'lists the classes defined in anyOf' do + expect(Bandwidth::MultiChannelChannelListResponseObject.openapi_any_of).to eq([ + :'MultiChannelChannelListMMSResponseObject', + :'MultiChannelChannelListRBMResponseObject', + :'MultiChannelChannelListSMSResponseObject' + ]) + end + end + + describe '.openapi_discriminator_name' do + it 'returns the discriminator property name' do + expect(Bandwidth::MultiChannelChannelListResponseObject.openapi_discriminator_name).to eq(:'channel') + end + end + + describe '.openapi_discriminator_mapping' do + it 'maps every discriminator value to an anyOf class' do + expect(Bandwidth::MultiChannelChannelListResponseObject.openapi_discriminator_mapping).to eq({ + :'MMS' => :'MultiChannelChannelListMMSResponseObject', + :'RBM' => :'MultiChannelChannelListRBMResponseObject', + :'SMS' => :'MultiChannelChannelListSMSResponseObject' + }) + end + + it 'maps only to classes listed in openapi_any_of' do + mapping_targets = Bandwidth::MultiChannelChannelListResponseObject.openapi_discriminator_mapping.values.uniq.sort + expect(mapping_targets).to eq(Bandwidth::MultiChannelChannelListResponseObject.openapi_any_of.sort) + end + end + + describe '.build' do + it 'routes MultiChannelChannelListMMSResponseObject discriminator values to MultiChannelChannelListMMSResponseObject.build_from_hash' do + Bandwidth::MultiChannelChannelListResponseObject.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'MultiChannelChannelListMMSResponseObject' + data = { channel: discriminator.to_s } + expect(Bandwidth::MultiChannelChannelListMMSResponseObject).to receive(:build_from_hash).with(data).and_return(:mms_result) + expect(Bandwidth::MultiChannelChannelListResponseObject.build(data)).to eq(:mms_result) + end + end + + it 'routes MultiChannelChannelListRBMResponseObject discriminator values to MultiChannelChannelListRBMResponseObject.build_from_hash' do + Bandwidth::MultiChannelChannelListResponseObject.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'MultiChannelChannelListRBMResponseObject' + data = { channel: discriminator.to_s } + expect(Bandwidth::MultiChannelChannelListRBMResponseObject).to receive(:build_from_hash).with(data).and_return(:rbm_result) + expect(Bandwidth::MultiChannelChannelListResponseObject.build(data)).to eq(:rbm_result) + end + end + + it 'routes MultiChannelChannelListSMSResponseObject discriminator values to MultiChannelChannelListSMSResponseObject.build_from_hash' do + Bandwidth::MultiChannelChannelListResponseObject.openapi_discriminator_mapping.each do |discriminator, klass| + next unless klass == :'MultiChannelChannelListSMSResponseObject' + data = { channel: discriminator.to_s } + expect(Bandwidth::MultiChannelChannelListSMSResponseObject).to receive(:build_from_hash).with(data).and_return(:sms_result) + expect(Bandwidth::MultiChannelChannelListResponseObject.build(data)).to eq(:sms_result) + end + end + + it 'returns nil when the discriminator value is missing' do + expect(Bandwidth::MultiChannelChannelListResponseObject.build({})).to be_nil + end + + it 'returns nil when the discriminator value does not match any mapping' do + expect(Bandwidth::MultiChannelChannelListResponseObject.build({ channel: 'unknown' })).to be_nil + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_sms_object_spec.rb b/spec/unit/models/multi_channel_channel_list_sms_object_spec.rb new file mode 100644 index 00000000..337e11ef --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_sms_object_spec.rb @@ -0,0 +1,114 @@ +# Unit tests for Bandwidth::MultiChannelChannelListSMSObject +describe Bandwidth::MultiChannelChannelListSMSObject do + let(:multi_channel_channel_list_sms_object_default) { Bandwidth::MultiChannelChannelListSMSObject.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: Bandwidth::SmsMessageContent.new({ text: 'baseline' }) + }) } + let(:multi_channel_channel_list_sms_object_values) { Bandwidth::MultiChannelChannelListSMSObject.new({ + from: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: Bandwidth::SmsMessageContent.new({ text: 'Hello world' }) + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListSMSObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListSMSObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelChannelListSMSObject.acceptable_attributes).to eq(Bandwidth::MultiChannelChannelListSMSObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelChannelListSMSObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelChannelListSMSObject created by the build_from_hash method' do + multi_channel_channel_list_sms_object_from_hash = Bandwidth::MultiChannelChannelListSMSObject.build_from_hash({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: { text: 'Hello world' } + }) + expect(multi_channel_channel_list_sms_object_from_hash).to be_instance_of(Bandwidth::MultiChannelChannelListSMSObject) + expect(multi_channel_channel_list_sms_object_from_hash.from).to eq('+19195554321') + expect(multi_channel_channel_list_sms_object_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(multi_channel_channel_list_sms_object_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::SMS) + expect(multi_channel_channel_list_sms_object_from_hash.content).to be_instance_of(Bandwidth::SmsMessageContent) + expect(multi_channel_channel_list_sms_object_from_hash.content.text).to eq('Hello world') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_channel_list_sms_object_values.to_s).to eq('{:from=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"SMS", :content=>{:text=>"Hello world"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_channel_list_sms_object_equal = Bandwidth::MultiChannelChannelListSMSObject.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: Bandwidth::SmsMessageContent.new({ text: 'baseline' }) + }) + expect(multi_channel_channel_list_sms_object_default.eql?(multi_channel_channel_list_sms_object_equal)).to be true + expect(multi_channel_channel_list_sms_object_default.eql?(multi_channel_channel_list_sms_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_channel_list_sms_object_values.to_body).to eq({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: { text: 'Hello world' } + }) + end + end + + describe 'custom attribute writers' do + it '#from=' do + expect { + Bandwidth::MultiChannelChannelListSMSObject.new({ from: nil }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#application_id=' do + expect { + Bandwidth::MultiChannelChannelListSMSObject.new({ from: '+15554443333', application_id: nil }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#channel=' do + expect { + Bandwidth::MultiChannelChannelListSMSObject.new({ from: '+15554443333', application_id: 'a', channel: nil }) + }.to raise_error(ArgumentError, 'channel cannot be nil') + end + + it '#content=' do + expect { + Bandwidth::MultiChannelChannelListSMSObject.new({ from: '+15554443333', application_id: 'a', channel: 'SMS', content: nil }) + }.to raise_error(ArgumentError, 'content cannot be nil') + end + end +end diff --git a/spec/unit/models/multi_channel_channel_list_sms_response_object_spec.rb b/spec/unit/models/multi_channel_channel_list_sms_response_object_spec.rb new file mode 100644 index 00000000..4e0f0d55 --- /dev/null +++ b/spec/unit/models/multi_channel_channel_list_sms_response_object_spec.rb @@ -0,0 +1,126 @@ +# Unit tests for Bandwidth::MultiChannelChannelListSMSResponseObject +describe Bandwidth::MultiChannelChannelListSMSResponseObject do + let(:multi_channel_channel_list_sms_response_object_default) { Bandwidth::MultiChannelChannelListSMSResponseObject.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: Bandwidth::SmsMessageContent.new({ text: 'baseline' }), + owner: '+15554443333' + }) } + let(:multi_channel_channel_list_sms_response_object_values) { Bandwidth::MultiChannelChannelListSMSResponseObject.new({ + from: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: Bandwidth::SmsMessageContent.new({ text: 'Hello world' }), + owner: '+19195554321' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListSMSResponseObject.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelChannelListSMSResponseObject.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelChannelListSMSResponseObject.acceptable_attributes).to eq(Bandwidth::MultiChannelChannelListSMSResponseObject.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelChannelListSMSResponseObject.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelChannelListSMSResponseObject created by the build_from_hash method' do + multi_channel_channel_list_sms_response_object_from_hash = Bandwidth::MultiChannelChannelListSMSResponseObject.build_from_hash({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: { text: 'Hello world' }, + owner: '+19195554321' + }) + expect(multi_channel_channel_list_sms_response_object_from_hash).to be_instance_of(Bandwidth::MultiChannelChannelListSMSResponseObject) + expect(multi_channel_channel_list_sms_response_object_from_hash.from).to eq('+19195554321') + expect(multi_channel_channel_list_sms_response_object_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(multi_channel_channel_list_sms_response_object_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::SMS) + expect(multi_channel_channel_list_sms_response_object_from_hash.content).to be_instance_of(Bandwidth::SmsMessageContent) + expect(multi_channel_channel_list_sms_response_object_from_hash.content.text).to eq('Hello world') + expect(multi_channel_channel_list_sms_response_object_from_hash.owner).to eq('+19195554321') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_channel_list_sms_response_object_values.to_s).to eq('{:from=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"SMS", :content=>{:text=>"Hello world"}, :owner=>"+19195554321"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_channel_list_sms_response_object_equal = Bandwidth::MultiChannelChannelListSMSResponseObject.new({ + from: '+15554443333', + application_id: 'baseline-app-id', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: Bandwidth::SmsMessageContent.new({ text: 'baseline' }), + owner: '+15554443333' + }) + expect(multi_channel_channel_list_sms_response_object_default.eql?(multi_channel_channel_list_sms_response_object_equal)).to be true + expect(multi_channel_channel_list_sms_response_object_default.eql?(multi_channel_channel_list_sms_response_object_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_channel_list_sms_response_object_values.to_body).to eq({ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: { text: 'Hello world' }, + owner: '+19195554321' + }) + end + end + + describe 'custom attribute writers' do + it '#from=' do + expect { + Bandwidth::MultiChannelChannelListSMSResponseObject.new({ from: nil }) + }.to raise_error(ArgumentError, 'from cannot be nil') + end + + it '#application_id=' do + expect { + Bandwidth::MultiChannelChannelListSMSResponseObject.new({ from: '+15554443333', application_id: nil }) + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#channel=' do + expect { + Bandwidth::MultiChannelChannelListSMSResponseObject.new({ from: '+15554443333', application_id: 'a', channel: nil }) + }.to raise_error(ArgumentError, 'channel cannot be nil') + end + + it '#content=' do + expect { + Bandwidth::MultiChannelChannelListSMSResponseObject.new({ from: '+15554443333', application_id: 'a', channel: 'SMS', content: nil }) + }.to raise_error(ArgumentError, 'content cannot be nil') + end + + it '#owner=' do + expect { + Bandwidth::MultiChannelChannelListSMSResponseObject.new({ from: '+15554443333', application_id: 'a', channel: 'SMS', content: 'c', owner: nil }) + }.to raise_error(ArgumentError, 'owner cannot be nil') + end + end +end diff --git a/spec/unit/models/multi_channel_error_spec.rb b/spec/unit/models/multi_channel_error_spec.rb new file mode 100644 index 00000000..1e7786fc --- /dev/null +++ b/spec/unit/models/multi_channel_error_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::MultiChannelError +describe Bandwidth::MultiChannelError do + let(:multi_channel_error_default) { Bandwidth::MultiChannelError.new } + let(:multi_channel_error_values) { Bandwidth::MultiChannelError.new({ + links: [Bandwidth::Link.new({ rel: 'next', href: 'https://example.com/next' })], + data: { someKey: 'someValue' }, + errors: [Bandwidth::ErrorObject.new({ type: 'invalid', description: 'Something went wrong', source: { parameter: 'foo' } })] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelError.acceptable_attributes).to eq(Bandwidth::MultiChannelError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::MultiChannelError.openapi_nullable).to eq(Set.new([:'data'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelError created by the build_from_hash method' do + multi_channel_error_from_hash = Bandwidth::MultiChannelError.build_from_hash({ + links: [{ rel: 'next', href: 'https://example.com/next' }], + data: { someKey: 'someValue' }, + errors: [{ type: 'invalid', description: 'Something went wrong', source: { parameter: 'foo' } }] + }) + expect(multi_channel_error_from_hash).to be_instance_of(Bandwidth::MultiChannelError) + expect(multi_channel_error_from_hash.links.first).to be_instance_of(Bandwidth::Link) + expect(multi_channel_error_from_hash.links.first.rel).to eq('next') + expect(multi_channel_error_from_hash.links.first.href).to eq('https://example.com/next') + expect(multi_channel_error_from_hash.data).to eq({ someKey: 'someValue' }) + expect(multi_channel_error_from_hash.errors.first).to be_instance_of(Bandwidth::ErrorObject) + expect(multi_channel_error_from_hash.errors.first.type).to eq('invalid') + expect(multi_channel_error_from_hash.errors.first.description).to eq('Something went wrong') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_error_values.to_s).to eq('{:links=>[{:rel=>"next", :href=>"https://example.com/next"}], :data=>{:someKey=>"someValue"}, :errors=>[{:type=>"invalid", :description=>"Something went wrong", :source=>{:parameter=>"foo"}}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(multi_channel_error_default.eql?(Bandwidth::MultiChannelError.new)).to be true + expect(multi_channel_error_default.eql?(multi_channel_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_error_values.to_body).to eq({ + links: [{ rel: 'next', href: 'https://example.com/next' }], + data: { someKey: 'someValue' }, + errors: [{ type: 'invalid', description: 'Something went wrong', source: { parameter: 'foo' } }] + }) + end + end +end diff --git a/spec/unit/models/multi_channel_message_channel_enum_spec.rb b/spec/unit/models/multi_channel_message_channel_enum_spec.rb new file mode 100644 index 00000000..5a95ac95 --- /dev/null +++ b/spec/unit/models/multi_channel_message_channel_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::MultiChannelMessageChannelEnum +describe Bandwidth::MultiChannelMessageChannelEnum do + describe 'constants' do + it 'defines RBM' do + expect(Bandwidth::MultiChannelMessageChannelEnum::RBM).to eq('RBM') + end + + it 'defines SMS' do + expect(Bandwidth::MultiChannelMessageChannelEnum::SMS).to eq('SMS') + end + + it 'defines MMS' do + expect(Bandwidth::MultiChannelMessageChannelEnum::MMS).to eq('MMS') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::MultiChannelMessageChannelEnum.all_vars).to eq([ + 'RBM', + 'SMS', + 'MMS' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::MultiChannelMessageChannelEnum.build_from_hash('RBM')).to eq('RBM') + expect(Bandwidth::MultiChannelMessageChannelEnum.build_from_hash('SMS')).to eq('SMS') + expect(Bandwidth::MultiChannelMessageChannelEnum.build_from_hash('MMS')).to eq('MMS') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::MultiChannelMessageChannelEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/multi_channel_message_content_spec.rb b/spec/unit/models/multi_channel_message_content_spec.rb new file mode 100644 index 00000000..6ea9931e --- /dev/null +++ b/spec/unit/models/multi_channel_message_content_spec.rb @@ -0,0 +1,69 @@ +# Unit tests for Bandwidth::MultiChannelMessageContent +describe Bandwidth::MultiChannelMessageContent do + let(:multi_channel_message_content_default) { Bandwidth::MultiChannelMessageContent.new } + let(:multi_channel_message_content_values) { Bandwidth::MultiChannelMessageContent.new({ + text: 'Hello world', + media: Bandwidth::RbmMessageContentFile.new({ file_url: 'https://dev.bandwidth.com/images/bandwidth-logo.png' }) + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelMessageContent.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelMessageContent.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelMessageContent.acceptable_attributes).to eq(Bandwidth::MultiChannelMessageContent.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelMessageContent.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelMessageContent created by the build_from_hash method' do + multi_channel_message_content_from_hash = Bandwidth::MultiChannelMessageContent.build_from_hash({ + text: 'Hello world', + media: { fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png' } + }) + expect(multi_channel_message_content_from_hash).to be_instance_of(Bandwidth::MultiChannelMessageContent) + expect(multi_channel_message_content_from_hash.text).to eq('Hello world') + expect(multi_channel_message_content_from_hash.media).to be_instance_of(Bandwidth::RbmMessageContentFile) + expect(multi_channel_message_content_from_hash.media.file_url).to eq('https://dev.bandwidth.com/images/bandwidth-logo.png') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_message_content_values.to_s).to eq('{:text=>"Hello world", :media=>{:fileUrl=>"https://dev.bandwidth.com/images/bandwidth-logo.png"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(multi_channel_message_content_default.eql?(Bandwidth::MultiChannelMessageContent.new)).to be true + expect(multi_channel_message_content_default.eql?(multi_channel_message_content_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_message_content_values.to_body).to eq({ + text: 'Hello world', + media: { fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png' } + }) + end + end +end diff --git a/spec/unit/models/multi_channel_message_request_spec.rb b/spec/unit/models/multi_channel_message_request_spec.rb new file mode 100644 index 00000000..6a1a16a3 --- /dev/null +++ b/spec/unit/models/multi_channel_message_request_spec.rb @@ -0,0 +1,125 @@ +# Unit tests for Bandwidth::MultiChannelMessageRequest +describe Bandwidth::MultiChannelMessageRequest do + let(:sms_channel_object) { Bandwidth::MultiChannelChannelListSMSObject.new({ + from: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: Bandwidth::SmsMessageContent.new({ text: 'Hello world' }) + }) } + let(:multi_channel_message_request_default) { Bandwidth::MultiChannelMessageRequest.new({ + to: '+15554443333', + channel_list: [sms_channel_object] + }) } + let(:multi_channel_message_request_values) { Bandwidth::MultiChannelMessageRequest.new({ + to: '+19195551234', + channel_list: [sms_channel_object], + tag: 'custom tag', + priority: Bandwidth::PriorityEnum::DEFAULT, + expiration: '2024-06-16T13:45:07.160Z' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelMessageRequest.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelMessageRequest.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelMessageRequest.acceptable_attributes).to eq(Bandwidth::MultiChannelMessageRequest.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelMessageRequest.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelMessageRequest created by the build_from_hash method' do + multi_channel_message_request_from_hash = Bandwidth::MultiChannelMessageRequest.build_from_hash({ + to: '+19195551234', + channelList: [{ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: { text: 'Hello world' } + }], + tag: 'custom tag', + priority: Bandwidth::PriorityEnum::DEFAULT, + expiration: '2024-06-16T13:45:07.160Z' + }) + expect(multi_channel_message_request_from_hash).to be_instance_of(Bandwidth::MultiChannelMessageRequest) + expect(multi_channel_message_request_from_hash.to).to eq('+19195551234') + expect(multi_channel_message_request_from_hash.channel_list.first).to be_instance_of(Bandwidth::MultiChannelChannelListSMSObject) + expect(multi_channel_message_request_from_hash.tag).to eq('custom tag') + expect(multi_channel_message_request_from_hash.priority).to eq(Bandwidth::PriorityEnum::DEFAULT) + expect(multi_channel_message_request_from_hash.expiration).to eq(Time.parse('2024-06-16T13:45:07.160Z')) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_message_request_values.to_s).to eq('{:to=>"+19195551234", :channelList=>[{:from=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"SMS", :content=>{:text=>"Hello world"}}], :tag=>"custom tag", :priority=>"default", :expiration=>"2024-06-16T13:45:07.160Z"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_message_request_equal = Bandwidth::MultiChannelMessageRequest.new({ + to: '+15554443333', + channel_list: [sms_channel_object] + }) + expect(multi_channel_message_request_default.eql?(multi_channel_message_request_equal)).to be true + expect(multi_channel_message_request_default.eql?(multi_channel_message_request_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_message_request_values.to_body).to eq({ + to: '+19195551234', + channelList: [{ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: { text: 'Hello world' } + }], + tag: 'custom tag', + priority: Bandwidth::PriorityEnum::DEFAULT, + expiration: '2024-06-16T13:45:07.160Z' + }) + end + end + + describe 'custom attribute writers' do + it '#to=' do + expect { + Bandwidth::MultiChannelMessageRequest.new({}) + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#channel_list=' do + expect { + Bandwidth::MultiChannelMessageRequest.new({ to: '+15554443333' }) + }.to raise_error(ArgumentError, 'channel_list cannot be nil') + + expect { + multi_channel_message_request_values.channel_list = nil + }.to raise_error(ArgumentError, 'channel_list cannot be nil') + + expect { + multi_channel_message_request_values.channel_list = [sms_channel_object] * 5 + }.to raise_error(ArgumentError, 'invalid value for "channel_list", number of items must be less than or equal to 4.') + end + end +end diff --git a/spec/unit/models/multi_channel_message_response_data_spec.rb b/spec/unit/models/multi_channel_message_response_data_spec.rb new file mode 100644 index 00000000..a8e3d20b --- /dev/null +++ b/spec/unit/models/multi_channel_message_response_data_spec.rb @@ -0,0 +1,168 @@ +# Unit tests for Bandwidth::MultiChannelMessageResponseData +describe Bandwidth::MultiChannelMessageResponseData do + let(:sms_channel_response) { Bandwidth::MultiChannelChannelListSMSResponseObject.new({ + from: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: Bandwidth::SmsMessageContent.new({ text: 'Hello world' }), + owner: '+19195554321' + }) } + let(:multi_channel_message_response_data_default) { Bandwidth::MultiChannelMessageResponseData.new({ + id: 'baseline-id', + time: '2024-01-01T00:00:00Z', + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+15554443333'], + channel_list: [sms_channel_response] + }) } + let(:multi_channel_message_response_data_values) { Bandwidth::MultiChannelMessageResponseData.new({ + id: '1589228074636lm4k2je7j7jklbn2', + time: '2024-06-16T13:15:07.160Z', + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + channel_list: [sms_channel_response], + tag: 'custom tag', + priority: Bandwidth::PriorityEnum::DEFAULT, + expiration: '2024-06-16T13:45:07.160Z' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::MultiChannelMessageResponseData.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::MultiChannelMessageResponseData.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::MultiChannelMessageResponseData.acceptable_attributes).to eq(Bandwidth::MultiChannelMessageResponseData.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::MultiChannelMessageResponseData.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of MultiChannelMessageResponseData created by the build_from_hash method' do + multi_channel_message_response_data_from_hash = Bandwidth::MultiChannelMessageResponseData.build_from_hash({ + id: '1589228074636lm4k2je7j7jklbn2', + time: '2024-06-16T13:15:07.160Z', + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + channelList: [{ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: { text: 'Hello world' }, + owner: '+19195554321' + }], + tag: 'custom tag', + priority: Bandwidth::PriorityEnum::DEFAULT, + expiration: '2024-06-16T13:45:07.160Z' + }) + expect(multi_channel_message_response_data_from_hash).to be_instance_of(Bandwidth::MultiChannelMessageResponseData) + expect(multi_channel_message_response_data_from_hash.id).to eq('1589228074636lm4k2je7j7jklbn2') + expect(multi_channel_message_response_data_from_hash.time).to eq(Time.parse('2024-06-16T13:15:07.160Z')) + expect(multi_channel_message_response_data_from_hash.direction).to eq(Bandwidth::MessageDirectionEnum::OUT) + expect(multi_channel_message_response_data_from_hash.to).to eq(['+19195551234']) + expect(multi_channel_message_response_data_from_hash.channel_list.first).to be_instance_of(Bandwidth::MultiChannelChannelListSMSResponseObject) + expect(multi_channel_message_response_data_from_hash.tag).to eq('custom tag') + expect(multi_channel_message_response_data_from_hash.priority).to eq(Bandwidth::PriorityEnum::DEFAULT) + expect(multi_channel_message_response_data_from_hash.expiration).to eq(Time.parse('2024-06-16T13:45:07.160Z')) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(multi_channel_message_response_data_values.to_s).to eq('{:id=>"1589228074636lm4k2je7j7jklbn2", :time=>"2024-06-16T13:15:07.160Z", :direction=>"out", :to=>["+19195551234"], :channelList=>[{:from=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :channel=>"SMS", :content=>{:text=>"Hello world"}, :owner=>"+19195554321"}], :tag=>"custom tag", :priority=>"default", :expiration=>"2024-06-16T13:45:07.160Z"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + multi_channel_message_response_data_equal = Bandwidth::MultiChannelMessageResponseData.new({ + id: 'baseline-id', + time: '2024-01-01T00:00:00Z', + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+15554443333'], + channel_list: [sms_channel_response] + }) + expect(multi_channel_message_response_data_default.eql?(multi_channel_message_response_data_equal)).to be true + expect(multi_channel_message_response_data_default.eql?(multi_channel_message_response_data_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(multi_channel_message_response_data_values.to_body).to eq({ + id: '1589228074636lm4k2je7j7jklbn2', + time: '2024-06-16T13:15:07.160Z', + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + channelList: [{ + from: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS, + content: { text: 'Hello world' }, + owner: '+19195554321' + }], + tag: 'custom tag', + priority: Bandwidth::PriorityEnum::DEFAULT, + expiration: '2024-06-16T13:45:07.160Z' + }) + end + end + + describe 'custom attribute writers' do + it '#id=' do + expect { + Bandwidth::MultiChannelMessageResponseData.new({ id: nil }) + }.to raise_error(ArgumentError, 'id cannot be nil') + end + + it '#time=' do + expect { + Bandwidth::MultiChannelMessageResponseData.new({ id: 'a', time: nil }) + }.to raise_error(ArgumentError, 'time cannot be nil') + end + + it '#direction=' do + expect { + Bandwidth::MultiChannelMessageResponseData.new({ id: 'a', time: 't', direction: nil }) + }.to raise_error(ArgumentError, 'direction cannot be nil') + end + + it '#to=' do + expect { + Bandwidth::MultiChannelMessageResponseData.new({ id: 'a', time: 't', direction: 'out' }) + }.to raise_error(ArgumentError, 'to cannot be nil') + + expect { + multi_channel_message_response_data_values.to = nil + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#channel_list=' do + expect { + Bandwidth::MultiChannelMessageResponseData.new({ id: 'a', time: 't', direction: 'out', to: ['x'] }) + }.to raise_error(ArgumentError, 'channel_list cannot be nil') + + expect { + multi_channel_message_response_data_values.channel_list = nil + }.to raise_error(ArgumentError, 'channel_list cannot be nil') + + expect { + multi_channel_message_response_data_values.channel_list = [sms_channel_response] * 5 + }.to raise_error(ArgumentError, 'invalid value for "channel_list", number of items must be less than or equal to 4.') + end + end +end diff --git a/spec/unit/models/opt_in_workflow_spec.rb b/spec/unit/models/opt_in_workflow_spec.rb new file mode 100644 index 00000000..2efe8fba --- /dev/null +++ b/spec/unit/models/opt_in_workflow_spec.rb @@ -0,0 +1,111 @@ +# Unit tests for Bandwidth::OptInWorkflow +describe Bandwidth::OptInWorkflow do + let(:opt_in_workflow_default) { Bandwidth::OptInWorkflow.new({ + description: 'baseline description', + image_urls: ['https://example.com/baseline.png'] + }) } + let(:opt_in_workflow_values) { Bandwidth::OptInWorkflow.new({ + description: 'A description of the opt in workflow', + image_urls: ['https://example.com/image1.png', 'https://example.com/image2.png'], + confirmation_response: 'Thanks for opting in!' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::OptInWorkflow.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::OptInWorkflow.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::OptInWorkflow.acceptable_attributes).to eq(Bandwidth::OptInWorkflow.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::OptInWorkflow.openapi_nullable).to eq(Set.new([:'confirmation_response'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of OptInWorkflow created by the build_from_hash method' do + opt_in_workflow_from_hash = Bandwidth::OptInWorkflow.build_from_hash({ + description: 'A description of the opt in workflow', + imageUrls: ['https://example.com/image1.png', 'https://example.com/image2.png'], + confirmationResponse: 'Thanks for opting in!' + }) + expect(opt_in_workflow_from_hash).to be_instance_of(Bandwidth::OptInWorkflow) + expect(opt_in_workflow_from_hash.description).to eq('A description of the opt in workflow') + expect(opt_in_workflow_from_hash.image_urls).to eq(['https://example.com/image1.png', 'https://example.com/image2.png']) + expect(opt_in_workflow_from_hash.confirmation_response).to eq('Thanks for opting in!') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(opt_in_workflow_values.to_s).to eq('{:description=>"A description of the opt in workflow", :imageUrls=>["https://example.com/image1.png", "https://example.com/image2.png"], :confirmationResponse=>"Thanks for opting in!"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + opt_in_workflow_equal = Bandwidth::OptInWorkflow.new({ + description: 'baseline description', + image_urls: ['https://example.com/baseline.png'] + }) + expect(opt_in_workflow_default.eql?(opt_in_workflow_equal)).to be true + expect(opt_in_workflow_default.eql?(opt_in_workflow_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(opt_in_workflow_values.to_body).to eq({ + description: 'A description of the opt in workflow', + imageUrls: ['https://example.com/image1.png', 'https://example.com/image2.png'], + confirmationResponse: 'Thanks for opting in!' + }) + end + end + + describe 'custom attribute writers' do + it '#description=' do + expect { + Bandwidth::OptInWorkflow.new({ description: nil }) + }.to raise_error(ArgumentError, 'description cannot be nil') + + expect { + Bandwidth::OptInWorkflow.new({ description: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 500.') + + expect { + Bandwidth::OptInWorkflow.new({ description: '' }) + }.to raise_error(ArgumentError, 'invalid value for "description", the character length must be greater than or equal to 1.') + end + + it '#image_urls=' do + expect { + Bandwidth::OptInWorkflow.new({ description: 'a' }) + }.to raise_error(ArgumentError, 'image_urls cannot be nil') + + expect { + opt_in_workflow_values.image_urls = nil + }.to raise_error(ArgumentError, 'image_urls cannot be nil') + end + + it '#confirmation_response=' do + expect { + opt_in_workflow_values.confirmation_response = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "confirmation_response", the character length must be smaller than or equal to 500.') + end + end +end diff --git a/spec/unit/models/page_info_spec.rb b/spec/unit/models/page_info_spec.rb new file mode 100644 index 00000000..eb08b34c --- /dev/null +++ b/spec/unit/models/page_info_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::PageInfo +describe Bandwidth::PageInfo do + let(:page_info_default) { Bandwidth::PageInfo.new } + let(:page_info_values) { Bandwidth::PageInfo.new({ + prev_page: 'https://example.com/prev', + next_page: 'https://example.com/next', + prev_page_token: 'prev-token', + next_page_token: 'next-token' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::PageInfo.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::PageInfo.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::PageInfo.acceptable_attributes).to eq(Bandwidth::PageInfo.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::PageInfo.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of PageInfo created by the build_from_hash method' do + page_info_from_hash = Bandwidth::PageInfo.build_from_hash({ + prevPage: 'https://example.com/prev', + nextPage: 'https://example.com/next', + prevPageToken: 'prev-token', + nextPageToken: 'next-token' + }) + expect(page_info_from_hash).to be_instance_of(Bandwidth::PageInfo) + expect(page_info_from_hash.prev_page).to eq('https://example.com/prev') + expect(page_info_from_hash.next_page).to eq('https://example.com/next') + expect(page_info_from_hash.prev_page_token).to eq('prev-token') + expect(page_info_from_hash.next_page_token).to eq('next-token') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(page_info_values.to_s).to eq('{:prevPage=>"https://example.com/prev", :nextPage=>"https://example.com/next", :prevPageToken=>"prev-token", :nextPageToken=>"next-token"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(page_info_default.eql?(Bandwidth::PageInfo.new)).to be true + expect(page_info_default.eql?(page_info_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(page_info_values.to_body).to eq({ + prevPage: 'https://example.com/prev', + nextPage: 'https://example.com/next', + prevPageToken: 'prev-token', + nextPageToken: 'next-token' + }) + end + end +end diff --git a/spec/unit/models/page_spec.rb b/spec/unit/models/page_spec.rb new file mode 100644 index 00000000..fb0705bc --- /dev/null +++ b/spec/unit/models/page_spec.rb @@ -0,0 +1,121 @@ +# Unit tests for Bandwidth::Page +describe Bandwidth::Page do + let(:page_default) { Bandwidth::Page.new({ + page_size: 25 + }) } + let(:page_values) { Bandwidth::Page.new({ + page_size: 100, + total_elements: 250, + total_pages: 3, + page_number: 1 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Page.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Page.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Page.acceptable_attributes).to eq(Bandwidth::Page.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Page.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Page created by the build_from_hash method' do + page_from_hash = Bandwidth::Page.build_from_hash({ + pageSize: 100, + totalElements: 250, + totalPages: 3, + pageNumber: 1 + }) + expect(page_from_hash).to be_instance_of(Bandwidth::Page) + expect(page_from_hash.page_size).to eq(100) + expect(page_from_hash.total_elements).to eq(250) + expect(page_from_hash.total_pages).to eq(3) + expect(page_from_hash.page_number).to eq(1) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(page_values.to_s).to eq('{:pageSize=>100, :totalElements=>250, :totalPages=>3, :pageNumber=>1}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + page_equal = Bandwidth::Page.new({ page_size: 25 }) + expect(page_default.eql?(page_equal)).to be true + expect(page_default.eql?(page_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(page_values.to_body).to eq({ + pageSize: 100, + totalElements: 250, + totalPages: 3, + pageNumber: 1 + }) + end + end + + describe 'custom attribute writers' do + it '#page_size=' do + expect { + Bandwidth::Page.new({ page_size: nil }) + }.to raise_error(ArgumentError, 'page_size cannot be nil') + + expect { + Bandwidth::Page.new({ page_size: -1 }) + }.to raise_error(ArgumentError, 'invalid value for "page_size", must be greater than or equal to 0.') + end + + it '#total_elements=' do + expect { + page_values.total_elements = nil + }.to raise_error(ArgumentError, 'total_elements cannot be nil') + + expect { + page_values.total_elements = -1 + }.to raise_error(ArgumentError, 'invalid value for "total_elements", must be greater than or equal to 0.') + end + + it '#total_pages=' do + expect { + page_values.total_pages = nil + }.to raise_error(ArgumentError, 'total_pages cannot be nil') + + expect { + page_values.total_pages = -1 + }.to raise_error(ArgumentError, 'invalid value for "total_pages", must be greater than or equal to 0.') + end + + it '#page_number=' do + expect { + page_values.page_number = nil + }.to raise_error(ArgumentError, 'page_number cannot be nil') + + expect { + page_values.page_number = -1 + }.to raise_error(ArgumentError, 'invalid value for "page_number", must be greater than or equal to 0.') + end + end +end diff --git a/spec/unit/models/priority_enum_spec.rb b/spec/unit/models/priority_enum_spec.rb new file mode 100644 index 00000000..00518530 --- /dev/null +++ b/spec/unit/models/priority_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::PriorityEnum +describe Bandwidth::PriorityEnum do + describe 'constants' do + it 'defines DEFAULT' do + expect(Bandwidth::PriorityEnum::DEFAULT).to eq('default') + end + + it 'defines HIGH' do + expect(Bandwidth::PriorityEnum::HIGH).to eq('high') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::PriorityEnum.all_vars).to eq([ + 'default', + 'high' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::PriorityEnum.build_from_hash('default')).to eq('default') + expect(Bandwidth::PriorityEnum.build_from_hash('high')).to eq('high') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::PriorityEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/product_type_enum_spec.rb b/spec/unit/models/product_type_enum_spec.rb new file mode 100644 index 00000000..eeefe574 --- /dev/null +++ b/spec/unit/models/product_type_enum_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::ProductTypeEnum +describe Bandwidth::ProductTypeEnum do + describe 'constants' do + it 'defines LOCAL_A2_P' do + expect(Bandwidth::ProductTypeEnum::LOCAL_A2_P).to eq('LOCAL_A2P') + end + + it 'defines P2_P' do + expect(Bandwidth::ProductTypeEnum::P2_P).to eq('P2P') + end + + it 'defines SHORT_CODE_REACH' do + expect(Bandwidth::ProductTypeEnum::SHORT_CODE_REACH).to eq('SHORT_CODE_REACH') + end + + it 'defines TOLL_FREE' do + expect(Bandwidth::ProductTypeEnum::TOLL_FREE).to eq('TOLL_FREE') + end + + it 'defines HOSTED_SHORT_CODE' do + expect(Bandwidth::ProductTypeEnum::HOSTED_SHORT_CODE).to eq('HOSTED_SHORT_CODE') + end + + it 'defines ALPHA_NUMERIC' do + expect(Bandwidth::ProductTypeEnum::ALPHA_NUMERIC).to eq('ALPHA_NUMERIC') + end + + it 'defines RBM_MEDIA' do + expect(Bandwidth::ProductTypeEnum::RBM_MEDIA).to eq('RBM_MEDIA') + end + + it 'defines RBM_RICH' do + expect(Bandwidth::ProductTypeEnum::RBM_RICH).to eq('RBM_RICH') + end + + it 'defines RBM_CONVERSATIONAL' do + expect(Bandwidth::ProductTypeEnum::RBM_CONVERSATIONAL).to eq('RBM_CONVERSATIONAL') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::ProductTypeEnum.all_vars).to eq([ + 'LOCAL_A2P', + 'P2P', + 'SHORT_CODE_REACH', + 'TOLL_FREE', + 'HOSTED_SHORT_CODE', + 'ALPHA_NUMERIC', + 'RBM_MEDIA', + 'RBM_RICH', + 'RBM_CONVERSATIONAL' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::ProductTypeEnum.build_from_hash('LOCAL_A2P')).to eq('LOCAL_A2P') + expect(Bandwidth::ProductTypeEnum.build_from_hash('P2P')).to eq('P2P') + expect(Bandwidth::ProductTypeEnum.build_from_hash('SHORT_CODE_REACH')).to eq('SHORT_CODE_REACH') + expect(Bandwidth::ProductTypeEnum.build_from_hash('TOLL_FREE')).to eq('TOLL_FREE') + expect(Bandwidth::ProductTypeEnum.build_from_hash('HOSTED_SHORT_CODE')).to eq('HOSTED_SHORT_CODE') + expect(Bandwidth::ProductTypeEnum.build_from_hash('ALPHA_NUMERIC')).to eq('ALPHA_NUMERIC') + expect(Bandwidth::ProductTypeEnum.build_from_hash('RBM_MEDIA')).to eq('RBM_MEDIA') + expect(Bandwidth::ProductTypeEnum.build_from_hash('RBM_RICH')).to eq('RBM_RICH') + expect(Bandwidth::ProductTypeEnum.build_from_hash('RBM_CONVERSATIONAL')).to eq('RBM_CONVERSATIONAL') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::ProductTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/rbm_action_base_spec.rb b/spec/unit/models/rbm_action_base_spec.rb new file mode 100644 index 00000000..7609cb91 --- /dev/null +++ b/spec/unit/models/rbm_action_base_spec.rb @@ -0,0 +1,109 @@ +# Unit tests for Bandwidth::RbmActionBase +describe Bandwidth::RbmActionBase do + let(:rbm_action_base_default) { Bandwidth::RbmActionBase.new({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'baseline', + postback_data: 'baseline_postback' + }) } + let(:rbm_action_base_values) { Bandwidth::RbmActionBase.new({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'Yes', + postback_data: 'reply_yes' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmActionBase.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmActionBase.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmActionBase.acceptable_attributes).to eq(Bandwidth::RbmActionBase.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmActionBase.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmActionBase created by the build_from_hash method' do + rbm_action_base_from_hash = Bandwidth::RbmActionBase.build_from_hash({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'Yes', + postbackData: 'reply_yes' + }) + expect(rbm_action_base_from_hash).to be_instance_of(Bandwidth::RbmActionBase) + expect(rbm_action_base_from_hash.type).to eq(Bandwidth::RbmActionTypeEnum::REPLY) + expect(rbm_action_base_from_hash.text).to eq('Yes') + expect(rbm_action_base_from_hash.postback_data).to eq('reply_yes') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_action_base_values.to_s).to eq('{:type=>"REPLY", :text=>"Yes", :postbackData=>"reply_yes"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_action_base_equal = Bandwidth::RbmActionBase.new({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'baseline', + postback_data: 'baseline_postback' + }) + expect(rbm_action_base_default.eql?(rbm_action_base_equal)).to be true + expect(rbm_action_base_default.eql?(rbm_action_base_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_action_base_values.to_body).to eq({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'Yes', + postbackData: 'reply_yes' + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::RbmActionBase.new({ type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#text=' do + expect { + Bandwidth::RbmActionBase.new({ type: 'REPLY', text: nil }) + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + Bandwidth::RbmActionBase.new({ type: 'REPLY', text: 'a' * 26 }) + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 25.') + end + + it '#postback_data=' do + expect { + Bandwidth::RbmActionBase.new({ type: 'REPLY', text: 'a', postback_data: nil }) + }.to raise_error(ArgumentError, 'postback_data cannot be nil') + + expect { + Bandwidth::RbmActionBase.new({ type: 'REPLY', text: 'a', postback_data: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "postback_data", the character length must be smaller than or equal to 2048.') + end + end +end diff --git a/spec/unit/models/rbm_action_dial_spec.rb b/spec/unit/models/rbm_action_dial_spec.rb new file mode 100644 index 00000000..9b8f32b2 --- /dev/null +++ b/spec/unit/models/rbm_action_dial_spec.rb @@ -0,0 +1,121 @@ +# Unit tests for Bandwidth::RbmActionDial +describe Bandwidth::RbmActionDial do + let(:rbm_action_dial_default) { Bandwidth::RbmActionDial.new({ + type: Bandwidth::RbmActionTypeEnum::DIAL_PHONE, + text: 'baseline', + postback_data: 'baseline_postback', + phone_number: '+15554443333' + }) } + let(:rbm_action_dial_values) { Bandwidth::RbmActionDial.new({ + type: Bandwidth::RbmActionTypeEnum::DIAL_PHONE, + text: 'Call us', + postback_data: 'dial_postback', + phone_number: '+19195554321' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmActionDial.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmActionDial.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmActionDial.acceptable_attributes).to eq(Bandwidth::RbmActionDial.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmActionDial.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmActionDial created by the build_from_hash method' do + rbm_action_dial_from_hash = Bandwidth::RbmActionDial.build_from_hash({ + type: Bandwidth::RbmActionTypeEnum::DIAL_PHONE, + text: 'Call us', + postbackData: 'dial_postback', + phoneNumber: '+19195554321' + }) + expect(rbm_action_dial_from_hash).to be_instance_of(Bandwidth::RbmActionDial) + expect(rbm_action_dial_from_hash.type).to eq(Bandwidth::RbmActionTypeEnum::DIAL_PHONE) + expect(rbm_action_dial_from_hash.text).to eq('Call us') + expect(rbm_action_dial_from_hash.postback_data).to eq('dial_postback') + expect(rbm_action_dial_from_hash.phone_number).to eq('+19195554321') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_action_dial_values.to_s).to eq('{:type=>"DIAL_PHONE", :text=>"Call us", :postbackData=>"dial_postback", :phoneNumber=>"+19195554321"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_action_dial_equal = Bandwidth::RbmActionDial.new({ + type: Bandwidth::RbmActionTypeEnum::DIAL_PHONE, + text: 'baseline', + postback_data: 'baseline_postback', + phone_number: '+15554443333' + }) + expect(rbm_action_dial_default.eql?(rbm_action_dial_equal)).to be true + expect(rbm_action_dial_default.eql?(rbm_action_dial_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_action_dial_values.to_body).to eq({ + type: Bandwidth::RbmActionTypeEnum::DIAL_PHONE, + text: 'Call us', + postbackData: 'dial_postback', + phoneNumber: '+19195554321' + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::RbmActionDial.new({ type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#text=' do + expect { + Bandwidth::RbmActionDial.new({ type: 'DIAL_PHONE', text: nil }) + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + Bandwidth::RbmActionDial.new({ type: 'DIAL_PHONE', text: 'a' * 26 }) + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 25.') + end + + it '#postback_data=' do + expect { + Bandwidth::RbmActionDial.new({ type: 'DIAL_PHONE', text: 'a', postback_data: nil }) + }.to raise_error(ArgumentError, 'postback_data cannot be nil') + + expect { + Bandwidth::RbmActionDial.new({ type: 'DIAL_PHONE', text: 'a', postback_data: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "postback_data", the character length must be smaller than or equal to 2048.') + end + + it '#phone_number=' do + expect { + Bandwidth::RbmActionDial.new({ type: 'DIAL_PHONE', text: 'a', postback_data: 'a', phone_number: nil }) + }.to raise_error(ArgumentError, 'phone_number cannot be nil') + end + end +end diff --git a/spec/unit/models/rbm_action_open_url_spec.rb b/spec/unit/models/rbm_action_open_url_spec.rb new file mode 100644 index 00000000..edef569b --- /dev/null +++ b/spec/unit/models/rbm_action_open_url_spec.rb @@ -0,0 +1,133 @@ +# Unit tests for Bandwidth::RbmActionOpenUrl +describe Bandwidth::RbmActionOpenUrl do + let(:rbm_action_open_url_default) { Bandwidth::RbmActionOpenUrl.new({ + type: Bandwidth::RbmActionTypeEnum::OPEN_URL, + text: 'baseline', + postback_data: 'baseline_postback', + url: 'https://example.com/baseline' + }) } + let(:rbm_action_open_url_values) { Bandwidth::RbmActionOpenUrl.new({ + type: Bandwidth::RbmActionTypeEnum::OPEN_URL, + text: 'Open URL', + postback_data: 'open_url_postback', + url: 'https://example.com', + application: Bandwidth::RbmOpenUrlEnum::BROWSER, + webview_view_mode: Bandwidth::RbmWebViewEnum::FULL + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmActionOpenUrl.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmActionOpenUrl.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmActionOpenUrl.acceptable_attributes).to eq(Bandwidth::RbmActionOpenUrl.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmActionOpenUrl.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmActionOpenUrl created by the build_from_hash method' do + rbm_action_open_url_from_hash = Bandwidth::RbmActionOpenUrl.build_from_hash({ + type: Bandwidth::RbmActionTypeEnum::OPEN_URL, + text: 'Open URL', + postbackData: 'open_url_postback', + url: 'https://example.com', + application: Bandwidth::RbmOpenUrlEnum::BROWSER, + webviewViewMode: Bandwidth::RbmWebViewEnum::FULL + }) + expect(rbm_action_open_url_from_hash).to be_instance_of(Bandwidth::RbmActionOpenUrl) + expect(rbm_action_open_url_from_hash.type).to eq(Bandwidth::RbmActionTypeEnum::OPEN_URL) + expect(rbm_action_open_url_from_hash.text).to eq('Open URL') + expect(rbm_action_open_url_from_hash.postback_data).to eq('open_url_postback') + expect(rbm_action_open_url_from_hash.url).to eq('https://example.com') + expect(rbm_action_open_url_from_hash.application).to eq(Bandwidth::RbmOpenUrlEnum::BROWSER) + expect(rbm_action_open_url_from_hash.webview_view_mode).to eq(Bandwidth::RbmWebViewEnum::FULL) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_action_open_url_values.to_s).to eq('{:type=>"OPEN_URL", :text=>"Open URL", :postbackData=>"open_url_postback", :url=>"https://example.com", :application=>"BROWSER", :webviewViewMode=>"FULL"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_action_open_url_equal = Bandwidth::RbmActionOpenUrl.new({ + type: Bandwidth::RbmActionTypeEnum::OPEN_URL, + text: 'baseline', + postback_data: 'baseline_postback', + url: 'https://example.com/baseline' + }) + expect(rbm_action_open_url_default.eql?(rbm_action_open_url_equal)).to be true + expect(rbm_action_open_url_default.eql?(rbm_action_open_url_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_action_open_url_values.to_body).to eq({ + type: Bandwidth::RbmActionTypeEnum::OPEN_URL, + text: 'Open URL', + postbackData: 'open_url_postback', + url: 'https://example.com', + application: Bandwidth::RbmOpenUrlEnum::BROWSER, + webviewViewMode: Bandwidth::RbmWebViewEnum::FULL + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::RbmActionOpenUrl.new({ type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#text=' do + expect { + Bandwidth::RbmActionOpenUrl.new({ type: 'OPEN_URL', text: nil }) + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + Bandwidth::RbmActionOpenUrl.new({ type: 'OPEN_URL', text: 'a' * 26 }) + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 25.') + end + + it '#postback_data=' do + expect { + Bandwidth::RbmActionOpenUrl.new({ type: 'OPEN_URL', text: 'a', postback_data: nil }) + }.to raise_error(ArgumentError, 'postback_data cannot be nil') + + expect { + Bandwidth::RbmActionOpenUrl.new({ type: 'OPEN_URL', text: 'a', postback_data: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "postback_data", the character length must be smaller than or equal to 2048.') + end + + it '#url=' do + expect { + Bandwidth::RbmActionOpenUrl.new({ type: 'OPEN_URL', text: 'a', postback_data: 'a', url: nil }) + }.to raise_error(ArgumentError, 'url cannot be nil') + + expect { + Bandwidth::RbmActionOpenUrl.new({ type: 'OPEN_URL', text: 'a', postback_data: 'a', url: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "url", the character length must be smaller than or equal to 2048.') + end + end +end diff --git a/spec/unit/models/rbm_action_type_enum_spec.rb b/spec/unit/models/rbm_action_type_enum_spec.rb new file mode 100644 index 00000000..e0e9a2ec --- /dev/null +++ b/spec/unit/models/rbm_action_type_enum_spec.rb @@ -0,0 +1,58 @@ +# Unit tests for Bandwidth::RbmActionTypeEnum +describe Bandwidth::RbmActionTypeEnum do + describe 'constants' do + it 'defines REPLY' do + expect(Bandwidth::RbmActionTypeEnum::REPLY).to eq('REPLY') + end + + it 'defines DIAL_PHONE' do + expect(Bandwidth::RbmActionTypeEnum::DIAL_PHONE).to eq('DIAL_PHONE') + end + + it 'defines SHOW_LOCATION' do + expect(Bandwidth::RbmActionTypeEnum::SHOW_LOCATION).to eq('SHOW_LOCATION') + end + + it 'defines CREATE_CALENDAR_EVENT' do + expect(Bandwidth::RbmActionTypeEnum::CREATE_CALENDAR_EVENT).to eq('CREATE_CALENDAR_EVENT') + end + + it 'defines OPEN_URL' do + expect(Bandwidth::RbmActionTypeEnum::OPEN_URL).to eq('OPEN_URL') + end + + it 'defines REQUEST_LOCATION' do + expect(Bandwidth::RbmActionTypeEnum::REQUEST_LOCATION).to eq('REQUEST_LOCATION') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::RbmActionTypeEnum.all_vars).to eq([ + 'REPLY', + 'DIAL_PHONE', + 'SHOW_LOCATION', + 'CREATE_CALENDAR_EVENT', + 'OPEN_URL', + 'REQUEST_LOCATION' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::RbmActionTypeEnum.build_from_hash('REPLY')).to eq('REPLY') + expect(Bandwidth::RbmActionTypeEnum.build_from_hash('DIAL_PHONE')).to eq('DIAL_PHONE') + expect(Bandwidth::RbmActionTypeEnum.build_from_hash('SHOW_LOCATION')).to eq('SHOW_LOCATION') + expect(Bandwidth::RbmActionTypeEnum.build_from_hash('CREATE_CALENDAR_EVENT')).to eq('CREATE_CALENDAR_EVENT') + expect(Bandwidth::RbmActionTypeEnum.build_from_hash('OPEN_URL')).to eq('OPEN_URL') + expect(Bandwidth::RbmActionTypeEnum.build_from_hash('REQUEST_LOCATION')).to eq('REQUEST_LOCATION') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::RbmActionTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/rbm_action_view_location_spec.rb b/spec/unit/models/rbm_action_view_location_spec.rb new file mode 100644 index 00000000..aae37247 --- /dev/null +++ b/spec/unit/models/rbm_action_view_location_spec.rb @@ -0,0 +1,147 @@ +# Unit tests for Bandwidth::RbmActionViewLocation +describe Bandwidth::RbmActionViewLocation do + let(:rbm_action_view_location_default) { Bandwidth::RbmActionViewLocation.new({ + type: Bandwidth::RbmActionTypeEnum::SHOW_LOCATION, + text: 'baseline', + postback_data: 'baseline_postback', + latitude: 0.0, + longitude: 0.0 + }) } + let(:rbm_action_view_location_values) { Bandwidth::RbmActionViewLocation.new({ + type: Bandwidth::RbmActionTypeEnum::SHOW_LOCATION, + text: 'View location', + postback_data: 'location_postback', + latitude: 35.7796, + longitude: -78.6382, + label: 'Bandwidth HQ' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmActionViewLocation.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmActionViewLocation.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmActionViewLocation.acceptable_attributes).to eq(Bandwidth::RbmActionViewLocation.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmActionViewLocation.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmActionViewLocation created by the build_from_hash method' do + rbm_action_view_location_from_hash = Bandwidth::RbmActionViewLocation.build_from_hash({ + type: Bandwidth::RbmActionTypeEnum::SHOW_LOCATION, + text: 'View location', + postbackData: 'location_postback', + latitude: 35.7796, + longitude: -78.6382, + label: 'Bandwidth HQ' + }) + expect(rbm_action_view_location_from_hash).to be_instance_of(Bandwidth::RbmActionViewLocation) + expect(rbm_action_view_location_from_hash.type).to eq(Bandwidth::RbmActionTypeEnum::SHOW_LOCATION) + expect(rbm_action_view_location_from_hash.text).to eq('View location') + expect(rbm_action_view_location_from_hash.postback_data).to eq('location_postback') + expect(rbm_action_view_location_from_hash.latitude).to eq(35.7796) + expect(rbm_action_view_location_from_hash.longitude).to eq(-78.6382) + expect(rbm_action_view_location_from_hash.label).to eq('Bandwidth HQ') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_action_view_location_values.to_s).to eq('{:type=>"SHOW_LOCATION", :text=>"View location", :postbackData=>"location_postback", :latitude=>35.7796, :longitude=>-78.6382, :label=>"Bandwidth HQ"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_action_view_location_equal = Bandwidth::RbmActionViewLocation.new({ + type: Bandwidth::RbmActionTypeEnum::SHOW_LOCATION, + text: 'baseline', + postback_data: 'baseline_postback', + latitude: 0.0, + longitude: 0.0 + }) + expect(rbm_action_view_location_default.eql?(rbm_action_view_location_equal)).to be true + expect(rbm_action_view_location_default.eql?(rbm_action_view_location_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_action_view_location_values.to_body).to eq({ + type: Bandwidth::RbmActionTypeEnum::SHOW_LOCATION, + text: 'View location', + postbackData: 'location_postback', + latitude: 35.7796, + longitude: -78.6382, + label: 'Bandwidth HQ' + }) + end + end + + describe 'custom attribute writers' do + it '#type=' do + expect { + Bandwidth::RbmActionViewLocation.new({ type: nil }) + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#text=' do + expect { + Bandwidth::RbmActionViewLocation.new({ type: 'SHOW_LOCATION', text: nil }) + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + Bandwidth::RbmActionViewLocation.new({ type: 'SHOW_LOCATION', text: 'a' * 26 }) + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 25.') + end + + it '#postback_data=' do + expect { + Bandwidth::RbmActionViewLocation.new({ type: 'SHOW_LOCATION', text: 'a', postback_data: nil }) + }.to raise_error(ArgumentError, 'postback_data cannot be nil') + + expect { + Bandwidth::RbmActionViewLocation.new({ type: 'SHOW_LOCATION', text: 'a', postback_data: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "postback_data", the character length must be smaller than or equal to 2048.') + end + + it '#latitude=' do + expect { + Bandwidth::RbmActionViewLocation.new({ type: 'SHOW_LOCATION', text: 'a', postback_data: 'a', latitude: nil }) + }.to raise_error(ArgumentError, 'latitude cannot be nil') + end + + it '#longitude=' do + expect { + Bandwidth::RbmActionViewLocation.new({ type: 'SHOW_LOCATION', text: 'a', postback_data: 'a', latitude: 0.0, longitude: nil }) + }.to raise_error(ArgumentError, 'longitude cannot be nil') + end + + it '#label=' do + expect { + rbm_action_view_location_values.label = nil + }.to raise_error(ArgumentError, 'label cannot be nil') + + expect { + rbm_action_view_location_values.label = 'a' * 101 + }.to raise_error(ArgumentError, 'invalid value for "label", the character length must be smaller than or equal to 100.') + end + end +end diff --git a/spec/unit/models/rbm_card_content_media_spec.rb b/spec/unit/models/rbm_card_content_media_spec.rb new file mode 100644 index 00000000..aea6a132 --- /dev/null +++ b/spec/unit/models/rbm_card_content_media_spec.rb @@ -0,0 +1,107 @@ +# Unit tests for Bandwidth::RbmCardContentMedia +describe Bandwidth::RbmCardContentMedia do + let(:rbm_card_content_media_default) { Bandwidth::RbmCardContentMedia.new({ + file_url: 'https://example.com/baseline.png', + height: Bandwidth::RbmMediaHeightEnum::SHORT + }) } + let(:rbm_card_content_media_values) { Bandwidth::RbmCardContentMedia.new({ + file_url: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + thumbnail_url: 'https://dev.bandwidth.com/images/bandwidth-logo-thumb.png', + height: Bandwidth::RbmMediaHeightEnum::MEDIUM + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmCardContentMedia.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmCardContentMedia.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmCardContentMedia.acceptable_attributes).to eq(Bandwidth::RbmCardContentMedia.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmCardContentMedia.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmCardContentMedia created by the build_from_hash method' do + rbm_card_content_media_from_hash = Bandwidth::RbmCardContentMedia.build_from_hash({ + fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + thumbnailUrl: 'https://dev.bandwidth.com/images/bandwidth-logo-thumb.png', + height: Bandwidth::RbmMediaHeightEnum::MEDIUM + }) + expect(rbm_card_content_media_from_hash).to be_instance_of(Bandwidth::RbmCardContentMedia) + expect(rbm_card_content_media_from_hash.file_url).to eq('https://dev.bandwidth.com/images/bandwidth-logo.png') + expect(rbm_card_content_media_from_hash.thumbnail_url).to eq('https://dev.bandwidth.com/images/bandwidth-logo-thumb.png') + expect(rbm_card_content_media_from_hash.height).to eq(Bandwidth::RbmMediaHeightEnum::MEDIUM) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_card_content_media_values.to_s).to eq('{:fileUrl=>"https://dev.bandwidth.com/images/bandwidth-logo.png", :thumbnailUrl=>"https://dev.bandwidth.com/images/bandwidth-logo-thumb.png", :height=>"MEDIUM"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_card_content_media_equal = Bandwidth::RbmCardContentMedia.new({ + file_url: 'https://example.com/baseline.png', + height: Bandwidth::RbmMediaHeightEnum::SHORT + }) + expect(rbm_card_content_media_default.eql?(rbm_card_content_media_equal)).to be true + expect(rbm_card_content_media_default.eql?(rbm_card_content_media_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_card_content_media_values.to_body).to eq({ + fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + thumbnailUrl: 'https://dev.bandwidth.com/images/bandwidth-logo-thumb.png', + height: Bandwidth::RbmMediaHeightEnum::MEDIUM + }) + end + end + + describe 'custom attribute writers' do + it '#file_url=' do + expect { + Bandwidth::RbmCardContentMedia.new({ file_url: nil }) + }.to raise_error(ArgumentError, 'file_url cannot be nil') + + expect { + Bandwidth::RbmCardContentMedia.new({ file_url: 'a' * 1001 }) + }.to raise_error(ArgumentError, 'invalid value for "file_url", the character length must be smaller than or equal to 1000.') + end + + it '#thumbnail_url=' do + expect { + rbm_card_content_media_values.thumbnail_url = nil + }.to raise_error(ArgumentError, 'thumbnail_url cannot be nil') + + expect { + rbm_card_content_media_values.thumbnail_url = 'a' * 1001 + }.to raise_error(ArgumentError, 'invalid value for "thumbnail_url", the character length must be smaller than or equal to 1000.') + end + + it '#height=' do + expect { + Bandwidth::RbmCardContentMedia.new({ file_url: 'a', height: nil }) + }.to raise_error(ArgumentError, 'height cannot be nil') + end + end +end diff --git a/spec/unit/models/rbm_card_content_spec.rb b/spec/unit/models/rbm_card_content_spec.rb new file mode 100644 index 00000000..5de3ef2f --- /dev/null +++ b/spec/unit/models/rbm_card_content_spec.rb @@ -0,0 +1,122 @@ +# Unit tests for Bandwidth::RbmCardContent +describe Bandwidth::RbmCardContent do + let(:reply_action) { Bandwidth::RbmActionBase.new({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'Yes', + postback_data: 'reply_yes' + }) } + let(:rbm_card_content_default) { Bandwidth::RbmCardContent.new } + let(:rbm_card_content_values) { Bandwidth::RbmCardContent.new({ + title: 'Card Title', + description: 'Card Description', + media: Bandwidth::RbmCardContentMedia.new({ + file_url: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + height: Bandwidth::RbmMediaHeightEnum::MEDIUM + }), + suggestions: [reply_action] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmCardContent.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmCardContent.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmCardContent.acceptable_attributes).to eq(Bandwidth::RbmCardContent.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmCardContent.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmCardContent created by the build_from_hash method' do + rbm_card_content_from_hash = Bandwidth::RbmCardContent.build_from_hash({ + title: 'Card Title', + description: 'Card Description', + media: { + fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + height: Bandwidth::RbmMediaHeightEnum::MEDIUM + }, + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + expect(rbm_card_content_from_hash).to be_instance_of(Bandwidth::RbmCardContent) + expect(rbm_card_content_from_hash.title).to eq('Card Title') + expect(rbm_card_content_from_hash.description).to eq('Card Description') + expect(rbm_card_content_from_hash.media).to be_instance_of(Bandwidth::RbmCardContentMedia) + expect(rbm_card_content_from_hash.suggestions.first).to be_instance_of(Bandwidth::RbmActionBase) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_card_content_values.to_s).to eq('{:title=>"Card Title", :description=>"Card Description", :media=>{:fileUrl=>"https://dev.bandwidth.com/images/bandwidth-logo.png", :height=>"MEDIUM"}, :suggestions=>[{:type=>"REPLY", :text=>"Yes", :postbackData=>"reply_yes"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(rbm_card_content_default.eql?(Bandwidth::RbmCardContent.new)).to be true + expect(rbm_card_content_default.eql?(rbm_card_content_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_card_content_values.to_body).to eq({ + title: 'Card Title', + description: 'Card Description', + media: { + fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + height: Bandwidth::RbmMediaHeightEnum::MEDIUM + }, + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + end + end + + describe 'custom attribute writers' do + it '#title=' do + expect { + Bandwidth::RbmCardContent.new({ title: nil }) + }.to raise_error(ArgumentError, 'title cannot be nil') + + expect { + Bandwidth::RbmCardContent.new({ title: 'a' * 201 }) + }.to raise_error(ArgumentError, 'invalid value for "title", the character length must be smaller than or equal to 200.') + end + + it '#description=' do + expect { + Bandwidth::RbmCardContent.new({ description: nil }) + }.to raise_error(ArgumentError, 'description cannot be nil') + + expect { + Bandwidth::RbmCardContent.new({ description: 'a' * 2001 }) + }.to raise_error(ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 2000.') + end + + it '#suggestions=' do + expect { + rbm_card_content_values.suggestions = nil + }.to raise_error(ArgumentError, 'suggestions cannot be nil') + + expect { + rbm_card_content_values.suggestions = [reply_action] * 5 + }.to raise_error(ArgumentError, 'invalid value for "suggestions", number of items must be less than or equal to 4.') + end + end +end diff --git a/spec/unit/models/rbm_location_response_spec.rb b/spec/unit/models/rbm_location_response_spec.rb new file mode 100644 index 00000000..3adcb16e --- /dev/null +++ b/spec/unit/models/rbm_location_response_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::RbmLocationResponse +describe Bandwidth::RbmLocationResponse do + let(:rbm_location_response_default) { Bandwidth::RbmLocationResponse.new } + let(:rbm_location_response_values) { Bandwidth::RbmLocationResponse.new({ + latitude: 35.7796, + longitude: -78.6382 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmLocationResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmLocationResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmLocationResponse.acceptable_attributes).to eq(Bandwidth::RbmLocationResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmLocationResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmLocationResponse created by the build_from_hash method' do + rbm_location_response_from_hash = Bandwidth::RbmLocationResponse.build_from_hash({ + latitude: 35.7796, + longitude: -78.6382 + }) + expect(rbm_location_response_from_hash).to be_instance_of(Bandwidth::RbmLocationResponse) + expect(rbm_location_response_from_hash.latitude).to eq(35.7796) + expect(rbm_location_response_from_hash.longitude).to eq(-78.6382) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_location_response_values.to_s).to eq('{:latitude=>35.7796, :longitude=>-78.6382}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(rbm_location_response_default.eql?(Bandwidth::RbmLocationResponse.new)).to be true + expect(rbm_location_response_default.eql?(rbm_location_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_location_response_values.to_body).to eq({ + latitude: 35.7796, + longitude: -78.6382 + }) + end + end +end diff --git a/spec/unit/models/rbm_media_height_enum_spec.rb b/spec/unit/models/rbm_media_height_enum_spec.rb new file mode 100644 index 00000000..e3118517 --- /dev/null +++ b/spec/unit/models/rbm_media_height_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::RbmMediaHeightEnum +describe Bandwidth::RbmMediaHeightEnum do + describe 'constants' do + it 'defines SHORT' do + expect(Bandwidth::RbmMediaHeightEnum::SHORT).to eq('SHORT') + end + + it 'defines MEDIUM' do + expect(Bandwidth::RbmMediaHeightEnum::MEDIUM).to eq('MEDIUM') + end + + it 'defines TALL' do + expect(Bandwidth::RbmMediaHeightEnum::TALL).to eq('TALL') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::RbmMediaHeightEnum.all_vars).to eq([ + 'SHORT', + 'MEDIUM', + 'TALL' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::RbmMediaHeightEnum.build_from_hash('SHORT')).to eq('SHORT') + expect(Bandwidth::RbmMediaHeightEnum.build_from_hash('MEDIUM')).to eq('MEDIUM') + expect(Bandwidth::RbmMediaHeightEnum.build_from_hash('TALL')).to eq('TALL') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::RbmMediaHeightEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/rbm_message_carousel_card_spec.rb b/spec/unit/models/rbm_message_carousel_card_spec.rb new file mode 100644 index 00000000..6f01ee16 --- /dev/null +++ b/spec/unit/models/rbm_message_carousel_card_spec.rb @@ -0,0 +1,123 @@ +# Unit tests for Bandwidth::RbmMessageCarouselCard +describe Bandwidth::RbmMessageCarouselCard do + let(:card_content) { Bandwidth::RbmCardContent.new({ + title: 'Card Title', + description: 'Card Description' + }) } + let(:reply_action) { Bandwidth::RbmActionBase.new({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'Yes', + postback_data: 'reply_yes' + }) } + let(:rbm_message_carousel_card_default) { Bandwidth::RbmMessageCarouselCard.new({ + card_width: Bandwidth::CardWidthEnum::SMALL, + card_contents: [card_content] + }) } + let(:rbm_message_carousel_card_values) { Bandwidth::RbmMessageCarouselCard.new({ + card_width: Bandwidth::CardWidthEnum::MEDIUM, + card_contents: [card_content, card_content], + suggestions: [reply_action] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmMessageCarouselCard.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmMessageCarouselCard.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmMessageCarouselCard.acceptable_attributes).to eq(Bandwidth::RbmMessageCarouselCard.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmMessageCarouselCard.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmMessageCarouselCard created by the build_from_hash method' do + rbm_message_carousel_card_from_hash = Bandwidth::RbmMessageCarouselCard.build_from_hash({ + cardWidth: Bandwidth::CardWidthEnum::MEDIUM, + cardContents: [{ title: 'Card Title', description: 'Card Description' }], + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + expect(rbm_message_carousel_card_from_hash).to be_instance_of(Bandwidth::RbmMessageCarouselCard) + expect(rbm_message_carousel_card_from_hash.card_width).to eq(Bandwidth::CardWidthEnum::MEDIUM) + expect(rbm_message_carousel_card_from_hash.card_contents.first).to be_instance_of(Bandwidth::RbmCardContent) + expect(rbm_message_carousel_card_from_hash.suggestions.first).to be_instance_of(Bandwidth::RbmActionBase) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_message_carousel_card_values.to_s).to eq('{:cardWidth=>"MEDIUM", :cardContents=>[{:title=>"Card Title", :description=>"Card Description"}, {:title=>"Card Title", :description=>"Card Description"}], :suggestions=>[{:type=>"REPLY", :text=>"Yes", :postbackData=>"reply_yes"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_message_carousel_card_equal = Bandwidth::RbmMessageCarouselCard.new({ + card_width: Bandwidth::CardWidthEnum::SMALL, + card_contents: [card_content] + }) + expect(rbm_message_carousel_card_default.eql?(rbm_message_carousel_card_equal)).to be true + expect(rbm_message_carousel_card_default.eql?(rbm_message_carousel_card_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_message_carousel_card_values.to_body).to eq({ + cardWidth: Bandwidth::CardWidthEnum::MEDIUM, + cardContents: [ + { title: 'Card Title', description: 'Card Description' }, + { title: 'Card Title', description: 'Card Description' } + ], + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + end + end + + describe 'custom attribute writers' do + it '#card_width=' do + expect { + Bandwidth::RbmMessageCarouselCard.new({ card_width: nil }) + }.to raise_error(ArgumentError, 'card_width cannot be nil') + end + + it '#card_contents=' do + expect { + Bandwidth::RbmMessageCarouselCard.new({ card_width: 'SMALL' }) + }.to raise_error(ArgumentError, 'card_contents cannot be nil') + + expect { + rbm_message_carousel_card_values.card_contents = nil + }.to raise_error(ArgumentError, 'card_contents cannot be nil') + + expect { + rbm_message_carousel_card_values.card_contents = [card_content] * 11 + }.to raise_error(ArgumentError, 'invalid value for "card_contents", number of items must be less than or equal to 10.') + end + + it '#suggestions=' do + expect { + rbm_message_carousel_card_values.suggestions = nil + }.to raise_error(ArgumentError, 'suggestions cannot be nil') + + expect { + rbm_message_carousel_card_values.suggestions = [reply_action] * 12 + }.to raise_error(ArgumentError, 'invalid value for "suggestions", number of items must be less than or equal to 11.') + end + end +end diff --git a/spec/unit/models/rbm_message_content_file_spec.rb b/spec/unit/models/rbm_message_content_file_spec.rb new file mode 100644 index 00000000..8bf7e2e3 --- /dev/null +++ b/spec/unit/models/rbm_message_content_file_spec.rb @@ -0,0 +1,95 @@ +# Unit tests for Bandwidth::RbmMessageContentFile +describe Bandwidth::RbmMessageContentFile do + let(:rbm_message_content_file_default) { Bandwidth::RbmMessageContentFile.new({ + file_url: 'https://example.com/baseline.png' + }) } + let(:rbm_message_content_file_values) { Bandwidth::RbmMessageContentFile.new({ + file_url: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + thumbnail_url: 'https://dev.bandwidth.com/images/bandwidth-logo-thumb.png' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmMessageContentFile.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmMessageContentFile.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmMessageContentFile.acceptable_attributes).to eq(Bandwidth::RbmMessageContentFile.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmMessageContentFile.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmMessageContentFile created by the build_from_hash method' do + rbm_message_content_file_from_hash = Bandwidth::RbmMessageContentFile.build_from_hash({ + fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + thumbnailUrl: 'https://dev.bandwidth.com/images/bandwidth-logo-thumb.png' + }) + expect(rbm_message_content_file_from_hash).to be_instance_of(Bandwidth::RbmMessageContentFile) + expect(rbm_message_content_file_from_hash.file_url).to eq('https://dev.bandwidth.com/images/bandwidth-logo.png') + expect(rbm_message_content_file_from_hash.thumbnail_url).to eq('https://dev.bandwidth.com/images/bandwidth-logo-thumb.png') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_message_content_file_values.to_s).to eq('{:fileUrl=>"https://dev.bandwidth.com/images/bandwidth-logo.png", :thumbnailUrl=>"https://dev.bandwidth.com/images/bandwidth-logo-thumb.png"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_message_content_file_equal = Bandwidth::RbmMessageContentFile.new({ + file_url: 'https://example.com/baseline.png' + }) + expect(rbm_message_content_file_default.eql?(rbm_message_content_file_equal)).to be true + expect(rbm_message_content_file_default.eql?(rbm_message_content_file_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_message_content_file_values.to_body).to eq({ + fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png', + thumbnailUrl: 'https://dev.bandwidth.com/images/bandwidth-logo-thumb.png' + }) + end + end + + describe 'custom attribute writers' do + it '#file_url=' do + expect { + Bandwidth::RbmMessageContentFile.new({ file_url: nil }) + }.to raise_error(ArgumentError, 'file_url cannot be nil') + + expect { + Bandwidth::RbmMessageContentFile.new({ file_url: 'a' * 1001 }) + }.to raise_error(ArgumentError, 'invalid value for "file_url", the character length must be smaller than or equal to 1000.') + end + + it '#thumbnail_url=' do + expect { + rbm_message_content_file_values.thumbnail_url = nil + }.to raise_error(ArgumentError, 'thumbnail_url cannot be nil') + + expect { + rbm_message_content_file_values.thumbnail_url = 'a' * 1001 + }.to raise_error(ArgumentError, 'invalid value for "thumbnail_url", the character length must be smaller than or equal to 1000.') + end + end +end diff --git a/spec/unit/models/rbm_message_content_rich_card_spec.rb b/spec/unit/models/rbm_message_content_rich_card_spec.rb new file mode 100644 index 00000000..907d006f --- /dev/null +++ b/spec/unit/models/rbm_message_content_rich_card_spec.rb @@ -0,0 +1,27 @@ +# Unit tests for Bandwidth::RbmMessageContentRichCard +describe Bandwidth::RbmMessageContentRichCard do + describe '.openapi_one_of' do + it 'lists the classes defined in oneOf' do + expect(Bandwidth::RbmMessageContentRichCard.openapi_one_of).to eq([ + :'RbmMessageCarouselCard', + :'RbmStandaloneCard' + ]) + end + end + + describe '.build' do + it 'routes payloads matching RbmMessageCarouselCard attributes to RbmMessageCarouselCard.build_from_hash' do + data = { cardWidth: 'SMALL', cardContents: [] } + expect(Bandwidth::RbmMessageContentRichCard.build(data)).to be_instance_of(Bandwidth::RbmMessageCarouselCard) + end + + it 'routes payloads matching RbmStandaloneCard attributes to RbmStandaloneCard.build_from_hash' do + data = { orientation: 'HORIZONTAL', thumbnailImageAlignment: 'LEFT', cardContent: { title: 'Card Title' } } + expect(Bandwidth::RbmMessageContentRichCard.build(data)).to be_instance_of(Bandwidth::RbmStandaloneCard) + end + + it 'returns nil when the payload does not match any oneOf schema' do + expect(Bandwidth::RbmMessageContentRichCard.build({ unknown: 'value' })).to be_nil + end + end +end diff --git a/spec/unit/models/rbm_message_content_text_spec.rb b/spec/unit/models/rbm_message_content_text_spec.rb new file mode 100644 index 00000000..e129dfdb --- /dev/null +++ b/spec/unit/models/rbm_message_content_text_spec.rb @@ -0,0 +1,100 @@ +# Unit tests for Bandwidth::RbmMessageContentText +describe Bandwidth::RbmMessageContentText do + let(:reply_action) { Bandwidth::RbmActionBase.new({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'Yes', + postback_data: 'reply_yes' + }) } + let(:rbm_message_content_text_default) { Bandwidth::RbmMessageContentText.new({ + text: 'baseline' + }) } + let(:rbm_message_content_text_values) { Bandwidth::RbmMessageContentText.new({ + text: 'Hello world', + suggestions: [reply_action] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmMessageContentText.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmMessageContentText.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmMessageContentText.acceptable_attributes).to eq(Bandwidth::RbmMessageContentText.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmMessageContentText.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmMessageContentText created by the build_from_hash method' do + rbm_message_content_text_from_hash = Bandwidth::RbmMessageContentText.build_from_hash({ + text: 'Hello world', + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + expect(rbm_message_content_text_from_hash).to be_instance_of(Bandwidth::RbmMessageContentText) + expect(rbm_message_content_text_from_hash.text).to eq('Hello world') + expect(rbm_message_content_text_from_hash.suggestions.first).to be_instance_of(Bandwidth::RbmActionBase) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_message_content_text_values.to_s).to eq('{:text=>"Hello world", :suggestions=>[{:type=>"REPLY", :text=>"Yes", :postbackData=>"reply_yes"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_message_content_text_equal = Bandwidth::RbmMessageContentText.new({ + text: 'baseline' + }) + expect(rbm_message_content_text_default.eql?(rbm_message_content_text_equal)).to be true + expect(rbm_message_content_text_default.eql?(rbm_message_content_text_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_message_content_text_values.to_body).to eq({ + text: 'Hello world', + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + end + end + + describe 'custom attribute writers' do + it '#text=' do + expect { + Bandwidth::RbmMessageContentText.new({ text: nil }) + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + Bandwidth::RbmMessageContentText.new({ text: 'a' * 3271 }) + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 3270.') + end + + it '#suggestions=' do + expect { + rbm_message_content_text_values.suggestions = nil + }.to raise_error(ArgumentError, 'suggestions cannot be nil') + + expect { + rbm_message_content_text_values.suggestions = [reply_action] * 12 + }.to raise_error(ArgumentError, 'invalid value for "suggestions", number of items must be less than or equal to 11.') + end + end +end diff --git a/spec/unit/models/rbm_message_media_spec.rb b/spec/unit/models/rbm_message_media_spec.rb new file mode 100644 index 00000000..2c00214e --- /dev/null +++ b/spec/unit/models/rbm_message_media_spec.rb @@ -0,0 +1,103 @@ +# Unit tests for Bandwidth::RbmMessageMedia +describe Bandwidth::RbmMessageMedia do + let(:media_file) { Bandwidth::RbmMessageContentFile.new({ + file_url: 'https://dev.bandwidth.com/images/bandwidth-logo.png' + }) } + let(:reply_action) { Bandwidth::RbmActionBase.new({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'Yes', + postback_data: 'reply_yes' + }) } + let(:rbm_message_media_default) { Bandwidth::RbmMessageMedia.new({ + media: [media_file] + }) } + let(:rbm_message_media_values) { Bandwidth::RbmMessageMedia.new({ + media: [media_file], + suggestions: [reply_action] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmMessageMedia.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmMessageMedia.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmMessageMedia.acceptable_attributes).to eq(Bandwidth::RbmMessageMedia.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmMessageMedia.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmMessageMedia created by the build_from_hash method' do + rbm_message_media_from_hash = Bandwidth::RbmMessageMedia.build_from_hash({ + media: [{ fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png' }], + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + expect(rbm_message_media_from_hash).to be_instance_of(Bandwidth::RbmMessageMedia) + expect(rbm_message_media_from_hash.media.first).to be_instance_of(Bandwidth::RbmMessageContentFile) + expect(rbm_message_media_from_hash.suggestions.first).to be_instance_of(Bandwidth::RbmActionBase) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_message_media_values.to_s).to eq('{:media=>[{:fileUrl=>"https://dev.bandwidth.com/images/bandwidth-logo.png"}], :suggestions=>[{:type=>"REPLY", :text=>"Yes", :postbackData=>"reply_yes"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_message_media_equal = Bandwidth::RbmMessageMedia.new({ + media: [media_file] + }) + expect(rbm_message_media_default.eql?(rbm_message_media_equal)).to be true + expect(rbm_message_media_default.eql?(rbm_message_media_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_message_media_values.to_body).to eq({ + media: [{ fileUrl: 'https://dev.bandwidth.com/images/bandwidth-logo.png' }], + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + end + end + + describe 'custom attribute writers' do + it '#media=' do + expect { + Bandwidth::RbmMessageMedia.new({}) + }.to raise_error(ArgumentError, 'media cannot be nil') + + expect { + rbm_message_media_values.media = nil + }.to raise_error(ArgumentError, 'media cannot be nil') + end + + it '#suggestions=' do + expect { + rbm_message_media_values.suggestions = nil + }.to raise_error(ArgumentError, 'suggestions cannot be nil') + + expect { + rbm_message_media_values.suggestions = [reply_action] * 12 + }.to raise_error(ArgumentError, 'invalid value for "suggestions", number of items must be less than or equal to 11.') + end + end +end diff --git a/spec/unit/models/rbm_open_url_enum_spec.rb b/spec/unit/models/rbm_open_url_enum_spec.rb new file mode 100644 index 00000000..6db2fdaa --- /dev/null +++ b/spec/unit/models/rbm_open_url_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::RbmOpenUrlEnum +describe Bandwidth::RbmOpenUrlEnum do + describe 'constants' do + it 'defines BROWSER' do + expect(Bandwidth::RbmOpenUrlEnum::BROWSER).to eq('BROWSER') + end + + it 'defines WEBVIEW' do + expect(Bandwidth::RbmOpenUrlEnum::WEBVIEW).to eq('WEBVIEW') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::RbmOpenUrlEnum.all_vars).to eq([ + 'BROWSER', + 'WEBVIEW' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::RbmOpenUrlEnum.build_from_hash('BROWSER')).to eq('BROWSER') + expect(Bandwidth::RbmOpenUrlEnum.build_from_hash('WEBVIEW')).to eq('WEBVIEW') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::RbmOpenUrlEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/rbm_standalone_card_spec.rb b/spec/unit/models/rbm_standalone_card_spec.rb new file mode 100644 index 00000000..3990eea5 --- /dev/null +++ b/spec/unit/models/rbm_standalone_card_spec.rb @@ -0,0 +1,124 @@ +# Unit tests for Bandwidth::RbmStandaloneCard +describe Bandwidth::RbmStandaloneCard do + let(:card_content) { Bandwidth::RbmCardContent.new({ + title: 'Card Title', + description: 'Card Description' + }) } + let(:reply_action) { Bandwidth::RbmActionBase.new({ + type: Bandwidth::RbmActionTypeEnum::REPLY, + text: 'Yes', + postback_data: 'reply_yes' + }) } + let(:rbm_standalone_card_default) { Bandwidth::RbmStandaloneCard.new({ + orientation: Bandwidth::StandaloneCardOrientationEnum::HORIZONTAL, + thumbnail_image_alignment: Bandwidth::ThumbnailAlignmentEnum::LEFT, + card_content: card_content + }) } + let(:rbm_standalone_card_values) { Bandwidth::RbmStandaloneCard.new({ + orientation: Bandwidth::StandaloneCardOrientationEnum::VERTICAL, + thumbnail_image_alignment: Bandwidth::ThumbnailAlignmentEnum::RIGHT, + card_content: card_content, + suggestions: [reply_action] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmStandaloneCard.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmStandaloneCard.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmStandaloneCard.acceptable_attributes).to eq(Bandwidth::RbmStandaloneCard.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmStandaloneCard.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmStandaloneCard created by the build_from_hash method' do + rbm_standalone_card_from_hash = Bandwidth::RbmStandaloneCard.build_from_hash({ + orientation: Bandwidth::StandaloneCardOrientationEnum::VERTICAL, + thumbnailImageAlignment: Bandwidth::ThumbnailAlignmentEnum::RIGHT, + cardContent: { title: 'Card Title', description: 'Card Description' }, + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + expect(rbm_standalone_card_from_hash).to be_instance_of(Bandwidth::RbmStandaloneCard) + expect(rbm_standalone_card_from_hash.orientation).to eq(Bandwidth::StandaloneCardOrientationEnum::VERTICAL) + expect(rbm_standalone_card_from_hash.thumbnail_image_alignment).to eq(Bandwidth::ThumbnailAlignmentEnum::RIGHT) + expect(rbm_standalone_card_from_hash.card_content).to be_instance_of(Bandwidth::RbmCardContent) + expect(rbm_standalone_card_from_hash.suggestions.first).to be_instance_of(Bandwidth::RbmActionBase) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_standalone_card_values.to_s).to eq('{:orientation=>"VERTICAL", :thumbnailImageAlignment=>"RIGHT", :cardContent=>{:title=>"Card Title", :description=>"Card Description"}, :suggestions=>[{:type=>"REPLY", :text=>"Yes", :postbackData=>"reply_yes"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + rbm_standalone_card_equal = Bandwidth::RbmStandaloneCard.new({ + orientation: Bandwidth::StandaloneCardOrientationEnum::HORIZONTAL, + thumbnail_image_alignment: Bandwidth::ThumbnailAlignmentEnum::LEFT, + card_content: card_content + }) + expect(rbm_standalone_card_default.eql?(rbm_standalone_card_equal)).to be true + expect(rbm_standalone_card_default.eql?(rbm_standalone_card_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_standalone_card_values.to_body).to eq({ + orientation: Bandwidth::StandaloneCardOrientationEnum::VERTICAL, + thumbnailImageAlignment: Bandwidth::ThumbnailAlignmentEnum::RIGHT, + cardContent: { title: 'Card Title', description: 'Card Description' }, + suggestions: [{ type: Bandwidth::RbmActionTypeEnum::REPLY, text: 'Yes', postbackData: 'reply_yes' }] + }) + end + end + + describe 'custom attribute writers' do + it '#orientation=' do + expect { + Bandwidth::RbmStandaloneCard.new({ orientation: nil }) + }.to raise_error(ArgumentError, 'orientation cannot be nil') + end + + it '#thumbnail_image_alignment=' do + expect { + Bandwidth::RbmStandaloneCard.new({ orientation: 'HORIZONTAL', thumbnail_image_alignment: nil }) + }.to raise_error(ArgumentError, 'thumbnail_image_alignment cannot be nil') + end + + it '#card_content=' do + expect { + Bandwidth::RbmStandaloneCard.new({ orientation: 'HORIZONTAL', thumbnail_image_alignment: 'LEFT', card_content: nil }) + }.to raise_error(ArgumentError, 'card_content cannot be nil') + end + + it '#suggestions=' do + expect { + rbm_standalone_card_values.suggestions = nil + }.to raise_error(ArgumentError, 'suggestions cannot be nil') + + expect { + rbm_standalone_card_values.suggestions = [reply_action] * 12 + }.to raise_error(ArgumentError, 'invalid value for "suggestions", number of items must be less than or equal to 11.') + end + end +end diff --git a/spec/unit/models/rbm_suggestion_response_spec.rb b/spec/unit/models/rbm_suggestion_response_spec.rb new file mode 100644 index 00000000..609da35e --- /dev/null +++ b/spec/unit/models/rbm_suggestion_response_spec.rb @@ -0,0 +1,80 @@ +# Unit tests for Bandwidth::RbmSuggestionResponse +describe Bandwidth::RbmSuggestionResponse do + let(:rbm_suggestion_response_default) { Bandwidth::RbmSuggestionResponse.new } + let(:rbm_suggestion_response_values) { Bandwidth::RbmSuggestionResponse.new({ + text: 'Yes', + postback_data: 'reply_yes' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RbmSuggestionResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RbmSuggestionResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RbmSuggestionResponse.acceptable_attributes).to eq(Bandwidth::RbmSuggestionResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RbmSuggestionResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RbmSuggestionResponse created by the build_from_hash method' do + rbm_suggestion_response_from_hash = Bandwidth::RbmSuggestionResponse.build_from_hash({ + text: 'Yes', + postbackData: 'reply_yes' + }) + expect(rbm_suggestion_response_from_hash).to be_instance_of(Bandwidth::RbmSuggestionResponse) + expect(rbm_suggestion_response_from_hash.text).to eq('Yes') + expect(rbm_suggestion_response_from_hash.postback_data).to eq('reply_yes') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(rbm_suggestion_response_values.to_s).to eq('{:text=>"Yes", :postbackData=>"reply_yes"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(rbm_suggestion_response_default.eql?(Bandwidth::RbmSuggestionResponse.new)).to be true + expect(rbm_suggestion_response_default.eql?(rbm_suggestion_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(rbm_suggestion_response_values.to_body).to eq({ + text: 'Yes', + postbackData: 'reply_yes' + }) + end + end + + describe 'custom attribute writers' do + it '#postback_data=' do + expect { + rbm_suggestion_response_values.postback_data = nil + }.to raise_error(ArgumentError, 'postback_data cannot be nil') + + expect { + rbm_suggestion_response_values.postback_data = 'a' * 2049 + }.to raise_error(ArgumentError, 'invalid value for "postback_data", the character length must be smaller than or equal to 2048.') + end + end +end diff --git a/spec/unit/models/rbm_web_view_enum_spec.rb b/spec/unit/models/rbm_web_view_enum_spec.rb new file mode 100644 index 00000000..d3c4d997 --- /dev/null +++ b/spec/unit/models/rbm_web_view_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::RbmWebViewEnum +describe Bandwidth::RbmWebViewEnum do + describe 'constants' do + it 'defines FULL' do + expect(Bandwidth::RbmWebViewEnum::FULL).to eq('FULL') + end + + it 'defines HALF' do + expect(Bandwidth::RbmWebViewEnum::HALF).to eq('HALF') + end + + it 'defines TALL' do + expect(Bandwidth::RbmWebViewEnum::TALL).to eq('TALL') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::RbmWebViewEnum.all_vars).to eq([ + 'FULL', + 'HALF', + 'TALL' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::RbmWebViewEnum.build_from_hash('FULL')).to eq('FULL') + expect(Bandwidth::RbmWebViewEnum.build_from_hash('HALF')).to eq('HALF') + expect(Bandwidth::RbmWebViewEnum.build_from_hash('TALL')).to eq('TALL') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::RbmWebViewEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/recording_available_callback_spec.rb b/spec/unit/models/recording_available_callback_spec.rb new file mode 100644 index 00000000..992fb6f0 --- /dev/null +++ b/spec/unit/models/recording_available_callback_spec.rb @@ -0,0 +1,152 @@ +# Unit tests for Bandwidth::RecordingAvailableCallback +describe Bandwidth::RecordingAvailableCallback do + let(:recording_available_callback_default) { Bandwidth::RecordingAvailableCallback.new } + let(:recording_available_callback_values) { Bandwidth::RecordingAvailableCallback.new({ + event_type: 'recordingAvailable', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parent_call_id: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recording_id: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + media_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + end_time: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + file_format: Bandwidth::FileFormatEnum::WAV, + channels: 1, + tag: 'custom tag', + status: 'complete', + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RecordingAvailableCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RecordingAvailableCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RecordingAvailableCallback.acceptable_attributes).to eq(Bandwidth::RecordingAvailableCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::RecordingAvailableCallback.openapi_nullable).to eq(Set.new([ + :'media_url', + :'enqueued_time', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RecordingAvailableCallback created by the build_from_hash method' do + recording_available_callback_from_hash = Bandwidth::RecordingAvailableCallback.build_from_hash({ + eventType: 'recordingAvailable', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recordingId: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + mediaUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + fileFormat: Bandwidth::FileFormatEnum::WAV, + channels: 1, + tag: 'custom tag', + status: 'complete', + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + expect(recording_available_callback_from_hash).to be_instance_of(Bandwidth::RecordingAvailableCallback) + expect(recording_available_callback_from_hash.event_type).to eq('recordingAvailable') + expect(recording_available_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(recording_available_callback_from_hash.account_id).to eq('9900000') + expect(recording_available_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(recording_available_callback_from_hash.from).to eq('+19195554321') + expect(recording_available_callback_from_hash.to).to eq('+19195551234') + expect(recording_available_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(recording_available_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(recording_available_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(recording_available_callback_from_hash.parent_call_id).to eq('c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99') + expect(recording_available_callback_from_hash.recording_id).to eq('r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(recording_available_callback_from_hash.media_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media') + expect(recording_available_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(recording_available_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(recording_available_callback_from_hash.end_time).to eq(Time.parse('2022-06-16T13:17:07.160Z')) + expect(recording_available_callback_from_hash.duration).to eq('PT2M') + expect(recording_available_callback_from_hash.file_format).to eq(Bandwidth::FileFormatEnum::WAV) + expect(recording_available_callback_from_hash.channels).to eq(1) + expect(recording_available_callback_from_hash.tag).to eq('custom tag') + expect(recording_available_callback_from_hash.status).to eq('complete') + expect(recording_available_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(recording_available_callback_from_hash.transfer_to).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(recording_available_callback_values.to_s).to eq('{:eventType=>"recordingAvailable", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"inbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :parentCallId=>"c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99", :recordingId=>"r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :mediaUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :endTime=>"2022-06-16T13:17:07.160Z", :duration=>"PT2M", :fileFormat=>"wav", :channels=>1, :tag=>"custom tag", :status=>"complete", :transferCallerId=>"+19195554321", :transferTo=>"+19195551234"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(recording_available_callback_default.eql?(Bandwidth::RecordingAvailableCallback.new)).to be true + expect(recording_available_callback_default.eql?(recording_available_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(recording_available_callback_values.to_body).to eq({ + eventType: 'recordingAvailable', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recordingId: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + mediaUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + fileFormat: Bandwidth::FileFormatEnum::WAV, + channels: 1, + tag: 'custom tag', + status: 'complete', + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + end + end +end diff --git a/spec/unit/models/recording_complete_callback_spec.rb b/spec/unit/models/recording_complete_callback_spec.rb new file mode 100644 index 00000000..ec5341ed --- /dev/null +++ b/spec/unit/models/recording_complete_callback_spec.rb @@ -0,0 +1,153 @@ +# Unit tests for Bandwidth::RecordingCompleteCallback +describe Bandwidth::RecordingCompleteCallback do + let(:recording_complete_callback_default) { Bandwidth::RecordingCompleteCallback.new } + let(:recording_complete_callback_values) { Bandwidth::RecordingCompleteCallback.new({ + event_type: 'recordingComplete', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parent_call_id: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recording_id: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + media_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + end_time: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + file_format: Bandwidth::FileFormatEnum::WAV, + channels: 1, + tag: 'custom tag', + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RecordingCompleteCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RecordingCompleteCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RecordingCompleteCallback.acceptable_attributes).to eq(Bandwidth::RecordingCompleteCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::RecordingCompleteCallback.openapi_nullable).to eq(Set.new([ + :'media_url', + :'enqueued_time', + :'answer_time', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RecordingCompleteCallback created by the build_from_hash method' do + recording_complete_callback_from_hash = Bandwidth::RecordingCompleteCallback.build_from_hash({ + eventType: 'recordingComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recordingId: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + mediaUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + endTime: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + fileFormat: Bandwidth::FileFormatEnum::WAV, + channels: 1, + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + expect(recording_complete_callback_from_hash).to be_instance_of(Bandwidth::RecordingCompleteCallback) + expect(recording_complete_callback_from_hash.event_type).to eq('recordingComplete') + expect(recording_complete_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(recording_complete_callback_from_hash.account_id).to eq('9900000') + expect(recording_complete_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(recording_complete_callback_from_hash.from).to eq('+19195554321') + expect(recording_complete_callback_from_hash.to).to eq('+19195551234') + expect(recording_complete_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(recording_complete_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(recording_complete_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(recording_complete_callback_from_hash.parent_call_id).to eq('c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99') + expect(recording_complete_callback_from_hash.recording_id).to eq('r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(recording_complete_callback_from_hash.media_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media') + expect(recording_complete_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(recording_complete_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(recording_complete_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(recording_complete_callback_from_hash.end_time).to eq(Time.parse('2022-06-16T13:17:07.160Z')) + expect(recording_complete_callback_from_hash.duration).to eq('PT2M') + expect(recording_complete_callback_from_hash.file_format).to eq(Bandwidth::FileFormatEnum::WAV) + expect(recording_complete_callback_from_hash.channels).to eq(1) + expect(recording_complete_callback_from_hash.tag).to eq('custom tag') + expect(recording_complete_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(recording_complete_callback_from_hash.transfer_to).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(recording_complete_callback_values.to_s).to eq('{:eventType=>"recordingComplete", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"inbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :parentCallId=>"c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99", :recordingId=>"r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :mediaUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :endTime=>"2022-06-16T13:17:07.160Z", :duration=>"PT2M", :fileFormat=>"wav", :channels=>1, :tag=>"custom tag", :transferCallerId=>"+19195554321", :transferTo=>"+19195551234"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(recording_complete_callback_default.eql?(Bandwidth::RecordingCompleteCallback.new)).to be true + expect(recording_complete_callback_default.eql?(recording_complete_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(recording_complete_callback_values.to_body).to eq({ + eventType: 'recordingComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recordingId: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + mediaUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + endTime: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + fileFormat: Bandwidth::FileFormatEnum::WAV, + channels: 1, + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + end + end +end diff --git a/spec/unit/models/recording_state_enum_spec.rb b/spec/unit/models/recording_state_enum_spec.rb new file mode 100644 index 00000000..805e9568 --- /dev/null +++ b/spec/unit/models/recording_state_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::RecordingStateEnum +describe Bandwidth::RecordingStateEnum do + describe 'constants' do + it 'defines PAUSED' do + expect(Bandwidth::RecordingStateEnum::PAUSED).to eq('paused') + end + + it 'defines RECORDING' do + expect(Bandwidth::RecordingStateEnum::RECORDING).to eq('recording') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::RecordingStateEnum.all_vars).to eq([ + 'paused', + 'recording' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::RecordingStateEnum.build_from_hash('paused')).to eq('paused') + expect(Bandwidth::RecordingStateEnum.build_from_hash('recording')).to eq('recording') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::RecordingStateEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/recording_transcription_metadata_spec.rb b/spec/unit/models/recording_transcription_metadata_spec.rb new file mode 100644 index 00000000..db8bba7c --- /dev/null +++ b/spec/unit/models/recording_transcription_metadata_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::RecordingTranscriptionMetadata +describe Bandwidth::RecordingTranscriptionMetadata do + let(:recording_transcription_metadata_default) { Bandwidth::RecordingTranscriptionMetadata.new } + let(:recording_transcription_metadata_values) { Bandwidth::RecordingTranscriptionMetadata.new({ + id: 't-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c', + status: 'available', + completed_time: '2022-06-17T22:21:30Z', + url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcriptions/t-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RecordingTranscriptionMetadata.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RecordingTranscriptionMetadata.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RecordingTranscriptionMetadata.acceptable_attributes).to eq(Bandwidth::RecordingTranscriptionMetadata.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RecordingTranscriptionMetadata.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RecordingTranscriptionMetadata created by the build_from_hash method' do + recording_transcription_metadata_from_hash = Bandwidth::RecordingTranscriptionMetadata.build_from_hash({ + id: 't-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c', + status: 'available', + completedTime: '2022-06-17T22:21:30Z', + url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcriptions/t-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c' + }) + expect(recording_transcription_metadata_from_hash).to be_instance_of(Bandwidth::RecordingTranscriptionMetadata) + expect(recording_transcription_metadata_from_hash.id).to eq('t-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c') + expect(recording_transcription_metadata_from_hash.status).to eq('available') + expect(recording_transcription_metadata_from_hash.completed_time).to eq(Time.parse('2022-06-17T22:21:30Z')) + expect(recording_transcription_metadata_from_hash.url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcriptions/t-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(recording_transcription_metadata_values.to_s).to eq('{:id=>"t-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c", :status=>"available", :completedTime=>"2022-06-17T22:21:30Z", :url=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcriptions/t-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(recording_transcription_metadata_default.eql?(Bandwidth::RecordingTranscriptionMetadata.new)).to be true + expect(recording_transcription_metadata_default.eql?(recording_transcription_metadata_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(recording_transcription_metadata_values.to_body).to eq({ + id: 't-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c', + status: 'available', + completedTime: '2022-06-17T22:21:30Z', + url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcriptions/t-3f758f24-c7a2fdac-7c2e-4d83-bf28-c7c1ed29563c' + }) + end + end +end diff --git a/spec/unit/models/recording_transcriptions_spec.rb b/spec/unit/models/recording_transcriptions_spec.rb new file mode 100644 index 00000000..a4d403ca --- /dev/null +++ b/spec/unit/models/recording_transcriptions_spec.rb @@ -0,0 +1,69 @@ +# Unit tests for Bandwidth::RecordingTranscriptions +describe Bandwidth::RecordingTranscriptions do + let(:recording_transcriptions_default) { Bandwidth::RecordingTranscriptions.new } + let(:recording_transcriptions_values) { Bandwidth::RecordingTranscriptions.new({ + transcripts: [ + Bandwidth::Transcription.new({ text: 'Hello World! Thank you for calling.', confidence: 0.9 }) + ] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RecordingTranscriptions.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RecordingTranscriptions.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RecordingTranscriptions.acceptable_attributes).to eq(Bandwidth::RecordingTranscriptions.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::RecordingTranscriptions.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RecordingTranscriptions created by the build_from_hash method' do + recording_transcriptions_from_hash = Bandwidth::RecordingTranscriptions.build_from_hash({ + transcripts: [{ text: 'Hello World! Thank you for calling.', confidence: 0.9 }] + }) + expect(recording_transcriptions_from_hash).to be_instance_of(Bandwidth::RecordingTranscriptions) + expect(recording_transcriptions_from_hash.transcripts).to be_instance_of(Array) + expect(recording_transcriptions_from_hash.transcripts.first).to be_instance_of(Bandwidth::Transcription) + expect(recording_transcriptions_from_hash.transcripts.first.text).to eq('Hello World! Thank you for calling.') + expect(recording_transcriptions_from_hash.transcripts.first.confidence).to eq(0.9) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(recording_transcriptions_values.to_s).to eq('{:transcripts=>[{:text=>"Hello World! Thank you for calling.", :confidence=>0.9}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(recording_transcriptions_default.eql?(Bandwidth::RecordingTranscriptions.new)).to be true + expect(recording_transcriptions_default.eql?(recording_transcriptions_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(recording_transcriptions_values.to_body).to eq({ + transcripts: [{ text: 'Hello World! Thank you for calling.', confidence: 0.9 }] + }) + end + end +end diff --git a/spec/unit/models/redirect_callback_spec.rb b/spec/unit/models/redirect_callback_spec.rb new file mode 100644 index 00000000..e1344d9c --- /dev/null +++ b/spec/unit/models/redirect_callback_spec.rb @@ -0,0 +1,128 @@ +# Unit tests for Bandwidth::RedirectCallback +describe Bandwidth::RedirectCallback do + let(:redirect_callback_default) { Bandwidth::RedirectCallback.new } + let(:redirect_callback_values) { Bandwidth::RedirectCallback.new({ + event_type: 'redirect', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parent_call_id: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::RedirectCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::RedirectCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::RedirectCallback.acceptable_attributes).to eq(Bandwidth::RedirectCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::RedirectCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of RedirectCallback created by the build_from_hash method' do + redirect_callback_from_hash = Bandwidth::RedirectCallback.build_from_hash({ + eventType: 'redirect', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + expect(redirect_callback_from_hash).to be_instance_of(Bandwidth::RedirectCallback) + expect(redirect_callback_from_hash.event_type).to eq('redirect') + expect(redirect_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(redirect_callback_from_hash.account_id).to eq('9900000') + expect(redirect_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(redirect_callback_from_hash.from).to eq('+19195554321') + expect(redirect_callback_from_hash.to).to eq('+19195551234') + expect(redirect_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(redirect_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(redirect_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(redirect_callback_from_hash.parent_call_id).to eq('c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99') + expect(redirect_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(redirect_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(redirect_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(redirect_callback_from_hash.tag).to eq('custom tag') + expect(redirect_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(redirect_callback_from_hash.transfer_to).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(redirect_callback_values.to_s).to eq('{:eventType=>"redirect", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"inbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :parentCallId=>"c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag", :transferCallerId=>"+19195554321", :transferTo=>"+19195551234"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(redirect_callback_default.eql?(Bandwidth::RedirectCallback.new)).to be true + expect(redirect_callback_default.eql?(redirect_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(redirect_callback_values.to_body).to eq({ + eventType: 'redirect', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + end + end +end diff --git a/spec/unit/models/redirect_method_enum_spec.rb b/spec/unit/models/redirect_method_enum_spec.rb new file mode 100644 index 00000000..d04dbaa0 --- /dev/null +++ b/spec/unit/models/redirect_method_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::RedirectMethodEnum +describe Bandwidth::RedirectMethodEnum do + describe 'constants' do + it 'defines GET' do + expect(Bandwidth::RedirectMethodEnum::GET).to eq('GET') + end + + it 'defines POST' do + expect(Bandwidth::RedirectMethodEnum::POST).to eq('POST') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::RedirectMethodEnum.all_vars).to eq([ + 'GET', + 'POST' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::RedirectMethodEnum.build_from_hash('GET')).to eq('GET') + expect(Bandwidth::RedirectMethodEnum.build_from_hash('POST')).to eq('POST') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::RedirectMethodEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/sip_connection_metadata_spec.rb b/spec/unit/models/sip_connection_metadata_spec.rb new file mode 100644 index 00000000..7c8c154d --- /dev/null +++ b/spec/unit/models/sip_connection_metadata_spec.rb @@ -0,0 +1,78 @@ +# Unit tests for Bandwidth::SipConnectionMetadata +describe Bandwidth::SipConnectionMetadata do + let(:sip_connection_metadata_default) { Bandwidth::SipConnectionMetadata.new } + let(:sip_connection_metadata_values) { Bandwidth::SipConnectionMetadata.new({ + ip_address: '192.168.1.1', + port: 5060, + credentials: Bandwidth::SipCredentials.new({ username: 'sipUser', password: 'sipPass' }), + uui_header: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::SipConnectionMetadata.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::SipConnectionMetadata.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::SipConnectionMetadata.acceptable_attributes).to eq(Bandwidth::SipConnectionMetadata.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::SipConnectionMetadata.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of SipConnectionMetadata created by the build_from_hash method' do + sip_connection_metadata_from_hash = Bandwidth::SipConnectionMetadata.build_from_hash({ + ipAddress: '192.168.1.1', + port: 5060, + credentials: { username: 'sipUser', password: 'sipPass' }, + uuiHeader: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9' + }) + expect(sip_connection_metadata_from_hash).to be_instance_of(Bandwidth::SipConnectionMetadata) + expect(sip_connection_metadata_from_hash.ip_address).to eq('192.168.1.1') + expect(sip_connection_metadata_from_hash.port).to eq(5060) + expect(sip_connection_metadata_from_hash.credentials).to be_instance_of(Bandwidth::SipCredentials) + expect(sip_connection_metadata_from_hash.credentials.username).to eq('sipUser') + expect(sip_connection_metadata_from_hash.credentials.password).to eq('sipPass') + expect(sip_connection_metadata_from_hash.uui_header).to eq('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(sip_connection_metadata_values.to_s).to eq('{:ipAddress=>"192.168.1.1", :port=>5060, :credentials=>{:username=>"sipUser", :password=>"sipPass"}, :uuiHeader=>"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(sip_connection_metadata_default.eql?(Bandwidth::SipConnectionMetadata.new)).to be true + expect(sip_connection_metadata_default.eql?(sip_connection_metadata_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(sip_connection_metadata_values.to_body).to eq({ + ipAddress: '192.168.1.1', + port: 5060, + credentials: { username: 'sipUser', password: 'sipPass' }, + uuiHeader: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9' + }) + end + end +end diff --git a/spec/unit/models/sip_credentials_spec.rb b/spec/unit/models/sip_credentials_spec.rb new file mode 100644 index 00000000..3c855b8d --- /dev/null +++ b/spec/unit/models/sip_credentials_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::SipCredentials +describe Bandwidth::SipCredentials do + let(:sip_credentials_default) { Bandwidth::SipCredentials.new } + let(:sip_credentials_values) { Bandwidth::SipCredentials.new({ + username: 'sipUser', + password: 'sipPass' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::SipCredentials.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::SipCredentials.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::SipCredentials.acceptable_attributes).to eq(Bandwidth::SipCredentials.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::SipCredentials.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of SipCredentials created by the build_from_hash method' do + sip_credentials_from_hash = Bandwidth::SipCredentials.build_from_hash({ + username: 'sipUser', + password: 'sipPass' + }) + expect(sip_credentials_from_hash).to be_instance_of(Bandwidth::SipCredentials) + expect(sip_credentials_from_hash.username).to eq('sipUser') + expect(sip_credentials_from_hash.password).to eq('sipPass') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(sip_credentials_values.to_s).to eq('{:username=>"sipUser", :password=>"sipPass"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(sip_credentials_default.eql?(Bandwidth::SipCredentials.new)).to be true + expect(sip_credentials_default.eql?(sip_credentials_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(sip_credentials_values.to_body).to eq({ + username: 'sipUser', + password: 'sipPass' + }) + end + end +end diff --git a/spec/unit/models/sms_message_content_spec.rb b/spec/unit/models/sms_message_content_spec.rb new file mode 100644 index 00000000..d7694e3a --- /dev/null +++ b/spec/unit/models/sms_message_content_spec.rb @@ -0,0 +1,81 @@ +# Unit tests for Bandwidth::SmsMessageContent +describe Bandwidth::SmsMessageContent do + let(:sms_message_content_default) { Bandwidth::SmsMessageContent.new({ + text: 'baseline' + }) } + let(:sms_message_content_values) { Bandwidth::SmsMessageContent.new({ + text: 'Hello world' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::SmsMessageContent.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::SmsMessageContent.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::SmsMessageContent.acceptable_attributes).to eq(Bandwidth::SmsMessageContent.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::SmsMessageContent.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of SmsMessageContent created by the build_from_hash method' do + sms_message_content_from_hash = Bandwidth::SmsMessageContent.build_from_hash({ + text: 'Hello world' + }) + expect(sms_message_content_from_hash).to be_instance_of(Bandwidth::SmsMessageContent) + expect(sms_message_content_from_hash.text).to eq('Hello world') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(sms_message_content_values.to_s).to eq('{:text=>"Hello world"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + sms_message_content_equal = Bandwidth::SmsMessageContent.new({ + text: 'baseline' + }) + expect(sms_message_content_default.eql?(sms_message_content_equal)).to be true + expect(sms_message_content_default.eql?(sms_message_content_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(sms_message_content_values.to_body).to eq({ + text: 'Hello world' + }) + end + end + + describe 'custom attribute writers' do + it '#text=' do + expect { + Bandwidth::SmsMessageContent.new({ text: nil }) + }.to raise_error(ArgumentError, 'text cannot be nil') + + expect { + Bandwidth::SmsMessageContent.new({ text: 'a' * 2049 }) + }.to raise_error(ArgumentError, 'invalid value for "text", the character length must be smaller than or equal to 2048.') + end + end +end diff --git a/spec/unit/models/standalone_card_orientation_enum_spec.rb b/spec/unit/models/standalone_card_orientation_enum_spec.rb new file mode 100644 index 00000000..bd4054ee --- /dev/null +++ b/spec/unit/models/standalone_card_orientation_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::StandaloneCardOrientationEnum +describe Bandwidth::StandaloneCardOrientationEnum do + describe 'constants' do + it 'defines HORIZONTAL' do + expect(Bandwidth::StandaloneCardOrientationEnum::HORIZONTAL).to eq('HORIZONTAL') + end + + it 'defines VERTICAL' do + expect(Bandwidth::StandaloneCardOrientationEnum::VERTICAL).to eq('VERTICAL') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::StandaloneCardOrientationEnum.all_vars).to eq([ + 'HORIZONTAL', + 'VERTICAL' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::StandaloneCardOrientationEnum.build_from_hash('HORIZONTAL')).to eq('HORIZONTAL') + expect(Bandwidth::StandaloneCardOrientationEnum.build_from_hash('VERTICAL')).to eq('VERTICAL') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::StandaloneCardOrientationEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/status_callback_message_spec.rb b/spec/unit/models/status_callback_message_spec.rb new file mode 100644 index 00000000..7be07bcd --- /dev/null +++ b/spec/unit/models/status_callback_message_spec.rb @@ -0,0 +1,181 @@ +# Unit tests for Bandwidth::StatusCallbackMessage +describe Bandwidth::StatusCallbackMessage do + let(:status_callback_message_default) { Bandwidth::StatusCallbackMessage.new({ + id: 'baseline-id', + owner: '+19195554321', + application_id: 'baseline-app', + time: '2022-06-16T13:15:07.160Z', + segment_count: 1, + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + from: '+19195554321' + }) } + let(:status_callback_message_values) { Bandwidth::StatusCallbackMessage.new({ + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + application_id: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segment_count: 2, + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + tag: 'custom tag', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + priority: Bandwidth::PriorityEnum::DEFAULT, + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::StatusCallbackMessage.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::StatusCallbackMessage.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::StatusCallbackMessage.acceptable_attributes).to eq(Bandwidth::StatusCallbackMessage.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::StatusCallbackMessage.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of StatusCallbackMessage created by the build_from_hash method' do + status_callback_message_from_hash = Bandwidth::StatusCallbackMessage.build_from_hash({ + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 2, + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + tag: 'custom tag', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + priority: Bandwidth::PriorityEnum::DEFAULT, + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS + }) + expect(status_callback_message_from_hash).to be_instance_of(Bandwidth::StatusCallbackMessage) + expect(status_callback_message_from_hash.id).to eq('1589228074636lm4k2je7j7jklbn2') + expect(status_callback_message_from_hash.owner).to eq('+19195554321') + expect(status_callback_message_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') + expect(status_callback_message_from_hash.time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(status_callback_message_from_hash.segment_count).to eq(2) + expect(status_callback_message_from_hash.direction).to eq(Bandwidth::MessageDirectionEnum::OUT) + expect(status_callback_message_from_hash.to).to eq(['+19195551234']) + expect(status_callback_message_from_hash.from).to eq('+19195554321') + expect(status_callback_message_from_hash.text).to eq('Hello world') + expect(status_callback_message_from_hash.tag).to eq('custom tag') + expect(status_callback_message_from_hash.media).to eq(['https://dev.bandwidth.com/images/bandwidth-logo.png']) + expect(status_callback_message_from_hash.priority).to eq(Bandwidth::PriorityEnum::DEFAULT) + expect(status_callback_message_from_hash.channel).to eq(Bandwidth::MultiChannelMessageChannelEnum::SMS) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(status_callback_message_values.to_s).to eq('{:id=>"1589228074636lm4k2je7j7jklbn2", :owner=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :time=>"2022-06-16T13:15:07.160Z", :segmentCount=>2, :direction=>"out", :to=>["+19195551234"], :from=>"+19195554321", :text=>"Hello world", :tag=>"custom tag", :media=>["https://dev.bandwidth.com/images/bandwidth-logo.png"], :priority=>"default", :channel=>"SMS"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + status_callback_message_equal = Bandwidth::StatusCallbackMessage.new({ + id: 'baseline-id', + owner: '+19195554321', + application_id: 'baseline-app', + time: '2022-06-16T13:15:07.160Z', + segment_count: 1, + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + from: '+19195554321' + }) + expect(status_callback_message_default.eql?(status_callback_message_equal)).to be true + expect(status_callback_message_default.eql?(status_callback_message_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(status_callback_message_values.to_body).to eq({ + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 2, + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world', + tag: 'custom tag', + media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], + priority: Bandwidth::PriorityEnum::DEFAULT, + channel: Bandwidth::MultiChannelMessageChannelEnum::SMS + }) + end + end + + describe 'custom attribute writers' do + it '#id=' do + expect { + status_callback_message_values.id = nil + }.to raise_error(ArgumentError, 'id cannot be nil') + end + + it '#owner=' do + expect { + status_callback_message_values.owner = nil + }.to raise_error(ArgumentError, 'owner cannot be nil') + end + + it '#application_id=' do + expect { + status_callback_message_values.application_id = nil + }.to raise_error(ArgumentError, 'application_id cannot be nil') + end + + it '#time=' do + expect { + status_callback_message_values.time = nil + }.to raise_error(ArgumentError, 'time cannot be nil') + end + + it '#segment_count=' do + expect { + status_callback_message_values.segment_count = nil + }.to raise_error(ArgumentError, 'segment_count cannot be nil') + end + + it '#direction=' do + expect { + status_callback_message_values.direction = nil + }.to raise_error(ArgumentError, 'direction cannot be nil') + end + + it '#to=' do + expect { + status_callback_message_values.to = nil + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#from=' do + expect { + status_callback_message_values.from = nil + }.to raise_error(ArgumentError, 'from cannot be nil') + end + end +end diff --git a/spec/unit/models/status_callback_spec.rb b/spec/unit/models/status_callback_spec.rb new file mode 100644 index 00000000..62fe4444 --- /dev/null +++ b/spec/unit/models/status_callback_spec.rb @@ -0,0 +1,169 @@ +# Unit tests for Bandwidth::StatusCallback +describe Bandwidth::StatusCallback do + let(:status_callback_default) { Bandwidth::StatusCallback.new({ + time: '2022-06-16T13:15:07.160Z', + type: Bandwidth::StatusCallbackTypeEnum::MESSAGE_DELIVERED, + to: '+19195551234', + description: 'baseline description', + message: { id: 'baseline' } + }) } + let(:status_callback_values) { Bandwidth::StatusCallback.new({ + time: '2022-06-16T13:15:07.160Z', + event_time: '2022-06-16T13:16:07.160Z', + type: Bandwidth::StatusCallbackTypeEnum::MESSAGE_DELIVERED, + to: '+19195551234', + description: 'Message delivered to carrier', + message: { + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 1, + direction: 'out', + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world' + }, + error_code: 0, + carrier_name: 'Verizon' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::StatusCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::StatusCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::StatusCallback.acceptable_attributes).to eq(Bandwidth::StatusCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::StatusCallback.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of StatusCallback created by the build_from_hash method' do + status_callback_from_hash = Bandwidth::StatusCallback.build_from_hash({ + time: '2022-06-16T13:15:07.160Z', + eventTime: '2022-06-16T13:16:07.160Z', + type: Bandwidth::StatusCallbackTypeEnum::MESSAGE_DELIVERED, + to: '+19195551234', + description: 'Message delivered to carrier', + message: { + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 1, + direction: Bandwidth::MessageDirectionEnum::OUT, + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world' + }, + errorCode: 0, + carrierName: 'Verizon' + }) + expect(status_callback_from_hash).to be_instance_of(Bandwidth::StatusCallback) + expect(status_callback_from_hash.time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(status_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:16:07.160Z')) + expect(status_callback_from_hash.type).to eq(Bandwidth::StatusCallbackTypeEnum::MESSAGE_DELIVERED) + expect(status_callback_from_hash.to).to eq('+19195551234') + expect(status_callback_from_hash.description).to eq('Message delivered to carrier') + expect(status_callback_from_hash.message).to be_instance_of(Bandwidth::StatusCallbackMessage) + expect(status_callback_from_hash.message.id).to eq('1589228074636lm4k2je7j7jklbn2') + expect(status_callback_from_hash.message.text).to eq('Hello world') + expect(status_callback_from_hash.error_code).to eq(0) + expect(status_callback_from_hash.carrier_name).to eq('Verizon') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(status_callback_values.to_s).to eq('{:time=>"2022-06-16T13:15:07.160Z", :eventTime=>"2022-06-16T13:16:07.160Z", :type=>"message-delivered", :to=>"+19195551234", :description=>"Message delivered to carrier", :message=>{:id=>"1589228074636lm4k2je7j7jklbn2", :owner=>"+19195554321", :applicationId=>"93de2206-9669-4e07-948d-329f4b722ee2", :time=>"2022-06-16T13:15:07.160Z", :segmentCount=>1, :direction=>"out", :to=>["+19195551234"], :from=>"+19195554321", :text=>"Hello world"}, :errorCode=>0, :carrierName=>"Verizon"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + status_callback_equal = Bandwidth::StatusCallback.new({ + time: '2022-06-16T13:15:07.160Z', + type: Bandwidth::StatusCallbackTypeEnum::MESSAGE_DELIVERED, + to: '+19195551234', + description: 'baseline description', + message: { id: 'baseline' } + }) + expect(status_callback_default.eql?(status_callback_equal)).to be true + expect(status_callback_default.eql?(status_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(status_callback_values.to_body).to eq({ + time: '2022-06-16T13:15:07.160Z', + eventTime: '2022-06-16T13:16:07.160Z', + type: Bandwidth::StatusCallbackTypeEnum::MESSAGE_DELIVERED, + to: '+19195551234', + description: 'Message delivered to carrier', + message: { + id: '1589228074636lm4k2je7j7jklbn2', + owner: '+19195554321', + applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', + time: '2022-06-16T13:15:07.160Z', + segmentCount: 1, + direction: 'out', + to: ['+19195551234'], + from: '+19195554321', + text: 'Hello world' + }, + errorCode: 0, + carrierName: 'Verizon' + }) + end + end + + describe 'custom attribute writers' do + it '#time=' do + expect { + status_callback_values.time = nil + }.to raise_error(ArgumentError, 'time cannot be nil') + end + + it '#type=' do + expect { + status_callback_values.type = nil + }.to raise_error(ArgumentError, 'type cannot be nil') + end + + it '#to=' do + expect { + status_callback_values.to = nil + }.to raise_error(ArgumentError, 'to cannot be nil') + end + + it '#description=' do + expect { + status_callback_values.description = nil + }.to raise_error(ArgumentError, 'description cannot be nil') + end + + it '#message=' do + expect { + status_callback_values.message = nil + }.to raise_error(ArgumentError, 'message cannot be nil') + end + end +end diff --git a/spec/unit/models/status_callback_type_enum_spec.rb b/spec/unit/models/status_callback_type_enum_spec.rb new file mode 100644 index 00000000..abcf0398 --- /dev/null +++ b/spec/unit/models/status_callback_type_enum_spec.rb @@ -0,0 +1,46 @@ +# Unit tests for Bandwidth::StatusCallbackTypeEnum +describe Bandwidth::StatusCallbackTypeEnum do + describe 'constants' do + it 'defines MESSAGE_SENDING' do + expect(Bandwidth::StatusCallbackTypeEnum::MESSAGE_SENDING).to eq('message-sending') + end + + it 'defines MESSAGE_DELIVERED' do + expect(Bandwidth::StatusCallbackTypeEnum::MESSAGE_DELIVERED).to eq('message-delivered') + end + + it 'defines MESSAGE_FAILED' do + expect(Bandwidth::StatusCallbackTypeEnum::MESSAGE_FAILED).to eq('message-failed') + end + + it 'defines MESSAGE_READ' do + expect(Bandwidth::StatusCallbackTypeEnum::MESSAGE_READ).to eq('message-read') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::StatusCallbackTypeEnum.all_vars).to eq([ + 'message-sending', + 'message-delivered', + 'message-failed', + 'message-read' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::StatusCallbackTypeEnum.build_from_hash('message-sending')).to eq('message-sending') + expect(Bandwidth::StatusCallbackTypeEnum.build_from_hash('message-delivered')).to eq('message-delivered') + expect(Bandwidth::StatusCallbackTypeEnum.build_from_hash('message-failed')).to eq('message-failed') + expect(Bandwidth::StatusCallbackTypeEnum.build_from_hash('message-read')).to eq('message-read') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::StatusCallbackTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/stir_shaken_spec.rb b/spec/unit/models/stir_shaken_spec.rb new file mode 100644 index 00000000..0edb60e7 --- /dev/null +++ b/spec/unit/models/stir_shaken_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::StirShaken +describe Bandwidth::StirShaken do + let(:stir_shaken_default) { Bandwidth::StirShaken.new } + let(:stir_shaken_values) { Bandwidth::StirShaken.new({ + verstat: 'TN-Validation-Passed', + attestation_indicator: 'A', + originating_id: '99759086-1335-11ed-9bcf-5f7d464e91af' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::StirShaken.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::StirShaken.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::StirShaken.acceptable_attributes).to eq(Bandwidth::StirShaken.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::StirShaken.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of StirShaken created by the build_from_hash method' do + stir_shaken_from_hash = Bandwidth::StirShaken.build_from_hash({ + verstat: 'TN-Validation-Passed', + attestationIndicator: 'A', + originatingId: '99759086-1335-11ed-9bcf-5f7d464e91af' + }) + expect(stir_shaken_from_hash).to be_instance_of(Bandwidth::StirShaken) + expect(stir_shaken_from_hash.verstat).to eq('TN-Validation-Passed') + expect(stir_shaken_from_hash.attestation_indicator).to eq('A') + expect(stir_shaken_from_hash.originating_id).to eq('99759086-1335-11ed-9bcf-5f7d464e91af') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(stir_shaken_values.to_s).to eq('{:verstat=>"TN-Validation-Passed", :attestationIndicator=>"A", :originatingId=>"99759086-1335-11ed-9bcf-5f7d464e91af"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(stir_shaken_default.eql?(Bandwidth::StirShaken.new)).to be true + expect(stir_shaken_default.eql?(stir_shaken_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(stir_shaken_values.to_body).to eq({ + verstat: 'TN-Validation-Passed', + attestationIndicator: 'A', + originatingId: '99759086-1335-11ed-9bcf-5f7d464e91af' + }) + end + end +end diff --git a/spec/unit/models/sync_lookup_request_spec.rb b/spec/unit/models/sync_lookup_request_spec.rb new file mode 100644 index 00000000..97314209 --- /dev/null +++ b/spec/unit/models/sync_lookup_request_spec.rb @@ -0,0 +1,91 @@ +# Unit tests for Bandwidth::SyncLookupRequest +describe Bandwidth::SyncLookupRequest do + let(:sync_lookup_request_default) { Bandwidth::SyncLookupRequest.new({ + phone_numbers: ['+19195551234'] + }) } + let(:sync_lookup_request_values) { Bandwidth::SyncLookupRequest.new({ + phone_numbers: ['+19195551234', '+19195554321'], + rcs_agent: 'my_agent' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::SyncLookupRequest.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::SyncLookupRequest.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::SyncLookupRequest.acceptable_attributes).to eq(Bandwidth::SyncLookupRequest.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::SyncLookupRequest.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of SyncLookupRequest created by the build_from_hash method' do + sync_lookup_request_from_hash = Bandwidth::SyncLookupRequest.build_from_hash({ + phoneNumbers: ['+19195551234', '+19195554321'], + rcsAgent: 'my_agent' + }) + expect(sync_lookup_request_from_hash).to be_instance_of(Bandwidth::SyncLookupRequest) + expect(sync_lookup_request_from_hash.phone_numbers).to eq(['+19195551234', '+19195554321']) + expect(sync_lookup_request_from_hash.rcs_agent).to eq('my_agent') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(sync_lookup_request_values.to_s).to eq('{:phoneNumbers=>["+19195551234", "+19195554321"], :rcsAgent=>"my_agent"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + sync_lookup_request_equal = Bandwidth::SyncLookupRequest.new({ + phone_numbers: ['+19195551234'] + }) + expect(sync_lookup_request_default.eql?(sync_lookup_request_equal)).to be true + expect(sync_lookup_request_default.eql?(sync_lookup_request_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(sync_lookup_request_values.to_body).to eq({ + phoneNumbers: ['+19195551234', '+19195554321'], + rcsAgent: 'my_agent' + }) + end + end + + describe 'custom attribute writers' do + it '#phone_numbers=' do + expect { + sync_lookup_request_values.phone_numbers = nil + }.to raise_error(ArgumentError, 'phone_numbers cannot be nil') + end + + it '#rcs_agent=' do + expect { + Bandwidth::SyncLookupRequest.new({ phone_numbers: ['+19195551234'], rcs_agent: nil }) + }.to raise_error(ArgumentError, 'rcs_agent cannot be nil') + + expect { + Bandwidth::SyncLookupRequest.new({ phone_numbers: ['+19195551234'], rcs_agent: 'invalid agent!' }) + }.to raise_error(ArgumentError, 'invalid value for "rcs_agent", must conform to the pattern (?-mix:^[A-Za-z0-9_-]{1,40}$).') + end + end +end diff --git a/spec/unit/models/telephone_number_spec.rb b/spec/unit/models/telephone_number_spec.rb new file mode 100644 index 00000000..9f5aa890 --- /dev/null +++ b/spec/unit/models/telephone_number_spec.rb @@ -0,0 +1,64 @@ +# Unit tests for Bandwidth::TelephoneNumber +describe Bandwidth::TelephoneNumber do + let(:telephone_number_default) { Bandwidth::TelephoneNumber.new } + let(:telephone_number_values) { Bandwidth::TelephoneNumber.new({ + telephone_number: '+19195551234' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TelephoneNumber.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TelephoneNumber.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TelephoneNumber.acceptable_attributes).to eq(Bandwidth::TelephoneNumber.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::TelephoneNumber.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TelephoneNumber created by the build_from_hash method' do + telephone_number_from_hash = Bandwidth::TelephoneNumber.build_from_hash({ + telephoneNumber: '+19195551234' + }) + expect(telephone_number_from_hash).to be_instance_of(Bandwidth::TelephoneNumber) + expect(telephone_number_from_hash.telephone_number).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(telephone_number_values.to_s).to eq('{:telephoneNumber=>"+19195551234"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(telephone_number_default.eql?(Bandwidth::TelephoneNumber.new)).to be true + expect(telephone_number_default.eql?(telephone_number_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(telephone_number_values.to_body).to eq({ + telephoneNumber: '+19195551234' + }) + end + end +end diff --git a/spec/unit/models/tfv_basic_authentication_spec.rb b/spec/unit/models/tfv_basic_authentication_spec.rb new file mode 100644 index 00000000..ce09e8bc --- /dev/null +++ b/spec/unit/models/tfv_basic_authentication_spec.rb @@ -0,0 +1,97 @@ +# Unit tests for Bandwidth::TfvBasicAuthentication +describe Bandwidth::TfvBasicAuthentication do + let(:tfv_basic_authentication_default) { Bandwidth::TfvBasicAuthentication.new({ + username: 'baseline', + password: 'baselinePass' + }) } + let(:tfv_basic_authentication_values) { Bandwidth::TfvBasicAuthentication.new({ + username: 'mySecretUsername', + password: 'mySecretPassword' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TfvBasicAuthentication.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TfvBasicAuthentication.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TfvBasicAuthentication.acceptable_attributes).to eq(Bandwidth::TfvBasicAuthentication.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::TfvBasicAuthentication.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TfvBasicAuthentication created by the build_from_hash method' do + tfv_basic_authentication_from_hash = Bandwidth::TfvBasicAuthentication.build_from_hash({ + username: 'mySecretUsername', + password: 'mySecretPassword' + }) + expect(tfv_basic_authentication_from_hash).to be_instance_of(Bandwidth::TfvBasicAuthentication) + expect(tfv_basic_authentication_from_hash.username).to eq('mySecretUsername') + expect(tfv_basic_authentication_from_hash.password).to eq('mySecretPassword') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(tfv_basic_authentication_values.to_s).to eq('{:username=>"mySecretUsername", :password=>"mySecretPassword"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + tfv_basic_authentication_equal = Bandwidth::TfvBasicAuthentication.new({ + username: 'baseline', + password: 'baselinePass' + }) + expect(tfv_basic_authentication_default.eql?(tfv_basic_authentication_equal)).to be true + expect(tfv_basic_authentication_default.eql?(tfv_basic_authentication_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(tfv_basic_authentication_values.to_body).to eq({ + username: 'mySecretUsername', + password: 'mySecretPassword' + }) + end + end + + describe 'custom attribute writers' do + it '#username=' do + expect { + Bandwidth::TfvBasicAuthentication.new({ username: nil, password: 'pass' }) + }.to raise_error(ArgumentError, 'username cannot be nil') + + expect { + Bandwidth::TfvBasicAuthentication.new({ username: 'a' * 101, password: 'pass' }) + }.to raise_error(ArgumentError, 'invalid value for "username", the character length must be smaller than or equal to 100.') + end + + it '#password=' do + expect { + Bandwidth::TfvBasicAuthentication.new({ username: 'user', password: nil }) + }.to raise_error(ArgumentError, 'password cannot be nil') + + expect { + Bandwidth::TfvBasicAuthentication.new({ username: 'user', password: 'a' * 201 }) + }.to raise_error(ArgumentError, 'invalid value for "password", the character length must be smaller than or equal to 200.') + end + end +end diff --git a/spec/unit/models/tfv_callback_status_enum_spec.rb b/spec/unit/models/tfv_callback_status_enum_spec.rb new file mode 100644 index 00000000..d75e8fe9 --- /dev/null +++ b/spec/unit/models/tfv_callback_status_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::TfvCallbackStatusEnum +describe Bandwidth::TfvCallbackStatusEnum do + describe 'constants' do + it 'defines VERIFIED' do + expect(Bandwidth::TfvCallbackStatusEnum::VERIFIED).to eq('VERIFIED') + end + + it 'defines UNVERIFIED' do + expect(Bandwidth::TfvCallbackStatusEnum::UNVERIFIED).to eq('UNVERIFIED') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::TfvCallbackStatusEnum.all_vars).to eq([ + 'VERIFIED', + 'UNVERIFIED' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::TfvCallbackStatusEnum.build_from_hash('VERIFIED')).to eq('VERIFIED') + expect(Bandwidth::TfvCallbackStatusEnum.build_from_hash('UNVERIFIED')).to eq('UNVERIFIED') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::TfvCallbackStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/tfv_error_spec.rb b/spec/unit/models/tfv_error_spec.rb index f6cd7d0b..f7634b09 100644 --- a/spec/unit/models/tfv_error_spec.rb +++ b/spec/unit/models/tfv_error_spec.rb @@ -27,9 +27,9 @@ end end - describe 'enum validation' do - it 'works' do - + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::TfvError.openapi_nullable).to eq(Set.new([])) end end @@ -47,12 +47,6 @@ end end - describe '#hash' do - it 'returns a hash code according to attributes' do - expect(tfv_error_default.hash).to be_instance_of(Integer) - end - end - describe '#to_s' do it 'returns a string representation of the object' do expect(tfv_error_values.to_s).to eq('{:type=>"type", :description=>"description", :errors=>{:key=>"value"}}') diff --git a/spec/unit/models/tfv_status_enum_spec.rb b/spec/unit/models/tfv_status_enum_spec.rb new file mode 100644 index 00000000..3b37e1df --- /dev/null +++ b/spec/unit/models/tfv_status_enum_spec.rb @@ -0,0 +1,40 @@ +# Unit tests for Bandwidth::TfvStatusEnum +describe Bandwidth::TfvStatusEnum do + describe 'constants' do + it 'defines VERIFIED' do + expect(Bandwidth::TfvStatusEnum::VERIFIED).to eq('VERIFIED') + end + + it 'defines UNVERIFIED' do + expect(Bandwidth::TfvStatusEnum::UNVERIFIED).to eq('UNVERIFIED') + end + + it 'defines PENDING' do + expect(Bandwidth::TfvStatusEnum::PENDING).to eq('PENDING') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::TfvStatusEnum.all_vars).to eq([ + 'VERIFIED', + 'UNVERIFIED', + 'PENDING' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::TfvStatusEnum.build_from_hash('VERIFIED')).to eq('VERIFIED') + expect(Bandwidth::TfvStatusEnum.build_from_hash('UNVERIFIED')).to eq('UNVERIFIED') + expect(Bandwidth::TfvStatusEnum.build_from_hash('PENDING')).to eq('PENDING') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::TfvStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/tfv_status_spec.rb b/spec/unit/models/tfv_status_spec.rb new file mode 100644 index 00000000..baa953ed --- /dev/null +++ b/spec/unit/models/tfv_status_spec.rb @@ -0,0 +1,130 @@ +# Unit tests for Bandwidth::TfvStatus +describe Bandwidth::TfvStatus do + let(:tfv_status_default) { Bandwidth::TfvStatus.new } + let(:tfv_status_values) { Bandwidth::TfvStatus.new({ + phone_number: '+18005554321', + status: Bandwidth::TfvStatusEnum::VERIFIED, + internal_ticket_number: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3', + decline_reason_description: 'The reason for declining', + resubmit_allowed: false, + created_date_time: '2024-01-01T00:00:00Z', + modified_date_time: '2024-01-02T00:00:00Z', + submission: { businessAddress: { name: 'Bandwidth' } }, + blocked: false, + blocked_reason: 'The reason for blocking', + cv_token: 'cv_token_value' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TfvStatus.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TfvStatus.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TfvStatus.acceptable_attributes).to eq(Bandwidth::TfvStatus.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::TfvStatus.openapi_nullable).to eq(Set.new([:'cv_token'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TfvStatus created by the build_from_hash method' do + tfv_status_from_hash = Bandwidth::TfvStatus.build_from_hash({ + phoneNumber: '+18005554321', + status: Bandwidth::TfvStatusEnum::VERIFIED, + internalTicketNumber: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3', + declineReasonDescription: 'The reason for declining', + resubmitAllowed: false, + createdDateTime: '2024-01-01T00:00:00Z', + modifiedDateTime: '2024-01-02T00:00:00Z', + submission: { businessAddress: { name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: 'https://www.bandwidth.com' } }, + blocked: false, + blockedReason: 'The reason for blocking', + cvToken: 'cv_token_value' + }) + expect(tfv_status_from_hash).to be_instance_of(Bandwidth::TfvStatus) + expect(tfv_status_from_hash.phone_number).to eq('+18005554321') + expect(tfv_status_from_hash.status).to eq(Bandwidth::TfvStatusEnum::VERIFIED) + expect(tfv_status_from_hash.internal_ticket_number).to eq('8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3') + expect(tfv_status_from_hash.decline_reason_description).to eq('The reason for declining') + expect(tfv_status_from_hash.resubmit_allowed).to eq(false) + expect(tfv_status_from_hash.created_date_time).to eq(Time.parse('2024-01-01T00:00:00Z')) + expect(tfv_status_from_hash.modified_date_time).to eq(Time.parse('2024-01-02T00:00:00Z')) + expect(tfv_status_from_hash.submission).to be_instance_of(Bandwidth::TfvSubmissionInfo) + expect(tfv_status_from_hash.blocked).to eq(false) + expect(tfv_status_from_hash.blocked_reason).to eq('The reason for blocking') + expect(tfv_status_from_hash.cv_token).to eq('cv_token_value') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(tfv_status_values.to_s).to eq('{:phoneNumber=>"+18005554321", :status=>"VERIFIED", :internalTicketNumber=>"8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3", :declineReasonDescription=>"The reason for declining", :resubmitAllowed=>false, :createdDateTime=>"2024-01-01T00:00:00Z", :modifiedDateTime=>"2024-01-02T00:00:00Z", :submission=>{:businessAddress=>{:name=>"Bandwidth"}}, :blocked=>false, :blockedReason=>"The reason for blocking", :cvToken=>"cv_token_value"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(tfv_status_default.eql?(Bandwidth::TfvStatus.new)).to be true + expect(tfv_status_default.eql?(tfv_status_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(tfv_status_values.to_body).to eq({ + phoneNumber: '+18005554321', + status: Bandwidth::TfvStatusEnum::VERIFIED, + internalTicketNumber: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3', + declineReasonDescription: 'The reason for declining', + resubmitAllowed: false, + createdDateTime: '2024-01-01T00:00:00Z', + modifiedDateTime: '2024-01-02T00:00:00Z', + submission: { businessAddress: { name: 'Bandwidth' } }, + blocked: false, + blockedReason: 'The reason for blocking', + cvToken: 'cv_token_value' + }) + end + end + + describe 'custom attribute writers' do + it '#phone_number=' do + expect { + Bandwidth::TfvStatus.new({ phone_number: nil }) + }.to raise_error(ArgumentError, 'phone_number cannot be nil') + + expect { + Bandwidth::TfvStatus.new({ phone_number: '+1800555432' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be greater than or equal to 12.') + + expect { + Bandwidth::TfvStatus.new({ phone_number: '+180055543210' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be smaller than or equal to 12.') + + expect { + Bandwidth::TfvStatus.new({ phone_number: '+12345678901' }) + }.to raise_error(ArgumentError, /invalid value for "phone_number", must conform to the pattern/) + end + + it '#cv_token=' do + expect { + Bandwidth::TfvStatus.new({ cv_token: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "cv_token", the character length must be smaller than or equal to 500.') + end + end +end diff --git a/spec/unit/models/tfv_submission_info_spec.rb b/spec/unit/models/tfv_submission_info_spec.rb new file mode 100644 index 00000000..92584d16 --- /dev/null +++ b/spec/unit/models/tfv_submission_info_spec.rb @@ -0,0 +1,224 @@ +# Unit tests for Bandwidth::TfvSubmissionInfo +describe Bandwidth::TfvSubmissionInfo do + let(:tfv_submission_info_default) { Bandwidth::TfvSubmissionInfo.new } + let(:tfv_submission_info_values) { Bandwidth::TfvSubmissionInfo.new({ + business_address: { name: 'Bandwidth' }, + business_contact: { firstName: 'Jane' }, + message_volume: 1000, + use_case: 'Customer notifications', + use_case_summary: 'Send customers updates about their orders', + production_message_content: 'Your order has shipped', + opt_in_workflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additional_information: 'extra info', + isv_reseller: 'My ISV', + privacy_policy_url: 'https://example.com/privacy', + terms_and_conditions_url: 'https://example.com/terms', + business_dba: 'Bandwidth Inc', + business_registration_number: '12-3456789', + business_registration_type: Bandwidth::BusinessRegistrationTypeEnum::EIN, + business_registration_issuing_country: 'USA', + business_entity_type: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TfvSubmissionInfo.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TfvSubmissionInfo.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TfvSubmissionInfo.acceptable_attributes).to eq(Bandwidth::TfvSubmissionInfo.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::TfvSubmissionInfo.openapi_nullable).to eq(Set.new([ + :'additional_information', + :'isv_reseller', + :'business_registration_number', + :'business_registration_type', + :'business_registration_issuing_country' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TfvSubmissionInfo created by the build_from_hash method' do + tfv_submission_info_from_hash = Bandwidth::TfvSubmissionInfo.build_from_hash({ + businessAddress: { name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: 'https://www.bandwidth.com' }, + businessContact: { firstName: 'Jane', lastName: 'Doe', email: 'jane@bandwidth.com', phoneNumber: '+19195551234' }, + messageVolume: 1000, + useCase: 'Customer notifications', + useCaseSummary: 'Send customers updates about their orders', + productionMessageContent: 'Your order has shipped', + optInWorkflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additionalInformation: 'extra info', + isvReseller: 'My ISV', + privacyPolicyUrl: 'https://example.com/privacy', + termsAndConditionsUrl: 'https://example.com/terms', + businessDba: 'Bandwidth Inc', + businessRegistrationNumber: '12-3456789', + businessRegistrationType: Bandwidth::BusinessRegistrationTypeEnum::EIN, + businessRegistrationIssuingCountry: 'USA', + businessEntityType: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT + }) + expect(tfv_submission_info_from_hash).to be_instance_of(Bandwidth::TfvSubmissionInfo) + expect(tfv_submission_info_from_hash.business_address).to be_instance_of(Bandwidth::Address) + expect(tfv_submission_info_from_hash.business_contact).to be_instance_of(Bandwidth::Contact) + expect(tfv_submission_info_from_hash.message_volume).to eq(1000) + expect(tfv_submission_info_from_hash.use_case).to eq('Customer notifications') + expect(tfv_submission_info_from_hash.use_case_summary).to eq('Send customers updates about their orders') + expect(tfv_submission_info_from_hash.production_message_content).to eq('Your order has shipped') + expect(tfv_submission_info_from_hash.opt_in_workflow).to be_instance_of(Bandwidth::OptInWorkflow) + expect(tfv_submission_info_from_hash.additional_information).to eq('extra info') + expect(tfv_submission_info_from_hash.isv_reseller).to eq('My ISV') + expect(tfv_submission_info_from_hash.privacy_policy_url).to eq('https://example.com/privacy') + expect(tfv_submission_info_from_hash.terms_and_conditions_url).to eq('https://example.com/terms') + expect(tfv_submission_info_from_hash.business_dba).to eq('Bandwidth Inc') + expect(tfv_submission_info_from_hash.business_registration_number).to eq('12-3456789') + expect(tfv_submission_info_from_hash.business_registration_type).to eq(Bandwidth::BusinessRegistrationTypeEnum::EIN) + expect(tfv_submission_info_from_hash.business_registration_issuing_country).to eq('USA') + expect(tfv_submission_info_from_hash.business_entity_type).to eq(Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(tfv_submission_info_values.to_s).to eq('{:businessAddress=>{:name=>"Bandwidth"}, :businessContact=>{:firstName=>"Jane"}, :messageVolume=>1000, :useCase=>"Customer notifications", :useCaseSummary=>"Send customers updates about their orders", :productionMessageContent=>"Your order has shipped", :optInWorkflow=>{:description=>"opt-in via website", :imageUrls=>["https://example.com/optin.png"]}, :additionalInformation=>"extra info", :isvReseller=>"My ISV", :privacyPolicyUrl=>"https://example.com/privacy", :termsAndConditionsUrl=>"https://example.com/terms", :businessDba=>"Bandwidth Inc", :businessRegistrationNumber=>"12-3456789", :businessRegistrationType=>"EIN", :businessRegistrationIssuingCountry=>"USA", :businessEntityType=>"PRIVATE_PROFIT"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(tfv_submission_info_default.eql?(Bandwidth::TfvSubmissionInfo.new)).to be true + expect(tfv_submission_info_default.eql?(tfv_submission_info_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(tfv_submission_info_values.to_body).to eq({ + businessAddress: { name: 'Bandwidth' }, + businessContact: { firstName: 'Jane' }, + messageVolume: 1000, + useCase: 'Customer notifications', + useCaseSummary: 'Send customers updates about their orders', + productionMessageContent: 'Your order has shipped', + optInWorkflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additionalInformation: 'extra info', + isvReseller: 'My ISV', + privacyPolicyUrl: 'https://example.com/privacy', + termsAndConditionsUrl: 'https://example.com/terms', + businessDba: 'Bandwidth Inc', + businessRegistrationNumber: '12-3456789', + businessRegistrationType: Bandwidth::BusinessRegistrationTypeEnum::EIN, + businessRegistrationIssuingCountry: 'USA', + businessEntityType: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT + }) + end + end + + describe 'custom attribute writers' do + it '#message_volume=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ message_volume: nil }) + }.to raise_error(ArgumentError, 'message_volume cannot be nil') + + expect { + Bandwidth::TfvSubmissionInfo.new({ message_volume: 10000001 }) + }.to raise_error(ArgumentError, 'invalid value for "message_volume", must be smaller than or equal to 10000000.') + + expect { + Bandwidth::TfvSubmissionInfo.new({ message_volume: 9 }) + }.to raise_error(ArgumentError, 'invalid value for "message_volume", must be greater than or equal to 10.') + end + + it '#use_case=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ use_case: nil }) + }.to raise_error(ArgumentError, 'use_case cannot be nil') + + expect { + Bandwidth::TfvSubmissionInfo.new({ use_case: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "use_case", the character length must be smaller than or equal to 500.') + end + + it '#use_case_summary=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ use_case_summary: nil }) + }.to raise_error(ArgumentError, 'use_case_summary cannot be nil') + + expect { + Bandwidth::TfvSubmissionInfo.new({ use_case_summary: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "use_case_summary", the character length must be smaller than or equal to 500.') + end + + it '#production_message_content=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ production_message_content: nil }) + }.to raise_error(ArgumentError, 'production_message_content cannot be nil') + + expect { + Bandwidth::TfvSubmissionInfo.new({ production_message_content: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "production_message_content", the character length must be smaller than or equal to 500.') + end + + it '#additional_information=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ additional_information: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "additional_information", the character length must be smaller than or equal to 500.') + end + + it '#isv_reseller=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ isv_reseller: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "isv_reseller", the character length must be smaller than or equal to 500.') + end + + it '#privacy_policy_url=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ privacy_policy_url: nil }) + }.to raise_error(ArgumentError, 'privacy_policy_url cannot be nil') + + expect { + Bandwidth::TfvSubmissionInfo.new({ privacy_policy_url: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "privacy_policy_url", the character length must be smaller than or equal to 500.') + end + + it '#terms_and_conditions_url=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ terms_and_conditions_url: nil }) + }.to raise_error(ArgumentError, 'terms_and_conditions_url cannot be nil') + + expect { + Bandwidth::TfvSubmissionInfo.new({ terms_and_conditions_url: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "terms_and_conditions_url", the character length must be smaller than or equal to 500.') + end + + it '#business_dba=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ business_dba: nil }) + }.to raise_error(ArgumentError, 'business_dba cannot be nil') + + expect { + Bandwidth::TfvSubmissionInfo.new({ business_dba: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "business_dba", the character length must be smaller than or equal to 500.') + end + + it '#business_registration_number=' do + expect { + Bandwidth::TfvSubmissionInfo.new({ business_registration_number: 'a' * 501 }) + }.to raise_error(ArgumentError, 'invalid value for "business_registration_number", the character length must be smaller than or equal to 500.') + end + end +end diff --git a/spec/unit/models/tfv_submission_wrapper_spec.rb b/spec/unit/models/tfv_submission_wrapper_spec.rb new file mode 100644 index 00000000..58a9dd08 --- /dev/null +++ b/spec/unit/models/tfv_submission_wrapper_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::TfvSubmissionWrapper +describe Bandwidth::TfvSubmissionWrapper do + let(:tfv_submission_wrapper_default) { Bandwidth::TfvSubmissionWrapper.new } + let(:tfv_submission_wrapper_values) { Bandwidth::TfvSubmissionWrapper.new({ + submission: { businessDba: 'Bandwidth Inc' } + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TfvSubmissionWrapper.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TfvSubmissionWrapper.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TfvSubmissionWrapper.acceptable_attributes).to eq(Bandwidth::TfvSubmissionWrapper.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::TfvSubmissionWrapper.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TfvSubmissionWrapper created by the build_from_hash method' do + tfv_submission_wrapper_from_hash = Bandwidth::TfvSubmissionWrapper.build_from_hash({ + submission: { + businessAddress: { name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: 'https://www.bandwidth.com' }, + businessContact: { firstName: 'Jane', lastName: 'Doe', email: 'jane@bandwidth.com', phoneNumber: '+19195551234' }, + messageVolume: 1000, + useCase: 'Customer notifications', + useCaseSummary: 'Send customers updates about their orders', + productionMessageContent: 'Your order has shipped', + optInWorkflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + privacyPolicyUrl: 'https://example.com/privacy', + termsAndConditionsUrl: 'https://example.com/terms', + businessDba: 'Bandwidth Inc' + } + }) + expect(tfv_submission_wrapper_from_hash).to be_instance_of(Bandwidth::TfvSubmissionWrapper) + expect(tfv_submission_wrapper_from_hash.submission).to be_instance_of(Bandwidth::VerificationUpdateRequest) + expect(tfv_submission_wrapper_from_hash.submission.business_dba).to eq('Bandwidth Inc') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(tfv_submission_wrapper_values.to_s).to eq('{:submission=>{:businessDba=>"Bandwidth Inc"}}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(tfv_submission_wrapper_default.eql?(Bandwidth::TfvSubmissionWrapper.new)).to be true + expect(tfv_submission_wrapper_default.eql?(tfv_submission_wrapper_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(tfv_submission_wrapper_values.to_body).to eq({ + submission: { businessDba: 'Bandwidth Inc' } + }) + end + end +end diff --git a/spec/unit/models/thumbnail_alignment_enum_spec.rb b/spec/unit/models/thumbnail_alignment_enum_spec.rb new file mode 100644 index 00000000..9794677d --- /dev/null +++ b/spec/unit/models/thumbnail_alignment_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::ThumbnailAlignmentEnum +describe Bandwidth::ThumbnailAlignmentEnum do + describe 'constants' do + it 'defines LEFT' do + expect(Bandwidth::ThumbnailAlignmentEnum::LEFT).to eq('LEFT') + end + + it 'defines RIGHT' do + expect(Bandwidth::ThumbnailAlignmentEnum::RIGHT).to eq('RIGHT') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::ThumbnailAlignmentEnum.all_vars).to eq([ + 'LEFT', + 'RIGHT' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::ThumbnailAlignmentEnum.build_from_hash('LEFT')).to eq('LEFT') + expect(Bandwidth::ThumbnailAlignmentEnum.build_from_hash('RIGHT')).to eq('RIGHT') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::ThumbnailAlignmentEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/transcribe_recording_spec.rb b/spec/unit/models/transcribe_recording_spec.rb new file mode 100644 index 00000000..d25d13ef --- /dev/null +++ b/spec/unit/models/transcribe_recording_spec.rb @@ -0,0 +1,119 @@ +# Unit tests for Bandwidth::TranscribeRecording +describe Bandwidth::TranscribeRecording do + let(:transcribe_recording_default) { Bandwidth::TranscribeRecording.new } + let(:transcribe_recording_values) { Bandwidth::TranscribeRecording.new({ + callback_url: 'https://example.com/callback', + callback_method: Bandwidth::CallbackMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + tag: 'arbitrary tag', + callback_timeout: 5.5, + detect_language: true + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TranscribeRecording.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TranscribeRecording.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TranscribeRecording.acceptable_attributes).to eq(Bandwidth::TranscribeRecording.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::TranscribeRecording.openapi_nullable).to eq(Set.new([ + :'callback_method', + :'username', + :'password', + :'tag', + :'callback_timeout', + :'detect_language' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TranscribeRecording created by the build_from_hash method' do + transcribe_recording_from_hash = Bandwidth::TranscribeRecording.build_from_hash({ + callbackUrl: 'https://example.com/callback', + callbackMethod: Bandwidth::CallbackMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + tag: 'arbitrary tag', + callbackTimeout: 5.5, + detectLanguage: true + }) + expect(transcribe_recording_from_hash).to be_instance_of(Bandwidth::TranscribeRecording) + expect(transcribe_recording_from_hash.callback_url).to eq('https://example.com/callback') + expect(transcribe_recording_from_hash.callback_method).to eq(Bandwidth::CallbackMethodEnum::POST) + expect(transcribe_recording_from_hash.username).to eq('mySecretUsername') + expect(transcribe_recording_from_hash.password).to eq('mySecretPassword') + expect(transcribe_recording_from_hash.tag).to eq('arbitrary tag') + expect(transcribe_recording_from_hash.callback_timeout).to eq(5.5) + expect(transcribe_recording_from_hash.detect_language).to eq(true) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(transcribe_recording_values.to_s).to eq('{:callbackUrl=>"https://example.com/callback", :callbackMethod=>"POST", :username=>"mySecretUsername", :password=>"mySecretPassword", :tag=>"arbitrary tag", :callbackTimeout=>5.5, :detectLanguage=>true}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(transcribe_recording_default.eql?(Bandwidth::TranscribeRecording.new)).to be true + expect(transcribe_recording_default.eql?(transcribe_recording_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(transcribe_recording_values.to_body).to eq({ + callbackUrl: 'https://example.com/callback', + callbackMethod: Bandwidth::CallbackMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + tag: 'arbitrary tag', + callbackTimeout: 5.5, + detectLanguage: true + }) + end + end + + describe 'custom attribute writers' do + it '#username=' do + expect { + Bandwidth::TranscribeRecording.new({ username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "username", the character length must be smaller than or equal to 1024.') + end + + it '#password=' do + expect { + Bandwidth::TranscribeRecording.new({ password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "password", the character length must be smaller than or equal to 1024.') + end + + it '#callback_timeout=' do + expect { + Bandwidth::TranscribeRecording.new({ callback_timeout: 26 }) + }.to raise_error(ArgumentError, 'invalid value for "callback_timeout", must be smaller than or equal to 25.') + + expect { + Bandwidth::TranscribeRecording.new({ callback_timeout: 0.5 }) + }.to raise_error(ArgumentError, 'invalid value for "callback_timeout", must be greater than or equal to 1.') + end + end +end diff --git a/spec/unit/models/transcription_available_callback_spec.rb b/spec/unit/models/transcription_available_callback_spec.rb new file mode 100644 index 00000000..60a155ea --- /dev/null +++ b/spec/unit/models/transcription_available_callback_spec.rb @@ -0,0 +1,150 @@ +# Unit tests for Bandwidth::TranscriptionAvailableCallback +describe Bandwidth::TranscriptionAvailableCallback do + let(:transcription_available_callback_default) { Bandwidth::TranscriptionAvailableCallback.new } + let(:transcription_available_callback_values) { Bandwidth::TranscriptionAvailableCallback.new({ + event_type: 'transcriptionAvailable', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + media_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + parent_call_id: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recording_id: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + end_time: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + file_format: Bandwidth::FileFormatEnum::WAV, + tag: 'custom tag', + transcription: { text: 'Hello world.', confidence: 0.9 }, + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TranscriptionAvailableCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TranscriptionAvailableCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TranscriptionAvailableCallback.acceptable_attributes).to eq(Bandwidth::TranscriptionAvailableCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::TranscriptionAvailableCallback.openapi_nullable).to eq(Set.new([ + :'media_url', + :'enqueued_time', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TranscriptionAvailableCallback created by the build_from_hash method' do + transcription_available_callback_from_hash = Bandwidth::TranscriptionAvailableCallback.build_from_hash({ + eventType: 'transcriptionAvailable', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + mediaUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recordingId: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + fileFormat: Bandwidth::FileFormatEnum::WAV, + tag: 'custom tag', + transcription: { text: 'Hello world.', confidence: 0.9 }, + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + expect(transcription_available_callback_from_hash).to be_instance_of(Bandwidth::TranscriptionAvailableCallback) + expect(transcription_available_callback_from_hash.event_type).to eq('transcriptionAvailable') + expect(transcription_available_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transcription_available_callback_from_hash.account_id).to eq('9900000') + expect(transcription_available_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(transcription_available_callback_from_hash.from).to eq('+19195554321') + expect(transcription_available_callback_from_hash.to).to eq('+19195551234') + expect(transcription_available_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::INBOUND) + expect(transcription_available_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transcription_available_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transcription_available_callback_from_hash.media_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media') + expect(transcription_available_callback_from_hash.parent_call_id).to eq('c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99') + expect(transcription_available_callback_from_hash.recording_id).to eq('r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transcription_available_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transcription_available_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transcription_available_callback_from_hash.end_time).to eq(Time.parse('2022-06-16T13:17:07.160Z')) + expect(transcription_available_callback_from_hash.duration).to eq('PT2M') + expect(transcription_available_callback_from_hash.file_format).to eq(Bandwidth::FileFormatEnum::WAV) + expect(transcription_available_callback_from_hash.tag).to eq('custom tag') + expect(transcription_available_callback_from_hash.transcription).to be_instance_of(Bandwidth::Transcription) + expect(transcription_available_callback_from_hash.transcription.text).to eq('Hello world.') + expect(transcription_available_callback_from_hash.transcription.confidence).to eq(0.9) + expect(transcription_available_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(transcription_available_callback_from_hash.transfer_to).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(transcription_available_callback_values.to_s).to eq('{:eventType=>"transcriptionAvailable", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"inbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :mediaUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media", :parentCallId=>"c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99", :recordingId=>"r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :endTime=>"2022-06-16T13:17:07.160Z", :duration=>"PT2M", :fileFormat=>"wav", :tag=>"custom tag", :transcription=>{:text=>"Hello world.", :confidence=>0.9}, :transferCallerId=>"+19195554321", :transferTo=>"+19195551234"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(transcription_available_callback_default.eql?(Bandwidth::TranscriptionAvailableCallback.new)).to be true + expect(transcription_available_callback_default.eql?(transcription_available_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(transcription_available_callback_values.to_body).to eq({ + eventType: 'transcriptionAvailable', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::INBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + mediaUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/media', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + recordingId: 'r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + endTime: '2022-06-16T13:17:07.160Z', + duration: 'PT2M', + fileFormat: Bandwidth::FileFormatEnum::WAV, + tag: 'custom tag', + transcription: { text: 'Hello world.', confidence: 0.9 }, + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + end + end +end diff --git a/spec/unit/models/transcription_spec.rb b/spec/unit/models/transcription_spec.rb new file mode 100644 index 00000000..02a15f23 --- /dev/null +++ b/spec/unit/models/transcription_spec.rb @@ -0,0 +1,68 @@ +# Unit tests for Bandwidth::Transcription +describe Bandwidth::Transcription do + let(:transcription_default) { Bandwidth::Transcription.new } + let(:transcription_values) { Bandwidth::Transcription.new({ + text: 'Hello World! Thank you for calling.', + confidence: 0.9 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::Transcription.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::Transcription.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::Transcription.acceptable_attributes).to eq(Bandwidth::Transcription.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::Transcription.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of Transcription created by the build_from_hash method' do + transcription_from_hash = Bandwidth::Transcription.build_from_hash({ + text: 'Hello World! Thank you for calling.', + confidence: 0.9 + }) + expect(transcription_from_hash).to be_instance_of(Bandwidth::Transcription) + expect(transcription_from_hash.text).to eq('Hello World! Thank you for calling.') + expect(transcription_from_hash.confidence).to eq(0.9) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(transcription_values.to_s).to eq('{:text=>"Hello World! Thank you for calling.", :confidence=>0.9}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(transcription_default.eql?(Bandwidth::Transcription.new)).to be true + expect(transcription_default.eql?(transcription_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(transcription_values.to_body).to eq({ + text: 'Hello World! Thank you for calling.', + confidence: 0.9 + }) + end + end +end diff --git a/spec/unit/models/transfer_answer_callback_spec.rb b/spec/unit/models/transfer_answer_callback_spec.rb new file mode 100644 index 00000000..368b3dc1 --- /dev/null +++ b/spec/unit/models/transfer_answer_callback_spec.rb @@ -0,0 +1,124 @@ +# Unit tests for Bandwidth::TransferAnswerCallback +describe Bandwidth::TransferAnswerCallback do + let(:transfer_answer_callback_default) { Bandwidth::TransferAnswerCallback.new } + let(:transfer_answer_callback_values) { Bandwidth::TransferAnswerCallback.new({ + event_type: 'transferAnswer', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TransferAnswerCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TransferAnswerCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TransferAnswerCallback.acceptable_attributes).to eq(Bandwidth::TransferAnswerCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::TransferAnswerCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TransferAnswerCallback created by the build_from_hash method' do + transfer_answer_callback_from_hash = Bandwidth::TransferAnswerCallback.build_from_hash({ + eventType: 'transferAnswer', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + expect(transfer_answer_callback_from_hash).to be_instance_of(Bandwidth::TransferAnswerCallback) + expect(transfer_answer_callback_from_hash.event_type).to eq('transferAnswer') + expect(transfer_answer_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_answer_callback_from_hash.account_id).to eq('9900000') + expect(transfer_answer_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(transfer_answer_callback_from_hash.from).to eq('+19195554321') + expect(transfer_answer_callback_from_hash.to).to eq('+19195551234') + expect(transfer_answer_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::OUTBOUND) + expect(transfer_answer_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transfer_answer_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transfer_answer_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_answer_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_answer_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(transfer_answer_callback_from_hash.tag).to eq('custom tag') + expect(transfer_answer_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(transfer_answer_callback_from_hash.transfer_to).to eq('+19195551234') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(transfer_answer_callback_values.to_s).to eq('{:eventType=>"transferAnswer", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"outbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag", :transferCallerId=>"+19195554321", :transferTo=>"+19195551234"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(transfer_answer_callback_default.eql?(Bandwidth::TransferAnswerCallback.new)).to be true + expect(transfer_answer_callback_default.eql?(transfer_answer_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(transfer_answer_callback_values.to_body).to eq({ + eventType: 'transferAnswer', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234' + }) + end + end +end diff --git a/spec/unit/models/transfer_complete_callback_spec.rb b/spec/unit/models/transfer_complete_callback_spec.rb new file mode 100644 index 00000000..4cb44fc6 --- /dev/null +++ b/spec/unit/models/transfer_complete_callback_spec.rb @@ -0,0 +1,138 @@ +# Unit tests for Bandwidth::TransferCompleteCallback +describe Bandwidth::TransferCompleteCallback do + let(:transfer_complete_callback_default) { Bandwidth::TransferCompleteCallback.new } + let(:transfer_complete_callback_values) { Bandwidth::TransferCompleteCallback.new({ + event_type: 'transferComplete', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234', + cause: 'hangup', + error_message: 'call rejected', + error_id: '4642074b-7b58-478b-96e4-3a60955c6765' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TransferCompleteCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TransferCompleteCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TransferCompleteCallback.acceptable_attributes).to eq(Bandwidth::TransferCompleteCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::TransferCompleteCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag', + :'error_message', + :'error_id' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TransferCompleteCallback created by the build_from_hash method' do + transfer_complete_callback_from_hash = Bandwidth::TransferCompleteCallback.build_from_hash({ + eventType: 'transferComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234', + cause: 'hangup', + errorMessage: 'call rejected', + errorId: '4642074b-7b58-478b-96e4-3a60955c6765' + }) + expect(transfer_complete_callback_from_hash).to be_instance_of(Bandwidth::TransferCompleteCallback) + expect(transfer_complete_callback_from_hash.event_type).to eq('transferComplete') + expect(transfer_complete_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_complete_callback_from_hash.account_id).to eq('9900000') + expect(transfer_complete_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(transfer_complete_callback_from_hash.from).to eq('+19195554321') + expect(transfer_complete_callback_from_hash.to).to eq('+19195551234') + expect(transfer_complete_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::OUTBOUND) + expect(transfer_complete_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transfer_complete_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transfer_complete_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_complete_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_complete_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(transfer_complete_callback_from_hash.tag).to eq('custom tag') + expect(transfer_complete_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(transfer_complete_callback_from_hash.transfer_to).to eq('+19195551234') + expect(transfer_complete_callback_from_hash.cause).to eq('hangup') + expect(transfer_complete_callback_from_hash.error_message).to eq('call rejected') + expect(transfer_complete_callback_from_hash.error_id).to eq('4642074b-7b58-478b-96e4-3a60955c6765') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(transfer_complete_callback_values.to_s).to eq('{:eventType=>"transferComplete", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"outbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag", :transferCallerId=>"+19195554321", :transferTo=>"+19195551234", :cause=>"hangup", :errorMessage=>"call rejected", :errorId=>"4642074b-7b58-478b-96e4-3a60955c6765"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(transfer_complete_callback_default.eql?(Bandwidth::TransferCompleteCallback.new)).to be true + expect(transfer_complete_callback_default.eql?(transfer_complete_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(transfer_complete_callback_values.to_body).to eq({ + eventType: 'transferComplete', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234', + cause: 'hangup', + errorMessage: 'call rejected', + errorId: '4642074b-7b58-478b-96e4-3a60955c6765' + }) + end + end +end diff --git a/spec/unit/models/transfer_disconnect_callback_spec.rb b/spec/unit/models/transfer_disconnect_callback_spec.rb new file mode 100644 index 00000000..8c6ec5c2 --- /dev/null +++ b/spec/unit/models/transfer_disconnect_callback_spec.rb @@ -0,0 +1,146 @@ +# Unit tests for Bandwidth::TransferDisconnectCallback +describe Bandwidth::TransferDisconnectCallback do + let(:transfer_disconnect_callback_default) { Bandwidth::TransferDisconnectCallback.new } + let(:transfer_disconnect_callback_values) { Bandwidth::TransferDisconnectCallback.new({ + event_type: 'transferDisconnect', + event_time: '2022-06-16T13:15:07.160Z', + account_id: '9900000', + application_id: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + call_url: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parent_call_id: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + enqueued_time: '2022-06-16T13:15:07.160Z', + start_time: '2022-06-16T13:15:07.160Z', + answer_time: '2022-06-16T13:15:18.126Z', + end_time: '2022-06-16T13:16:18.126Z', + tag: 'custom tag', + transfer_caller_id: '+19195554321', + transfer_to: '+19195551234', + cause: 'hangup', + error_message: 'call rejected', + error_id: '4642074b-7b58-478b-96e4-3a60955c6765' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::TransferDisconnectCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::TransferDisconnectCallback.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::TransferDisconnectCallback.acceptable_attributes).to eq(Bandwidth::TransferDisconnectCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::TransferDisconnectCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag', + :'error_message', + :'error_id' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of TransferDisconnectCallback created by the build_from_hash method' do + transfer_disconnect_callback_from_hash = Bandwidth::TransferDisconnectCallback.build_from_hash({ + eventType: 'transferDisconnect', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + endTime: '2022-06-16T13:16:18.126Z', + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234', + cause: 'hangup', + errorMessage: 'call rejected', + errorId: '4642074b-7b58-478b-96e4-3a60955c6765' + }) + expect(transfer_disconnect_callback_from_hash).to be_instance_of(Bandwidth::TransferDisconnectCallback) + expect(transfer_disconnect_callback_from_hash.event_type).to eq('transferDisconnect') + expect(transfer_disconnect_callback_from_hash.event_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_disconnect_callback_from_hash.account_id).to eq('9900000') + expect(transfer_disconnect_callback_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f') + expect(transfer_disconnect_callback_from_hash.from).to eq('+19195554321') + expect(transfer_disconnect_callback_from_hash.to).to eq('+19195551234') + expect(transfer_disconnect_callback_from_hash.direction).to eq(Bandwidth::CallDirectionEnum::OUTBOUND) + expect(transfer_disconnect_callback_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transfer_disconnect_callback_from_hash.call_url).to eq('https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + expect(transfer_disconnect_callback_from_hash.parent_call_id).to eq('c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99') + expect(transfer_disconnect_callback_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_disconnect_callback_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) + expect(transfer_disconnect_callback_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z')) + expect(transfer_disconnect_callback_from_hash.end_time).to eq(Time.parse('2022-06-16T13:16:18.126Z')) + expect(transfer_disconnect_callback_from_hash.tag).to eq('custom tag') + expect(transfer_disconnect_callback_from_hash.transfer_caller_id).to eq('+19195554321') + expect(transfer_disconnect_callback_from_hash.transfer_to).to eq('+19195551234') + expect(transfer_disconnect_callback_from_hash.cause).to eq('hangup') + expect(transfer_disconnect_callback_from_hash.error_message).to eq('call rejected') + expect(transfer_disconnect_callback_from_hash.error_id).to eq('4642074b-7b58-478b-96e4-3a60955c6765') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(transfer_disconnect_callback_values.to_s).to eq('{:eventType=>"transferDisconnect", :eventTime=>"2022-06-16T13:15:07.160Z", :accountId=>"9900000", :applicationId=>"04e88489-df02-4e34-a0ee-27a91849555f", :from=>"+19195554321", :to=>"+19195551234", :direction=>"outbound", :callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :callUrl=>"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", :parentCallId=>"c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99", :enqueuedTime=>"2022-06-16T13:15:07.160Z", :startTime=>"2022-06-16T13:15:07.160Z", :answerTime=>"2022-06-16T13:15:18.126Z", :endTime=>"2022-06-16T13:16:18.126Z", :tag=>"custom tag", :transferCallerId=>"+19195554321", :transferTo=>"+19195551234", :cause=>"hangup", :errorMessage=>"call rejected", :errorId=>"4642074b-7b58-478b-96e4-3a60955c6765"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(transfer_disconnect_callback_default.eql?(Bandwidth::TransferDisconnectCallback.new)).to be true + expect(transfer_disconnect_callback_default.eql?(transfer_disconnect_callback_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(transfer_disconnect_callback_values.to_body).to eq({ + eventType: 'transferDisconnect', + eventTime: '2022-06-16T13:15:07.160Z', + accountId: '9900000', + applicationId: '04e88489-df02-4e34-a0ee-27a91849555f', + from: '+19195554321', + to: '+19195551234', + direction: Bandwidth::CallDirectionEnum::OUTBOUND, + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + callUrl: 'https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85', + parentCallId: 'c-95ac29a2-1331029c-2cb0-4a07-b215-b22865662d99', + enqueuedTime: '2022-06-16T13:15:07.160Z', + startTime: '2022-06-16T13:15:07.160Z', + answerTime: '2022-06-16T13:15:18.126Z', + endTime: '2022-06-16T13:16:18.126Z', + tag: 'custom tag', + transferCallerId: '+19195554321', + transferTo: '+19195551234', + cause: 'hangup', + errorMessage: 'call rejected', + errorId: '4642074b-7b58-478b-96e4-3a60955c6765' + }) + end + end +end diff --git a/spec/unit/models/update_call_recording_spec.rb b/spec/unit/models/update_call_recording_spec.rb new file mode 100644 index 00000000..02a849c4 --- /dev/null +++ b/spec/unit/models/update_call_recording_spec.rb @@ -0,0 +1,77 @@ +# Unit tests for Bandwidth::UpdateCallRecording +describe Bandwidth::UpdateCallRecording do + let(:update_call_recording_default) { Bandwidth::UpdateCallRecording.new({ + state: Bandwidth::RecordingStateEnum::PAUSED + }) } + let(:update_call_recording_values) { Bandwidth::UpdateCallRecording.new({ + state: Bandwidth::RecordingStateEnum::RECORDING + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::UpdateCallRecording.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::UpdateCallRecording.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::UpdateCallRecording.acceptable_attributes).to eq(Bandwidth::UpdateCallRecording.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::UpdateCallRecording.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of UpdateCallRecording created by the build_from_hash method' do + update_call_recording_from_hash = Bandwidth::UpdateCallRecording.build_from_hash({ + state: Bandwidth::RecordingStateEnum::RECORDING + }) + expect(update_call_recording_from_hash).to be_instance_of(Bandwidth::UpdateCallRecording) + expect(update_call_recording_from_hash.state).to eq(Bandwidth::RecordingStateEnum::RECORDING) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(update_call_recording_values.to_s).to eq('{:state=>"recording"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + update_call_recording_equal = Bandwidth::UpdateCallRecording.new({ + state: Bandwidth::RecordingStateEnum::PAUSED + }) + expect(update_call_recording_default.eql?(update_call_recording_equal)).to be true + expect(update_call_recording_default.eql?(update_call_recording_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(update_call_recording_values.to_body).to eq({ + state: Bandwidth::RecordingStateEnum::RECORDING + }) + end + end + + describe 'custom attribute writers' do + it '#state=' do + expect { + Bandwidth::UpdateCallRecording.new({ state: nil }) + }.to raise_error(ArgumentError, 'state cannot be nil') + end + end +end diff --git a/spec/unit/models/update_call_spec.rb b/spec/unit/models/update_call_spec.rb new file mode 100644 index 00000000..1258d458 --- /dev/null +++ b/spec/unit/models/update_call_spec.rb @@ -0,0 +1,143 @@ +# Unit tests for Bandwidth::UpdateCall +describe Bandwidth::UpdateCall do + let(:update_call_default) { Bandwidth::UpdateCall.new } + let(:update_call_values) { Bandwidth::UpdateCall.new({ + state: Bandwidth::CallStateEnum::ACTIVE, + redirect_url: 'https://example.com/redirect', + redirect_method: Bandwidth::RedirectMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + redirect_fallback_url: 'https://example.com/fallback', + redirect_fallback_method: Bandwidth::RedirectMethodEnum::GET, + fallback_username: 'fallbackUser', + fallback_password: 'fallbackPass', + tag: 'custom tag' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::UpdateCall.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::UpdateCall.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::UpdateCall.acceptable_attributes).to eq(Bandwidth::UpdateCall.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::UpdateCall.openapi_nullable).to eq(Set.new([ + :'state', + :'redirect_url', + :'redirect_method', + :'username', + :'password', + :'redirect_fallback_url', + :'redirect_fallback_method', + :'fallback_username', + :'fallback_password', + :'tag' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of UpdateCall created by the build_from_hash method' do + update_call_from_hash = Bandwidth::UpdateCall.build_from_hash({ + state: Bandwidth::CallStateEnum::ACTIVE, + redirectUrl: 'https://example.com/redirect', + redirectMethod: Bandwidth::RedirectMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + redirectFallbackUrl: 'https://example.com/fallback', + redirectFallbackMethod: Bandwidth::RedirectMethodEnum::GET, + fallbackUsername: 'fallbackUser', + fallbackPassword: 'fallbackPass', + tag: 'custom tag' + }) + expect(update_call_from_hash).to be_instance_of(Bandwidth::UpdateCall) + expect(update_call_from_hash.state).to eq(Bandwidth::CallStateEnum::ACTIVE) + expect(update_call_from_hash.redirect_url).to eq('https://example.com/redirect') + expect(update_call_from_hash.redirect_method).to eq(Bandwidth::RedirectMethodEnum::POST) + expect(update_call_from_hash.username).to eq('mySecretUsername') + expect(update_call_from_hash.password).to eq('mySecretPassword') + expect(update_call_from_hash.redirect_fallback_url).to eq('https://example.com/fallback') + expect(update_call_from_hash.redirect_fallback_method).to eq(Bandwidth::RedirectMethodEnum::GET) + expect(update_call_from_hash.fallback_username).to eq('fallbackUser') + expect(update_call_from_hash.fallback_password).to eq('fallbackPass') + expect(update_call_from_hash.tag).to eq('custom tag') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(update_call_values.to_s).to eq('{:state=>"active", :redirectUrl=>"https://example.com/redirect", :redirectMethod=>"POST", :username=>"mySecretUsername", :password=>"mySecretPassword", :redirectFallbackUrl=>"https://example.com/fallback", :redirectFallbackMethod=>"GET", :fallbackUsername=>"fallbackUser", :fallbackPassword=>"fallbackPass", :tag=>"custom tag"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(update_call_default.eql?(Bandwidth::UpdateCall.new)).to be true + expect(update_call_default.eql?(update_call_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(update_call_values.to_body).to eq({ + state: Bandwidth::CallStateEnum::ACTIVE, + redirectUrl: 'https://example.com/redirect', + redirectMethod: Bandwidth::RedirectMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + redirectFallbackUrl: 'https://example.com/fallback', + redirectFallbackMethod: Bandwidth::RedirectMethodEnum::GET, + fallbackUsername: 'fallbackUser', + fallbackPassword: 'fallbackPass', + tag: 'custom tag' + }) + end + end + + describe 'custom attribute writers' do + it '#username=' do + expect { + Bandwidth::UpdateCall.new({ username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "username", the character length must be smaller than or equal to 1024.') + end + + it '#password=' do + expect { + Bandwidth::UpdateCall.new({ password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "password", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_username=' do + expect { + Bandwidth::UpdateCall.new({ fallback_username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_username", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_password=' do + expect { + Bandwidth::UpdateCall.new({ fallback_password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_password", the character length must be smaller than or equal to 1024.') + end + + it '#tag=' do + expect { + Bandwidth::UpdateCall.new({ tag: 'a' * 4097 }) + }.to raise_error(ArgumentError, 'invalid value for "tag", the character length must be smaller than or equal to 4096.') + end + end +end diff --git a/spec/unit/models/update_conference_member_spec.rb b/spec/unit/models/update_conference_member_spec.rb new file mode 100644 index 00000000..400fcca9 --- /dev/null +++ b/spec/unit/models/update_conference_member_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::UpdateConferenceMember +describe Bandwidth::UpdateConferenceMember do + let(:update_conference_member_default) { Bandwidth::UpdateConferenceMember.new } + let(:update_conference_member_values) { Bandwidth::UpdateConferenceMember.new({ + mute: true, + hold: false, + call_ids_to_coach: ['c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::UpdateConferenceMember.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::UpdateConferenceMember.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::UpdateConferenceMember.acceptable_attributes).to eq(Bandwidth::UpdateConferenceMember.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::UpdateConferenceMember.openapi_nullable).to eq(Set.new([:'call_ids_to_coach'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of UpdateConferenceMember created by the build_from_hash method' do + update_conference_member_from_hash = Bandwidth::UpdateConferenceMember.build_from_hash({ + mute: true, + hold: false, + callIdsToCoach: ['c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'] + }) + expect(update_conference_member_from_hash).to be_instance_of(Bandwidth::UpdateConferenceMember) + expect(update_conference_member_from_hash.mute).to eq(true) + expect(update_conference_member_from_hash.hold).to eq(false) + expect(update_conference_member_from_hash.call_ids_to_coach).to eq(['c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85']) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(update_conference_member_values.to_s).to eq('{:mute=>true, :hold=>false, :callIdsToCoach=>["c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(update_conference_member_default.eql?(Bandwidth::UpdateConferenceMember.new)).to be true + expect(update_conference_member_default.eql?(update_conference_member_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(update_conference_member_values.to_body).to eq({ + mute: true, + hold: false, + callIdsToCoach: ['c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'] + }) + end + end +end diff --git a/spec/unit/models/update_conference_spec.rb b/spec/unit/models/update_conference_spec.rb new file mode 100644 index 00000000..b83fe009 --- /dev/null +++ b/spec/unit/models/update_conference_spec.rb @@ -0,0 +1,132 @@ +# Unit tests for Bandwidth::UpdateConference +describe Bandwidth::UpdateConference do + let(:update_conference_default) { Bandwidth::UpdateConference.new } + let(:update_conference_values) { Bandwidth::UpdateConference.new({ + status: Bandwidth::ConferenceStateEnum::ACTIVE, + redirect_url: 'https://example.com/redirect', + redirect_method: Bandwidth::RedirectMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + redirect_fallback_url: 'https://example.com/fallback', + redirect_fallback_method: Bandwidth::RedirectMethodEnum::GET, + fallback_username: 'fallbackUser', + fallback_password: 'fallbackPass' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::UpdateConference.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::UpdateConference.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::UpdateConference.acceptable_attributes).to eq(Bandwidth::UpdateConference.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::UpdateConference.openapi_nullable).to eq(Set.new([ + :'status', + :'redirect_url', + :'redirect_method', + :'username', + :'password', + :'redirect_fallback_url', + :'redirect_fallback_method', + :'fallback_username', + :'fallback_password' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of UpdateConference created by the build_from_hash method' do + update_conference_from_hash = Bandwidth::UpdateConference.build_from_hash({ + status: Bandwidth::ConferenceStateEnum::ACTIVE, + redirectUrl: 'https://example.com/redirect', + redirectMethod: Bandwidth::RedirectMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + redirectFallbackUrl: 'https://example.com/fallback', + redirectFallbackMethod: Bandwidth::RedirectMethodEnum::GET, + fallbackUsername: 'fallbackUser', + fallbackPassword: 'fallbackPass' + }) + expect(update_conference_from_hash).to be_instance_of(Bandwidth::UpdateConference) + expect(update_conference_from_hash.status).to eq(Bandwidth::ConferenceStateEnum::ACTIVE) + expect(update_conference_from_hash.redirect_url).to eq('https://example.com/redirect') + expect(update_conference_from_hash.redirect_method).to eq(Bandwidth::RedirectMethodEnum::POST) + expect(update_conference_from_hash.username).to eq('mySecretUsername') + expect(update_conference_from_hash.password).to eq('mySecretPassword') + expect(update_conference_from_hash.redirect_fallback_url).to eq('https://example.com/fallback') + expect(update_conference_from_hash.redirect_fallback_method).to eq(Bandwidth::RedirectMethodEnum::GET) + expect(update_conference_from_hash.fallback_username).to eq('fallbackUser') + expect(update_conference_from_hash.fallback_password).to eq('fallbackPass') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(update_conference_values.to_s).to eq('{:status=>"active", :redirectUrl=>"https://example.com/redirect", :redirectMethod=>"POST", :username=>"mySecretUsername", :password=>"mySecretPassword", :redirectFallbackUrl=>"https://example.com/fallback", :redirectFallbackMethod=>"GET", :fallbackUsername=>"fallbackUser", :fallbackPassword=>"fallbackPass"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(update_conference_default.eql?(Bandwidth::UpdateConference.new)).to be true + expect(update_conference_default.eql?(update_conference_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(update_conference_values.to_body).to eq({ + status: Bandwidth::ConferenceStateEnum::ACTIVE, + redirectUrl: 'https://example.com/redirect', + redirectMethod: Bandwidth::RedirectMethodEnum::POST, + username: 'mySecretUsername', + password: 'mySecretPassword', + redirectFallbackUrl: 'https://example.com/fallback', + redirectFallbackMethod: Bandwidth::RedirectMethodEnum::GET, + fallbackUsername: 'fallbackUser', + fallbackPassword: 'fallbackPass' + }) + end + end + + describe 'custom attribute writers' do + it '#username=' do + expect { + Bandwidth::UpdateConference.new({ username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "username", the character length must be smaller than or equal to 1024.') + end + + it '#password=' do + expect { + Bandwidth::UpdateConference.new({ password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "password", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_username=' do + expect { + Bandwidth::UpdateConference.new({ fallback_username: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_username", the character length must be smaller than or equal to 1024.') + end + + it '#fallback_password=' do + expect { + Bandwidth::UpdateConference.new({ fallback_password: 'a' * 1025 }) + }.to raise_error(ArgumentError, 'invalid value for "fallback_password", the character length must be smaller than or equal to 1024.') + end + end +end diff --git a/spec/unit/models/verification_denial_webhook_spec.rb b/spec/unit/models/verification_denial_webhook_spec.rb new file mode 100644 index 00000000..b3af6419 --- /dev/null +++ b/spec/unit/models/verification_denial_webhook_spec.rb @@ -0,0 +1,123 @@ +# Unit tests for Bandwidth::VerificationDenialWebhook +describe Bandwidth::VerificationDenialWebhook do + let(:verification_denial_webhook_default) { Bandwidth::VerificationDenialWebhook.new } + let(:verification_denial_webhook_values) { Bandwidth::VerificationDenialWebhook.new({ + account_id: '9900000', + additional_denial_reasons: [ + Bandwidth::AdditionalDenialReason.new({ status_code: 100, reason: 'reason text', resubmit_allowed: true }) + ], + decline_reason_description: 'The reason for declining', + denial_status_code: 100, + internal_ticket_number: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3', + phone_number: '+18005554321', + resubmit_allowed: true, + status: 'UNVERIFIED', + blocked: false, + blocked_reason: 'The reason for blocking' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::VerificationDenialWebhook.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::VerificationDenialWebhook.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::VerificationDenialWebhook.acceptable_attributes).to eq(Bandwidth::VerificationDenialWebhook.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::VerificationDenialWebhook.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of VerificationDenialWebhook created by the build_from_hash method' do + verification_denial_webhook_from_hash = Bandwidth::VerificationDenialWebhook.build_from_hash({ + accountId: '9900000', + additionalDenialReasons: [{ statusCode: 100, reason: 'reason text', resubmitAllowed: true }], + declineReasonDescription: 'The reason for declining', + denialStatusCode: 100, + internalTicketNumber: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3', + phoneNumber: '+18005554321', + resubmitAllowed: true, + status: 'UNVERIFIED', + blocked: false, + blockedReason: 'The reason for blocking' + }) + expect(verification_denial_webhook_from_hash).to be_instance_of(Bandwidth::VerificationDenialWebhook) + expect(verification_denial_webhook_from_hash.account_id).to eq('9900000') + expect(verification_denial_webhook_from_hash.additional_denial_reasons).to be_instance_of(Array) + expect(verification_denial_webhook_from_hash.additional_denial_reasons.first).to be_instance_of(Bandwidth::AdditionalDenialReason) + expect(verification_denial_webhook_from_hash.decline_reason_description).to eq('The reason for declining') + expect(verification_denial_webhook_from_hash.denial_status_code).to eq(100) + expect(verification_denial_webhook_from_hash.internal_ticket_number).to eq('8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3') + expect(verification_denial_webhook_from_hash.phone_number).to eq('+18005554321') + expect(verification_denial_webhook_from_hash.resubmit_allowed).to eq(true) + expect(verification_denial_webhook_from_hash.status).to eq('UNVERIFIED') + expect(verification_denial_webhook_from_hash.blocked).to eq(false) + expect(verification_denial_webhook_from_hash.blocked_reason).to eq('The reason for blocking') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(verification_denial_webhook_values.to_s).to eq('{:accountId=>"9900000", :additionalDenialReasons=>[{:statusCode=>100, :reason=>"reason text", :resubmitAllowed=>true}], :declineReasonDescription=>"The reason for declining", :denialStatusCode=>100, :internalTicketNumber=>"8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3", :phoneNumber=>"+18005554321", :resubmitAllowed=>true, :status=>"UNVERIFIED", :blocked=>false, :blockedReason=>"The reason for blocking"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(verification_denial_webhook_default.eql?(Bandwidth::VerificationDenialWebhook.new)).to be true + expect(verification_denial_webhook_default.eql?(verification_denial_webhook_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(verification_denial_webhook_values.to_body).to eq({ + accountId: '9900000', + additionalDenialReasons: [{ statusCode: 100, reason: 'reason text', resubmitAllowed: true }], + declineReasonDescription: 'The reason for declining', + denialStatusCode: 100, + internalTicketNumber: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3', + phoneNumber: '+18005554321', + resubmitAllowed: true, + status: 'UNVERIFIED', + blocked: false, + blockedReason: 'The reason for blocking' + }) + end + end + + describe 'custom attribute writers' do + it '#phone_number=' do + expect { + Bandwidth::VerificationDenialWebhook.new({ phone_number: nil }) + }.to raise_error(ArgumentError, 'phone_number cannot be nil') + + expect { + Bandwidth::VerificationDenialWebhook.new({ phone_number: '+1800555432' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be greater than or equal to 12.') + + expect { + Bandwidth::VerificationDenialWebhook.new({ phone_number: '+180055543210' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be smaller than or equal to 12.') + + expect { + Bandwidth::VerificationDenialWebhook.new({ phone_number: '+12345678901' }) + }.to raise_error(ArgumentError, /invalid value for "phone_number", must conform to the pattern/) + end + end +end diff --git a/spec/unit/models/verification_request_spec.rb b/spec/unit/models/verification_request_spec.rb new file mode 100644 index 00000000..79a186c6 --- /dev/null +++ b/spec/unit/models/verification_request_spec.rb @@ -0,0 +1,313 @@ +# Unit tests for Bandwidth::VerificationRequest +describe Bandwidth::VerificationRequest do + let(:verification_request_default) { Bandwidth::VerificationRequest.new({ + business_address: { name: 'Bandwidth' }, + business_contact: { firstName: 'Jane' }, + message_volume: 100, + phone_numbers: ['+18005550100'], + use_case: 'baseline use case', + use_case_summary: 'baseline summary', + production_message_content: 'baseline message', + opt_in_workflow: { description: 'baseline opt-in', imageUrls: [] }, + business_entity_type: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT + }) } + let(:verification_request_values) { Bandwidth::VerificationRequest.new({ + business_address: { name: 'Bandwidth' }, + business_contact: { firstName: 'Jane' }, + message_volume: 1000, + phone_numbers: ['+18005554321'], + use_case: 'Customer notifications', + use_case_summary: 'Send customers updates about their orders', + production_message_content: 'Your order has shipped', + opt_in_workflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additional_information: 'extra info', + isv_reseller: 'My ISV', + privacy_policy_url: 'https://example.com/privacy', + terms_and_conditions_url: 'https://example.com/terms', + business_dba: 'Bandwidth Inc', + business_registration_number: '12-3456789', + business_registration_type: Bandwidth::BusinessRegistrationTypeEnum::EIN, + business_registration_issuing_country: 'USA', + business_entity_type: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT, + help_message_response: 'For help reply with HELP', + age_gated_content: false, + cv_token: 'cv_token_value' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::VerificationRequest.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::VerificationRequest.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::VerificationRequest.acceptable_attributes).to eq(Bandwidth::VerificationRequest.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::VerificationRequest.openapi_nullable).to eq(Set.new([ + :'additional_information', + :'isv_reseller', + :'business_registration_number', + :'business_registration_type', + :'business_registration_issuing_country', + :'help_message_response', + :'cv_token' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of VerificationRequest created by the build_from_hash method' do + verification_request_from_hash = Bandwidth::VerificationRequest.build_from_hash({ + businessAddress: { name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: 'https://www.bandwidth.com' }, + businessContact: { firstName: 'Jane', lastName: 'Doe', email: 'jane@bandwidth.com', phoneNumber: '+19195551234' }, + messageVolume: 1000, + phoneNumbers: ['+18005554321'], + useCase: 'Customer notifications', + useCaseSummary: 'Send customers updates about their orders', + productionMessageContent: 'Your order has shipped', + optInWorkflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additionalInformation: 'extra info', + isvReseller: 'My ISV', + privacyPolicyUrl: 'https://example.com/privacy', + termsAndConditionsUrl: 'https://example.com/terms', + businessDba: 'Bandwidth Inc', + businessRegistrationNumber: '12-3456789', + businessRegistrationType: Bandwidth::BusinessRegistrationTypeEnum::EIN, + businessRegistrationIssuingCountry: 'USA', + businessEntityType: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT, + helpMessageResponse: 'For help reply with HELP', + ageGatedContent: false, + cvToken: 'cv_token_value' + }) + expect(verification_request_from_hash).to be_instance_of(Bandwidth::VerificationRequest) + expect(verification_request_from_hash.business_address).to be_instance_of(Bandwidth::Address) + expect(verification_request_from_hash.business_contact).to be_instance_of(Bandwidth::Contact) + expect(verification_request_from_hash.message_volume).to eq(1000) + expect(verification_request_from_hash.phone_numbers).to eq(['+18005554321']) + expect(verification_request_from_hash.use_case).to eq('Customer notifications') + expect(verification_request_from_hash.use_case_summary).to eq('Send customers updates about their orders') + expect(verification_request_from_hash.production_message_content).to eq('Your order has shipped') + expect(verification_request_from_hash.opt_in_workflow).to be_instance_of(Bandwidth::OptInWorkflow) + expect(verification_request_from_hash.additional_information).to eq('extra info') + expect(verification_request_from_hash.isv_reseller).to eq('My ISV') + expect(verification_request_from_hash.privacy_policy_url).to eq('https://example.com/privacy') + expect(verification_request_from_hash.terms_and_conditions_url).to eq('https://example.com/terms') + expect(verification_request_from_hash.business_dba).to eq('Bandwidth Inc') + expect(verification_request_from_hash.business_registration_number).to eq('12-3456789') + expect(verification_request_from_hash.business_registration_type).to eq(Bandwidth::BusinessRegistrationTypeEnum::EIN) + expect(verification_request_from_hash.business_registration_issuing_country).to eq('USA') + expect(verification_request_from_hash.business_entity_type).to eq(Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT) + expect(verification_request_from_hash.help_message_response).to eq('For help reply with HELP') + expect(verification_request_from_hash.age_gated_content).to eq(false) + expect(verification_request_from_hash.cv_token).to eq('cv_token_value') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(verification_request_values.to_s).to eq('{:businessAddress=>{:name=>"Bandwidth"}, :businessContact=>{:firstName=>"Jane"}, :messageVolume=>1000, :phoneNumbers=>["+18005554321"], :useCase=>"Customer notifications", :useCaseSummary=>"Send customers updates about their orders", :productionMessageContent=>"Your order has shipped", :optInWorkflow=>{:description=>"opt-in via website", :imageUrls=>["https://example.com/optin.png"]}, :additionalInformation=>"extra info", :isvReseller=>"My ISV", :privacyPolicyUrl=>"https://example.com/privacy", :termsAndConditionsUrl=>"https://example.com/terms", :businessDba=>"Bandwidth Inc", :businessRegistrationNumber=>"12-3456789", :businessRegistrationType=>"EIN", :businessRegistrationIssuingCountry=>"USA", :businessEntityType=>"PRIVATE_PROFIT", :helpMessageResponse=>"For help reply with HELP", :ageGatedContent=>false, :cvToken=>"cv_token_value"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + verification_request_equal = Bandwidth::VerificationRequest.new({ + business_address: { name: 'Bandwidth' }, + business_contact: { firstName: 'Jane' }, + message_volume: 100, + phone_numbers: ['+18005550100'], + use_case: 'baseline use case', + use_case_summary: 'baseline summary', + production_message_content: 'baseline message', + opt_in_workflow: { description: 'baseline opt-in', imageUrls: [] }, + business_entity_type: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT + }) + expect(verification_request_default.eql?(verification_request_equal)).to be true + expect(verification_request_default.eql?(verification_request_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(verification_request_values.to_body).to eq({ + businessAddress: { name: 'Bandwidth' }, + businessContact: { firstName: 'Jane' }, + messageVolume: 1000, + phoneNumbers: ['+18005554321'], + useCase: 'Customer notifications', + useCaseSummary: 'Send customers updates about their orders', + productionMessageContent: 'Your order has shipped', + optInWorkflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additionalInformation: 'extra info', + isvReseller: 'My ISV', + privacyPolicyUrl: 'https://example.com/privacy', + termsAndConditionsUrl: 'https://example.com/terms', + businessDba: 'Bandwidth Inc', + businessRegistrationNumber: '12-3456789', + businessRegistrationType: Bandwidth::BusinessRegistrationTypeEnum::EIN, + businessRegistrationIssuingCountry: 'USA', + businessEntityType: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT, + helpMessageResponse: 'For help reply with HELP', + ageGatedContent: false, + cvToken: 'cv_token_value' + }) + end + end + + describe 'custom attribute writers' do + it '#business_address=' do + expect { + verification_request_values.business_address = nil + }.to raise_error(ArgumentError, 'business_address cannot be nil') + end + + it '#business_contact=' do + expect { + verification_request_values.business_contact = nil + }.to raise_error(ArgumentError, 'business_contact cannot be nil') + end + + it '#message_volume=' do + expect { + verification_request_values.message_volume = nil + }.to raise_error(ArgumentError, 'message_volume cannot be nil') + + expect { + verification_request_values.message_volume = 10000001 + }.to raise_error(ArgumentError, 'invalid value for "message_volume", must be smaller than or equal to 10000000.') + + expect { + verification_request_values.message_volume = 9 + }.to raise_error(ArgumentError, 'invalid value for "message_volume", must be greater than or equal to 10.') + end + + it '#phone_numbers=' do + expect { + verification_request_values.phone_numbers = nil + }.to raise_error(ArgumentError, 'phone_numbers cannot be nil') + + expect { + verification_request_values.phone_numbers = Array.new(11) { '+18005551234' } + }.to raise_error(ArgumentError, 'invalid value for "phone_numbers", number of items must be less than or equal to 10.') + + expect { + verification_request_values.phone_numbers = [] + }.to raise_error(ArgumentError, 'invalid value for "phone_numbers", number of items must be greater than or equal to 1.') + end + + it '#use_case=' do + expect { + verification_request_values.use_case = nil + }.to raise_error(ArgumentError, 'use_case cannot be nil') + + expect { + verification_request_values.use_case = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "use_case", the character length must be smaller than or equal to 500.') + end + + it '#use_case_summary=' do + expect { + verification_request_values.use_case_summary = nil + }.to raise_error(ArgumentError, 'use_case_summary cannot be nil') + + expect { + verification_request_values.use_case_summary = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "use_case_summary", the character length must be smaller than or equal to 500.') + end + + it '#production_message_content=' do + expect { + verification_request_values.production_message_content = nil + }.to raise_error(ArgumentError, 'production_message_content cannot be nil') + + expect { + verification_request_values.production_message_content = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "production_message_content", the character length must be smaller than or equal to 500.') + end + + it '#opt_in_workflow=' do + expect { + verification_request_values.opt_in_workflow = nil + }.to raise_error(ArgumentError, 'opt_in_workflow cannot be nil') + end + + it '#additional_information=' do + expect { + verification_request_values.additional_information = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "additional_information", the character length must be smaller than or equal to 500.') + end + + it '#isv_reseller=' do + expect { + verification_request_values.isv_reseller = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "isv_reseller", the character length must be smaller than or equal to 500.') + end + + it '#privacy_policy_url=' do + expect { + verification_request_values.privacy_policy_url = nil + }.to raise_error(ArgumentError, 'privacy_policy_url cannot be nil') + + expect { + verification_request_values.privacy_policy_url = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "privacy_policy_url", the character length must be smaller than or equal to 500.') + end + + it '#terms_and_conditions_url=' do + expect { + verification_request_values.terms_and_conditions_url = nil + }.to raise_error(ArgumentError, 'terms_and_conditions_url cannot be nil') + + expect { + verification_request_values.terms_and_conditions_url = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "terms_and_conditions_url", the character length must be smaller than or equal to 500.') + end + + it '#business_dba=' do + expect { + verification_request_values.business_dba = nil + }.to raise_error(ArgumentError, 'business_dba cannot be nil') + + expect { + verification_request_values.business_dba = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "business_dba", the character length must be smaller than or equal to 500.') + end + + it '#business_registration_number=' do + expect { + verification_request_values.business_registration_number = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "business_registration_number", the character length must be smaller than or equal to 500.') + end + + it '#business_entity_type=' do + expect { + verification_request_values.business_entity_type = nil + }.to raise_error(ArgumentError, 'business_entity_type cannot be nil') + end + + it '#help_message_response=' do + expect { + verification_request_values.help_message_response = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "help_message_response", the character length must be smaller than or equal to 500.') + end + + it '#cv_token=' do + expect { + verification_request_values.cv_token = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "cv_token", the character length must be smaller than or equal to 500.') + end + end +end diff --git a/spec/unit/models/verification_update_request_spec.rb b/spec/unit/models/verification_update_request_spec.rb new file mode 100644 index 00000000..c72b8e60 --- /dev/null +++ b/spec/unit/models/verification_update_request_spec.rb @@ -0,0 +1,285 @@ +# Unit tests for Bandwidth::VerificationUpdateRequest +describe Bandwidth::VerificationUpdateRequest do + let(:verification_update_request_default) { Bandwidth::VerificationUpdateRequest.new({ + business_address: { name: 'Bandwidth' }, + business_contact: { firstName: 'Jane' }, + message_volume: 100, + use_case: 'baseline use case', + use_case_summary: 'baseline summary', + production_message_content: 'baseline message', + opt_in_workflow: { description: 'baseline opt-in', imageUrls: [] } + }) } + let(:verification_update_request_values) { Bandwidth::VerificationUpdateRequest.new({ + business_address: { name: 'Bandwidth' }, + business_contact: { firstName: 'Jane' }, + message_volume: 1000, + use_case: 'Customer notifications', + use_case_summary: 'Send customers updates about their orders', + production_message_content: 'Your order has shipped', + opt_in_workflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additional_information: 'extra info', + isv_reseller: 'My ISV', + privacy_policy_url: 'https://example.com/privacy', + terms_and_conditions_url: 'https://example.com/terms', + business_dba: 'Bandwidth Inc', + business_registration_number: '12-3456789', + business_registration_type: Bandwidth::BusinessRegistrationTypeEnum::EIN, + business_entity_type: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT, + business_registration_issuing_country: 'USA', + help_message_response: 'For help reply with HELP', + age_gated_content: false, + cv_token: 'cv_token_value' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::VerificationUpdateRequest.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::VerificationUpdateRequest.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::VerificationUpdateRequest.acceptable_attributes).to eq(Bandwidth::VerificationUpdateRequest.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::VerificationUpdateRequest.openapi_nullable).to eq(Set.new([ + :'additional_information', + :'isv_reseller', + :'business_registration_number', + :'business_registration_type', + :'business_registration_issuing_country', + :'help_message_response', + :'cv_token' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of VerificationUpdateRequest created by the build_from_hash method' do + verification_update_request_from_hash = Bandwidth::VerificationUpdateRequest.build_from_hash({ + businessAddress: { name: 'Bandwidth', addr1: '900 Main Campus Dr', city: 'Raleigh', state: 'NC', zip: '27606', url: 'https://www.bandwidth.com' }, + businessContact: { firstName: 'Jane', lastName: 'Doe', email: 'jane@bandwidth.com', phoneNumber: '+19195551234' }, + messageVolume: 1000, + useCase: 'Customer notifications', + useCaseSummary: 'Send customers updates about their orders', + productionMessageContent: 'Your order has shipped', + optInWorkflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additionalInformation: 'extra info', + isvReseller: 'My ISV', + privacyPolicyUrl: 'https://example.com/privacy', + termsAndConditionsUrl: 'https://example.com/terms', + businessDba: 'Bandwidth Inc', + businessRegistrationNumber: '12-3456789', + businessRegistrationType: Bandwidth::BusinessRegistrationTypeEnum::EIN, + businessEntityType: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT, + businessRegistrationIssuingCountry: 'USA', + helpMessageResponse: 'For help reply with HELP', + ageGatedContent: false, + cvToken: 'cv_token_value' + }) + expect(verification_update_request_from_hash).to be_instance_of(Bandwidth::VerificationUpdateRequest) + expect(verification_update_request_from_hash.business_address).to be_instance_of(Bandwidth::Address) + expect(verification_update_request_from_hash.business_contact).to be_instance_of(Bandwidth::Contact) + expect(verification_update_request_from_hash.message_volume).to eq(1000) + expect(verification_update_request_from_hash.use_case).to eq('Customer notifications') + expect(verification_update_request_from_hash.use_case_summary).to eq('Send customers updates about their orders') + expect(verification_update_request_from_hash.production_message_content).to eq('Your order has shipped') + expect(verification_update_request_from_hash.opt_in_workflow).to be_instance_of(Bandwidth::OptInWorkflow) + expect(verification_update_request_from_hash.additional_information).to eq('extra info') + expect(verification_update_request_from_hash.isv_reseller).to eq('My ISV') + expect(verification_update_request_from_hash.privacy_policy_url).to eq('https://example.com/privacy') + expect(verification_update_request_from_hash.terms_and_conditions_url).to eq('https://example.com/terms') + expect(verification_update_request_from_hash.business_dba).to eq('Bandwidth Inc') + expect(verification_update_request_from_hash.business_registration_number).to eq('12-3456789') + expect(verification_update_request_from_hash.business_registration_type).to eq(Bandwidth::BusinessRegistrationTypeEnum::EIN) + expect(verification_update_request_from_hash.business_entity_type).to eq(Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT) + expect(verification_update_request_from_hash.business_registration_issuing_country).to eq('USA') + expect(verification_update_request_from_hash.help_message_response).to eq('For help reply with HELP') + expect(verification_update_request_from_hash.age_gated_content).to eq(false) + expect(verification_update_request_from_hash.cv_token).to eq('cv_token_value') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(verification_update_request_values.to_s).to eq('{:businessAddress=>{:name=>"Bandwidth"}, :businessContact=>{:firstName=>"Jane"}, :messageVolume=>1000, :useCase=>"Customer notifications", :useCaseSummary=>"Send customers updates about their orders", :productionMessageContent=>"Your order has shipped", :optInWorkflow=>{:description=>"opt-in via website", :imageUrls=>["https://example.com/optin.png"]}, :additionalInformation=>"extra info", :isvReseller=>"My ISV", :privacyPolicyUrl=>"https://example.com/privacy", :termsAndConditionsUrl=>"https://example.com/terms", :businessDba=>"Bandwidth Inc", :businessRegistrationNumber=>"12-3456789", :businessRegistrationType=>"EIN", :businessEntityType=>"PRIVATE_PROFIT", :businessRegistrationIssuingCountry=>"USA", :helpMessageResponse=>"For help reply with HELP", :ageGatedContent=>false, :cvToken=>"cv_token_value"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + verification_update_request_equal = Bandwidth::VerificationUpdateRequest.new({ + business_address: { name: 'Bandwidth' }, + business_contact: { firstName: 'Jane' }, + message_volume: 100, + use_case: 'baseline use case', + use_case_summary: 'baseline summary', + production_message_content: 'baseline message', + opt_in_workflow: { description: 'baseline opt-in', imageUrls: [] } + }) + expect(verification_update_request_default.eql?(verification_update_request_equal)).to be true + expect(verification_update_request_default.eql?(verification_update_request_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(verification_update_request_values.to_body).to eq({ + businessAddress: { name: 'Bandwidth' }, + businessContact: { firstName: 'Jane' }, + messageVolume: 1000, + useCase: 'Customer notifications', + useCaseSummary: 'Send customers updates about their orders', + productionMessageContent: 'Your order has shipped', + optInWorkflow: { description: 'opt-in via website', imageUrls: ['https://example.com/optin.png'] }, + additionalInformation: 'extra info', + isvReseller: 'My ISV', + privacyPolicyUrl: 'https://example.com/privacy', + termsAndConditionsUrl: 'https://example.com/terms', + businessDba: 'Bandwidth Inc', + businessRegistrationNumber: '12-3456789', + businessRegistrationType: Bandwidth::BusinessRegistrationTypeEnum::EIN, + businessEntityType: Bandwidth::BusinessEntityTypeEnum::PRIVATE_PROFIT, + businessRegistrationIssuingCountry: 'USA', + helpMessageResponse: 'For help reply with HELP', + ageGatedContent: false, + cvToken: 'cv_token_value' + }) + end + end + + describe 'custom attribute writers' do + it '#business_address=' do + expect { + verification_update_request_values.business_address = nil + }.to raise_error(ArgumentError, 'business_address cannot be nil') + end + + it '#business_contact=' do + expect { + verification_update_request_values.business_contact = nil + }.to raise_error(ArgumentError, 'business_contact cannot be nil') + end + + it '#message_volume=' do + expect { + verification_update_request_values.message_volume = nil + }.to raise_error(ArgumentError, 'message_volume cannot be nil') + + expect { + verification_update_request_values.message_volume = 10000001 + }.to raise_error(ArgumentError, 'invalid value for "message_volume", must be smaller than or equal to 10000000.') + + expect { + verification_update_request_values.message_volume = 9 + }.to raise_error(ArgumentError, 'invalid value for "message_volume", must be greater than or equal to 10.') + end + + it '#use_case=' do + expect { + verification_update_request_values.use_case = nil + }.to raise_error(ArgumentError, 'use_case cannot be nil') + + expect { + verification_update_request_values.use_case = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "use_case", the character length must be smaller than or equal to 500.') + end + + it '#use_case_summary=' do + expect { + verification_update_request_values.use_case_summary = nil + }.to raise_error(ArgumentError, 'use_case_summary cannot be nil') + + expect { + verification_update_request_values.use_case_summary = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "use_case_summary", the character length must be smaller than or equal to 500.') + end + + it '#production_message_content=' do + expect { + verification_update_request_values.production_message_content = nil + }.to raise_error(ArgumentError, 'production_message_content cannot be nil') + + expect { + verification_update_request_values.production_message_content = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "production_message_content", the character length must be smaller than or equal to 500.') + end + + it '#opt_in_workflow=' do + expect { + verification_update_request_values.opt_in_workflow = nil + }.to raise_error(ArgumentError, 'opt_in_workflow cannot be nil') + end + + it '#additional_information=' do + expect { + verification_update_request_values.additional_information = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "additional_information", the character length must be smaller than or equal to 500.') + end + + it '#isv_reseller=' do + expect { + verification_update_request_values.isv_reseller = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "isv_reseller", the character length must be smaller than or equal to 500.') + end + + it '#privacy_policy_url=' do + expect { + verification_update_request_values.privacy_policy_url = nil + }.to raise_error(ArgumentError, 'privacy_policy_url cannot be nil') + + expect { + verification_update_request_values.privacy_policy_url = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "privacy_policy_url", the character length must be smaller than or equal to 500.') + end + + it '#terms_and_conditions_url=' do + expect { + verification_update_request_values.terms_and_conditions_url = nil + }.to raise_error(ArgumentError, 'terms_and_conditions_url cannot be nil') + + expect { + verification_update_request_values.terms_and_conditions_url = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "terms_and_conditions_url", the character length must be smaller than or equal to 500.') + end + + it '#business_dba=' do + expect { + verification_update_request_values.business_dba = nil + }.to raise_error(ArgumentError, 'business_dba cannot be nil') + + expect { + verification_update_request_values.business_dba = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "business_dba", the character length must be smaller than or equal to 500.') + end + + it '#business_registration_number=' do + expect { + verification_update_request_values.business_registration_number = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "business_registration_number", the character length must be smaller than or equal to 500.') + end + + it '#help_message_response=' do + expect { + verification_update_request_values.help_message_response = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "help_message_response", the character length must be smaller than or equal to 500.') + end + + it '#cv_token=' do + expect { + verification_update_request_values.cv_token = 'a' * 501 + }.to raise_error(ArgumentError, 'invalid value for "cv_token", the character length must be smaller than or equal to 500.') + end + end +end diff --git a/spec/unit/models/verification_webhook_spec.rb b/spec/unit/models/verification_webhook_spec.rb new file mode 100644 index 00000000..294bd4d7 --- /dev/null +++ b/spec/unit/models/verification_webhook_spec.rb @@ -0,0 +1,96 @@ +# Unit tests for Bandwidth::VerificationWebhook +describe Bandwidth::VerificationWebhook do + let(:verification_webhook_default) { Bandwidth::VerificationWebhook.new } + let(:verification_webhook_values) { Bandwidth::VerificationWebhook.new({ + account_id: '9900000', + phone_number: '+18005554321', + status: Bandwidth::TfvCallbackStatusEnum::VERIFIED, + internal_ticket_number: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::VerificationWebhook.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::VerificationWebhook.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::VerificationWebhook.acceptable_attributes).to eq(Bandwidth::VerificationWebhook.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::VerificationWebhook.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of VerificationWebhook created by the build_from_hash method' do + verification_webhook_from_hash = Bandwidth::VerificationWebhook.build_from_hash({ + accountId: '9900000', + phoneNumber: '+18005554321', + status: Bandwidth::TfvCallbackStatusEnum::VERIFIED, + internalTicketNumber: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3' + }) + expect(verification_webhook_from_hash).to be_instance_of(Bandwidth::VerificationWebhook) + expect(verification_webhook_from_hash.account_id).to eq('9900000') + expect(verification_webhook_from_hash.phone_number).to eq('+18005554321') + expect(verification_webhook_from_hash.status).to eq(Bandwidth::TfvCallbackStatusEnum::VERIFIED) + expect(verification_webhook_from_hash.internal_ticket_number).to eq('8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(verification_webhook_values.to_s).to eq('{:accountId=>"9900000", :phoneNumber=>"+18005554321", :status=>"VERIFIED", :internalTicketNumber=>"8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(verification_webhook_default.eql?(Bandwidth::VerificationWebhook.new)).to be true + expect(verification_webhook_default.eql?(verification_webhook_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(verification_webhook_values.to_body).to eq({ + accountId: '9900000', + phoneNumber: '+18005554321', + status: Bandwidth::TfvCallbackStatusEnum::VERIFIED, + internalTicketNumber: '8c8f33f8-0d72-43c8-8b6c-1da8f0a9e6b3' + }) + end + end + + describe 'custom attribute writers' do + it '#phone_number=' do + expect { + Bandwidth::VerificationWebhook.new({ phone_number: nil }) + }.to raise_error(ArgumentError, 'phone_number cannot be nil') + + expect { + Bandwidth::VerificationWebhook.new({ phone_number: '+1800555432' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be greater than or equal to 12.') + + expect { + Bandwidth::VerificationWebhook.new({ phone_number: '+180055543210' }) + }.to raise_error(ArgumentError, 'invalid value for "phone_number", the character length must be smaller than or equal to 12.') + + expect { + Bandwidth::VerificationWebhook.new({ phone_number: '+12345678901' }) + }.to raise_error(ArgumentError, /invalid value for "phone_number", must conform to the pattern/) + end + end +end diff --git a/spec/unit/models/verify_code_request_spec.rb b/spec/unit/models/verify_code_request_spec.rb index 1bcaeefe..c982ec42 100644 --- a/spec/unit/models/verify_code_request_spec.rb +++ b/spec/unit/models/verify_code_request_spec.rb @@ -1,5 +1,10 @@ # Unit tests for Bandwidth::VerifyCodeRequest describe Bandwidth::VerifyCodeRequest do + let(:verify_code_request_default) { Bandwidth::VerifyCodeRequest.new({ + to: '+19195551234', + expiration_time_in_minutes: 1.0, + code: '123456' + }) } let(:verify_code_request_values) { Bandwidth::VerifyCodeRequest.new({ to: '+19195551234', scope: '2FA', @@ -49,12 +54,6 @@ end end - describe '#hash' do - it 'returns a hash code according to attributes' do - expect(verify_code_request_values.hash).to be_instance_of(Integer) - end - end - describe '#to_s' do it 'returns a string representation of the object' do expect(verify_code_request_values.to_s).to eq('{:to=>"+19195551234", :scope=>"2FA", :expirationTimeInMinutes=>1.0, :code=>"123456"}') @@ -65,11 +64,11 @@ it 'returns true/false when comparing objects' do verify_code_request_equal = Bandwidth::VerifyCodeRequest.new({ to: '+19195551234', - scope: '2FA', expiration_time_in_minutes: 1.0, code: '123456' }) - expect(verify_code_request_equal.eql?(verify_code_request_values)).to be true + expect(verify_code_request_default.eql?(verify_code_request_equal)).to be true + expect(verify_code_request_default.eql?(verify_code_request_values)).to be false end end diff --git a/spec/unit/models/verify_code_response_spec.rb b/spec/unit/models/verify_code_response_spec.rb index 43d592fb..e8614742 100644 --- a/spec/unit/models/verify_code_response_spec.rb +++ b/spec/unit/models/verify_code_response_spec.rb @@ -40,12 +40,6 @@ expect(verify_code_response_from_hash.valid).to be true end end - - describe '#hash' do - it 'returns a hash code according to attributes' do - expect(verify_code_response_default.hash).to be_instance_of(Integer) - end - end describe '#to_s' do it 'returns a string representation of the object' do diff --git a/spec/unit/models/voice_api_error_spec.rb b/spec/unit/models/voice_api_error_spec.rb new file mode 100644 index 00000000..5a6c6aa1 --- /dev/null +++ b/spec/unit/models/voice_api_error_spec.rb @@ -0,0 +1,72 @@ +# Unit tests for Bandwidth::VoiceApiError +describe Bandwidth::VoiceApiError do + let(:voice_api_error_default) { Bandwidth::VoiceApiError.new } + let(:voice_api_error_values) { Bandwidth::VoiceApiError.new({ + type: 'validation', + description: 'request body is invalid', + id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::VoiceApiError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::VoiceApiError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::VoiceApiError.acceptable_attributes).to eq(Bandwidth::VoiceApiError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::VoiceApiError.openapi_nullable).to eq(Set.new([:'id'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of VoiceApiError created by the build_from_hash method' do + voice_api_error_from_hash = Bandwidth::VoiceApiError.build_from_hash({ + type: 'validation', + description: 'request body is invalid', + id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85' + }) + expect(voice_api_error_from_hash).to be_instance_of(Bandwidth::VoiceApiError) + expect(voice_api_error_from_hash.type).to eq('validation') + expect(voice_api_error_from_hash.description).to eq('request body is invalid') + expect(voice_api_error_from_hash.id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(voice_api_error_values.to_s).to eq('{:type=>"validation", :description=>"request body is invalid", :id=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(voice_api_error_default.eql?(Bandwidth::VoiceApiError.new)).to be true + expect(voice_api_error_default.eql?(voice_api_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(voice_api_error_values.to_body).to eq({ + type: 'validation', + description: 'request body is invalid', + id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85' + }) + end + end +end diff --git a/spec/unit/models/voice_code_response_spec.rb b/spec/unit/models/voice_code_response_spec.rb new file mode 100644 index 00000000..1226cf4d --- /dev/null +++ b/spec/unit/models/voice_code_response_spec.rb @@ -0,0 +1,64 @@ +# Unit tests for Bandwidth::VoiceCodeResponse +describe Bandwidth::VoiceCodeResponse do + let(:voice_code_response_default) { Bandwidth::VoiceCodeResponse.new } + let(:voice_code_response_values) { Bandwidth::VoiceCodeResponse.new({ + call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::VoiceCodeResponse.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::VoiceCodeResponse.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::VoiceCodeResponse.acceptable_attributes).to eq(Bandwidth::VoiceCodeResponse.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::VoiceCodeResponse.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of VoiceCodeResponse created by the build_from_hash method' do + voice_code_response_from_hash = Bandwidth::VoiceCodeResponse.build_from_hash({ + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85' + }) + expect(voice_code_response_from_hash).to be_instance_of(Bandwidth::VoiceCodeResponse) + expect(voice_code_response_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(voice_code_response_values.to_s).to eq('{:callId=>"c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(voice_code_response_default.eql?(Bandwidth::VoiceCodeResponse.new)).to be true + expect(voice_code_response_default.eql?(voice_code_response_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(voice_code_response_values.to_body).to eq({ + callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85' + }) + end + end +end diff --git a/spec/unit/models/webhook_subscription_basic_authentication_spec.rb b/spec/unit/models/webhook_subscription_basic_authentication_spec.rb new file mode 100644 index 00000000..fb5d3276 --- /dev/null +++ b/spec/unit/models/webhook_subscription_basic_authentication_spec.rb @@ -0,0 +1,97 @@ +# Unit tests for Bandwidth::WebhookSubscriptionBasicAuthentication +describe Bandwidth::WebhookSubscriptionBasicAuthentication do + let(:webhook_subscription_basic_authentication_default) { Bandwidth::WebhookSubscriptionBasicAuthentication.new({ + username: 'baseline', + password: 'baselinePass' + }) } + let(:webhook_subscription_basic_authentication_values) { Bandwidth::WebhookSubscriptionBasicAuthentication.new({ + username: 'mySecretUsername', + password: 'mySecretPassword' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::WebhookSubscriptionBasicAuthentication.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::WebhookSubscriptionBasicAuthentication.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::WebhookSubscriptionBasicAuthentication.acceptable_attributes).to eq(Bandwidth::WebhookSubscriptionBasicAuthentication.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::WebhookSubscriptionBasicAuthentication.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of WebhookSubscriptionBasicAuthentication created by the build_from_hash method' do + webhook_subscription_basic_authentication_from_hash = Bandwidth::WebhookSubscriptionBasicAuthentication.build_from_hash({ + username: 'mySecretUsername', + password: 'mySecretPassword' + }) + expect(webhook_subscription_basic_authentication_from_hash).to be_instance_of(Bandwidth::WebhookSubscriptionBasicAuthentication) + expect(webhook_subscription_basic_authentication_from_hash.username).to eq('mySecretUsername') + expect(webhook_subscription_basic_authentication_from_hash.password).to eq('mySecretPassword') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(webhook_subscription_basic_authentication_values.to_s).to eq('{:username=>"mySecretUsername", :password=>"mySecretPassword"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + webhook_subscription_basic_authentication_equal = Bandwidth::WebhookSubscriptionBasicAuthentication.new({ + username: 'baseline', + password: 'baselinePass' + }) + expect(webhook_subscription_basic_authentication_default.eql?(webhook_subscription_basic_authentication_equal)).to be true + expect(webhook_subscription_basic_authentication_default.eql?(webhook_subscription_basic_authentication_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(webhook_subscription_basic_authentication_values.to_body).to eq({ + username: 'mySecretUsername', + password: 'mySecretPassword' + }) + end + end + + describe 'custom attribute writers' do + it '#username=' do + expect { + Bandwidth::WebhookSubscriptionBasicAuthentication.new({ username: nil, password: 'pass' }) + }.to raise_error(ArgumentError, 'username cannot be nil') + + expect { + Bandwidth::WebhookSubscriptionBasicAuthentication.new({ username: 'a' * 101, password: 'pass' }) + }.to raise_error(ArgumentError, 'invalid value for "username", the character length must be smaller than or equal to 100.') + end + + it '#password=' do + expect { + Bandwidth::WebhookSubscriptionBasicAuthentication.new({ username: 'user', password: nil }) + }.to raise_error(ArgumentError, 'password cannot be nil') + + expect { + Bandwidth::WebhookSubscriptionBasicAuthentication.new({ username: 'user', password: 'a' * 201 }) + }.to raise_error(ArgumentError, 'invalid value for "password", the character length must be smaller than or equal to 200.') + end + end +end diff --git a/spec/unit/models/webhook_subscription_error_spec.rb b/spec/unit/models/webhook_subscription_error_spec.rb new file mode 100644 index 00000000..cc1aec89 --- /dev/null +++ b/spec/unit/models/webhook_subscription_error_spec.rb @@ -0,0 +1,76 @@ +# Unit tests for Bandwidth::WebhookSubscriptionError +describe Bandwidth::WebhookSubscriptionError do + let(:webhook_subscription_error_default) { Bandwidth::WebhookSubscriptionError.new } + let(:webhook_subscription_error_values) { Bandwidth::WebhookSubscriptionError.new({ + code: 400, + description: 'Invalid request', + telephone_numbers: [ + Bandwidth::TelephoneNumber.new({ telephone_number: '+18005554321' }) + ] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::WebhookSubscriptionError.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::WebhookSubscriptionError.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::WebhookSubscriptionError.acceptable_attributes).to eq(Bandwidth::WebhookSubscriptionError.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::WebhookSubscriptionError.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of WebhookSubscriptionError created by the build_from_hash method' do + webhook_subscription_error_from_hash = Bandwidth::WebhookSubscriptionError.build_from_hash({ + code: 400, + description: 'Invalid request', + telephoneNumbers: [{ telephoneNumber: '+18005554321' }] + }) + expect(webhook_subscription_error_from_hash).to be_instance_of(Bandwidth::WebhookSubscriptionError) + expect(webhook_subscription_error_from_hash.code).to eq(400) + expect(webhook_subscription_error_from_hash.description).to eq('Invalid request') + expect(webhook_subscription_error_from_hash.telephone_numbers).to be_instance_of(Array) + expect(webhook_subscription_error_from_hash.telephone_numbers.first).to be_instance_of(Bandwidth::TelephoneNumber) + expect(webhook_subscription_error_from_hash.telephone_numbers.first.telephone_number).to eq('+18005554321') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(webhook_subscription_error_values.to_s).to eq('{:code=>400, :description=>"Invalid request", :telephoneNumbers=>[{:telephoneNumber=>"+18005554321"}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(webhook_subscription_error_default.eql?(Bandwidth::WebhookSubscriptionError.new)).to be true + expect(webhook_subscription_error_default.eql?(webhook_subscription_error_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(webhook_subscription_error_values.to_body).to eq({ + code: 400, + description: 'Invalid request', + telephoneNumbers: [{ telephoneNumber: '+18005554321' }] + }) + end + end +end diff --git a/spec/unit/models/webhook_subscription_request_schema_spec.rb b/spec/unit/models/webhook_subscription_request_schema_spec.rb new file mode 100644 index 00000000..3ac265e4 --- /dev/null +++ b/spec/unit/models/webhook_subscription_request_schema_spec.rb @@ -0,0 +1,99 @@ +# Unit tests for Bandwidth::WebhookSubscriptionRequestSchema +describe Bandwidth::WebhookSubscriptionRequestSchema do + let(:webhook_subscription_request_schema_default) { Bandwidth::WebhookSubscriptionRequestSchema.new } + let(:webhook_subscription_request_schema_values) { Bandwidth::WebhookSubscriptionRequestSchema.new({ + basic_authentication: Bandwidth::TfvBasicAuthentication.new({ username: 'user', password: 'pass' }), + callback_url: 'https://example.com/callback', + shared_secret_key: 'abc123abc123abc1' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::WebhookSubscriptionRequestSchema.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::WebhookSubscriptionRequestSchema.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::WebhookSubscriptionRequestSchema.acceptable_attributes).to eq(Bandwidth::WebhookSubscriptionRequestSchema.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::WebhookSubscriptionRequestSchema.openapi_nullable).to eq(Set.new([ + :'callback_url', + :'shared_secret_key' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of WebhookSubscriptionRequestSchema created by the build_from_hash method' do + webhook_subscription_request_schema_from_hash = Bandwidth::WebhookSubscriptionRequestSchema.build_from_hash({ + basicAuthentication: { username: 'user', password: 'pass' }, + callbackUrl: 'https://example.com/callback', + sharedSecretKey: 'abc123abc123abc1' + }) + expect(webhook_subscription_request_schema_from_hash).to be_instance_of(Bandwidth::WebhookSubscriptionRequestSchema) + expect(webhook_subscription_request_schema_from_hash.basic_authentication).to be_instance_of(Bandwidth::TfvBasicAuthentication) + expect(webhook_subscription_request_schema_from_hash.basic_authentication.username).to eq('user') + expect(webhook_subscription_request_schema_from_hash.basic_authentication.password).to eq('pass') + expect(webhook_subscription_request_schema_from_hash.callback_url).to eq('https://example.com/callback') + expect(webhook_subscription_request_schema_from_hash.shared_secret_key).to eq('abc123abc123abc1') + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(webhook_subscription_request_schema_values.to_s).to eq('{:basicAuthentication=>{:username=>"user", :password=>"pass"}, :callbackUrl=>"https://example.com/callback", :sharedSecretKey=>"abc123abc123abc1"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(webhook_subscription_request_schema_default.eql?(Bandwidth::WebhookSubscriptionRequestSchema.new)).to be true + expect(webhook_subscription_request_schema_default.eql?(webhook_subscription_request_schema_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(webhook_subscription_request_schema_values.to_body).to eq({ + basicAuthentication: { username: 'user', password: 'pass' }, + callbackUrl: 'https://example.com/callback', + sharedSecretKey: 'abc123abc123abc1' + }) + end + end + + describe 'custom attribute writers' do + it '#callback_url=' do + expect { + webhook_subscription_request_schema_values.callback_url = 'a' * 2001 + }.to raise_error(ArgumentError, 'invalid value for "callback_url", the character length must be smaller than or equal to 2000.') + + expect { + webhook_subscription_request_schema_values.callback_url = 'not a url' + }.to raise_error(ArgumentError, /invalid value for "callback_url", must conform to the pattern/) + end + + it '#shared_secret_key=' do + expect { + webhook_subscription_request_schema_values.shared_secret_key = 'a' * 65 + }.to raise_error(ArgumentError, 'invalid value for "shared_secret_key", the character length must be smaller than or equal to 64.') + + expect { + webhook_subscription_request_schema_values.shared_secret_key = 'a' * 15 + }.to raise_error(ArgumentError, 'invalid value for "shared_secret_key", the character length must be greater than or equal to 16.') + end + end +end diff --git a/spec/unit/models/webhook_subscription_spec.rb b/spec/unit/models/webhook_subscription_spec.rb new file mode 100644 index 00000000..a7073693 --- /dev/null +++ b/spec/unit/models/webhook_subscription_spec.rb @@ -0,0 +1,100 @@ +# Unit tests for Bandwidth::WebhookSubscription +describe Bandwidth::WebhookSubscription do + let(:webhook_subscription_default) { Bandwidth::WebhookSubscription.new } + let(:webhook_subscription_values) { Bandwidth::WebhookSubscription.new({ + id: '6cf73464-0c9f-431f-bd16-3711df296b9a', + account_id: '9900000', + callback_url: 'https://example.com/callback', + type: Bandwidth::WebhookSubscriptionTypeEnum::TOLLFREE_VERIFICATION_STATUS, + basic_authentication: Bandwidth::WebhookSubscriptionBasicAuthentication.new({ username: 'user', password: 'pass' }), + created_date: '2024-01-01T00:00:00Z', + modified_date: '2024-01-02T00:00:00Z' + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::WebhookSubscription.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::WebhookSubscription.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::WebhookSubscription.acceptable_attributes).to eq(Bandwidth::WebhookSubscription.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::WebhookSubscription.openapi_nullable).to eq(Set.new([:'callback_url'])) + end + end + + describe '#build_from_hash' do + it 'validates instance of WebhookSubscription created by the build_from_hash method' do + webhook_subscription_from_hash = Bandwidth::WebhookSubscription.build_from_hash({ + id: '6cf73464-0c9f-431f-bd16-3711df296b9a', + accountId: '9900000', + callbackUrl: 'https://example.com/callback', + type: Bandwidth::WebhookSubscriptionTypeEnum::TOLLFREE_VERIFICATION_STATUS, + basicAuthentication: { username: 'user', password: 'pass' }, + createdDate: '2024-01-01T00:00:00Z', + modifiedDate: '2024-01-02T00:00:00Z' + }) + expect(webhook_subscription_from_hash).to be_instance_of(Bandwidth::WebhookSubscription) + expect(webhook_subscription_from_hash.id).to eq('6cf73464-0c9f-431f-bd16-3711df296b9a') + expect(webhook_subscription_from_hash.account_id).to eq('9900000') + expect(webhook_subscription_from_hash.callback_url).to eq('https://example.com/callback') + expect(webhook_subscription_from_hash.type).to eq(Bandwidth::WebhookSubscriptionTypeEnum::TOLLFREE_VERIFICATION_STATUS) + expect(webhook_subscription_from_hash.basic_authentication).to be_instance_of(Bandwidth::WebhookSubscriptionBasicAuthentication) + expect(webhook_subscription_from_hash.created_date).to eq(Time.parse('2024-01-01T00:00:00Z')) + expect(webhook_subscription_from_hash.modified_date).to eq(Time.parse('2024-01-02T00:00:00Z')) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(webhook_subscription_values.to_s).to eq('{:id=>"6cf73464-0c9f-431f-bd16-3711df296b9a", :accountId=>"9900000", :callbackUrl=>"https://example.com/callback", :type=>"TOLLFREE_VERIFICATION_STATUS", :basicAuthentication=>{:username=>"user", :password=>"pass"}, :createdDate=>"2024-01-01T00:00:00Z", :modifiedDate=>"2024-01-02T00:00:00Z"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(webhook_subscription_default.eql?(Bandwidth::WebhookSubscription.new)).to be true + expect(webhook_subscription_default.eql?(webhook_subscription_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(webhook_subscription_values.to_body).to eq({ + id: '6cf73464-0c9f-431f-bd16-3711df296b9a', + accountId: '9900000', + callbackUrl: 'https://example.com/callback', + type: Bandwidth::WebhookSubscriptionTypeEnum::TOLLFREE_VERIFICATION_STATUS, + basicAuthentication: { username: 'user', password: 'pass' }, + createdDate: '2024-01-01T00:00:00Z', + modifiedDate: '2024-01-02T00:00:00Z' + }) + end + end + + describe 'custom attribute writers' do + it '#callback_url=' do + expect { + webhook_subscription_values.callback_url = 'a' * 2001 + }.to raise_error(ArgumentError, 'invalid value for "callback_url", the character length must be smaller than or equal to 2000.') + + expect { + webhook_subscription_values.callback_url = 'not a url' + }.to raise_error(ArgumentError, /invalid value for "callback_url", must conform to the pattern/) + end + end +end diff --git a/spec/unit/models/webhook_subscription_type_enum_spec.rb b/spec/unit/models/webhook_subscription_type_enum_spec.rb new file mode 100644 index 00000000..d5c4624a --- /dev/null +++ b/spec/unit/models/webhook_subscription_type_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::WebhookSubscriptionTypeEnum +describe Bandwidth::WebhookSubscriptionTypeEnum do + describe 'constants' do + it 'defines TOLLFREE_VERIFICATION_STATUS' do + expect(Bandwidth::WebhookSubscriptionTypeEnum::TOLLFREE_VERIFICATION_STATUS).to eq('TOLLFREE_VERIFICATION_STATUS') + end + + it 'defines MESSAGING_PORTOUT_APPROVAL_STATUS' do + expect(Bandwidth::WebhookSubscriptionTypeEnum::MESSAGING_PORTOUT_APPROVAL_STATUS).to eq('MESSAGING_PORTOUT_APPROVAL_STATUS') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::WebhookSubscriptionTypeEnum.all_vars).to eq([ + 'TOLLFREE_VERIFICATION_STATUS', + 'MESSAGING_PORTOUT_APPROVAL_STATUS' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::WebhookSubscriptionTypeEnum.build_from_hash('TOLLFREE_VERIFICATION_STATUS')).to eq('TOLLFREE_VERIFICATION_STATUS') + expect(Bandwidth::WebhookSubscriptionTypeEnum.build_from_hash('MESSAGING_PORTOUT_APPROVAL_STATUS')).to eq('MESSAGING_PORTOUT_APPROVAL_STATUS') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::WebhookSubscriptionTypeEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/webhook_subscriptions_list_body_spec.rb b/spec/unit/models/webhook_subscriptions_list_body_spec.rb new file mode 100644 index 00000000..c89cbfe8 --- /dev/null +++ b/spec/unit/models/webhook_subscriptions_list_body_spec.rb @@ -0,0 +1,91 @@ +# Unit tests for Bandwidth::WebhookSubscriptionsListBody +describe Bandwidth::WebhookSubscriptionsListBody do + let(:webhook_subscriptions_list_body_default) { Bandwidth::WebhookSubscriptionsListBody.new({ + data: [] + }) } + let(:webhook_subscriptions_list_body_values) { Bandwidth::WebhookSubscriptionsListBody.new({ + links: { self: 'https://example.com/self' }, + errors: [ + Bandwidth::WebhookSubscriptionError.new({ code: 400, description: 'Invalid request' }) + ], + data: [ + Bandwidth::WebhookSubscription.new({ id: '6cf73464-0c9f-431f-bd16-3711df296b9a', account_id: '9900000' }) + ] + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::WebhookSubscriptionsListBody.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::WebhookSubscriptionsListBody.new({ invalid: true }) + }.to raise_error(ArgumentError) + end + end + + describe '#acceptable_attributes' do + it 'expects acceptable JSON attributes to be those in the attribute map' do + expect(Bandwidth::WebhookSubscriptionsListBody.acceptable_attributes).to eq(Bandwidth::WebhookSubscriptionsListBody.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be an empty set' do + expect(Bandwidth::WebhookSubscriptionsListBody.openapi_nullable).to eq(Set.new([])) + end + end + + describe '#build_from_hash' do + it 'validates instance of WebhookSubscriptionsListBody created by the build_from_hash method' do + webhook_subscriptions_list_body_from_hash = Bandwidth::WebhookSubscriptionsListBody.build_from_hash({ + links: { self: 'https://example.com/self' }, + errors: [{ code: 400, description: 'Invalid request' }], + data: [{ id: '6cf73464-0c9f-431f-bd16-3711df296b9a', accountId: '9900000' }] + }) + expect(webhook_subscriptions_list_body_from_hash).to be_instance_of(Bandwidth::WebhookSubscriptionsListBody) + expect(webhook_subscriptions_list_body_from_hash.links).to be_instance_of(Bandwidth::LinksObject) + expect(webhook_subscriptions_list_body_from_hash.errors).to be_instance_of(Array) + expect(webhook_subscriptions_list_body_from_hash.errors.first).to be_instance_of(Bandwidth::WebhookSubscriptionError) + expect(webhook_subscriptions_list_body_from_hash.data).to be_instance_of(Array) + expect(webhook_subscriptions_list_body_from_hash.data.first).to be_instance_of(Bandwidth::WebhookSubscription) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(webhook_subscriptions_list_body_values.to_s).to eq('{:links=>{:self=>"https://example.com/self"}, :errors=>[{:code=>400, :description=>"Invalid request"}], :data=>[{:id=>"6cf73464-0c9f-431f-bd16-3711df296b9a", :accountId=>"9900000", :callbackUrl=>nil}]}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + webhook_subscriptions_list_body_equal = Bandwidth::WebhookSubscriptionsListBody.new({ + data: [] + }) + expect(webhook_subscriptions_list_body_default.eql?(webhook_subscriptions_list_body_equal)).to be true + expect(webhook_subscriptions_list_body_default.eql?(webhook_subscriptions_list_body_values)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the object' do + expect(webhook_subscriptions_list_body_values.to_body).to eq({ + links: { self: 'https://example.com/self' }, + errors: [{ code: 400, description: 'Invalid request' }], + data: [{ id: '6cf73464-0c9f-431f-bd16-3711df296b9a', accountId: '9900000', callbackUrl: nil }] + }) + end + end + + describe 'custom attribute writers' do + it '#data=' do + expect { + webhook_subscriptions_list_body_values.data = nil + }.to raise_error(ArgumentError, 'data cannot be nil') + end + end +end