samwise 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +143 -24
- data/bin/samwise +5 -0
- data/lib/samwise.rb +1 -0
- data/lib/samwise/cli.rb +60 -0
- data/lib/samwise/client.rb +33 -5
- data/lib/samwise/protocol.rb +1 -1
- data/lib/samwise/util.rb +7 -0
- data/lib/samwise/version.rb +1 -1
- data/samwise.gemspec +1 -1
- data/spec/cli_mocks/bad.json +1 -0
- data/spec/cli_mocks/test.json +1 -0
- data/spec/cli_spec.rb +125 -0
- data/spec/client_spec.rb +26 -0
- data/spec/factory.rb +44 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/util_spec.rb +13 -0
- data/spec/vcr/Samwise_Cli.yml +245 -0
- data/spec/vcr/Samwise_Client.yml +1089 -1
- metadata +19 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2ca088ec51febc2528f8c85bd8def3f12916bcf
|
4
|
+
data.tar.gz: 30d7eefed09aa261d36f52fd9c1c78ac41cf050b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97eecd5982d49f78a088753e3ca05f8f043f96b45d3789e635c9b40d2260265fb27c140b36daf97efed3294f4841339a9035405889648fe99b96ff7465e75311
|
7
|
+
data.tar.gz: 17e4d853e602d24e94eea6176072a3c15b603a42290d7cc8897fa66c2da0717783c75208f0ec1cd66718aa792ef8f87a385cc213e9f0acb6cb52055d7739874d
|
data/README.md
CHANGED
@@ -36,36 +36,122 @@ client.duns_is_in_sam?(duns: '080037478')
|
|
36
36
|
#=> true
|
37
37
|
```
|
38
38
|
|
39
|
+
### Verify Vendor is not on the excluded parties list
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
client.excluded?(duns: '080037478')
|
43
|
+
#=> false
|
44
|
+
```
|
45
|
+
|
46
|
+
### Verify Vendor is a small business
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
client.small_business?(duns: '080037478', naicsCode: 541511)
|
50
|
+
#=> false
|
51
|
+
```
|
52
|
+
|
39
53
|
### Get DUNS info
|
40
54
|
|
41
55
|
```ruby
|
42
|
-
client.get_duns_info(duns: '080037478')
|
43
|
-
|
56
|
+
duns_info = client.get_duns_info(duns: '080037478')
|
57
|
+
|
44
58
|
{
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
"sam_data"=>{
|
60
|
+
"registration"=>{
|
61
|
+
"govtBusinessPoc"=>{
|
62
|
+
"lastName"=>"SUDOL",
|
63
|
+
"address"=>{
|
64
|
+
"zip"=>"22203",
|
65
|
+
"countryCode"=>"USA",
|
66
|
+
"line1"=>"4301 N HENDERSON RD APT 408",
|
67
|
+
"stateorProvince"=>"VA",
|
68
|
+
"city"=>"Arlington"
|
69
|
+
},
|
70
|
+
"email"=>"BRENDANSUDOL@GMAIL.COM",
|
71
|
+
"usPhone"=>"5404218332",
|
72
|
+
"firstName"=>"BRENDAN"
|
73
|
+
},
|
74
|
+
"qualifications"=>{
|
75
|
+
},
|
76
|
+
"dunsPlus4"=>"0000",
|
77
|
+
"activationDate"=>"2015-10-30 11:42:30.0",
|
78
|
+
"fiscalYearEndCloseDate"=>"12\/31",
|
79
|
+
"businessTypes"=>[
|
80
|
+
"VW",
|
81
|
+
"2X",
|
82
|
+
"27"
|
83
|
+
],
|
84
|
+
"registrationDate"=>"2015-10-28 00:00:00.0",
|
85
|
+
"certificationsURL"=>{
|
86
|
+
"pdfUrl":
|
87
|
+
"https:\/\/www.sam.gov\/SAMPortal\/filedownload?reportType=1&orgId=kZhDothaHaS8Y%2BBby2ety%2B1PIcKkDuGxkhITFtBfiwpmpGqNLrKsCz9OrI6CaxsI&pitId=Pg1XpWC8vQH7LKi9e8r5BK5D6ORH953kPtjfCGikUDnIY8Fsp71cFeSgzD8W9Uqd&requestId=OBq2t61SZrN75k9"
|
88
|
+
},
|
89
|
+
"hasDelinquentFederalDebt"=>false,
|
90
|
+
"duns"=>"080037478",
|
91
|
+
"cage"=>"7H1Y7",
|
92
|
+
"hasKnownExclusion"=>false,
|
93
|
+
"publicDisplay"=>true,
|
94
|
+
"expirationDate"=>"2016-10-27 10:53:02.0",
|
95
|
+
"status"=>"ACTIVE",
|
96
|
+
"corporateStructureCode"=>"2J",
|
97
|
+
"stateOfIncorporation"=>"VA",
|
98
|
+
"corporateStructureName"=>"Sole Proprietorship",
|
99
|
+
"legalBusinessName"=>"Sudol, Brendan",
|
100
|
+
"congressionalDistrict"=>"VA 08",
|
101
|
+
"bondingInformation"=>{
|
102
|
+
},
|
103
|
+
"businessStartDate"=>"2015-10-28",
|
104
|
+
"statusMessage"=>"Active",
|
105
|
+
"lastUpdateDate"=>"2015-11-02 17:36:23.0",
|
106
|
+
"samAddress"=>{
|
107
|
+
"zipPlus4"=>"2511",
|
108
|
+
"zip"=>"22203",
|
109
|
+
"countryCode"=>"USA",
|
110
|
+
"line1"=>"4301 N Henderson Rd Apt 408",
|
111
|
+
"stateorProvince"=>"VA",
|
112
|
+
"city"=>"Arlington"
|
113
|
+
},
|
114
|
+
"submissionDate"=>"2015-10-28 10:53:02.0",
|
115
|
+
"naics"=>[
|
116
|
+
{
|
117
|
+
"isPrimary"=>false,
|
118
|
+
"naicsCode"=>"518210",
|
119
|
+
"naicsName"=>"DATA PROCESSING, HOSTING, AND RELATED SERVICES"
|
120
|
+
},
|
121
|
+
{
|
122
|
+
"isPrimary"=>true,
|
123
|
+
"naicsCode"=>"541511",
|
124
|
+
"naicsName"=>"CUSTOM COMPUTER PROGRAMMING SERVICES"
|
66
125
|
}
|
126
|
+
],
|
127
|
+
"creditCardUsage"=>true,
|
128
|
+
"countryOfIncorporation"=>"USA",
|
129
|
+
"electronicBusinessPoc"=>{
|
130
|
+
"lastName"=>"SUDOL",
|
131
|
+
"address"=>{
|
132
|
+
"zip"=>"22203",
|
133
|
+
"countryCode"=>"USA",
|
134
|
+
"line1"=>"4301 N HENDERSON RD APT 408",
|
135
|
+
"stateorProvince"=>"VA",
|
136
|
+
"city"=>"Arlington"
|
137
|
+
},
|
138
|
+
"email"=>"BRENDANSUDOL@GMAIL.COM",
|
139
|
+
"usPhone"=>"5404218332",
|
140
|
+
"firstName"=>"BRENDAN"
|
141
|
+
},
|
142
|
+
"mailingAddress"=>{
|
143
|
+
"zipPlus4"=>"2511",
|
144
|
+
"zip"=>"22203",
|
145
|
+
"countryCode"=>"USA",
|
146
|
+
"line1"=>"4301 N Henderson Rd Apt 408",
|
147
|
+
"stateorProvince"=>"VA",
|
148
|
+
"city"=>"Arlington"
|
149
|
+
},
|
150
|
+
"purposeOfRegistration"=>"ALL_AWARDS"
|
67
151
|
}
|
152
|
+
}
|
68
153
|
}
|
154
|
+
#=>
|
69
155
|
```
|
70
156
|
|
71
157
|
### Validate the format of a DUNS number
|
@@ -101,8 +187,9 @@ Samwise::Util.format_duns(duns: '08-011-5718')
|
|
101
187
|
#=> "0801157180000"
|
102
188
|
```
|
103
189
|
|
104
|
-
`duns` can be
|
190
|
+
`duns` can be a 7, 8, 9, or 13 digit number (hyphens are removed):
|
105
191
|
|
192
|
+
- If it is 7 digits, `00` is prepended, and `0000` is added to the end.
|
106
193
|
- If it is 8 digits, `0` is prepended, and `0000` is added to the end.
|
107
194
|
- If it is 9 digits, `0000` is added to the end.
|
108
195
|
- If it is 13 digits, the number is unchanged.
|
@@ -144,6 +231,38 @@ gem 'samwise', github: '18f/samwise'
|
|
144
231
|
$ gem install samwise
|
145
232
|
```
|
146
233
|
|
234
|
+
## Command Line Interface
|
235
|
+
The samwise gem can be run via command line via a piped in file or with a file input flag.
|
236
|
+
|
237
|
+
To make the gem executable run `gem install samwise` which calls makes the contents of the `bin` directory executable in the gemspec.
|
238
|
+
|
239
|
+
#### Input Format
|
240
|
+
The CLI expects a .json with the following schema:
|
241
|
+
|
242
|
+
```json
|
243
|
+
{"users":[{"other_keys": "other_values", "duns":"duns_number"}]}
|
244
|
+
```
|
245
|
+
|
246
|
+
If the JSON does not include a `"duns"` key, the CLI will abort.
|
247
|
+
|
248
|
+
The JSON can be piped in or fed in from a file via a `-i` flag. For example:
|
249
|
+
```bash
|
250
|
+
cat "input_file.json" | samwise verify > output.json
|
251
|
+
samwise verify -i "input_file.json" > output.json
|
252
|
+
```
|
253
|
+
|
254
|
+
#### Output
|
255
|
+
The CLI will output a JSON to `STDOUT` with an addition key to be determined by the method run (see below for reference).
|
256
|
+
|
257
|
+
#### Available Commands
|
258
|
+
| CLI Comand | Samwise Function | JSON OutKey |
|
259
|
+
|--------------------|-----------------------------------|-------------|
|
260
|
+
| `samwise verify` | `Samwise::Client.duns_is_in_sam?` | `verified` |
|
261
|
+
| `samwise excluded` | `Samwise::Client.excluded?` | `excluded` |
|
262
|
+
| `samwise get_info` | `Samwise::Client.get_duns_info` | `sam_data` |
|
263
|
+
| `samwise check_format` | `Samwise::Util.duns_is_properly_formatted?` | `valid_format` |
|
264
|
+
| `samwise format` | `Samwise::Util.format_duns` | `formatted_duns` |
|
265
|
+
|
147
266
|
## Public Domain
|
148
267
|
|
149
268
|
This project is in the worldwide [public domain](LICENSE.md). As stated in [CONTRIBUTING](CONTRIBUTING.md):
|
data/bin/samwise
ADDED
data/lib/samwise.rb
CHANGED
data/lib/samwise/cli.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "thor"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
# require 'samwise'
|
5
|
+
|
6
|
+
module Samwise
|
7
|
+
class Cli < Thor
|
8
|
+
method_option :infile, :aliases => "-i", :desc => "Nonpiped version input"
|
9
|
+
# method_option :dunsnum, :aliases => "-d", :desc => "DUNS number"
|
10
|
+
desc "verify", "Verify DUNS numbers are in SAM.gov"
|
11
|
+
def verify
|
12
|
+
wrap_sam("verified"){|c, u, j| u[j] = c.duns_is_in_sam?(duns: u['duns'])}
|
13
|
+
end
|
14
|
+
method_option :infile, :aliases => "-i", :desc => "Nonpiped version input"
|
15
|
+
desc "excluded", "Verify Vendor is not on the excluded parties list"
|
16
|
+
def excluded
|
17
|
+
wrap_sam("excluded"){|c, u, j| u[j] = c.excluded?(duns: u['duns'])}
|
18
|
+
end
|
19
|
+
|
20
|
+
method_option :infile, :aliases => "-i", :desc => "Nonpiped version input"
|
21
|
+
desc "get_info", "Get DUNS info"
|
22
|
+
def get_info
|
23
|
+
wrap_sam("user_info"){|c, u, j| u[j] = c.get_duns_info(duns: u['duns'])}
|
24
|
+
end
|
25
|
+
|
26
|
+
method_option :infile, :aliases => "-i", :desc => "Nonpiped version input"
|
27
|
+
desc "check_format", "Validate the format of a DUNS number"
|
28
|
+
def check_format
|
29
|
+
wrap_sam("valid_format"){|c, u, j| u[j] = Samwise::Util.duns_is_properly_formatted?(duns: u['duns'])}
|
30
|
+
end
|
31
|
+
|
32
|
+
method_option :infile, :aliases => "-i", :desc => "Nonpiped version input"
|
33
|
+
desc "format", "Format a DUNS number"
|
34
|
+
def format
|
35
|
+
wrap_sam("formatted_duns") {|c, u, j| u[j] = Samwise::Util.format_duns(duns: u['duns'])}
|
36
|
+
end
|
37
|
+
|
38
|
+
#Helpers
|
39
|
+
desc "private method wrap_sam JSonkeytoadd &block", "Opens the client and cli files for all of the calls"
|
40
|
+
def wrap_sam(jsonOutKey, &block)
|
41
|
+
infile = ($stdin.tty?) ? File.read(options[:infile]) : $stdin.read #read in a json of users to be samwised
|
42
|
+
duns_hash = JSON.parse(infile)
|
43
|
+
#check what method called wrap_sam. Do not init samwise client for utils
|
44
|
+
thor_method = caller_locations(1,1)[0].label
|
45
|
+
client = Samwise::Client.new unless (thor_method == "check_format") || (jsonOutKey =="format")
|
46
|
+
|
47
|
+
|
48
|
+
duns_hash['users'].each do |user|
|
49
|
+
#abort process do improperly formated duns
|
50
|
+
abort("please use a .json with a duns key") unless user.has_key?("duns")
|
51
|
+
block.call(client, user, jsonOutKey)
|
52
|
+
end
|
53
|
+
puts duns_hash.to_json
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
private :wrap_sam
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/samwise/client.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'faraday'
|
2
1
|
require 'json'
|
3
2
|
require 'httpclient'
|
4
3
|
|
@@ -7,9 +6,6 @@ module Samwise
|
|
7
6
|
def initialize(api_key: nil, sam_status_key: Samwise::Protocol::SAM_STATUS_KEY)
|
8
7
|
@api_key = api_key || ENV['DATA_DOT_GOV_API_KEY']
|
9
8
|
@sam_status_key = sam_status_key || ENV['SAM_STATUS_KEY']
|
10
|
-
@conn = Faraday.new do |faraday|
|
11
|
-
faraday.adapter :httpclient
|
12
|
-
end
|
13
9
|
@client = HTTPClient.new
|
14
10
|
end
|
15
11
|
|
@@ -18,7 +14,8 @@ module Samwise
|
|
18
14
|
JSON.parse(response.body)
|
19
15
|
end
|
20
16
|
|
21
|
-
def duns_is_in_sam?(duns: nil)
|
17
|
+
def duns_is_in_sam?(duns: nil, delay: 1)
|
18
|
+
sleep(delay)
|
22
19
|
response = lookup_duns(duns: duns)
|
23
20
|
response.status == 200
|
24
21
|
end
|
@@ -28,6 +25,37 @@ module Samwise
|
|
28
25
|
JSON.parse(response.body)
|
29
26
|
end
|
30
27
|
|
28
|
+
def excluded?(duns: nil)
|
29
|
+
response = lookup_duns(duns: duns)
|
30
|
+
JSON.parse(response.body)["hasKnownExclusion"] == false
|
31
|
+
end
|
32
|
+
|
33
|
+
def small_business?(duns: nil, naicsCode: nil)
|
34
|
+
response = lookup_duns(duns: duns)
|
35
|
+
data = JSON.parse(response.body)["sam_data"]["registration"]
|
36
|
+
|
37
|
+
if data["certifications"] == nil
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
data = data["certifications"]["farResponses"]
|
41
|
+
small_biz_array = data.find{|far|far["id"]=="FAR 52.219-1"}["answers"].find{"naics"}["naics"]
|
42
|
+
|
43
|
+
# Allows for exact matches of a NAICS Code *or* NAICS code that starts with the argument.
|
44
|
+
# E.g., 541511 matches, but 54151 also matches
|
45
|
+
if small_biz_array.class == Array
|
46
|
+
naics = small_biz_array.find{|naics|naics["naicsCode"].to_s.start_with?(naicsCode.to_s)}
|
47
|
+
else
|
48
|
+
naics = small_biz_array
|
49
|
+
end
|
50
|
+
|
51
|
+
# Check for the NAICS Code and, if found, check whether it's a small
|
52
|
+
if naics == nil
|
53
|
+
false
|
54
|
+
else
|
55
|
+
naics["isSmallBusiness"] == "Y"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
31
59
|
private
|
32
60
|
|
33
61
|
def lookup_duns(duns: nil)
|
data/lib/samwise/protocol.rb
CHANGED
data/lib/samwise/util.rb
CHANGED
@@ -8,6 +8,7 @@ module Samwise
|
|
8
8
|
|
9
9
|
return true if duns_contains_forbidden_characters?(duns: duns)
|
10
10
|
|
11
|
+
return true if duns_is_seven_digits?(duns: duns)
|
11
12
|
return true if duns_is_eight_digits?(duns: duns)
|
12
13
|
return true if duns_is_nine_digits?(duns: duns)
|
13
14
|
return true if duns_is_thirteen_digits?(duns: duns)
|
@@ -24,6 +25,8 @@ module Samwise
|
|
24
25
|
duns = "#{duns}0000"
|
25
26
|
elsif duns_is_eight_digits?(duns: duns)
|
26
27
|
duns = "0#{duns}0000"
|
28
|
+
elsif duns_is_seven_digits?(duns: duns)
|
29
|
+
duns = "00#{duns}0000"
|
27
30
|
end
|
28
31
|
|
29
32
|
duns
|
@@ -45,6 +48,10 @@ module Samwise
|
|
45
48
|
return true
|
46
49
|
end
|
47
50
|
|
51
|
+
def self.duns_is_seven_digits?(duns: nil)
|
52
|
+
duns.length == 7
|
53
|
+
end
|
54
|
+
|
48
55
|
def self.duns_is_eight_digits?(duns: nil)
|
49
56
|
duns.length == 8
|
50
57
|
end
|
data/lib/samwise/version.rb
CHANGED
data/samwise.gemspec
CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |gem|
|
|
37
37
|
gem.add_development_dependency 'vcr'
|
38
38
|
gem.add_development_dependency 'pry'
|
39
39
|
gem.add_development_dependency 'webmock'
|
40
|
+
gem.add_development_dependency 'thor'
|
40
41
|
|
41
42
|
gem.add_runtime_dependency 'httpclient'
|
42
|
-
gem.add_runtime_dependency 'faraday'
|
43
43
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"users":[{"uid":"1000"},{"uid":"100"}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"users":[{"uid":"1000","duns":"080037478"},{"uid":"100","duns":"080031478"}]}
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'samwise'
|
3
|
+
require 'json'
|
4
|
+
require 'factory'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
describe Samwise::Cli, vcr: { cassette_name: "Samwise::Cli", record: :new_episodes } do
|
8
|
+
let(:goodfile) {'spec/cli_mocks/test.json'}
|
9
|
+
let(:piped_file){$stdin = StringIO.new(File.read(goodfile))}
|
10
|
+
let(:badfile) {'spec/cli_mocks/bad.json'}
|
11
|
+
let(:user_array) {Factory.create_users(["1000", "100"], ["080037478", "080031478"])}
|
12
|
+
let(:abort_msg) {'please use a .json with a duns key'}
|
13
|
+
|
14
|
+
def output(method, file)
|
15
|
+
capture(:stdout){Samwise::Cli.new.invoke(method, [], {:infile => file})}
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:example) do
|
19
|
+
$stdin = STDIN
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".verify" do
|
23
|
+
let(:method) {:verify}
|
24
|
+
let(:verified_user) {Factory.build_users_json(user_array, [{"verified" => true}, {"verified" => false}])+"\n"}
|
25
|
+
it "verifies the duns for each user with streamed infile" do
|
26
|
+
piped_file
|
27
|
+
expect(output(method, goodfile)).to eq(verified_user)
|
28
|
+
end
|
29
|
+
it "verifies the duns for each user when given an -i flagged test.json with duns key" do
|
30
|
+
expect(output(method, goodfile)).to eq(verified_user)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "requests to recieve a good json when recieves json without duns key" do
|
34
|
+
begin
|
35
|
+
err = capture_stderr(output(method, badfile))
|
36
|
+
rescue Exception => e
|
37
|
+
expect(e.to_s).to eq(abort_msg)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".excluded" do
|
43
|
+
let(:method) {:excluded}
|
44
|
+
let(:excluded_user){Factory.build_users_json(user_array, [{"excluded" => false}, {"excluded" => false}])+"\n"}
|
45
|
+
it "checks if users are excluded for each user in a streamed infile" do
|
46
|
+
piped_file
|
47
|
+
expect(output(method, goodfile)).to eq(excluded_user)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "checks if users are excluded when given an -i flagged test.json with duns key" do
|
51
|
+
expect(output(method, goodfile)).to eq(excluded_user)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "requests to recieve a good json when recieves json without duns key" do
|
55
|
+
begin
|
56
|
+
output(method, badfile)
|
57
|
+
rescue Exception => e
|
58
|
+
expect(e.to_s).to eq(abort_msg)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".get_info" do
|
64
|
+
let(:method){:get_info}
|
65
|
+
let(:expected_info) {"sam_data"}
|
66
|
+
it "gets the users' information for each user in a streamed infile" do
|
67
|
+
piped_file
|
68
|
+
expect(output(method, goodfile)).to include(expected_info)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "gets the users' information and adds to the json when given an -i flagged test.json with duns key" do
|
72
|
+
expect(output(method, goodfile)).to include(expected_info)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "requests to recieve a good json when recieves json without duns key" do
|
76
|
+
begin
|
77
|
+
output(method, badfile)
|
78
|
+
rescue Exception => e
|
79
|
+
expect(e.to_s).to eq(abort_msg)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe ".check_format" do
|
85
|
+
let(:method) {:check_format}
|
86
|
+
let(:valid_duns){Factory.build_users_json(user_array, [{"valid_format" => true}, {"valid_format" => true}])+"\n"}
|
87
|
+
it "verifies that the each duns number is formatted for each user in a streamed infile" do
|
88
|
+
piped_file
|
89
|
+
expect(output(method, goodfile)).to eq(valid_duns)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "verifies that the each duns number is formatted for -i flagged test.json with duns key" do
|
93
|
+
expect(output(method, goodfile)).to eq(valid_duns)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "requests to recieve a good json when recieves json without duns key" do
|
97
|
+
begin
|
98
|
+
output(method, badfile)
|
99
|
+
rescue Exception => e
|
100
|
+
expect(e.to_s).to eq(abort_msg)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe ".format" do
|
106
|
+
let(:method) {:format}
|
107
|
+
let(:format_duns){Factory.build_users_json(user_array, [{"formatted_duns" => "0800374780000"}, {"formatted_duns" => "0800314780000"}])+"\n"}
|
108
|
+
it "formats duns numbers when streamed in json with users array and duns key" do
|
109
|
+
piped_file
|
110
|
+
expect(output(method, goodfile)).to eq(format_duns)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "formats duns numbers when given an -i flagged test.json with duns key " do
|
114
|
+
expect(output(method, goodfile)).to eq(format_duns)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "requests to recieve a good json when recieves json without duns key" do
|
118
|
+
begin
|
119
|
+
output(method, badfile)
|
120
|
+
rescue Exception => e
|
121
|
+
expect(e.to_s).to eq(abort_msg)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|