usps-imis-api 1.0.0.pre.rc.5 → 1.0.0.pre.rc.8

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -1
  3. data/Gemfile.lock +36 -30
  4. data/Readme.md +149 -33
  5. data/lib/usps/imis/api.rb +32 -39
  6. data/lib/usps/imis/business_object.rb +97 -47
  7. data/lib/usps/imis/config.rb +14 -3
  8. data/lib/usps/imis/data.rb +72 -0
  9. data/lib/usps/imis/error.rb +53 -0
  10. data/lib/usps/imis/errors/api_error.rb +11 -0
  11. data/lib/usps/imis/errors/config_error.rb +11 -0
  12. data/lib/usps/imis/errors/locked_id_error.rb +15 -0
  13. data/lib/usps/imis/errors/mapper_error.rb +29 -0
  14. data/lib/usps/imis/errors/not_found_error.rb +11 -0
  15. data/lib/usps/imis/errors/panel_unimplemented_error.rb +34 -0
  16. data/lib/usps/imis/{error → errors}/response_error.rb +5 -8
  17. data/lib/usps/imis/errors/unexpected_property_type_error.rb +31 -0
  18. data/lib/usps/imis/mapper.rb +51 -20
  19. data/lib/usps/imis/mocks/business_object.rb +47 -0
  20. data/lib/usps/imis/mocks.rb +11 -0
  21. data/lib/usps/imis/panels/base_panel.rb +154 -0
  22. data/lib/usps/imis/{panel → panels}/education.rb +2 -2
  23. data/lib/usps/imis/{panel → panels}/vsc.rb +2 -2
  24. data/lib/usps/imis/panels.rb +25 -0
  25. data/lib/usps/imis/properties.rb +50 -0
  26. data/lib/usps/imis/query.rb +94 -0
  27. data/lib/usps/imis/requests.rb +27 -3
  28. data/lib/usps/imis/version.rb +1 -1
  29. data/lib/usps/imis.rb +20 -15
  30. data/spec/lib/usps/imis/api_spec.rb +26 -13
  31. data/spec/lib/usps/imis/business_object_spec.rb +70 -33
  32. data/spec/lib/usps/imis/config_spec.rb +2 -2
  33. data/spec/lib/usps/imis/data_spec.rb +66 -0
  34. data/spec/lib/usps/imis/{error/api_error_spec.rb → error_spec.rb} +1 -1
  35. data/spec/lib/usps/imis/{error → errors}/response_error_spec.rb +4 -4
  36. data/spec/lib/usps/imis/mapper_spec.rb +27 -3
  37. data/spec/lib/usps/imis/mocks/business_object_spec.rb +65 -0
  38. data/spec/lib/usps/imis/panels/base_panel_spec.rb +33 -0
  39. data/spec/lib/usps/imis/panels/education_spec.rb +70 -0
  40. data/spec/lib/usps/imis/{panel → panels}/vsc_spec.rb +6 -7
  41. data/spec/lib/usps/imis/properties_spec.rb +19 -0
  42. data/spec/spec_helper.rb +2 -0
  43. data/usps-imis-api.gemspec +1 -1
  44. metadata +28 -16
  45. data/lib/ext/hash.rb +0 -10
  46. data/lib/usps/imis/error/api_error.rb +0 -44
  47. data/lib/usps/imis/error/mapper_error.rb +0 -11
  48. data/lib/usps/imis/panel/base_panel.rb +0 -101
  49. data/lib/usps/imis/panel/panel_properties.rb +0 -52
  50. data/spec/lib/usps/imis/panel/base_panel_spec.rb +0 -32
  51. data/spec/lib/usps/imis/panel/education_spec.rb +0 -55
  52. data/spec/lib/usps/imis/panel/panel_properties_spec.rb +0 -19
@@ -17,13 +17,13 @@ describe Usps::Imis::Api do
17
17
  it 'stores the initial imis_id' do
18
18
  api = described_class.new(imis_id: 42)
19
19
 
20
- expect(api.imis_id).to eq('42')
20
+ expect(api.imis_id).to eq(42)
21
21
  end
22
22
  end
23
23
 
24
24
  describe '#imis_id_for' do
25
25
  it 'gets the iMIS ID' do
26
- expect(api.imis_id_for('E231625')).to eq('31092')
26
+ expect(api.imis_id_for('E231625')).to eq(31092)
27
27
  end
28
28
 
29
29
  context 'with a query error' do
@@ -31,25 +31,38 @@ describe Usps::Imis::Api do
31
31
 
32
32
  it 'wraps errors' do
33
33
  expect { api.imis_id_for('E231625') }.to raise_error(
34
- Usps::Imis::Error::ApiError, 'Member not found'
34
+ Usps::Imis::Errors::NotFoundError, 'Member not found'
35
35
  )
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
+ describe '#query' do
41
+ let(:query) { api.query('$/ABC/ExampleQueryAll', {}) }
42
+
43
+ before do
44
+ allow(query).to receive(:fetch).and_return(
45
+ { 'Items' => { '$values' => [{ 'key1' => 'value1' }] }, 'HasNext' => true, 'NextOffset' => 1 },
46
+ { 'Items' => { '$values' => [{ 'key1' => 'value2' }] }, 'HasNext' => false, 'NextOffset' => 0 }
47
+ )
48
+ end
49
+
50
+ it 'collects all query results' do
51
+ expect(query.to_a).to eq([{ 'key1' => 'value1' }, { 'key1' => 'value2' }])
52
+ end
53
+ end
54
+
40
55
  describe '#put' do
41
56
  before { api.imis_id = 31092 }
42
57
 
43
58
  it 'sends an update' do
44
- expect(api.business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15)).to(
45
- be_a(Hash)
46
- )
59
+ expect(api.on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15)).to be_a(Hash)
47
60
  end
48
61
 
49
62
  context 'when receiving a response error' do
50
63
  let(:warning_text) do
51
64
  <<~WARNING.chomp
52
- Usps::Imis::Error::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
65
+ Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
53
66
  Something went wrong
54
67
  WARNING
55
68
  end
@@ -63,8 +76,8 @@ describe Usps::Imis::Api do
63
76
  end
64
77
 
65
78
  it 'wraps the error' do
66
- expect { api.business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }.to(
67
- raise_error(Usps::Imis::Error::ApiError, warning_text)
79
+ expect { api.on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }.to(
80
+ raise_error(Usps::Imis::Errors::ResponseError, warning_text)
68
81
  )
69
82
  end
70
83
  end
@@ -73,7 +86,7 @@ describe Usps::Imis::Api do
73
86
  describe '#with' do
74
87
  it 'sends an update from put' do
75
88
  expect(
76
- api.with(31092) { business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }
89
+ api.with(31092) { on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }
77
90
  ).to be_a(Hash)
78
91
  end
79
92
 
@@ -88,13 +101,13 @@ describe Usps::Imis::Api do
88
101
  it 'blocks calling imis_id=' do
89
102
  expect do
90
103
  api.with(31092) { self.imis_id = 31092 }
91
- end.to raise_error(Usps::Imis::Error::ApiError, 'Cannot change iMIS ID while locked')
104
+ end.to raise_error(Usps::Imis::Errors::LockedIdError, 'Cannot change iMIS ID while locked')
92
105
  end
93
106
 
94
107
  it 'blocks calling imis_id_for' do
95
108
  expect do
96
109
  api.with(31092) { imis_id_for('E231625') }
97
- end.to raise_error(Usps::Imis::Error::ApiError, 'Cannot change iMIS ID while locked')
110
+ end.to raise_error(Usps::Imis::Errors::LockedIdError, 'Cannot change iMIS ID while locked')
98
111
  end
99
112
  end
100
113
 
@@ -118,7 +131,7 @@ describe Usps::Imis::Api do
118
131
  end
119
132
 
120
133
  expect(result).to be_a(Hash)
121
- expect(api.imis_id).to eq('31092')
134
+ expect(api.imis_id).to eq(31092)
122
135
  end
123
136
 
124
137
  it 'nests on and with', :aggregate_failures do
@@ -3,48 +3,85 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Usps::Imis::BusinessObject do
6
- let(:business_object) { described_class.new(api, 'Stub') }
7
- let(:api) { Usps::Imis::Api.new }
8
-
9
- let(:expected) do
10
- {
11
- 'Properties' => {
12
- '$values' => [
13
- { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
14
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
15
- { 'Name' => 'Stub String', 'Value' => 'other' }
16
- ]
17
- }
18
- }
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
19
15
  end
20
16
 
21
- before do
22
- allow(business_object).to receive(:get).and_return({
23
- 'Properties' => {
24
- '$values' => [
25
- { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
26
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
27
- { 'Name' => 'Stub String', 'Value' => 'something' }
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
+ }
28
31
  ]
29
- }
30
- })
31
- end
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
32
39
 
33
- describe '#get_field' do
34
- it 'returns a string value' do
35
- expect(business_object.get_field('Stub String')).to eq('something')
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
36
49
  end
37
50
 
38
- it 'returns an integer value' do
39
- expect(business_object.get_field('Stub Integer')).to eq(42)
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
40
59
  end
41
- end
42
60
 
43
- describe '#filter_fields' do
44
- it 'formats fields correctly' do
45
- updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
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')
46
82
 
47
- expect(updated).to eq(expected)
83
+ expect(updated).to eq(expected)
84
+ end
48
85
  end
49
86
  end
50
87
  end
@@ -24,7 +24,7 @@ describe Usps::Imis::Config do
24
24
  subject { config.environment }
25
25
 
26
26
  let(:config) do
27
- described_class.new { |c| c.environment = 'test' }
27
+ described_class.new { it.environment = 'test' }
28
28
  end
29
29
 
30
30
  it { is_expected.to be_test }
@@ -51,7 +51,7 @@ describe Usps::Imis::Config do
51
51
 
52
52
  it 'raises an error' do
53
53
  expect { config.hostname }.to raise_error(
54
- Usps::Imis::Error::ApiError, 'Unexpected API environment: nothing'
54
+ Usps::Imis::Errors::ConfigError, 'Unexpected API environment: nothing'
55
55
  )
56
56
  end
57
57
  end
@@ -0,0 +1,66 @@
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 '#inspect' do
40
+ it 'generates the correct inspect string' do
41
+ expect(data.inspect).to eq('#<Usps::Imis::Data entity="ABC_ASC_Individual_Demog" imis_id=31092>')
42
+ end
43
+
44
+ context 'with data from a Panel' do
45
+ let(:data) do
46
+ described_class[
47
+ 'EntityTypeName' => 'ABC_ASC_Individual_Demog',
48
+ 'Properties' => {
49
+ '$values' => [
50
+ { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
51
+ { 'Name' => 'Ordinal', 'Value' => { '$value' => '99' } },
52
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
53
+ { 'Name' => 'Stub String', 'Value' => 'something' }
54
+ ]
55
+ }
56
+ ]
57
+ end
58
+
59
+ it 'generates the correct inspect string with an ordinal' do
60
+ expect(data.inspect).to eq(
61
+ '#<Usps::Imis::Data entity="ABC_ASC_Individual_Demog" imis_id=31092 ordinal=99>'
62
+ )
63
+ end
64
+ end
65
+ end
66
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Usps::Imis::Error::ApiError do
5
+ describe Usps::Imis::Error do
6
6
  it 'builds Bugsnag metadata' do
7
7
  error = described_class.new('Example', something: :else)
8
8
 
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  ApiResponseStub = Struct.new(:code, :body)
6
6
 
7
- describe Usps::Imis::Error::ResponseError do
7
+ describe Usps::Imis::Errors::ResponseError do
8
8
  let(:error) { described_class.from(response) }
9
9
 
10
10
  describe 'error codes' do
@@ -61,7 +61,7 @@ describe Usps::Imis::Error::ResponseError do
61
61
  let(:response) { ApiResponseStub.new('500', 'Body of the API response error') }
62
62
  let(:warning_text) do
63
63
  <<~WARNING.chomp
64
- Usps::Imis::Error::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
64
+ Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
65
65
  Body of the API response error
66
66
  WARNING
67
67
  end
@@ -78,7 +78,7 @@ describe Usps::Imis::Error::ResponseError do
78
78
  let(:response) { ApiResponseStub.new('500', response_body) }
79
79
  let(:warning_text) do
80
80
  <<~WARNING.chomp
81
- Usps::Imis::Error::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
81
+ Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
82
82
  description
83
83
  WARNING
84
84
  end
@@ -95,7 +95,7 @@ describe Usps::Imis::Error::ResponseError do
95
95
  let(:response) { ApiResponseStub.new('500', response_body) }
96
96
  let(:warning_text) do
97
97
  <<~WARNING.chomp
98
- Usps::Imis::Error::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
98
+ Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
99
99
  #{response_body}
100
100
  WARNING
101
101
  end
@@ -9,7 +9,31 @@ describe Usps::Imis::Mapper do
9
9
  it 'stores the initial imis_id' do
10
10
  mapper = described_class.new(imis_id: 42)
11
11
 
12
- expect(mapper.api.imis_id).to eq('42')
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
+ )
13
37
  end
14
38
  end
15
39
 
@@ -22,8 +46,8 @@ describe Usps::Imis::Mapper do
22
46
 
23
47
  it 'raises for unmapped updates' do
24
48
  expect { api.mapper.update(something: 'anything') }.to raise_error(
25
- Usps::Imis::Error::MapperError,
26
- 'Unrecognized field: "something". ' \
49
+ Usps::Imis::Errors::MapperError,
50
+ %(Mapper does not recognize field: "something".\n) \
27
51
  'Please report what data you are attempting to work with to ITCom leadership.'
28
52
  )
29
53
  end
@@ -0,0 +1,65 @@
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
@@ -0,0 +1,33 @@
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 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
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis::Panels::Education do
6
+ describe 'api example' do
7
+ let(:education) { described_class.new }
8
+
9
+ let(:details) do
10
+ {
11
+ certificate: 'E136924',
12
+ description: 'Marine Navigation',
13
+ effective_date: Time.now.strftime('%Y-%m-%dT00:00:00'),
14
+ source: 'Online Exams System',
15
+ code: 'MN',
16
+ type_code: 'CRS'
17
+ }
18
+ end
19
+
20
+ before { education.api.imis_id = 6374 }
21
+
22
+ describe '#get' do
23
+ it 'loads a specific object' do
24
+ expect(education.get(90737)).to be_a(Usps::Imis::Data)
25
+ end
26
+
27
+ it 'returns specific fields' do
28
+ expect(education.get(90737, 'ABC_Product_Code', 'ABC_Other_Code')).to eq(%w[CRS AP])
29
+ end
30
+ end
31
+
32
+ describe '#get_field' do
33
+ it 'returns a specific field' do
34
+ expect(education.get_field(90737, 'ABC_Product_Code')).to eq('CRS')
35
+ end
36
+ end
37
+
38
+ describe '#get_fields' do
39
+ it 'returns specific fields' do
40
+ expect(education.get_fields(90737, 'ABC_Product_Code', 'ABC_Other_Code')).to eq(%w[CRS AP])
41
+ end
42
+ end
43
+
44
+ # rubocop:disable RSpec/ExampleLength
45
+ it 'interacts with records correctly', :aggregate_failures do
46
+ new_record = education.create(details)
47
+ expect(new_record).to be_a(Usps::Imis::Data)
48
+
49
+ ordinal = new_record.ordinal
50
+
51
+ update_result =
52
+ education.update(details.merge(source: 'Online Exams System - Modified', ordinal:))
53
+ expect(update_result['ABC_Educ_Source_System']).to eq('Online Exams System - Modified')
54
+
55
+ put_fields_result = education.put_fields(ordinal, 'ABC_Educ_Source_System' => 'Online Exams System - Mod2')
56
+ expect(put_fields_result['ABC_Educ_Source_System']).to eq('Online Exams System - Mod2')
57
+
58
+ expect(education.destroy(ordinal)).to be(true)
59
+ end
60
+ # rubocop:enable RSpec/ExampleLength
61
+ end
62
+
63
+ describe 'initialization with ID' do
64
+ it 'can initialize with an iMIS ID' do
65
+ panel = described_class.new(imis_id: 6374)
66
+
67
+ expect(panel.api.imis_id).to eq(6374)
68
+ end
69
+ end
70
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Usps::Imis::Panel::Vsc do
5
+ describe Usps::Imis::Panels::Vsc do
6
6
  let(:vsc) { described_class.new }
7
7
 
8
8
  let(:details) do
@@ -17,22 +17,21 @@ describe Usps::Imis::Panel::Vsc do
17
17
 
18
18
  describe '#get' do
19
19
  it 'loads a specific object' do
20
- expect(vsc.get(1433)).to be_a(Hash)
20
+ expect(vsc.get(1433)).to be_a(Usps::Imis::Data)
21
21
  end
22
22
  end
23
23
 
24
24
  # rubocop:disable RSpec/ExampleLength
25
25
  it 'handles new records correctly', :aggregate_failures do
26
26
  new_record = vsc.create(details)
27
- expect(new_record).to be_a(Hash)
27
+ expect(new_record).to be_a(Usps::Imis::Data)
28
28
 
29
- ordinal = new_record['Identity']['IdentityElements']['$values'][1]
29
+ ordinal = new_record.ordinal
30
30
 
31
31
  update_result = vsc.update(details.merge(count: 43, ordinal:))
32
- updated = update_result['Properties']['$values'].find { |v| v['Name'] == 'Quantity' }
33
- expect(updated['Value']['$value']).to eq(43)
32
+ expect(update_result['Quantity']).to eq(43)
34
33
 
35
- expect(vsc.destroy(ordinal)).to eq('')
34
+ expect(vsc.destroy(ordinal)).to be(true)
36
35
  end
37
36
  # rubocop:enable RSpec/ExampleLength
38
37
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis::Properties do
6
+ let(:builder) { described_class.new }
7
+
8
+ it 'wraps boolean property values' do
9
+ expect(builder.send(:wrap, true)).to eq(
10
+ '$type' => 'System.Boolean', '$value' => true
11
+ )
12
+ end
13
+
14
+ it 'raises an error for unexpected property types' do
15
+ expect { builder.send(:wrap, {}) }.to raise_error(
16
+ Usps::Imis::Errors::UnexpectedPropertyTypeError, 'Unexpected property type: {}'
17
+ )
18
+ end
19
+ end
data/spec/spec_helper.rb CHANGED
@@ -31,6 +31,8 @@ RSpec.configure do |config|
31
31
 
32
32
  imis_config.username = ENV.fetch('IMIS_USERNAME', '')
33
33
  imis_config.password = ENV.fetch('IMIS_PASSWORD', '')
34
+
35
+ imis_config.logger = Logger.new(nil)
34
36
  end
35
37
  end
36
38
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Usps::Imis::VERSION
8
8
  s.summary = 'iMIS API Wrapper'
9
9
  s.description = 'A wrapper for the iMIS API.'
10
- s.homepage = 'http://rubygems.org/gems/usps-imis-api'
10
+ s.homepage = 'https://github.com/unitedstatespowersquadrons/imis-api-ruby'
11
11
  s.authors = ['Julian Fiander']
12
12
  s.email = 'jsfiander@gmail.com'
13
13
  s.require_paths = %w[lib]