From 48fa35eb0b8908cfcf32b3429a9a6bf5fa66f032 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Jun 2026 12:58:30 +0000 Subject: [PATCH] VAPI-3162: Add ReferCompleteCallback and ReferCallStatusEnum to Ruby SDK - Add referCallStatusEnum schema to bandwidth.yml - Add referCompleteCallback schema to bandwidth.yml with standard call context fields plus refer-specific fields (referTo, referCallStatus, referSipResponseCode, notifySipResponseCode) - Copy OpenAPI-generator-produced model files: lib/bandwidth-sdk/models/refer_call_status_enum.rb lib/bandwidth-sdk/models/refer_complete_callback.rb - Register both models in lib/bandwidth-sdk.rb and .openapi-generator/FILES - Add unit tests covering success, failure (405 rejected), and failure (202 + notifySipResponseCode) scenarios --- .openapi-generator/FILES | 2 + bandwidth.yml | 63 ++++ lib/bandwidth-sdk.rb | 2 + .../models/refer_call_status_enum.rb | 40 +++ .../models/refer_complete_callback.rb | 334 ++++++++++++++++++ .../models/refer_call_status_enum_spec.rb | 34 ++ .../models/refer_complete_callback_spec.rb | 200 +++++++++++ 7 files changed, 675 insertions(+) create mode 100644 lib/bandwidth-sdk/models/refer_call_status_enum.rb create mode 100644 lib/bandwidth-sdk/models/refer_complete_callback.rb create mode 100644 spec/unit/models/refer_call_status_enum_spec.rb create mode 100644 spec/unit/models/refer_complete_callback_spec.rb diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 425d0417..29d91be4 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -388,6 +388,8 @@ lib/bandwidth-sdk/models/recording_transcription_metadata.rb lib/bandwidth-sdk/models/recording_transcriptions.rb lib/bandwidth-sdk/models/redirect_callback.rb lib/bandwidth-sdk/models/redirect_method_enum.rb +lib/bandwidth-sdk/models/refer_call_status_enum.rb +lib/bandwidth-sdk/models/refer_complete_callback.rb lib/bandwidth-sdk/models/sip_connection_metadata.rb lib/bandwidth-sdk/models/sip_credentials.rb lib/bandwidth-sdk/models/sms_message_content.rb diff --git a/bandwidth.yml b/bandwidth.yml index 5927a5e8..23cef12b 100644 --- a/bandwidth.yml +++ b/bandwidth.yml @@ -3209,6 +3209,13 @@ components: Setting the conference state to `completed` ends the conference and ejects all members. example: completed + referCallStatusEnum: + type: string + enum: + - success + - failure + description: The status of the SIP REFER request. + example: success machineDetectionModeEnum: type: string default: async @@ -5047,6 +5054,62 @@ components: $ref: '#/components/schemas/transferCallerId' transferTo: $ref: '#/components/schemas/transferTo' + referCompleteCallback: + type: object + description: >- + This event is sent to the referCompleteUrl of the verb when the + SIP REFER request has been resolved — either the remote endpoint has + accepted and redirected the call (success) or the REFER was rejected or + timed out (failure). On success the original call is terminated. + properties: + eventType: + $ref: '#/components/schemas/eventType' + eventTime: + $ref: '#/components/schemas/eventTime' + accountId: + $ref: '#/components/schemas/accountId' + applicationId: + $ref: '#/components/schemas/applicationId1' + from: + $ref: '#/components/schemas/from' + to: + $ref: '#/components/schemas/to' + direction: + $ref: '#/components/schemas/callDirectionEnum' + callId: + $ref: '#/components/schemas/callId' + callUrl: + $ref: '#/components/schemas/callUrl' + enqueuedTime: + $ref: '#/components/schemas/enqueuedTime' + startTime: + $ref: '#/components/schemas/startTime' + answerTime: + $ref: '#/components/schemas/answerTime' + tag: + $ref: '#/components/schemas/tag1' + referTo: + type: string + description: The SIP URI that the call was referred to. + example: sip:alice@atlanta.example.com + referCallStatus: + $ref: '#/components/schemas/referCallStatusEnum' + referSipResponseCode: + type: integer + description: >- + The SIP response code received in response to the REFER request. + Present when the status of the REFER is known (e.g. 202 Accepted or + 405 Method Not Allowed). Absent when the REFER was not attempted. + example: 202 + nullable: true + notifySipResponseCode: + type: integer + description: >- + The SIP response code received in a NOTIFY from the remote endpoint + after it attempted to reach the transfer target. Present only if a + NOTIFY was received before the 30-second timeout. + example: 200 + nullable: true transcriptionAvailableCallback: type: object description: >- diff --git a/lib/bandwidth-sdk.rb b/lib/bandwidth-sdk.rb index 293421af..2a67ca96 100644 --- a/lib/bandwidth-sdk.rb +++ b/lib/bandwidth-sdk.rb @@ -174,6 +174,8 @@ require 'bandwidth-sdk/models/recording_transcriptions' require 'bandwidth-sdk/models/redirect_callback' require 'bandwidth-sdk/models/redirect_method_enum' +require 'bandwidth-sdk/models/refer_call_status_enum' +require 'bandwidth-sdk/models/refer_complete_callback' require 'bandwidth-sdk/models/sip_connection_metadata' require 'bandwidth-sdk/models/sip_credentials' require 'bandwidth-sdk/models/sms_message_content' diff --git a/lib/bandwidth-sdk/models/refer_call_status_enum.rb b/lib/bandwidth-sdk/models/refer_call_status_enum.rb new file mode 100644 index 00000000..eb0d301a --- /dev/null +++ b/lib/bandwidth-sdk/models/refer_call_status_enum.rb @@ -0,0 +1,40 @@ +=begin +#Bandwidth + +#Bandwidth's Communication APIs + +The version of the OpenAPI document: 1.0.0 +Contact: letstalk@bandwidth.com +Generated by: https://openapi-generator.tech +Generator version: 7.17.0 + +=end + +require 'date' +require 'time' + +module Bandwidth + class ReferCallStatusEnum + SUCCESS = "success".freeze + FAILURE = "failure".freeze + + def self.all_vars + @all_vars ||= [SUCCESS, FAILURE].freeze + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + return value if ReferCallStatusEnum.all_vars.include?(value) + raise "Invalid ENUM value #{value} for class #ReferCallStatusEnum" + end + end +end diff --git a/lib/bandwidth-sdk/models/refer_complete_callback.rb b/lib/bandwidth-sdk/models/refer_complete_callback.rb new file mode 100644 index 00000000..16e02ca6 --- /dev/null +++ b/lib/bandwidth-sdk/models/refer_complete_callback.rb @@ -0,0 +1,334 @@ +=begin +#Bandwidth + +#Bandwidth's Communication APIs + +The version of the OpenAPI document: 1.0.0 +Contact: letstalk@bandwidth.com +Generated by: https://openapi-generator.tech +Generator version: 7.17.0 + +=end + +require 'date' +require 'time' + +module Bandwidth + # This event is sent to the referCompleteUrl of the verb when the SIP REFER request has been resolved — either the remote endpoint has accepted and redirected the call (success) or the REFER was rejected or timed out (failure). On success the original call is terminated. + class ReferCompleteCallback < ApiModelBase + # The event type, value can be one of the following: answer, bridgeComplete, bridgeTargetComplete, conferenceCreated, conferenceRedirect, conferenceMemberJoin, conferenceMemberExit, conferenceCompleted, conferenceRecordingAvailable, disconnect, dtmf, gather, initiate, machineDetectionComplete, recordingComplete, recordingAvailable, redirect, transcriptionAvailable, transferAnswer, transferComplete, transferDisconnect. + attr_accessor :event_type + + # The approximate UTC date and time when the event was generated by the Bandwidth server, in ISO 8601 format. This may not be exactly the time of event execution. + attr_accessor :event_time + + # The user account associated with the call. + attr_accessor :account_id + + # The id of the application associated with the call. + attr_accessor :application_id + + # The provided identifier of the caller. Must be a phone number in E.164 format (e.g. +15555555555). + attr_accessor :from + + # The phone number that received the call, in E.164 format (e.g. +15555555555). + attr_accessor :to + + attr_accessor :direction + + # The call id associated with the event. + attr_accessor :call_id + + # The URL of the call associated with the event. + attr_accessor :call_url + + # (optional) If call queueing is enabled and this is an outbound call, time the call was queued, in ISO 8601 format. + attr_accessor :enqueued_time + + # Time the call was started, in ISO 8601 format. + attr_accessor :start_time + + # Time the call was answered, in ISO 8601 format. + attr_accessor :answer_time + + # (optional) The tag specified on call creation. If no tag was specified or it was previously cleared, this field will not be present. + attr_accessor :tag + + # The SIP URI that the call was referred to. + attr_accessor :refer_to + + attr_accessor :refer_call_status + + # The SIP response code received in response to the REFER request. Present when the status of the REFER is known (e.g. 202 Accepted or 405 Method Not Allowed). Absent when the REFER was not attempted. + attr_accessor :refer_sip_response_code + + # The SIP response code received in a NOTIFY from the remote endpoint after it attempted to reach the transfer target. Present only if a NOTIFY was received before the 30-second timeout. + attr_accessor :notify_sip_response_code + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'event_type' => :'eventType', + :'event_time' => :'eventTime', + :'account_id' => :'accountId', + :'application_id' => :'applicationId', + :'from' => :'from', + :'to' => :'to', + :'direction' => :'direction', + :'call_id' => :'callId', + :'call_url' => :'callUrl', + :'enqueued_time' => :'enqueuedTime', + :'start_time' => :'startTime', + :'answer_time' => :'answerTime', + :'tag' => :'tag', + :'refer_to' => :'referTo', + :'refer_call_status' => :'referCallStatus', + :'refer_sip_response_code' => :'referSipResponseCode', + :'notify_sip_response_code' => :'notifySipResponseCode' + } + end + + # Returns attribute mapping this model knows about + def self.acceptable_attribute_map + attribute_map + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + acceptable_attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'event_type' => :'String', + :'event_time' => :'Time', + :'account_id' => :'String', + :'application_id' => :'String', + :'from' => :'String', + :'to' => :'String', + :'direction' => :'CallDirectionEnum', + :'call_id' => :'String', + :'call_url' => :'String', + :'enqueued_time' => :'Time', + :'start_time' => :'Time', + :'answer_time' => :'Time', + :'tag' => :'String', + :'refer_to' => :'String', + :'refer_call_status' => :'ReferCallStatusEnum', + :'refer_sip_response_code' => :'Integer', + :'notify_sip_response_code' => :'Integer' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'enqueued_time', + :'answer_time', + :'tag', + :'refer_sip_response_code', + :'notify_sip_response_code' + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Bandwidth::ReferCompleteCallback` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + acceptable_attribute_map = self.class.acceptable_attribute_map + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!acceptable_attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `Bandwidth::ReferCompleteCallback`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'event_type') + self.event_type = attributes[:'event_type'] + end + + if attributes.key?(:'event_time') + self.event_time = attributes[:'event_time'] + end + + if attributes.key?(:'account_id') + self.account_id = attributes[:'account_id'] + end + + if attributes.key?(:'application_id') + self.application_id = attributes[:'application_id'] + end + + if attributes.key?(:'from') + self.from = attributes[:'from'] + end + + if attributes.key?(:'to') + self.to = attributes[:'to'] + end + + if attributes.key?(:'direction') + self.direction = attributes[:'direction'] + end + + if attributes.key?(:'call_id') + self.call_id = attributes[:'call_id'] + end + + if attributes.key?(:'call_url') + self.call_url = attributes[:'call_url'] + end + + if attributes.key?(:'enqueued_time') + self.enqueued_time = attributes[:'enqueued_time'] + end + + if attributes.key?(:'start_time') + self.start_time = attributes[:'start_time'] + end + + if attributes.key?(:'answer_time') + self.answer_time = attributes[:'answer_time'] + end + + if attributes.key?(:'tag') + self.tag = attributes[:'tag'] + end + + if attributes.key?(:'refer_to') + self.refer_to = attributes[:'refer_to'] + end + + if attributes.key?(:'refer_call_status') + self.refer_call_status = attributes[:'refer_call_status'] + end + + if attributes.key?(:'refer_sip_response_code') + self.refer_sip_response_code = attributes[:'refer_sip_response_code'] + end + + if attributes.key?(:'notify_sip_response_code') + self.notify_sip_response_code = attributes[:'notify_sip_response_code'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + event_type == o.event_type && + event_time == o.event_time && + account_id == o.account_id && + application_id == o.application_id && + from == o.from && + to == o.to && + direction == o.direction && + call_id == o.call_id && + call_url == o.call_url && + enqueued_time == o.enqueued_time && + start_time == o.start_time && + answer_time == o.answer_time && + tag == o.tag && + refer_to == o.refer_to && + refer_call_status == o.refer_call_status && + refer_sip_response_code == o.refer_sip_response_code && + notify_sip_response_code == o.notify_sip_response_code + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [event_type, event_time, account_id, application_id, from, to, direction, call_id, call_url, enqueued_time, start_time, answer_time, tag, refer_to, refer_call_status, refer_sip_response_code, notify_sip_response_code].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + end + +end diff --git a/spec/unit/models/refer_call_status_enum_spec.rb b/spec/unit/models/refer_call_status_enum_spec.rb new file mode 100644 index 00000000..9a3935ce --- /dev/null +++ b/spec/unit/models/refer_call_status_enum_spec.rb @@ -0,0 +1,34 @@ +# Unit tests for Bandwidth::ReferCallStatusEnum +describe Bandwidth::ReferCallStatusEnum do + describe 'constants' do + it 'defines SUCCESS' do + expect(Bandwidth::ReferCallStatusEnum::SUCCESS).to eq('success') + end + + it 'defines FAILURE' do + expect(Bandwidth::ReferCallStatusEnum::FAILURE).to eq('failure') + end + end + + describe '.all_vars' do + it 'returns every valid enum value' do + expect(Bandwidth::ReferCallStatusEnum.all_vars).to eq([ + 'success', + 'failure' + ]) + end + end + + describe '.build_from_hash' do + it 'returns the value when it matches a valid enum value' do + expect(Bandwidth::ReferCallStatusEnum.build_from_hash('success')).to eq('success') + expect(Bandwidth::ReferCallStatusEnum.build_from_hash('failure')).to eq('failure') + end + + it 'raises an error for an invalid enum value' do + expect { + Bandwidth::ReferCallStatusEnum.build_from_hash('invalid') + }.to raise_error(RuntimeError) + end + end +end diff --git a/spec/unit/models/refer_complete_callback_spec.rb b/spec/unit/models/refer_complete_callback_spec.rb new file mode 100644 index 00000000..b010c4f2 --- /dev/null +++ b/spec/unit/models/refer_complete_callback_spec.rb @@ -0,0 +1,200 @@ +# Unit tests for Bandwidth::ReferCompleteCallback +describe Bandwidth::ReferCompleteCallback do + let(:refer_complete_callback_default) { Bandwidth::ReferCompleteCallback.new } + let(:refer_complete_callback_success) { Bandwidth::ReferCompleteCallback.new({ + event_type: 'referComplete', + 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', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + refer_to: 'sip:alice@atlanta.example.com', + refer_call_status: Bandwidth::ReferCallStatusEnum::SUCCESS + }) } + let(:refer_complete_callback_failure) { Bandwidth::ReferCompleteCallback.new({ + event_type: 'referComplete', + 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', + answer_time: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + refer_to: 'sip:alice@atlanta.example.com', + refer_call_status: Bandwidth::ReferCallStatusEnum::FAILURE, + refer_sip_response_code: 405 + }) } + + describe '#initialize' do + it 'causes an ArgumentError by passing an Array to the initialize method' do + expect { + Bandwidth::ReferCompleteCallback.new([]) + }.to raise_error(ArgumentError) + end + + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do + expect { + Bandwidth::ReferCompleteCallback.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::ReferCompleteCallback.acceptable_attributes).to eq(Bandwidth::ReferCompleteCallback.attribute_map.values) + end + end + + describe '#openapi_nullable' do + it 'expects nullable attributes to be the set of nullable fields' do + expect(Bandwidth::ReferCompleteCallback.openapi_nullable).to eq(Set.new([ + :'enqueued_time', + :'answer_time', + :'tag', + :'refer_sip_response_code', + :'notify_sip_response_code' + ])) + end + end + + describe '#build_from_hash' do + it 'validates instance of ReferCompleteCallback created by the build_from_hash method (success)' do + callback = Bandwidth::ReferCompleteCallback.build_from_hash({ + eventType: 'referComplete', + 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', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + referTo: 'sip:alice@atlanta.example.com', + referCallStatus: 'success', + referSipResponseCode: nil, + notifySipResponseCode: nil + }) + expect(callback).to be_instance_of(Bandwidth::ReferCompleteCallback) + expect(callback.event_type).to eq('referComplete') + expect(callback.account_id).to eq('9900000') + expect(callback.refer_to).to eq('sip:alice@atlanta.example.com') + expect(callback.refer_call_status).to eq(Bandwidth::ReferCallStatusEnum::SUCCESS) + expect(callback.refer_sip_response_code).to be_nil + expect(callback.notify_sip_response_code).to be_nil + end + + it 'validates instance of ReferCompleteCallback for a rejected REFER (referSipResponseCode=405)' do + callback = Bandwidth::ReferCompleteCallback.build_from_hash({ + eventType: 'referComplete', + 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', + answerTime: '2022-06-16T13:15:18.126Z', + referTo: 'sip:alice@atlanta.example.com', + referCallStatus: 'failure', + referSipResponseCode: 405 + }) + expect(callback).to be_instance_of(Bandwidth::ReferCompleteCallback) + expect(callback.refer_call_status).to eq(Bandwidth::ReferCallStatusEnum::FAILURE) + expect(callback.refer_sip_response_code).to eq(405) + expect(callback.notify_sip_response_code).to be_nil + end + + it 'validates instance of ReferCompleteCallback for an unreachable destination (notifySipResponseCode present)' do + callback = Bandwidth::ReferCompleteCallback.build_from_hash({ + eventType: 'referComplete', + 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', + answerTime: '2022-06-16T13:15:18.126Z', + referTo: 'sip:alice@atlanta.example.com', + referCallStatus: 'failure', + referSipResponseCode: 202, + notifySipResponseCode: 503 + }) + expect(callback).to be_instance_of(Bandwidth::ReferCompleteCallback) + expect(callback.refer_call_status).to eq(Bandwidth::ReferCallStatusEnum::FAILURE) + expect(callback.refer_sip_response_code).to eq(202) + expect(callback.notify_sip_response_code).to eq(503) + end + end + + describe '#to_s' do + it 'returns a string representation of the object' do + expect(refer_complete_callback_success.to_s).to eq('{:eventType=>"referComplete", :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", :answerTime=>"2022-06-16T13:15:18.126Z", :tag=>"custom tag", :referTo=>"sip:alice@atlanta.example.com", :referCallStatus=>"success"}') + end + end + + describe '#eq? #==' do + it 'returns true/false when comparing objects' do + expect(refer_complete_callback_default.eql?(Bandwidth::ReferCompleteCallback.new)).to be true + expect(refer_complete_callback_default.eql?(refer_complete_callback_success)).to be false + end + end + + describe '#to_body #to_hash' do + it 'returns a hash representation of the success callback' do + expect(refer_complete_callback_success.to_body).to eq({ + eventType: 'referComplete', + 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', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + referTo: 'sip:alice@atlanta.example.com', + referCallStatus: Bandwidth::ReferCallStatusEnum::SUCCESS + }) + end + + it 'returns a hash representation of the failure callback with referSipResponseCode' do + expect(refer_complete_callback_failure.to_body).to eq({ + eventType: 'referComplete', + 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', + answerTime: '2022-06-16T13:15:18.126Z', + tag: 'custom tag', + referTo: 'sip:alice@atlanta.example.com', + referCallStatus: Bandwidth::ReferCallStatusEnum::FAILURE, + referSipResponseCode: 405 + }) + end + end +end