credit_card_processor 0.0.1 → 0.0.2

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjdmNTZmYmYzODhhMDZlYmIwZTg3NGIyMTZiN2NkZDI3NmQzM2VjYg==
4
+ NWQxMzM1MmFlOTZmMjI5N2M1OGY2N2JiNTQ3ZmE2MjAwYjkzZWEzYg==
5
5
  data.tar.gz: !binary |-
6
- ZTM4OWYyYTlkMmMxNzg5NmY3MTcxYTUwNmUwNTc4MDc2ZDUzNzNiYw==
6
+ NTYxYjBmN2IxNDBkYzY3OWFiNmExMTIxNDViNGJhOTdjODc0OGU1NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTE5MjQ2OWIzN2VhMzNkNTBlNDFiMjNjZjgwYTExOTMxNjY0MWNjZWRhNjYw
10
- NTJiY2ViZTkyODhlYzBiNjZlZGMxM2IzOThhMjhhNGJkYmNhNzBiYTVmODcx
11
- ZmZhOWUwNGIxMDY0OGJkM2YwYjg0OTY4ZmU0MjQ5N2Y0ZDA3MTU=
9
+ YWVmNDNmMjhkYzg1MTY5NmQ0ODBiOGIzZGQxZTJjNzFjNGJjZDRhYWU0ZjYy
10
+ NjJjYjBiYzczOWE4MmQ1ZDUxZThkY2FjZDMwYjNiMjJiMDdjMjY4NDAwMmUx
11
+ MTEzZjk3ZTRiZmM2MDEwYThhNDU5ZjBiODg4NGQ1MjhiOGNiMGI=
12
12
  data.tar.gz: !binary |-
13
- ZTg0ZTA5OTdkM2FkMGMzNjNjMTQyODIwYjkwMWI2ZThjY2Y5MmEwNDkyMzQy
14
- MTBlYjYwNjM5ZWQwYmZhNjBhYTAyOTNiOGNlOTAxMzYyNDQyYTgyOGNlYzY5
15
- MDIxM2RhMTZlMDg1OWFjMDI5MjkxM2IyMWVlZDU0YTY0YzgyY2Y=
13
+ MmNkNjQyODhhOGNjZjY1MDBjZDhiNTE5N2MwNzc4MDZkNTgwZmQ1M2RlMDdh
14
+ ZDMxZmE3NWQxNjg3ZTg5MjVlYjAxYzVkYmViMjllODVhNjU2MmU2YjBkMTNh
15
+ NzU0ZjZmMDM5N2Y5OTFlN2Q5YTlhYjhlOTA2YTY3NTg4NGNjY2E=
data/README.md CHANGED
@@ -5,6 +5,11 @@ Program to add new credit card accounts, process charges and credits against the
5
5
  ## Usage
6
6
  In the credit_card_processor repository run:
7
7
 
8
+ ```
9
+ gem install credit_card_processor
10
+ ```
11
+
12
+ Then run:
8
13
  ```
9
14
  bundle install
10
15
  ```
@@ -14,7 +19,7 @@ to get dependencies.
14
19
  Then run the executable from bin:
15
20
 
16
21
  ```
17
- ./bin/credit_card_processor -f path_to_myfile.txt
22
+ credit_card_processor -f path_to_myfile.txt
18
23
  ```
19
24
 
20
25
  ## Design Decisions
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/credit_card_processor.rb'
3
+
4
+ CreditCardProcessor::CCProcessor.new.main
@@ -1,3 +1,3 @@
1
1
  module CreditCardProcessor
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,120 @@
1
+ require_relative '../lib/credit_card_processor'
2
+
3
+ include CreditCardProcessor
4
+
5
+ RSpec.configure do |c|
6
+ c.before { allow($stdout).to receive(:puts) }
7
+ end
8
+
9
+ describe CCProcessor do
10
+ before(:each) do
11
+ @cc = CCProcessor.new('-f testfile.txt'.split)
12
+ DB.drop_table?(:accounts)
13
+ end
14
+
15
+ describe '#create_table' do
16
+ it 'creates accounts table' do
17
+ @cc.create_table
18
+ expect(DB.table_exists?(:accounts)).to be true
19
+ end
20
+ end
21
+
22
+ describe '#cc_valid?' do
23
+ it 'validates correct luhn' do
24
+ expect(@cc.cc_valid?(4_111_111_111_111_111)).to be true
25
+ end
26
+ it 'validates incorrect luhn' do
27
+ expect(@cc.cc_valid?(4_111_144_444_444_144_441)).to be false
28
+ end
29
+ end
30
+
31
+ describe '#add_account' do
32
+ it 'adds cc_number if valid' do
33
+ @cc.create_table
34
+ @cc.add_account('name', '4111111111111111', '1000')
35
+ cc_number = DB[:accounts].select(:cc_number).first
36
+ expect(cc_number[:cc_number]).to eq '4111111111111111'
37
+ end
38
+ it 'adds error of cc is not valid' do
39
+ @cc.create_table
40
+ @cc.add_account('name', '4111111111111111111', '1000')
41
+ cc_number = DB[:accounts].select(:cc_number).first
42
+ expect(cc_number[:cc_number]).to eq 'error'
43
+ end
44
+ end
45
+
46
+ describe '#charge' do
47
+ before(:each) do
48
+ @cc.create_table
49
+ @cc.add_account('name', '4111111111111111', '1000')
50
+ end
51
+ it 'updates balance if charge is less than credit available' do
52
+ @cc.charge('name', '100')
53
+ balance = DB[:accounts].select(:balance).first
54
+ expect(balance[:balance]).to eq 100
55
+ end
56
+ it 'updates balance if charge is equal to credit available' do
57
+ @cc.charge('name', '1000')
58
+ balance = DB[:accounts].select(:balance).first
59
+ expect(balance[:balance]).to eq 1000
60
+ end
61
+ it 'does nothing if charge is greater than credit available' do
62
+ @cc.charge('name', '1500')
63
+ balance = DB[:accounts].select(:balance).first
64
+ expect(balance[:balance]).to eq 0
65
+ end
66
+ end
67
+
68
+ describe '#credit' do
69
+ it 'updates balance' do
70
+ @cc.create_table
71
+ @cc.add_account('name', '4111111111111111', '1000')
72
+ @cc.credit('name', '100')
73
+ balance = DB[:accounts].select(:balance).first
74
+ expect(balance[:balance]).to eq(-100)
75
+ end
76
+ end
77
+
78
+ describe '#parse' do
79
+ it 'Rejects invalid functions' do
80
+ invalid = CCProcessor.new('-f spec/fixtures/bad_function.txt'.split)
81
+ file = 'spec/fixtures/bad_function.txt'
82
+ expect(STDOUT).to receive(:puts).with('Function is not valid')
83
+ invalid.parse(file)
84
+ end
85
+ end
86
+
87
+ describe '#output' do
88
+ it 'outputs balance if cc_number is valid' do
89
+ good_cc = CCProcessor.new('-f spec/fixtures/add_test_file.txt'.split)
90
+ expect(STDOUT).to receive(:puts).with('Tom: $0')
91
+ good_cc.main
92
+ end
93
+ it 'outputs error if cc_number is invalid' do
94
+ bad_cc = CCProcessor.new('-f spec/fixtures/bad_cc_test_file.txt'.split)
95
+ expect(STDOUT).to receive(:puts).with('Quincy: error')
96
+ bad_cc.main
97
+ end
98
+ end
99
+
100
+ describe '#main' do
101
+ before(:each) do
102
+ @cc.create_table
103
+ end
104
+ it 'Adds to accounts' do
105
+ add = CCProcessor.new('-f spec/fixtures/add_test_file.txt'.split)
106
+ expect(add).to receive(:add_account).with('Tom', '4111111111111111', 1000)
107
+ add.main
108
+ end
109
+ it 'Charges accounts' do
110
+ charge = CCProcessor.new('-f spec/fixtures/charge_test_file.txt'.split)
111
+ expect(charge).to receive(:charge).with('Tom', 500)
112
+ charge.main
113
+ end
114
+ it 'Credits accounts' do
115
+ credit = CCProcessor.new('-f spec/fixtures/credit_test_file.txt'.split)
116
+ expect(credit).to receive(:credit).with('Tom', 100)
117
+ credit.main
118
+ end
119
+ end
120
+ end
@@ -0,0 +1 @@
1
+ Add Tom 4111111111111111 $1000
@@ -0,0 +1 @@
1
+ Add Quincy 1234567890123456 $2000
@@ -0,0 +1 @@
1
+ Debit Quincy 1234567890123456 $2000
@@ -0,0 +1 @@
1
+ Charge Tom $500
@@ -0,0 +1 @@
1
+ Credit Tom $100
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credit_card_processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - meggiebonner
@@ -111,7 +111,8 @@ dependencies:
111
111
  description:
112
112
  email:
113
113
  - meggie.bonner@gmail.com
114
- executables: []
114
+ executables:
115
+ - credit_card_processor
115
116
  extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
@@ -120,9 +121,16 @@ files:
120
121
  - LICENSE.txt
121
122
  - README.md
122
123
  - Rakefile
124
+ - bin/credit_card_processor
123
125
  - credit_card_processor.gemspec
124
126
  - lib/credit_card_processor.rb
125
127
  - lib/credit_card_processor/version.rb
128
+ - spec/credit_card_processor_spec.rb
129
+ - spec/fixtures/add_test_file.txt
130
+ - spec/fixtures/bad_cc_test_file.txt
131
+ - spec/fixtures/bad_function.txt
132
+ - spec/fixtures/charge_test_file.txt
133
+ - spec/fixtures/credit_test_file.txt
126
134
  homepage:
127
135
  licenses: []
128
136
  metadata: {}
@@ -146,5 +154,11 @@ rubygems_version: 2.2.2
146
154
  signing_key:
147
155
  specification_version: 4
148
156
  summary: Gem for credit card processing.
149
- test_files: []
157
+ test_files:
158
+ - spec/credit_card_processor_spec.rb
159
+ - spec/fixtures/add_test_file.txt
160
+ - spec/fixtures/bad_cc_test_file.txt
161
+ - spec/fixtures/bad_function.txt
162
+ - spec/fixtures/charge_test_file.txt
163
+ - spec/fixtures/credit_test_file.txt
150
164
  has_rdoc: