usps-imis-api 0.9.9 → 0.9.10.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/lib/usps/imis/business_object.rb +0 -3
  3. data/lib/usps/imis/config.rb +1 -1
  4. data/lib/usps/imis/query.rb +0 -3
  5. data/lib/usps/imis/requests.rb +4 -0
  6. data/lib/usps/imis/version.rb +1 -1
  7. metadata +1 -70
  8. data/.github/workflows/main.yml +0 -57
  9. data/.gitignore +0 -5
  10. data/.rspec +0 -2
  11. data/.rubocop.yml +0 -89
  12. data/.ruby-version +0 -1
  13. data/.simplecov +0 -8
  14. data/Gemfile +0 -16
  15. data/Gemfile.lock +0 -147
  16. data/Rakefile +0 -12
  17. data/bin/console +0 -21
  18. data/bin/setup +0 -8
  19. data/spec/fixtures/vcr_cassettes/.keep +0 -0
  20. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_authorize/automatically_refreshes_an_expired_token.yml +0 -67
  21. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_imis_id_for/gets_the_iMIS_ID.yml +0 -131
  22. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_imis_id_for/with_a_query_error/wraps_errors.yml +0 -67
  23. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_inspect/does_not_show_the_token_instance_variable.yml +0 -67
  24. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_inspect/is_configured_to_exclude_the_token_instance_variable.yml +0 -67
  25. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/chains_with_on_to_a_single_block.yml +0 -256
  26. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/nests_on_and_with.yml +0 -256
  27. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/returns_a_BusinessObject_without_a_block.yml +0 -67
  28. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/sends_an_update_from_put.yml +0 -256
  29. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_put/sends_an_update.yml +0 -256
  30. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_put/when_receiving_a_response_error/wraps_the_error.yml +0 -67
  31. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_query/collects_all_query_results.yml +0 -67
  32. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/blocks_calling_imis_id_.yml +0 -67
  33. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/blocks_calling_imis_id_for.yml +0 -67
  34. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/sends_an_update_from_put.yml +0 -256
  35. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/sends_an_update_from_update.yml +0 -256
  36. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/uses_a_panel_correctly.yml +0 -145
  37. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/stores_the_initial_imis_id.yml +0 -67
  38. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/_put_field/submits_the_correct_update_request.yml +0 -627
  39. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_filter_fields/formats_fields_correctly.yml +0 -67
  40. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get/delegation_to_get_fields/delegates_to_get_fields.yml +0 -67
  41. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get/returns_multiple_values.yml +0 -67
  42. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_field/returns_a_string_value.yml +0 -67
  43. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_field/returns_an_integer_value.yml +0 -67
  44. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_fields/returns_multiple_values.yml +0 -67
  45. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/fetches_a_mapped_field.yml +0 -158
  46. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/raises_for_unmapped_updates.yml +0 -67
  47. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/supports_Hash_access_syntax.yml +0 -158
  48. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/supports_Hash_access_syntax_on_the_Api_directly.yml +0 -158
  49. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_update/raises_for_unmapped_updates.yml +0 -67
  50. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_update/sends_a_mapped_update.yml +0 -256
  51. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/initialize_with_imis_id/stores_the_initial_imis_id.yml +0 -67
  52. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_BasePanel/requires_business_object_to_be_defined.yml +0 -67
  53. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_BasePanel/requires_payload_data_to_be_defined.yml +0 -67
  54. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get/loads_a_specific_object.yml +0 -146
  55. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get/returns_specific_fields.yml +0 -146
  56. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get_field/returns_a_specific_field.yml +0 -146
  57. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get_fields/returns_specific_fields.yml +0 -146
  58. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/interacts_with_records_correctly.yml +0 -495
  59. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/initialization_with_ID/can_initialize_with_an_iMIS_ID.yml +0 -67
  60. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Vsc/_get/loads_a_specific_object.yml +0 -145
  61. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Vsc/handles_new_records_correctly.yml +0 -319
  62. data/spec/lib/usps/imis/api_spec.rb +0 -161
  63. data/spec/lib/usps/imis/business_object_spec.rb +0 -87
  64. data/spec/lib/usps/imis/config_spec.rb +0 -59
  65. data/spec/lib/usps/imis/data_spec.rb +0 -75
  66. data/spec/lib/usps/imis/error_spec.rb +0 -17
  67. data/spec/lib/usps/imis/errors/response_error_spec.rb +0 -107
  68. data/spec/lib/usps/imis/mapper_spec.rb +0 -55
  69. data/spec/lib/usps/imis/mocks/business_object_spec.rb +0 -65
  70. data/spec/lib/usps/imis/panels/base_panel_spec.rb +0 -33
  71. data/spec/lib/usps/imis/panels/education_spec.rb +0 -70
  72. data/spec/lib/usps/imis/panels/vsc_spec.rb +0 -37
  73. data/spec/lib/usps/imis/properties_spec.rb +0 -19
  74. data/spec/lib/usps/imis_spec.rb +0 -11
  75. data/spec/spec_helper.rb +0 -78
  76. data/usps-imis-api.gemspec +0 -20
@@ -1,161 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Usps::Imis::Api, :vcr do
6
- let(:api) { described_class.new }
7
-
8
- it 'stores the initial imis_id' do
9
- api = described_class.new(imis_id: 42)
10
-
11
- expect(api.imis_id).to eq(42)
12
- end
13
-
14
- describe '#imis_id_for' do
15
- it 'gets the iMIS ID' do
16
- expect(api.imis_id_for('E231625')).to eq(31092)
17
- end
18
-
19
- context 'with a query error' do
20
- before { allow(api).to receive(:query).and_raise('Stub') }
21
-
22
- it 'wraps errors' do
23
- expect { api.imis_id_for('E231625') }.to raise_error(
24
- Usps::Imis::Errors::NotFoundError, 'Member not found'
25
- )
26
- end
27
- end
28
- end
29
-
30
- describe '#query' do
31
- let(:query) { api.query('$/ABC/ExampleQueryAll', {}) }
32
-
33
- before do
34
- allow(query).to receive(:fetch).and_return(
35
- { 'Items' => { '$values' => [{ 'key1' => 'value1' }] }, 'HasNext' => true, 'NextOffset' => 1 },
36
- { 'Items' => { '$values' => [{ 'key1' => 'value2' }] }, 'HasNext' => false, 'NextOffset' => 0 }
37
- )
38
- end
39
-
40
- it 'collects all query results' do
41
- expect(query.to_a).to eq([{ 'key1' => 'value1' }, { 'key1' => 'value2' }])
42
- end
43
- end
44
-
45
- describe '#put' do
46
- before { api.imis_id = 31092 }
47
-
48
- it 'sends an update' do
49
- expect(api.on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15)).to be_a(Hash)
50
- end
51
-
52
- context 'when receiving a response error' do
53
- let(:warning_text) do
54
- <<~WARNING.chomp
55
- Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
56
- Something went wrong
57
- WARNING
58
- end
59
-
60
- before do
61
- error = Struct.new(:code, :body).new('500', 'Something went wrong')
62
-
63
- # rubocop:disable RSpec/AnyInstance
64
- allow_any_instance_of(Net::HTTP).to receive(:request).and_return(error)
65
- # rubocop:enable RSpec/AnyInstance
66
- end
67
-
68
- it 'wraps the error' do
69
- expect { api.on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }.to(
70
- raise_error(Usps::Imis::Errors::ResponseError, warning_text)
71
- )
72
- end
73
- end
74
- end
75
-
76
- describe '#with' do
77
- it 'sends an update from put' do
78
- expect(
79
- api.with(31092) { on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }
80
- ).to be_a(Hash)
81
- end
82
-
83
- it 'sends an update from update' do
84
- expect(api.with(31092) { update(mm: 15) }.first).to be_a(Hash)
85
- end
86
-
87
- it 'uses a panel correctly' do
88
- expect(api.with(6374) { panels.vsc.get(1433) }).to be_a(Hash)
89
- end
90
-
91
- it 'blocks calling imis_id=' do
92
- expect do
93
- api.with(31092) { self.imis_id = 31092 }
94
- end.to raise_error(Usps::Imis::Errors::LockedIdError, 'Cannot change iMIS ID while locked')
95
- end
96
-
97
- it 'blocks calling imis_id_for' do
98
- expect do
99
- api.with(31092) { imis_id_for('E231625') }
100
- end.to raise_error(Usps::Imis::Errors::LockedIdError, 'Cannot change iMIS ID while locked')
101
- end
102
- end
103
-
104
- describe '#on' do
105
- it 'returns a BusinessObject without a block' do
106
- expect(api.on('ABC_ASC_Individual_Demog')).to be_a(Usps::Imis::BusinessObject)
107
- end
108
-
109
- it 'sends an update from put', :aggregate_failures do
110
- result = api.with(31092) do
111
- on('ABC_ASC_Individual_Demog') { put_fields({ 'TotMMS' => 15 }) }
112
- end
113
-
114
- expect(result).to be_a(Hash)
115
- expect(api.imis_id).to be_nil
116
- end
117
-
118
- it 'chains .with().on() to a single block', :aggregate_failures do
119
- result = api.with(31092).on('ABC_ASC_Individual_Demog') do
120
- put_fields({ 'TotMMS' => 15 })
121
- end
122
-
123
- expect(result).to be_a(Hash)
124
- expect(api.imis_id).to eq(31092)
125
- end
126
-
127
- it 'nests on and with', :aggregate_failures do
128
- result = api.on('ABC_ASC_Individual_Demog') do |object|
129
- api.with(31092) { object.put_fields({ 'TotMMS' => 15 }) }
130
- end
131
-
132
- expect(result).to be_a(Hash)
133
- expect(api.imis_id).to be_nil
134
- end
135
- end
136
-
137
- describe '#inspect' do
138
- it 'is configured to exclude the token instance variable' do
139
- expect(api.instance_variables_to_inspect).not_to include(:@token)
140
- end
141
-
142
- it 'does not show the token instance variable' do
143
- pending 'Requires Ruby 3.5' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new(3.5)
144
-
145
- expect(api.inspect).not_to match(/ @token="/)
146
- end
147
- end
148
-
149
- describe '#authorize' do
150
- before { allow(api).to receive(:authenticate) }
151
-
152
- it 'automatically refreshes an expired token' do
153
- api.instance_variable_set(:@token_expiration, Time.now - 60)
154
-
155
- request = Net::HTTP::Put.new('/')
156
- api.send(:authorize, request)
157
-
158
- expect(api).to have_received(:authenticate)
159
- end
160
- end
161
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Usps::Imis::BusinessObject, :vcr do
6
- describe '#put_field' do
7
- let(:business_object) { api.on('ABC_ASC_Individual_Demog') }
8
- let(:api) { Usps::Imis::Api.new.with(31092) }
9
-
10
- before { business_object.put_field('TotMMS', 15) }
11
-
12
- it 'submits the correct update request' do
13
- expect { business_object['TotMMS'] = 16 }.to change { business_object['TotMMS'] }.from(15).to(16)
14
- end
15
- end
16
-
17
- context 'with stubbed data' do
18
- let(:business_object) { described_class.new(api, 'Stub') }
19
- let(:api) { Usps::Imis::Api.new }
20
-
21
- before do
22
- allow(business_object).to receive(:raw_object).and_return(
23
- Usps::Imis::Data[
24
- 'Properties' => {
25
- '$values' => [
26
- { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
27
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
28
- { 'Name' => 'Stub String', 'Value' => 'something' }
29
- ]
30
- }
31
- ]
32
- )
33
- end
34
-
35
- describe '#get' do
36
- it 'returns multiple values' do
37
- expect(business_object.get('Stub String', 'Stub Integer')).to eq(['something', 42])
38
- end
39
-
40
- describe 'delegation to get_fields' do
41
- before { allow(business_object).to receive(:get_fields).with('Stub String', 'Stub Integer') }
42
-
43
- it 'delegates to get_fields' do
44
- business_object.get('Stub String', 'Stub Integer')
45
-
46
- expect(business_object).to have_received(:get_fields).with('Stub String', 'Stub Integer')
47
- end
48
- end
49
- end
50
-
51
- describe '#get_field' do
52
- it 'returns a string value' do
53
- expect(business_object.get_field('Stub String')).to eq('something')
54
- end
55
-
56
- it 'returns an integer value' do
57
- expect(business_object.get_field('Stub Integer')).to eq(42)
58
- end
59
- end
60
-
61
- describe '#get_fields' do
62
- it 'returns multiple values' do
63
- expect(business_object.get_fields('Stub String', 'Stub Integer')).to eq(['something', 42])
64
- end
65
- end
66
-
67
- describe '#filter_fields' do
68
- let(:expected) do
69
- {
70
- 'Properties' => {
71
- '$values' => [
72
- { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
73
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
74
- { 'Name' => 'Stub String', 'Value' => 'other' }
75
- ]
76
- }
77
- }
78
- end
79
-
80
- it 'formats fields correctly' do
81
- updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
82
-
83
- expect(updated).to eq(expected)
84
- end
85
- end
86
- end
87
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Usps::Imis::Config do
6
- let(:config) { described_class.new }
7
-
8
- describe 'environment' do
9
- subject { config.environment }
10
-
11
- let(:config) { described_class.new }
12
-
13
- context 'when not specified' do
14
- it { is_expected.to be_development }
15
- end
16
-
17
- context 'when specified' do
18
- before { config.environment = 'something' }
19
-
20
- it { is_expected.to be_something }
21
- end
22
-
23
- context 'when specified on initialize' do
24
- subject { config.environment }
25
-
26
- let(:config) do
27
- described_class.new { it.environment = 'test' }
28
- end
29
-
30
- it { is_expected.to be_test }
31
- end
32
-
33
- context 'when in Rails' do
34
- before { stub_const('Rails', Struct.new(:env).new(ActiveSupport::StringInquirer.new('qa'))) }
35
-
36
- it { is_expected.to be_qa }
37
- end
38
- end
39
-
40
- describe '#hostname' do
41
- context 'with production environment' do
42
- before { config.environment = 'production' }
43
-
44
- it 'returns the production hostname' do
45
- expect(config.hostname).to eq(described_class::IMIS_ROOT_URL_PROD)
46
- end
47
- end
48
-
49
- context 'with unrecognized environment' do
50
- before { config.environment = 'nothing' }
51
-
52
- it 'raises an error' do
53
- expect { config.hostname }.to raise_error(
54
- Usps::Imis::Errors::ConfigError, 'Unexpected API environment: nothing'
55
- )
56
- end
57
- end
58
- end
59
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Usps::Imis::Data do
6
- let(:data) do
7
- described_class[
8
- 'EntityTypeName' => 'ABC_ASC_Individual_Demog',
9
- 'Properties' => {
10
- '$values' => [
11
- { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
12
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
13
- { 'Name' => 'Stub String', 'Value' => 'something' }
14
- ]
15
- }
16
- ]
17
- end
18
-
19
- describe 'missing property' do
20
- it 'returns nil for missing properties' do
21
- expect(data['Not Found']).to be_nil
22
- end
23
- end
24
-
25
- describe '#properties' do
26
- it 'iterates over the properties, excluding IDs' do
27
- expect(data.properties.map { |field, value| "#{field}: #{value}" }).to eq(
28
- ['Stub Integer: 42', 'Stub String: something']
29
- )
30
- end
31
-
32
- it 'iterates over the properties, including IDs' do
33
- expect(data.properties(include_ids: true).map { |field, value| "#{field}: #{value}" }).to eq(
34
- ['ID: 31092', 'Stub Integer: 42', 'Stub String: something']
35
- )
36
- end
37
- end
38
-
39
- describe '#[]=' do
40
- it 'does not support setting values' do
41
- expect { described_class.new[:something] = :another }.to raise_error(
42
- Usps::Imis::Errors::ApiError,
43
- '`Data` does not support setting values. If you need to modify it, call `.raw` on it.'
44
- )
45
- end
46
- end
47
-
48
- describe '#inspect' do
49
- it 'generates the correct inspect string' do
50
- expect(data.inspect).to eq('#<Usps::Imis::Data entity="ABC_ASC_Individual_Demog" imis_id=31092>')
51
- end
52
-
53
- context 'with data from a Panel' do
54
- let(:data) do
55
- described_class[
56
- 'EntityTypeName' => 'ABC_ASC_Individual_Demog',
57
- 'Properties' => {
58
- '$values' => [
59
- { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
60
- { 'Name' => 'Ordinal', 'Value' => { '$value' => '99' } },
61
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
62
- { 'Name' => 'Stub String', 'Value' => 'something' }
63
- ]
64
- }
65
- ]
66
- end
67
-
68
- it 'generates the correct inspect string with an ordinal' do
69
- expect(data.inspect).to eq(
70
- '#<Usps::Imis::Data entity="ABC_ASC_Individual_Demog" imis_id=31092 ordinal=99>'
71
- )
72
- end
73
- end
74
- end
75
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Usps::Imis::Error do
6
- it 'builds Bugsnag metadata' do
7
- error = described_class.new('Example', something: :else)
8
-
9
- expect(error.bugsnag_meta_data).to eq(api: { something: :else })
10
- end
11
-
12
- it 'ignores Bugsnag metadata with none provided' do
13
- error = described_class.new('Example')
14
-
15
- expect(error.bugsnag_meta_data).to eq({})
16
- end
17
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- ApiResponseStub = Struct.new(:code, :body)
6
-
7
- describe Usps::Imis::Errors::ResponseError do
8
- let(:error) { described_class.from(response) }
9
-
10
- describe 'error codes' do
11
- context 'with a 400' do
12
- let(:response) { ApiResponseStub.new('400', 'body') }
13
-
14
- it 'builds the Bugsnag metadata correctly' do
15
- expect(error.bugsnag_meta_data).to eq(api: { status: :bad_request, body: 'body' })
16
- end
17
- end
18
-
19
- context 'with a 401' do
20
- let(:response) { ApiResponseStub.new('401', 'body') }
21
-
22
- it 'builds the Bugsnag metadata correctly' do
23
- expect(error.bugsnag_meta_data).to eq(api: { status: :unauthorized, body: 'body' })
24
- end
25
- end
26
-
27
- context 'with a 404' do
28
- let(:response) { ApiResponseStub.new('404', 'body') }
29
-
30
- it 'builds the Bugsnag metadata correctly' do
31
- expect(error.bugsnag_meta_data).to eq(api: { status: :not_found, body: 'body' })
32
- end
33
- end
34
-
35
- context 'with a 422' do
36
- let(:response) { ApiResponseStub.new('422', 'body') }
37
-
38
- it 'builds the Bugsnag metadata correctly' do
39
- expect(error.bugsnag_meta_data).to eq(api: { status: :unprocessable_entity, body: 'body' })
40
- end
41
- end
42
-
43
- context 'with a 500' do
44
- let(:response) { ApiResponseStub.new('500', 'body') }
45
-
46
- it 'builds the Bugsnag metadata correctly' do
47
- expect(error.bugsnag_meta_data).to eq(api: { status: :internal_server_error, body: 'body' })
48
- end
49
- end
50
-
51
- context 'with a 429' do
52
- let(:response) { ApiResponseStub.new('429', 'body') }
53
-
54
- it 'builds the Bugsnag metadata correctly' do
55
- expect(error.bugsnag_meta_data).to eq(api: { status: '429', body: 'body' })
56
- end
57
- end
58
- end
59
-
60
- context 'with a string response body' do
61
- let(:response) { ApiResponseStub.new('500', 'Body of the API response error') }
62
- let(:warning_text) do
63
- <<~WARNING.chomp
64
- Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
65
- Body of the API response error
66
- WARNING
67
- end
68
-
69
- it 'builds the correct message' do
70
- expect(error.message).to eq(warning_text)
71
- end
72
- end
73
-
74
- context 'with an invalid_grant hash response body' do
75
- let(:response_body) do
76
- { 'error' => 'invalid_grant', 'error_description' => 'description' }
77
- end
78
- let(:response) { ApiResponseStub.new('500', response_body) }
79
- let(:warning_text) do
80
- <<~WARNING.chomp
81
- Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
82
- description
83
- WARNING
84
- end
85
-
86
- it 'builds the correct message' do
87
- expect(error.message).to eq(warning_text)
88
- end
89
- end
90
-
91
- context 'with a generic hash response body' do
92
- let(:response_body) do
93
- { 'error' => 'summary', 'error_description' => 'description' }
94
- end
95
- let(:response) { ApiResponseStub.new('500', response_body) }
96
- let(:warning_text) do
97
- <<~WARNING.chomp
98
- Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
99
- #{response_body}
100
- WARNING
101
- end
102
-
103
- it 'builds the correct message' do
104
- expect(error.message).to eq(warning_text)
105
- end
106
- end
107
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Usps::Imis::Mapper, :vcr do
6
- let(:api) { described_class.new.api }
7
-
8
- describe 'initialize with imis_id' do
9
- it 'stores the initial imis_id' do
10
- mapper = described_class.new(imis_id: 42)
11
-
12
- expect(mapper.api.imis_id).to eq(42)
13
- end
14
- end
15
-
16
- describe '#fetch' do
17
- before { api.imis_id = 31092 }
18
-
19
- it 'fetches a mapped field' do
20
- expect(api.mapper.fetch(:mm)).to be_a(Integer)
21
- end
22
-
23
- it 'supports Hash access syntax' do
24
- expect(api.mapper[:mm]).to be_a(Integer)
25
- end
26
-
27
- it 'supports Hash access syntax on the Api directly' do
28
- expect(api[:mm]).to be_a(Integer)
29
- end
30
-
31
- it 'raises for unmapped updates' do
32
- expect { api.mapper.fetch(:another) }.to raise_error(
33
- Usps::Imis::Errors::MapperError,
34
- %(Mapper does not recognize field: "another".\n) \
35
- 'Please report what data you are attempting to work with to ITCom leadership.'
36
- )
37
- end
38
- end
39
-
40
- describe '#update' do
41
- before { api.imis_id = 31092 }
42
-
43
- it 'sends a mapped update' do
44
- expect(api.mapper.update(mm: 15).first).to be_a(Hash)
45
- end
46
-
47
- it 'raises for unmapped updates' do
48
- expect { api.mapper.update(something: 'anything') }.to raise_error(
49
- Usps::Imis::Errors::MapperError,
50
- %(Mapper does not recognize field: "something".\n) \
51
- 'Please report what data you are attempting to work with to ITCom leadership.'
52
- )
53
- end
54
- end
55
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Usps::Imis::Mocks::BusinessObject do
6
- let(:mock) { described_class.new(**fields) }
7
- let(:fields) { { TotMMS: 2, Something: 'Another' } }
8
-
9
- let(:data) do
10
- Usps::Imis::Properties.build do |props|
11
- props.add 'TotMMS', 2
12
- props.add 'Something', 'Another'
13
- end
14
- end
15
-
16
- describe 'get' do
17
- it 'returns the correct data' do
18
- expect(mock.get).to eq(data)
19
- end
20
- end
21
-
22
- describe 'get_field' do
23
- it 'returns the correct field value' do
24
- expect(mock.get_field('TotMMS')).to eq(2)
25
- end
26
- end
27
-
28
- describe 'get_fields' do
29
- it 'returns the correct field values' do
30
- expect(mock.get_fields('TotMMS', 'Something')).to eq([2, 'Another'])
31
- end
32
- end
33
-
34
- describe 'put_fields' do
35
- let(:combined_data) do
36
- Usps::Imis::Properties.build do |props|
37
- props.add 'TotMMS', 2
38
- props.add 'Something', 'Another'
39
- props.add 'SomethingElse', 'interesting'
40
- end
41
- end
42
-
43
- it 'returns the correct data' do
44
- expect(mock.put_fields(SomethingElse: 'interesting')).to eq(combined_data)
45
- end
46
- end
47
-
48
- describe 'put' do
49
- it 'returns the correct data' do
50
- expect(mock.put(data)).to eq(data)
51
- end
52
- end
53
-
54
- describe 'post' do
55
- it 'returns the correct data' do
56
- expect(mock.post(data)).to eq(data)
57
- end
58
- end
59
-
60
- describe 'delete' do
61
- it 'returns the correct data' do
62
- expect(mock.delete).to eq('')
63
- end
64
- end
65
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Usps
6
- module Imis
7
- module Panels
8
- class InvalidPanel < BasePanel; end
9
-
10
- class InvalidPanelWithBusinessObject < BasePanel
11
- private
12
-
13
- def business_object = 'Something'
14
- end
15
- end
16
- end
17
- end
18
-
19
- describe Usps::Imis::Panels::BasePanel, :vcr do
20
- it 'requires #business_object to be defined' do
21
- expect { Usps::Imis::Panels::InvalidPanel.new.get(1) }.to raise_error(
22
- Usps::Imis::Errors::PanelUnimplementedError,
23
- 'Usps::Imis::Panels::InvalidPanel must implement #business_object'
24
- )
25
- end
26
-
27
- it 'requires #payload(data) to be defined' do
28
- expect { Usps::Imis::Panels::InvalidPanelWithBusinessObject.new.create({}) }.to raise_error(
29
- Usps::Imis::Errors::PanelUnimplementedError,
30
- 'Usps::Imis::Panels::InvalidPanelWithBusinessObject must implement #payload(data)'
31
- )
32
- end
33
- end