Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Fix zero dollar values as words bug for CA #333

Merged
merged 2 commits into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.2.4
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- "2.1.6"
- "2.2.4"
before_install: gem install foreman
script: foreman run bundle exec rspec spec
notifications:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'
ruby '2.1.6'
ruby '2.2.4'

gem 'sinatra'
gem 'sinatra-contrib'
Expand Down
105 changes: 55 additions & 50 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,91 +1,93 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (4.2.0)
activesupport (4.2.5)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.6)
backports (3.6.4)
addressable (2.4.0)
backports (3.6.7)
builder (3.2.2)
coderay (1.1.0)
crack (0.4.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.2.5)
dotenv (0.10.0)
foreman (0.63.0)
dotenv (>= 0.7)
thor (>= 0.13.6)
dotenv (2.0.2)
foreman (0.78.0)
thor (~> 0.19.1)
hashdiff (0.2.3)
i18n (0.7.0)
json (1.8.2)
jwt (1.0.0)
kgio (2.9.2)
json (1.8.3)
jwt (1.5.2)
kgio (2.10.0)
method_source (0.8.2)
mini_portile (0.6.0)
minitest (5.5.1)
multi_json (1.10.1)
newrelic_rpm (3.7.3.204)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
mini_portile2 (2.0.0)
minitest (5.8.3)
multi_json (1.11.2)
newrelic_rpm (3.14.1.311)
nokogiri (1.6.7.1)
mini_portile2 (~> 2.0.0.rc2)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rack (1.6.4)
rack-protection (1.5.3)
rack
rack-ssl (1.4.1)
rack
rack-test (0.6.2)
rack-test (0.6.3)
rack (>= 1.0)
rack-timeout (0.1.1)
raindrops (0.13.0)
require_all (1.3.2)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.3)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.3)
rack-timeout (0.3.2)
raindrops (0.15.0)
require_all (1.3.3)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.1)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.3)
rspec-support (~> 3.0.0)
rspec-support (3.0.3)
safe_yaml (1.0.2)
sinatra (1.4.5)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
safe_yaml (1.0.4)
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-contrib (1.4.2)
tilt (>= 1.3, < 3)
sinatra-contrib (1.4.6)
backports (>= 2.0)
multi_json
rack-protection
rack-test
sinatra (~> 1.4.0)
tilt (~> 1.3)
slop (3.5.0)
tilt (>= 1.3, < 3)
slop (3.6.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
timecop (0.7.3)
twilio-ruby (3.11.6)
tilt (2.0.1)
timecop (0.8.0)
twilio-ruby (4.9.0)
builder (>= 2.1.2)
jwt (>= 0.1.2)
jwt (~> 1.0)
multi_json (>= 1.3.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
unicorn (4.8.2)
unicorn (5.0.1)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
vcr (2.9.0)
webmock (1.17.4)
addressable (>= 2.2.7)
vcr (3.0.0)
webmock (1.22.3)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff

PLATFORMS
ruby
Expand All @@ -109,3 +111,6 @@ DEPENDENCIES
unicorn
vcr
webmock

BUNDLED WITH
1.11.2
5 changes: 3 additions & 2 deletions lib/state_handler/ca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def transcribe_balance_response(transcription_text, language = :english)
if transcription_text == nil
return mg.having_trouble_try_again_message
end
regex_matches = transcription_text.scan(/(\$\S+)/)
if transcription_text.include?("non working card")
processed_transcription = process_transcription_for_zero_text(transcription_text)
regex_matches = processed_transcription.scan(/(\$\S+)/)
if processed_transcription.include?("non working card")
mg.card_number_not_found_message
elsif regex_matches.count > 1
ebt_amount = clean_trailing_period(regex_matches[0][0])
Expand Down
4 changes: 4 additions & 0 deletions lib/transcription_parsing_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ def clean_trailing_period(amount_string)
amount_string
end
end

def process_transcription_for_zero_text(text)
text.gsub("zero dollars", "$0")
end
end
32 changes: 27 additions & 5 deletions spec/lib/state_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,46 +152,51 @@
end

describe 'balance transcriber' do
let(:successful_transcription_1) { "Your food stamp balance is $136.33 your cash account balance is $0 as a reminder by saving the receipt from your last purchase and your last a cash purchase for Cash Bank Transaction you will always have your current balance at and will also print your balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee (running?) this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for (pin?) replacement press 4 for additional options press 5" }
let(:successful_transcription_2) { "(Stamp?) balance is $123.11 your cash account balance is $11.32 as a reminder by saving the receipt from your last purchase and your last a cash purchase or cash back transaction you will always have your current balance at and will also print the balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for (pin?) replacement press 4 for additional options press 5" }
let(:successful_transcription_3) { "Devon Alan is $156.89 your cash account balance is $4.23 as a reminder by saving the receipt from your last purchase and your last the cash purchase or cash back for (action?) you will always have your current balance. I'm at and will also print the balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee (running?) this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for pain placement press 4 for additional options press 5" }
let(:successful_transcription_extra_periods) { "Your food stamp balance is $9.11. Your cash account balance is $13.93. As a reminder. Bye C." }
let(:transcription_ebt_not_found) { "Our records indicate the number you have entered it's for an non working card in case your number was entered incorrectly please reenter your 16 digit card number followed by the pound sign." }


context 'for English' do
let(:language) { :english }

context 'with transcription containing balance variation 1' do
it 'sends response with balance amounts' do
successful_transcription_1 = "Your food stamp balance is $136.33 your cash account balance is $0 as a reminder by saving the receipt from your last purchase and your last a cash purchase for Cash Bank Transaction you will always have your current balance at and will also print your balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee (running?) this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for (pin?) replacement press 4 for additional options press 5"

reply_for_user = subject.transcribe_balance_response(successful_transcription_1)
expect(reply_for_user).to eq("Hi! Your food stamp balance is $136.33 and your cash balance is $0.")
end
end

context 'with transcription containing balance variation 2' do
it 'sends response with balance amounts' do
successful_transcription_2 = "(Stamp?) balance is $123.11 your cash account balance is $11.32 as a reminder by saving the receipt from your last purchase and your last a cash purchase or cash back transaction you will always have your current balance at and will also print the balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for (pin?) replacement press 4 for additional options press 5"

reply_for_user = subject.transcribe_balance_response(successful_transcription_2)
expect(reply_for_user).to eq("Hi! Your food stamp balance is $123.11 and your cash balance is $11.32.")
end
end

context 'with transcription containing balance variation 3' do
it 'sends response with balance amounts' do
successful_transcription_3 = "Devon Alan is $156.89 your cash account balance is $4.23 as a reminder by saving the receipt from your last purchase and your last the cash purchase or cash back for (action?) you will always have your current balance. I'm at and will also print the balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee (running?) this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for pain placement press 4 for additional options press 5"

reply_for_user = subject.transcribe_balance_response(successful_transcription_3)
expect(reply_for_user).to eq("Hi! Your food stamp balance is $156.89 and your cash balance is $4.23.")
end
end

context 'with a transcription with extraneous periods' do
it 'sends response with balance amounts without extra periods' do
successful_transcription_extra_periods = "Your food stamp balance is $9.11. Your cash account balance is $13.93. As a reminder. Bye C."

reply_for_user = subject.transcribe_balance_response(successful_transcription_extra_periods)
expect(reply_for_user).to eq("Hi! Your food stamp balance is $9.11 and your cash balance is $13.93.")
end
end

context 'with EBT card not found in system' do
it 'sends EBT-not-found message' do
transcription_ebt_not_found = "Our records indicate the number you have entered it's for an non working card in case your number was entered incorrectly please reenter your 16 digit card number followed by the pound sign."

reply_for_user = subject.transcribe_balance_response(transcription_ebt_not_found)
expect(reply_for_user).to eq("I'm sorry, that card number was not found. Please try again.")
end
Expand All @@ -205,33 +210,50 @@
expect(reply_for_user).to eq(MessageGenerator.new.having_trouble_try_again_message)
end
end

context 'with zero dollar values in words' do
it 'correctly parses the zeroes as values' do
transcription_with_zero_as_words = "Balance is zero dollars. Your cash account balance is zero dollars. As a reminder by saving the receipt from your last purchase and or your last cash purchase or cash back transaction."

reply_for_user = subject.transcribe_balance_response(transcription_with_zero_as_words)
expect(reply_for_user).to eq("Hi! Your food stamp balance is $0 and your cash balance is $0.")
end
end
end

context 'for Spanish' do
let(:language) { :spanish }

context 'with transcription containing balance variation 1' do
it 'sends response with balance amounts' do
successful_transcription_1 = "Your food stamp balance is $136.33 your cash account balance is $0 as a reminder by saving the receipt from your last purchase and your last a cash purchase for Cash Bank Transaction you will always have your current balance at and will also print your balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee (running?) this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for (pin?) replacement press 4 for additional options press 5"

reply_for_user = subject.transcribe_balance_response(successful_transcription_1, language)
expect(reply_for_user).to eq("Hola! El saldo de su cuenta de estampillas para comida es $136.33 y su balance de dinero en efectivo es $0.")
end
end

context 'with transcription containing balance variation 2' do
it 'sends response with balance amounts' do
successful_transcription_2 = "(Stamp?) balance is $123.11 your cash account balance is $11.32 as a reminder by saving the receipt from your last purchase and your last a cash purchase or cash back transaction you will always have your current balance at and will also print the balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for (pin?) replacement press 4 for additional options press 5"

reply_for_user = subject.transcribe_balance_response(successful_transcription_2, language)
expect(reply_for_user).to eq("Hola! El saldo de su cuenta de estampillas para comida es $123.11 y su balance de dinero en efectivo es $11.32.")
end
end

context 'with transcription containing balance variation 3' do
it 'sends response with balance amounts' do
successful_transcription_3 = "Devon Alan is $156.89 your cash account balance is $4.23 as a reminder by saving the receipt from your last purchase and your last the cash purchase or cash back for (action?) you will always have your current balance. I'm at and will also print the balance on the Cash Withdrawal receipt to hear the number of Cash Withdrawal for that a transaction fee (running?) this month press 1 to hear your last 10 transactions report a transaction there file a claim or check the status of a claim press 2 to report your card lost stolen or damaged press 3 for pain placement press 4 for additional options press 5"

reply_for_user = subject.transcribe_balance_response(successful_transcription_3, language)
expect(reply_for_user).to eq("Hola! El saldo de su cuenta de estampillas para comida es $156.89 y su balance de dinero en efectivo es $4.23.")
end
end

context 'with EBT card not found in system' do
transcription_ebt_not_found = "Our records indicate the number you have entered it's for an non working card in case your number was entered incorrectly please reenter your 16 digit card number followed by the pound sign."

it 'sends EBT-not-found message' do
reply_for_user = subject.transcribe_balance_response(transcription_ebt_not_found, language)
expect(reply_for_user).to eq("Lo siento, no se encontró el número de tarjeta. Por favor, inténtelo de nuevo.")
Expand Down