|
1 | 1 | # Unit tests for Bandwidth::PhoneNumberLookupApi |
2 | 2 | describe 'PhoneNumberLookupApi' do |
3 | | - let(:request_id) { '21e6d818-eaa9-4ca9-b1d8-d6085f5c79d4' } |
| 3 | + let(:phone_numbers) { [BW_NUMBER, USER_NUMBER] } |
| 4 | + let(:request_id) { '123e4567-e89b-12d3-a456-426614174000' } |
4 | 5 |
|
5 | 6 | before(:all) do |
6 | 7 | Bandwidth.configure do |config| |
|
10 | 11 | config.ignore_operation_servers = true |
11 | 12 | config.host = '127.0.0.1:4010' |
12 | 13 | end |
13 | | - @phone_number_lookup_api_instance = Bandwidth::PhoneNumberLookupApi.new |
| 14 | + @api_instance = Bandwidth::PhoneNumberLookupApi.new |
14 | 15 | end |
15 | | - |
16 | 16 | describe 'test an instance of PhoneNumberLookupApi' do |
17 | 17 | it 'should create an instance of PhoneNumberLookupApi' do |
18 | | - expect(@phone_number_lookup_api_instance).to be_instance_of(Bandwidth::PhoneNumberLookupApi) |
| 18 | + expect(@api_instance).to be_instance_of(Bandwidth::PhoneNumberLookupApi) |
19 | 19 | end |
20 | 20 | end |
21 | 21 |
|
22 | | - # Create Lookup |
23 | | - describe 'create_lookup' do |
24 | | - it 'creates a tn lookup request' do |
25 | | - tn_body = Bandwidth::LookupRequest.new( |
26 | | - tns: [BW_NUMBER] |
| 22 | + # Create Asynchronous Bulk Number Lookup |
| 23 | + describe 'create_async_bulk_lookup test' do |
| 24 | + it 'should work' do |
| 25 | + request = Bandwidth::AsyncLookupRequest.new( |
| 26 | + phone_numbers: phone_numbers, |
27 | 27 | ) |
28 | | - data, status_code = @phone_number_lookup_api_instance.create_lookup_with_http_info(BW_ACCOUNT_ID, tn_body) |
29 | 28 |
|
30 | | - expect(status_code).to eq(202) |
31 | | - expect(data).to be_instance_of(Bandwidth::CreateLookupResponse) |
32 | | - expect(data.request_id.length).to eq(36) |
33 | | - expect(data.status).to be_one_of(Bandwidth::LookupStatusEnum.all_vars) |
34 | | - end |
35 | | - |
36 | | - it 'causes an ArgumentError for a missing account_id' do |
37 | | - expect { |
38 | | - @phone_number_lookup_api_instance.create_lookup(nil, {}) |
39 | | - }.to raise_error(ArgumentError) |
40 | | - end |
| 29 | + data, status_code = @api_instance.create_async_bulk_lookup_with_http_info(BW_ACCOUNT_ID, request) |
41 | 30 |
|
42 | | - it 'causes an ArgumentError for a missing lookup_request' do |
43 | | - expect { |
44 | | - @phone_number_lookup_api_instance.create_lookup(BW_ACCOUNT_ID, nil) |
45 | | - }.to raise_error(ArgumentError) |
| 31 | + expect(status_code).to eq(202) |
| 32 | + expect(data).to be_instance_of(Bandwidth::CreateAsyncBulkLookupResponse) |
| 33 | + expect(data.links[0]).to be_instance_of(Bandwidth::LinkSchema) |
| 34 | + expect(data.links[0].rel).to be_instance_of(String) |
| 35 | + expect(data.links[0].href).to be_instance_of(String) |
| 36 | + expect(data.links[0].method).to be_instance_of(String) |
| 37 | + expect(data.data).to be_instance_of(Bandwidth::CreateAsyncBulkLookupResponseData) |
| 38 | + expect(data.data.request_id).to be_instance_of(String) |
| 39 | + expect(data.data.status).to eq(Bandwidth::InProgressLookupStatusEnum::IN_PROGRESS) |
| 40 | + expect(data.errors).to be_instance_of(Array) |
46 | 41 | end |
47 | 42 | end |
48 | 43 |
|
49 | | - # Get Lookup Status |
50 | | - describe 'get_lookup_status' do |
51 | | - it 'gets lookup status' do |
52 | | - data, status_code = @phone_number_lookup_api_instance.get_lookup_status_with_http_info( |
53 | | - BW_ACCOUNT_ID, request_id, { header_params: { 'Prefer' => 'example=lookupMultipleNumbersPartialCompleteExample' } }) |
| 44 | + # Create Synchronous Number Lookup |
| 45 | + describe 'create_sync_lookup test' do |
| 46 | + it 'should work' do |
| 47 | + request = Bandwidth::SyncLookupRequest.new( |
| 48 | + phone_numbers: phone_numbers, |
| 49 | + ) |
54 | 50 |
|
55 | | - expect(status_code).to eq(200) |
56 | | - expect(data).to be_instance_of(Bandwidth::LookupStatus) |
57 | | - expect(data.request_id.length).to eq(36) |
58 | | - expect(data.status).to be_one_of(Bandwidth::LookupStatusEnum.all_vars) |
59 | | - expect(data.result).to be_instance_of(Array) |
60 | | - expect(data.result[0]).to be_instance_of(Bandwidth::LookupResult) |
61 | | - expect(data.result[0].response_code).to be_instance_of(Integer) |
62 | | - expect(data.result[0].message).to be_instance_of(String) |
63 | | - expect(data.result[0].e_164_format.length).to eq(12) |
64 | | - expect(data.result[0].formatted.length).to eq(14) |
65 | | - expect(data.result[0].country).to be_instance_of(String) |
66 | | - expect(data.result[0].line_type).to be_instance_of(String) |
67 | | - expect(data.result[0].line_provider).to be_instance_of(String) |
68 | | - expect(data.result[0].mobile_country_code).to be_instance_of(String) |
69 | | - expect(data.result[0].mobile_network_code).to be_instance_of(String) |
70 | | - expect(data.failed_telephone_numbers).to be_instance_of(Array) |
71 | | - expect(data.failed_telephone_numbers[0]).to be_instance_of(String) |
72 | | - end |
| 51 | + data, status_code = @api_instance.create_sync_lookup_with_http_info(BW_ACCOUNT_ID, request) |
73 | 52 |
|
74 | | - it 'causes an ArgumentError for a missing account_id' do |
75 | | - expect { |
76 | | - @phone_number_lookup_api_instance.get_lookup_status(nil, '') |
77 | | - }.to raise_error(ArgumentError) |
| 53 | + expect(status_code).to equal_to(200) |
| 54 | + expect(data).to be_instance_of(Bandwidth::CreateSyncLookupResponse) |
| 55 | + expect(data.links[0]).to be_instance_of(Bandwidth::LinkSchema) |
| 56 | + expect(data.links[0].rel).to be_instance_of(String) |
| 57 | + expect(data.links[0].href).to be_instance_of(String) |
| 58 | + expect(data.links[0].method).to be_instance_of(String) |
| 59 | + expect(data.data.request_id).to be_instance_of(String) |
| 60 | + expect(data.data.status).to eq(Bandwidth::CompletedLookupStatusEnum::COMPLETE) |
| 61 | + expect(data.data.results).to be_instance_of(Array) |
| 62 | + expect(data.data.results[0]).to be_instance_of(Bandwidth::LookupResult) |
| 63 | + expect(data.data.results[0].phone_number).to be_instance_of(String) |
| 64 | + expect(data.data.results[0].line_type).to eq(Bandwidth::LineTypeEnum::MOBILE) |
| 65 | + expect(data.data.results[0].messaging_provider).to be_instance_of(String) |
| 66 | + expect(data.data.results[0].voice_provider).to be_instance_of(String) |
| 67 | + expect(data.data.results[0].country_code_a3).to be_instance_of(String) |
| 68 | + expect(data.data.results[0].latest_message_delivery_status).to eq(Bandwidth::LatestMessageDeliveryStatusEnum::ACTIVE) |
| 69 | + expect(data.data.results[0].initial_message_delivery_status_date).to be_instance_of(Date) |
| 70 | + expect(data.data.results[0].latest_message_delivery_status_date).to be_instance_of(Date) |
| 71 | + expect(data.errors).to be_instance_of(Array) |
78 | 72 | end |
| 73 | + end |
| 74 | + |
| 75 | + # Get Asynchronous Bulk Number Lookup |
| 76 | + describe 'get_async_bulk_lookup test' do |
| 77 | + it 'should work' do |
| 78 | + data, status_code = @api_instance.get_async_bulk_lookup_with_http_info(BW_ACCOUNT_ID, request_id) |
79 | 79 |
|
80 | | - it 'causes an ArgumentError for a missing request_id' do |
81 | | - expect { |
82 | | - @phone_number_lookup_api_instance.get_lookup_status(BW_ACCOUNT_ID, nil) |
83 | | - }.to raise_error(ArgumentError) |
| 80 | + expect(status_code).to equal_to(200) |
| 81 | + expect(data).to be_instance_of(Bandwidth::GetAsyncBulkLookupResponse) |
| 82 | + expect(data.links[0]).to be_instance_of(Bandwidth::LinkSchema) |
| 83 | + expect(data.links[0].rel).to be_instance_of(String) |
| 84 | + expect(data.links[0].href).to be_instance_of(String) |
| 85 | + expect(data.links[0].method).to be_instance_of(String) |
| 86 | + expect(data.data.request_id).to be_instance_of(String) |
| 87 | + expect(data.data.status).to eq(Bandwidth::InProgressLookupStatusEnum::COMPLETE) |
| 88 | + expect(data.data.results).to be_instance_of(Array) |
| 89 | + expect(data.data.results[0]).to be_instance_of(Bandwidth::LookupResult) |
| 90 | + expect(data.data.results[0].phone_number).to be_instance_of(String) |
| 91 | + expect(data.data.results[0].line_type).to eq(Bandwidth::LineTypeEnum::MOBILE) |
| 92 | + expect(data.data.results[0].messaging_provider).to be_instance_of(String) |
| 93 | + expect(data.data.results[0].voice_provider).to be_instance_of(String) |
| 94 | + expect(data.data.results[0].country_code_a3).to be_instance_of(String) |
| 95 | + expect(data.data.results[0].latest_message_delivery_status).to eq(Bandwidth::LatestMessageDeliveryStatusEnum::ACTIVE) |
| 96 | + expect(data.data.results[0].initial_message_delivery_status_date).to be_instance_of(Date) |
| 97 | + expect(data.data.results[0].latest_message_delivery_status_date).to be_instance_of(Date) |
| 98 | + expect(data.errors).to be_instance_of(Array) |
84 | 99 | end |
85 | 100 | end |
86 | 101 | end |
0 commit comments