Skip to content

Commit 66d9fcd

Browse files
committed
unit tests
1 parent a7a2504 commit 66d9fcd

4 files changed

Lines changed: 129 additions & 5 deletions

File tree

spec/unit/api/recordings_api_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
expect(data).to be_instance_of(Bandwidth::RecordingTranscriptions)
192192
expect(data.transcripts).to be_instance_of(Array)
193193
expect(data.transcripts[0]).to be_instance_of(Bandwidth::Transcription)
194+
expect(data.transcripts[0].speaker).to be_instance_of(Integer)
194195
expect(data.transcripts[0].text).to be_instance_of(String)
195196
expect(data.transcripts[0].confidence).to be_instance_of(Float)
196197
end
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Unit tests for Bandwidth::RecordingTranscriptionClip
2+
describe Bandwidth::RecordingTranscriptionClip do
3+
let(:recording_transcription_clip_default) { Bandwidth::RecordingTranscriptionClip.new }
4+
let(:recording_transcription_clip_values) { Bandwidth::RecordingTranscriptionClip.new({
5+
speaker: 0,
6+
text: 'Hello world',
7+
confidence: 0.9,
8+
start_time_seconds: 1.5,
9+
end_time_seconds: 3.2
10+
}) }
11+
12+
describe '#initialize' do
13+
it 'causes an ArgumentError by passing an Array to the initialize method' do
14+
expect {
15+
Bandwidth::RecordingTranscriptionClip.new([])
16+
}.to raise_error(ArgumentError)
17+
end
18+
19+
it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do
20+
expect {
21+
Bandwidth::RecordingTranscriptionClip.new({ invalid: true })
22+
}.to raise_error(ArgumentError)
23+
end
24+
end
25+
26+
describe '#acceptable_attributes' do
27+
it 'expects acceptable JSON attributes to be those in the attribute map' do
28+
expect(Bandwidth::RecordingTranscriptionClip.acceptable_attributes).to eq(Bandwidth::RecordingTranscriptionClip.attribute_map.values)
29+
end
30+
end
31+
32+
describe '#openapi_nullable' do
33+
it 'expects nullable attributes to be an empty set' do
34+
expect(Bandwidth::RecordingTranscriptionClip.openapi_nullable).to eq(Set.new([]))
35+
end
36+
end
37+
38+
describe '#build_from_hash' do
39+
it 'validates instance of RecordingTranscriptionClip created by the build_from_hash method' do
40+
recording_transcription_clip_from_hash = Bandwidth::RecordingTranscriptionClip.build_from_hash({
41+
speaker: 0,
42+
text: 'Hello world',
43+
confidence: 0.9,
44+
startTimeSeconds: 1.5,
45+
endTimeSeconds: 3.2
46+
})
47+
expect(recording_transcription_clip_from_hash).to be_instance_of(Bandwidth::RecordingTranscriptionClip)
48+
expect(recording_transcription_clip_from_hash.speaker).to eq(0)
49+
expect(recording_transcription_clip_from_hash.text).to eq('Hello world')
50+
expect(recording_transcription_clip_from_hash.confidence).to eq(0.9)
51+
expect(recording_transcription_clip_from_hash.start_time_seconds).to eq(1.5)
52+
expect(recording_transcription_clip_from_hash.end_time_seconds).to eq(3.2)
53+
end
54+
end
55+
56+
describe '#to_s' do
57+
it 'returns a string representation of the object' do
58+
expect(recording_transcription_clip_values.to_s).to eq('{:speaker=>0, :text=>"Hello world", :confidence=>0.9, :startTimeSeconds=>1.5, :endTimeSeconds=>3.2}')
59+
end
60+
end
61+
62+
describe '#eq? #==' do
63+
it 'returns true/false when comparing objects' do
64+
expect(recording_transcription_clip_default.eql?(Bandwidth::RecordingTranscriptionClip.new)).to be true
65+
expect(recording_transcription_clip_default.eql?(recording_transcription_clip_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(recording_transcription_clip_values.to_body).to eq({
72+
speaker: 0,
73+
text: 'Hello world',
74+
confidence: 0.9,
75+
startTimeSeconds: 1.5,
76+
endTimeSeconds: 3.2
77+
})
78+
end
79+
end
80+
81+
describe 'custom attribute writers' do
82+
it '#confidence=' do
83+
expect {
84+
Bandwidth::RecordingTranscriptionClip.new({ confidence: nil })
85+
}.to raise_error(ArgumentError, 'confidence cannot be nil')
86+
87+
expect {
88+
Bandwidth::RecordingTranscriptionClip.new({ confidence: 1.5 })
89+
}.to raise_error(ArgumentError, 'invalid value for "confidence", must be smaller than or equal to 1.')
90+
91+
expect {
92+
Bandwidth::RecordingTranscriptionClip.new({ confidence: -0.5 })
93+
}.to raise_error(ArgumentError, 'invalid value for "confidence", must be greater than or equal to 0.')
94+
end
95+
end
96+
end

spec/unit/models/recording_transcriptions_spec.rb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33
let(:recording_transcriptions_default) { Bandwidth::RecordingTranscriptions.new }
44
let(:recording_transcriptions_values) { Bandwidth::RecordingTranscriptions.new({
55
transcripts: [
6-
Bandwidth::Transcription.new({ text: 'Hello World! Thank you for calling.', confidence: 0.9 })
6+
Bandwidth::Transcription.new({
7+
speaker: 1,
8+
text: 'Hello World! Thank you for calling.',
9+
confidence: 0.9
10+
})
11+
],
12+
clips: [
13+
Bandwidth::RecordingTranscriptionClip.new({
14+
speaker: 1,
15+
text: 'Hello World! Thank you for calling.',
16+
confidence: 0.9,
17+
start_time_seconds: 1.0,
18+
end_time_seconds: 5.0
19+
})
720
]
821
}) }
922

@@ -36,19 +49,28 @@
3649
describe '#build_from_hash' do
3750
it 'validates instance of RecordingTranscriptions created by the build_from_hash method' do
3851
recording_transcriptions_from_hash = Bandwidth::RecordingTranscriptions.build_from_hash({
39-
transcripts: [{ text: 'Hello World! Thank you for calling.', confidence: 0.9 }]
52+
transcripts: [{ text: 'Hello World! Thank you for calling.', confidence: 0.9, speaker: 1 }],
53+
clips: [{ text: 'Hello World! Thank you for calling.', confidence: 0.9, speaker: 1, startTimeSeconds: 1.0, endTimeSeconds: 5.0 }]
4054
})
4155
expect(recording_transcriptions_from_hash).to be_instance_of(Bandwidth::RecordingTranscriptions)
4256
expect(recording_transcriptions_from_hash.transcripts).to be_instance_of(Array)
4357
expect(recording_transcriptions_from_hash.transcripts.first).to be_instance_of(Bandwidth::Transcription)
58+
expect(recording_transcriptions_from_hash.transcripts.first.speaker).to eq(1)
4459
expect(recording_transcriptions_from_hash.transcripts.first.text).to eq('Hello World! Thank you for calling.')
4560
expect(recording_transcriptions_from_hash.transcripts.first.confidence).to eq(0.9)
61+
expect(recording_transcriptions_from_hash.clips).to be_instance_of(Array)
62+
expect(recording_transcriptions_from_hash.clips.first).to be_instance_of(Bandwidth::RecordingTranscriptionClip)
63+
expect(recording_transcriptions_from_hash.clips.first.speaker).to eq(1)
64+
expect(recording_transcriptions_from_hash.clips.first.text).to eq('Hello World! Thank you for calling.')
65+
expect(recording_transcriptions_from_hash.clips.first.confidence).to eq(0.9)
66+
expect(recording_transcriptions_from_hash.clips.first.start_time_seconds).to eq(1.0)
67+
expect(recording_transcriptions_from_hash.clips.first.end_time_seconds).to eq(5.0)
4668
end
4769
end
4870

4971
describe '#to_s' do
5072
it 'returns a string representation of the object' do
51-
expect(recording_transcriptions_values.to_s).to eq('{:transcripts=>[{:text=>"Hello World! Thank you for calling.", :confidence=>0.9}]}')
73+
expect(recording_transcriptions_values.to_s).to eq('{:transcripts=>[{:speaker=>1, :text=>"Hello World! Thank you for calling.", :confidence=>0.9}], :clips=>[{:speaker=>1, :text=>"Hello World! Thank you for calling.", :confidence=>0.9, :startTimeSeconds=>1.0, :endTimeSeconds=>5.0}]}')
5274
end
5375
end
5476

@@ -62,7 +84,8 @@
6284
describe '#to_body #to_hash' do
6385
it 'returns a hash representation of the object' do
6486
expect(recording_transcriptions_values.to_body).to eq({
65-
transcripts: [{ text: 'Hello World! Thank you for calling.', confidence: 0.9 }]
87+
transcripts: [{ text: 'Hello World! Thank you for calling.', confidence: 0.9, speaker: 1 }],
88+
clips: [{ text: 'Hello World! Thank you for calling.', confidence: 0.9, speaker: 1, startTimeSeconds: 1.0, endTimeSeconds: 5.0 }]
6689
})
6790
end
6891
end

spec/unit/models/transcription_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
describe Bandwidth::Transcription do
33
let(:transcription_default) { Bandwidth::Transcription.new }
44
let(:transcription_values) { Bandwidth::Transcription.new({
5+
speaker: 1,
56
text: 'Hello World! Thank you for calling.',
67
confidence: 0.9
78
}) }
@@ -35,18 +36,20 @@
3536
describe '#build_from_hash' do
3637
it 'validates instance of Transcription created by the build_from_hash method' do
3738
transcription_from_hash = Bandwidth::Transcription.build_from_hash({
39+
speaker: 1,
3840
text: 'Hello World! Thank you for calling.',
3941
confidence: 0.9
4042
})
4143
expect(transcription_from_hash).to be_instance_of(Bandwidth::Transcription)
44+
expect(transcription_from_hash.speaker).to eq(1)
4245
expect(transcription_from_hash.text).to eq('Hello World! Thank you for calling.')
4346
expect(transcription_from_hash.confidence).to eq(0.9)
4447
end
4548
end
4649

4750
describe '#to_s' do
4851
it 'returns a string representation of the object' do
49-
expect(transcription_values.to_s).to eq('{:text=>"Hello World! Thank you for calling.", :confidence=>0.9}')
52+
expect(transcription_values.to_s).to eq('{:speaker=>1, :text=>"Hello World! Thank you for calling.", :confidence=>0.9}')
5053
end
5154
end
5255

@@ -60,6 +63,7 @@
6063
describe '#to_body #to_hash' do
6164
it 'returns a hash representation of the object' do
6265
expect(transcription_values.to_body).to eq({
66+
speaker: 1,
6367
text: 'Hello World! Thank you for calling.',
6468
confidence: 0.9
6569
})

0 commit comments

Comments
 (0)