usps-imis-api 0.4.2 → 0.4.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99786c3ccf2dc019726db917d318e8c992a61f091aa1b474402612a73c0558d7
4
- data.tar.gz: bffec4e5ed9662e63112c1d8e26f99137d922439eb9c3bfb07fab0dad7236e56
3
+ metadata.gz: 62e3948cb55d98465788a509e531d293e7d4b6c4120bd7d9fc5c91e902285a9c
4
+ data.tar.gz: b31b47b360f74ec720b9acc9b1b63251c24c8a0546d83f91da7d92f7f4fc8c60
5
5
  SHA512:
6
- metadata.gz: 1d0ba175348c95c4d7bdbea774b785f6ed3c807d5e3349b805544cbc1909b8695c3809d7c56765e77d3aadfb1d2c5c20ee0054840899b48b4385de9c27d59c4a
7
- data.tar.gz: 533532e2686386bd3411550cb68f9da9503762b80f38fea86523f33d0ad168427af5ee5c9967959e9d56259f6dfd34c25124faad813abbbda5f83877fa1160e4
6
+ metadata.gz: 5ed6d327340268f29d595c0942f1836b7ca168a137e59d9533afd3011de3b22c2976640ef43c2f843793b012a9d57f1456e6e2996b898adb1fb50af671216311
7
+ data.tar.gz: 76a41b9150dfcf11bcbc43d6e6986b65396718a86067497d6a944d93fbe15cb4c3f3e4cdac105fd0dd20d1fc8cab28ebe4d86d3eee18926a16e8150e5697abfe
@@ -16,17 +16,25 @@ jobs:
16
16
  rubocop:
17
17
  runs-on: ubuntu-24.04
18
18
  environment: "USPS iMIS API - Ruby"
19
+ strategy:
20
+ matrix:
21
+ ruby: ['3.4', head]
19
22
  steps:
20
23
  - name: Checkout Code
21
24
  uses: actions/checkout@v4
22
25
  - name: Setup Ruby
23
26
  uses: ruby/setup-ruby@v1
24
- with: { bundler-cache: true }
27
+ with:
28
+ ruby-version: ${{ matrix.ruby }}
29
+ bundler-cache: true
25
30
  - name: Run Rubocop
26
31
  run: bundle exec rubocop
27
32
  rspec:
28
33
  runs-on: ubuntu-24.04
29
34
  environment: "USPS iMIS API - Ruby"
35
+ strategy:
36
+ matrix:
37
+ ruby: ['3.4', head]
30
38
  env:
31
39
  IMIS_USERNAME: ${{ secrets.IMIS_USERNAME }}
32
40
  IMIS_PASSWORD: ${{ secrets.IMIS_PASSWORD }}
@@ -36,12 +44,14 @@ jobs:
36
44
  uses: actions/checkout@v4
37
45
  - name: Setup Ruby
38
46
  uses: ruby/setup-ruby@v1
39
- with: { bundler-cache: true }
47
+ with:
48
+ ruby-version: ${{ matrix.ruby }}
49
+ bundler-cache: true
40
50
  - name: Run Rspec
41
51
  run: bundle exec rspec --format documentation --order rand --color --tty
42
52
  - name: Store Coverage
43
53
  uses: actions/upload-artifact@v4
44
54
  with:
45
- name: coverage-rspec
55
+ name: coverage-rspec-${{ matrix.ruby }}
46
56
  include-hidden-files: true
47
57
  path: coverage/
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ require:
2
2
  - rubocop-rspec
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 3.0
5
+ TargetRubyVersion: 3.4
6
6
  Exclude:
7
7
  - bin/**/*
8
8
  - config/**/*
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.3
1
+ 3.5-dev
data/.simplecov ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.start do
4
+ enable_coverage :branch
5
+ primary_coverage :branch
6
+
7
+ add_filter '/spec'
8
+ end
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'dotenv', '>= 3.1.4'
7
+ gem 'irb', '>= 1.15.2'
7
8
  gem 'rake', '>= 13.2.1'
8
9
  gem 'rspec', '>= 3.13.0'
9
10
  gem 'rubocop', '>= 1.66.1'
data/Gemfile.lock CHANGED
@@ -1,25 +1,44 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.4.2)
4
+ usps-imis-api (0.4.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
+ date (3.4.1)
10
11
  diff-lcs (1.5.1)
11
12
  docile (1.4.1)
12
13
  dotenv (3.1.4)
14
+ erb (5.0.3)
15
+ io-console (0.8.1)
16
+ irb (1.15.2)
17
+ pp (>= 0.6.0)
18
+ rdoc (>= 4.0.0)
19
+ reline (>= 0.4.2)
13
20
  json (2.7.2)
14
21
  language_server-protocol (3.17.0.3)
15
22
  parallel (1.26.3)
16
23
  parser (3.3.5.0)
17
24
  ast (~> 2.4.1)
18
25
  racc
26
+ pp (0.6.3)
27
+ prettyprint
28
+ prettyprint (0.2.0)
29
+ psych (5.2.6)
30
+ date
31
+ stringio
19
32
  racc (1.8.1)
20
33
  rainbow (3.1.1)
21
34
  rake (13.2.1)
35
+ rdoc (6.15.0)
36
+ erb
37
+ psych (>= 4.0.0)
38
+ tsort
22
39
  regexp_parser (2.9.2)
40
+ reline (0.6.2)
41
+ io-console (~> 0.5)
23
42
  rspec (3.13.0)
24
43
  rspec-core (~> 3.13.0)
25
44
  rspec-expectations (~> 3.13.0)
@@ -54,6 +73,8 @@ GEM
54
73
  simplecov_json_formatter (~> 0.1)
55
74
  simplecov-html (0.13.1)
56
75
  simplecov_json_formatter (0.1.4)
76
+ stringio (3.1.7)
77
+ tsort (0.2.0)
57
78
  unicode-display_width (2.6.0)
58
79
 
59
80
  PLATFORMS
@@ -62,6 +83,7 @@ PLATFORMS
62
83
 
63
84
  DEPENDENCIES
64
85
  dotenv (>= 3.1.4)
86
+ irb (>= 1.15.2)
65
87
  rake (>= 13.2.1)
66
88
  rspec (>= 3.13.0)
67
89
  rubocop (>= 1.66.1)
data/lib/usps/imis/api.rb CHANGED
@@ -6,7 +6,7 @@ module Usps
6
6
  AUTHENTICATION_PATH = 'Token'
7
7
  API_PATH = 'api'
8
8
  QUERY_PATH = 'api/Query'
9
- PANELS = Struct.new(:vsc)
9
+ PANELS = Struct.new(:vsc, :education)
10
10
 
11
11
  attr_reader :token, :token_expiration, :imis_id
12
12
 
@@ -24,7 +24,7 @@ module Usps
24
24
  # Convert a member's certificate number into an iMIS ID number
25
25
  #
26
26
  def imis_id_for(certificate)
27
- result = query(Imis.configuration.imis_id_query_name, { certificate: certificate })
27
+ result = query(Imis.configuration.imis_id_query_name, { certificate: })
28
28
  @imis_id = result['Items']['$values'][0]['ID']
29
29
  rescue StandardError
30
30
  raise Error::Api, 'Member not found'
@@ -34,10 +34,10 @@ module Usps
34
34
  #
35
35
  # This should be used with methods that do not change the value of `imis_id`
36
36
  #
37
- def with(id, &block)
37
+ def with(id, &)
38
38
  old_id = imis_id
39
39
  self.imis_id = id
40
- instance_eval(&block)
40
+ instance_eval(&)
41
41
  ensure
42
42
  self.imis_id = old_id
43
43
  end
@@ -45,7 +45,7 @@ module Usps
45
45
  # Get a business object for the current member
46
46
  #
47
47
  def get(business_object_name, url_id: nil)
48
- uri = uri_for(business_object_name, url_id: url_id)
48
+ uri = uri_for(business_object_name, url_id:)
49
49
  request = Net::HTTP::Get.new(uri)
50
50
  result = submit(uri, authorize(request))
51
51
  JSON.parse(result.body)
@@ -57,13 +57,13 @@ module Usps
57
57
  #
58
58
  def put_fields(business_object_name, fields, url_id: nil)
59
59
  updated = filter_fields(business_object_name, fields)
60
- put(business_object_name, updated, url_id: url_id)
60
+ put(business_object_name, updated, url_id:)
61
61
  end
62
62
 
63
63
  # Update a business object for the current member
64
64
  #
65
65
  def put(business_object_name, body, url_id: nil)
66
- uri = uri_for(business_object_name, url_id: url_id)
66
+ uri = uri_for(business_object_name, url_id:)
67
67
  request = Net::HTTP::Put.new(uri)
68
68
  request.body = JSON.dump(body)
69
69
  result = submit(uri, authorize(request))
@@ -73,7 +73,7 @@ module Usps
73
73
  # Create a business object for the current member
74
74
  #
75
75
  def post(business_object_name, body, url_id: nil)
76
- uri = uri_for(business_object_name, url_id: url_id)
76
+ uri = uri_for(business_object_name, url_id:)
77
77
  request = Net::HTTP::Post.new(uri)
78
78
  request.body = JSON.dump(body)
79
79
  result = submit(uri, authorize(request))
@@ -85,7 +85,7 @@ module Usps
85
85
  # Returns empty string on success
86
86
  #
87
87
  def delete(business_object_name, url_id: nil)
88
- uri = uri_for(business_object_name, url_id: url_id)
88
+ uri = uri_for(business_object_name, url_id:)
89
89
  request = Net::HTTP::Delete.new(uri)
90
90
  result = submit(uri, authorize(request))
91
91
  result.body
@@ -111,7 +111,8 @@ module Usps
111
111
 
112
112
  def panels
113
113
  @panels ||= PANELS.new(
114
- Panel::Vsc.new(self)
114
+ Panel::Vsc.new(self),
115
+ Panel::Education.new(self)
115
116
  )
116
117
  end
117
118
 
@@ -119,6 +120,8 @@ module Usps
119
120
  mapper.update(data)
120
121
  end
121
122
 
123
+ def instance_variables_to_inspect = %i[@token_expiration @imis_id]
124
+
122
125
  private
123
126
 
124
127
  def client(uri)
@@ -22,6 +22,8 @@ module Usps
22
22
  raise Error::Api, "Unexpected API environment: #{environment}"
23
23
  end
24
24
  end
25
+
26
+ def instance_variables_to_inspect = %i[@environment @imis_id_query_name @username]
25
27
  end
26
28
  end
27
29
  end
@@ -9,18 +9,16 @@ module Usps
9
9
  def initialize(message, metadata = {})
10
10
  super(message)
11
11
  @metadata = metadata
12
-
13
- warn inspect if ENV.fetch('IMIS_ERROR_LOG_TO_STDERR', 'false') == 'true'
14
12
  end
15
13
 
16
14
  def bugsnag_meta_data
17
- metadata == {} ? {} : { api: metadata }
15
+ metadata == {} ? {} : base_metadata
18
16
  end
19
17
 
20
18
  private
21
19
 
22
20
  def base_metadata
23
- { api: {} }
21
+ { api: metadata }
24
22
  end
25
23
  end
26
24
  end
@@ -31,7 +31,7 @@ module Usps
31
31
  private
32
32
 
33
33
  def base_metadata
34
- { api: { status: status, body: body } }
34
+ { api: { status:, body: } }
35
35
  end
36
36
 
37
37
  def status
@@ -47,6 +47,8 @@ module Usps
47
47
  :unprocessable_entity # validation error
48
48
  when /^50\d$/
49
49
  :internal_server_error # error within iMIS
50
+ else
51
+ response.code
50
52
  end
51
53
  end
52
54
 
@@ -52,11 +52,13 @@ module Usps
52
52
 
53
53
  def missing_mapping(field_name)
54
54
  unless ENV['TESTING']
55
+ # :nocov:
55
56
  warn(
56
57
  "Mapper does not know how to handle field \"#{field_name}\".\n\n" \
57
58
  'You can use api.put_fields(business_object_name, { field_name => value }) ' \
58
59
  "if you know the business object and iMIS-specific field name.\n\n"
59
60
  )
61
+ # :nocov:
60
62
  end
61
63
 
62
64
  raise(
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.4.2'
5
+ VERSION = '0.4.4'
6
6
  end
7
7
  end
data/lib/usps/imis.rb CHANGED
@@ -7,7 +7,9 @@ require 'time'
7
7
  require 'cgi'
8
8
 
9
9
  # Extensions
10
+ # :nocov:
10
11
  require 'ext/hash' unless defined?(Rails)
12
+ # :nocov:
11
13
 
12
14
  # Internal requires
13
15
  require_relative 'imis/config'
@@ -5,10 +5,36 @@ require 'spec_helper'
5
5
  describe Usps::Imis::Api do
6
6
  let(:api) { described_class.new }
7
7
 
8
+ describe '#initialize' do
9
+ it 'skips authentication' do
10
+ # rubocop:disable RSpec/AnyInstance
11
+ expect_any_instance_of(described_class).not_to receive(:authenticate)
12
+ # rubocop:enable RSpec/AnyInstance
13
+
14
+ described_class.new(skip_authentication: true)
15
+ end
16
+
17
+ it 'stores the initial imis_id' do
18
+ api = described_class.new(imis_id: 42)
19
+
20
+ expect(api.imis_id).to eq('42')
21
+ end
22
+ end
23
+
8
24
  describe '#imis_id_for' do
9
25
  it 'gets the iMIS ID' do
10
26
  expect(api.imis_id_for('E231625')).to eq('31092')
11
27
  end
28
+
29
+ context 'with a query error' do
30
+ before { allow(api).to receive(:query).and_raise('Stub') }
31
+
32
+ it 'wraps errors' do
33
+ expect { api.imis_id_for('E231625') }.to raise_error(
34
+ Usps::Imis::Error::Api, 'Member not found'
35
+ )
36
+ end
37
+ end
12
38
  end
13
39
 
14
40
  describe '#put' do
@@ -17,6 +43,29 @@ describe Usps::Imis::Api do
17
43
  it 'sends an update' do
18
44
  expect(api.put_fields('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 })).to be_a(Hash)
19
45
  end
46
+
47
+ context 'when receiving a response error' do
48
+ let(:warning_text) do
49
+ <<~WARNING.chomp
50
+ Usps::Imis::Error::Response: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
51
+ Something went wrong
52
+ WARNING
53
+ end
54
+
55
+ before do
56
+ error = Struct.new(:code, :body).new('500', 'Something went wrong')
57
+
58
+ # rubocop:disable RSpec/AnyInstance
59
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_return(error)
60
+ # rubocop:enable RSpec/AnyInstance
61
+ end
62
+
63
+ it 'wraps the error' do
64
+ expect { api.put_fields('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 }) }.to raise_error(
65
+ Usps::Imis::Error::Api, warning_text
66
+ )
67
+ end
68
+ end
20
69
  end
21
70
 
22
71
  describe '#with' do
@@ -34,4 +83,61 @@ describe Usps::Imis::Api do
34
83
  expect(api.with(6374) { panels.vsc.get(1433) }).to be_a(Hash)
35
84
  end
36
85
  end
86
+
87
+ describe '#inspect' do
88
+ it 'is configured to exclude the token instance variable' do
89
+ expect(api.instance_variables_to_inspect).not_to include(:@token)
90
+ end
91
+
92
+ it 'does not show the token instance variable' do
93
+ pending 'Requires Ruby 3.5' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new(3.5)
94
+
95
+ expect(api.inspect).not_to match(/ @token="/)
96
+ end
97
+ end
98
+
99
+ describe '#authorize' do
100
+ before { allow(api).to receive(:authenticate) }
101
+
102
+ it 'automatically refreshes an expired token' do
103
+ api.instance_variable_set(:@token_expiration, Time.now - 60)
104
+
105
+ request = Net::HTTP::Put.new('/')
106
+ api.send(:authorize, request)
107
+
108
+ expect(api).to have_received(:authenticate)
109
+ end
110
+ end
111
+
112
+ describe '#filter_fields' do
113
+ let(:expected) do
114
+ {
115
+ 'Properties' => {
116
+ '$values' => [
117
+ { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
118
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
119
+ { 'Name' => 'Stub String', 'Value' => 'other' }
120
+ ]
121
+ }
122
+ }
123
+ end
124
+
125
+ before do
126
+ allow(api).to receive(:get).and_return({
127
+ 'Properties' => {
128
+ '$values' => [
129
+ { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
130
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
131
+ { 'Name' => 'Stub String', 'Value' => 'something' }
132
+ ]
133
+ }
134
+ })
135
+ end
136
+
137
+ it 'formats fields correctly' do
138
+ updated = api.send(:filter_fields, 'Stub', { 'Stub Integer' => 43, 'Stub String' => 'other' })
139
+
140
+ expect(updated).to eq(expected)
141
+ end
142
+ end
37
143
  end
@@ -0,0 +1,33 @@
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
+ it 'sets values on initialize' do
9
+ config = described_class.new { |c| c.environment = 'test' }
10
+
11
+ expect(config.environment).to eq('test')
12
+ end
13
+
14
+ describe '#hostname' do
15
+ context 'with production environment' do
16
+ before { config.environment = 'production' }
17
+
18
+ it 'returns the production hostname' do
19
+ expect(config.hostname).to eq(described_class::IMIS_ROOT_URL_PROD)
20
+ end
21
+ end
22
+
23
+ context 'with unrecognized environment' do
24
+ before { config.environment = 'nothing' }
25
+
26
+ it 'raises an error' do
27
+ expect { config.hostname }.to raise_error(
28
+ Usps::Imis::Error::Api, 'Unexpected API environment: nothing'
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis::Error::Api 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
@@ -5,15 +5,103 @@ require 'spec_helper'
5
5
  ApiResponseStub = Struct.new(:code, :body)
6
6
 
7
7
  describe Usps::Imis::Error::Response do
8
- let(:response) { ApiResponseStub.new('500', 'Body of the API response error') }
9
- let(:warning_text) do
10
- <<~WARNING.chomp
11
- Usps::Imis::Error::Response: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
12
- Body of the API response error
13
- WARNING
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::Error::Response: [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
14
72
  end
15
73
 
16
- it 'handles an API response correctly' do
17
- expect(described_class.from(response).message).to eq(warning_text)
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::Error::Response: [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::Error::Response: [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
18
106
  end
19
107
  end
@@ -5,6 +5,14 @@ require 'spec_helper'
5
5
  describe Usps::Imis::Mapper do
6
6
  let(:api) { described_class.new.api }
7
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
+
8
16
  describe '#update' do
9
17
  before { api.imis_id = 31092 }
10
18
 
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Usps
6
+ module Imis
7
+ module Panel
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::Panel::BasePanel do
20
+ it 'requires #business_object to be defined' do
21
+ expect { Usps::Imis::Panel::InvalidPanel.new.get(1) }.to raise_error(
22
+ Usps::Imis::Error::Api, 'Usps::Imis::Panel::InvalidPanel must implement #business_object'
23
+ )
24
+ end
25
+
26
+ it 'requires #payload(data) to be defined' do
27
+ expect { Usps::Imis::Panel::InvalidPanelWithBusinessObject.new.create({}) }.to raise_error(
28
+ Usps::Imis::Error::Api,
29
+ 'Usps::Imis::Panel::InvalidPanelWithBusinessObject must implement #payload(data)'
30
+ )
31
+ end
32
+ end
@@ -34,7 +34,7 @@ describe Usps::Imis::Panel::Education do
34
34
  ordinal = new_record['Identity']['IdentityElements']['$values'][1]
35
35
 
36
36
  update_result =
37
- education.update(details.merge(source: 'Online Exams System - Modified', ordinal: ordinal))
37
+ education.update(details.merge(source: 'Online Exams System - Modified', ordinal:))
38
38
  updated = update_result['Properties']['$values'].find do |v|
39
39
  v['Name'] == 'ABC_Educ_Source_System'
40
40
  end
@@ -28,7 +28,7 @@ describe Usps::Imis::Panel::Vsc do
28
28
 
29
29
  ordinal = new_record['Identity']['IdentityElements']['$values'][1]
30
30
 
31
- update_result = vsc.update(details.merge(count: 43, ordinal: ordinal))
31
+ update_result = vsc.update(details.merge(count: 43, ordinal:))
32
32
  updated = update_result['Properties']['$values'].find { |v| v['Name'] == 'Quantity' }
33
33
  expect(updated['Value']['$value']).to eq(43)
34
34
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis do
6
+ it 'returns configuration from configure without a block' do
7
+ described_class.configuration.environment = 'development'
8
+
9
+ expect(described_class.configure.environment).to eq('development')
10
+ end
11
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,10 +3,7 @@
3
3
  require 'bundler/setup'
4
4
  Bundler.setup
5
5
  require 'simplecov'
6
- SimpleCov.start do
7
- add_filter '/spec'
8
- end
9
- # SimpleCov.minimum_coverage(100)
6
+ SimpleCov.minimum_coverage(line: 100, branch: 100)
10
7
 
11
8
  require 'dotenv/load'
12
9
  require 'usps/imis'
@@ -14,5 +14,5 @@ Gem::Specification.new do |s|
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.metadata['rubygems_mfa_required'] = 'true'
16
16
 
17
- s.required_ruby_version = '>= 3.0'
17
+ s.required_ruby_version = '>= 3.4'
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-imis-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -20,6 +20,7 @@ files:
20
20
  - ".rspec"
21
21
  - ".rubocop.yml"
22
22
  - ".ruby-version"
23
+ - ".simplecov"
23
24
  - Gemfile
24
25
  - Gemfile.lock
25
26
  - Rakefile
@@ -39,10 +40,14 @@ files:
39
40
  - lib/usps/imis/panel/vsc.rb
40
41
  - lib/usps/imis/version.rb
41
42
  - spec/lib/usps/imis/api_spec.rb
43
+ - spec/lib/usps/imis/config_spec.rb
44
+ - spec/lib/usps/imis/error/api_spec.rb
42
45
  - spec/lib/usps/imis/error/response_spec.rb
43
46
  - spec/lib/usps/imis/mapper_spec.rb
47
+ - spec/lib/usps/imis/panel/base_panel_spec.rb
44
48
  - spec/lib/usps/imis/panel/education_spec.rb
45
49
  - spec/lib/usps/imis/panel/vsc_spec.rb
50
+ - spec/lib/usps/imis_spec.rb
46
51
  - spec/spec_helper.rb
47
52
  - usps-imis-api.gemspec
48
53
  homepage: http://rubygems.org/gems/usps-imis-api
@@ -56,14 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
61
  requirements:
57
62
  - - ">="
58
63
  - !ruby/object:Gem::Version
59
- version: '3.0'
64
+ version: '3.4'
60
65
  required_rubygems_version: !ruby/object:Gem::Requirement
61
66
  requirements:
62
67
  - - ">="
63
68
  - !ruby/object:Gem::Version
64
69
  version: '0'
65
70
  requirements: []
66
- rubygems_version: 3.6.9
71
+ rubygems_version: 4.0.0.dev
67
72
  specification_version: 4
68
73
  summary: iMIS API Wrapper
69
74
  test_files: []