|
| 1 | +# Unit tests for Bandwidth::TfvError |
| 2 | +describe Bandwidth::TfvError do |
| 3 | + let(:tfv_error_default) { Bandwidth::TfvError.new } |
| 4 | + let(:tfv_error_values) { Bandwidth::TfvError.new({ |
| 5 | + type: 'type', |
| 6 | + description: 'description', |
| 7 | + errors: { key: 'value' } |
| 8 | + }) } |
| 9 | + |
| 10 | + describe '#initialize' do |
| 11 | + it 'causes an ArgumentError by passing an Array to the initialize method' do |
| 12 | + expect { |
| 13 | + Bandwidth::TfvError.new([]) |
| 14 | + }.to raise_error(ArgumentError) |
| 15 | + end |
| 16 | + |
| 17 | + it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do |
| 18 | + expect { |
| 19 | + Bandwidth::TfvError.new({ invalid: true }) |
| 20 | + }.to raise_error(ArgumentError) |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + describe '#acceptable_attributes' do |
| 25 | + it 'expects acceptable JSON attributes to be those in the attribute map' do |
| 26 | + expect(Bandwidth::TfvError.acceptable_attributes).to eq(Bandwidth::TfvError.attribute_map.values) |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + describe 'enum validation' do |
| 31 | + it 'works' do |
| 32 | + |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + describe '#build_from_hash' do |
| 37 | + it 'validates instance of TfvError created by the build_from_hash method' do |
| 38 | + tfv_error_from_hash = Bandwidth::TfvError.build_from_hash({ |
| 39 | + type: 'type', |
| 40 | + description: 'description', |
| 41 | + errors: { key: 'value' } |
| 42 | + }) |
| 43 | + expect(tfv_error_from_hash).to be_instance_of(Bandwidth::TfvError) |
| 44 | + expect(tfv_error_from_hash.type).to eq('type') |
| 45 | + expect(tfv_error_from_hash.description).to eq('description') |
| 46 | + expect(tfv_error_from_hash.errors).to eq({ key: 'value' }) |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + describe '#hash' do |
| 51 | + it 'returns a hash code according to attributes' do |
| 52 | + expect(tfv_error_default.hash).to be_instance_of(Integer) |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + describe '#to_s' do |
| 57 | + it 'returns a string representation of the object' do |
| 58 | + expect(tfv_error_values.to_s).to eq('{:type=>"type", :description=>"description", :errors=>{:key=>"value"}}') |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + describe '#eq? #==' do |
| 63 | + it 'returns true/false when comparing objects' do |
| 64 | + expect(tfv_error_default.eql?(Bandwidth::TfvError.new)).to be true |
| 65 | + expect(tfv_error_default.eql?(tfv_error_values)).to be false |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe '#to_body #to_hash' do |
| 70 | + it 'returns a hash representation of the object' do |
| 71 | + expect(tfv_error_values.to_body).to eq({ |
| 72 | + type: 'type', |
| 73 | + description: 'description', |
| 74 | + errors: { key: 'value' } |
| 75 | + }) |
| 76 | + end |
| 77 | + end |
| 78 | +end |
0 commit comments