-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Steven Spiegl #2230
base: main
Are you sure you want to change the base?
Steven Spiegl #2230
Changes from 11 commits
49a36bf
d418efd
ecc2598
fbf1603
c884e34
24da351
1fba4bf
d4f5797
b2e345c
1cdf619
b6b7fac
7c626af
afb5210
f53cf28
2df5680
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
# Local cache of Rubocop remote config | ||
.rubocop-* | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,7 @@ end | |
|
||
group :development, :test do | ||
gem 'rubocop', '1.20' | ||
gem 'twilio-ruby' | ||
gem 'dotenv' | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Menu | ||
|
||
attr_reader :items | ||
|
||
def initialize | ||
@items = [{ item_number: 1, scaldy: "hot pea", price: 4.00, available: true }, | ||
{ item_number: 2, scaldy: "hot tomato", price: 4.25, available: true }, | ||
{ item_number: 3, scaldy: "matzo ball", price: 5.00, available: false }, | ||
{ item_number: 4, scaldy: "hot potato", price: 3.75, available: true} | ||
] | ||
end | ||
|
||
def view_menu | ||
@items | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require_relative 'menu' | ||
require_relative 'SMS' | ||
|
||
class Order | ||
|
||
attr_reader :selection, :items, :total | ||
|
||
def initialize | ||
@selection = [] | ||
@items = Menu.new.items | ||
@total = 0 | ||
end | ||
|
||
def view_menu | ||
Menu.new | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You previously grab the items on line 10, so you could re-use that instance of Menu to print the dishes instead. |
||
end | ||
|
||
def add(item_index) | ||
|
||
fail 'item not available' if @items[item_index - 1][:available] == false | ||
@selection << @items[item_index - 1] | ||
@total += @items[item_index - 1][:price] | ||
@selected_item = @items[item_index - 1][:scaldy] | ||
item_added_confirmation | ||
end | ||
|
||
def checkout | ||
p check_order_prompt, @selection, total_summary | ||
# checkout_confirmation | ||
end | ||
|
||
def check_order_prompt | ||
"Please check your order against your total:" | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did I understand User Story 3 correctly or did I go overboard?
did I satisfy this condition simply by giving the customer a 'total' method? |
||
def selection_summary | ||
@selection | ||
end | ||
|
||
def total_summary | ||
"Your total is: £#{@total}. Please use the complete_order function, entering your phone number as an argument, to complete your order" | ||
end | ||
|
||
def item_added_confirmation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This functionality is not mentioned in the spec. You should try to adhere to the spec as closely as possible so you're not introducing unnecessary complexity to your project. |
||
"You successfully added #{@selected_item} to your basket" | ||
end | ||
|
||
def complete_order(phone_number) | ||
SMS.new.send_sms(phone_number) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
require 'twilio-ruby' | ||
require 'dotenv/load' | ||
|
||
class SMS | ||
|
||
ETA = (Time.now + 3600).strftime("%H:%M") | ||
|
||
attr_reader :sent, :phone_number | ||
|
||
def initialize | ||
@sent = false | ||
end | ||
|
||
def sms | ||
|
||
@client = Twilio::REST::Client.new ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN'] | ||
message = @client.messages.create( | ||
body: "Thank you! Your order has been logged and will be with before #{ETA}", | ||
to: "+#{@phone_number}", | ||
from: ENV['TWILIO_PHONE']) | ||
|
||
puts message.sid | ||
end | ||
|
||
def send_sms(phone_number) | ||
@phone_number = phone_number | ||
sms | ||
@sent = true | ||
sms_sent_confirmation | ||
end | ||
|
||
def sent? | ||
@sent | ||
end | ||
|
||
def sms_sent_confirmation | ||
"A confirmation message has been sent to the number you provided" | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'menu' | ||
describe Menu do | ||
|
||
it 'is an instance of menu' do | ||
expect(subject).to be_instance_of(Menu) | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'order' | ||
|
||
describe Order do | ||
|
||
describe '#add dishes' do | ||
|
||
context 'when a customer selects an available dish' do | ||
it 'it should change the order by adding a dish to it' do | ||
expect { subject.add(1) }.to change(subject, :selection) | ||
end | ||
end | ||
|
||
context 'when a customer selects an unavailable dish' do | ||
it 'it should not let them pick a dish' do | ||
expect { subject.add(3) }.to raise_error 'item not available' | ||
end | ||
end | ||
|
||
context 'when a customer selects a meal' do | ||
it 'it should add the cost of that dish to the total' do | ||
expect { subject.add(1) }.to change(subject, :total) | ||
end | ||
end | ||
|
||
context 'when a customer selects a dish' do | ||
it 'it should change the confirmation message accordingly' do | ||
expect { subject.add(1) }.to change(subject, :item_added_confirmation) | ||
end | ||
end | ||
|
||
describe '#summary' do | ||
context 'when a customer has finished choosing meals and clicks on checkout' do | ||
it 'should show the customer their summary' do | ||
subject.add(1) | ||
expect(subject.checkout).to include(subject.selection) | ||
end | ||
|
||
it 'should prompt the customer to compare the total against the order summary' do | ||
subject.add(1) | ||
expect(subject.checkout).to include("Please check your order against your total:") | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#complete_order' do | ||
context 'when a customer has checked their summary and enters complete_order' do | ||
it 'should call the SMS class' do | ||
subject.add(1) | ||
subject.checkout | ||
expect(subject).to respond_to(subject.complete_order).with(SMS.new.send_sms(ENV['MY_PHONE'])) | ||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how to actually check that complete_order((ENV['MY_PHONE'])) calls SMS.new.send_sms? I realised I was misusing respond_to above and below comment so changed it above, but now all the test does is check that the method takes one argument. I want to implement a test to make sure that when someone enters their phone number it calls the SMS class... |
||
context 'when a customer has checked their summary and enters complete_order' do | ||
it 'should be instance of SMS' do | ||
subject.add(1) | ||
subject.checkout | ||
expect(subject.complete_order).to_(SMS.new.send_sms) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'SMS' | ||
# require 'dotenv/load' | ||
|
||
describe SMS do | ||
|
||
subject(:sms) { described_class.new } | ||
|
||
before do | ||
allow(sms).to receive(:sms) | ||
end | ||
|
||
it 'sends a payment confirmation text message' do | ||
expect(sms).to receive(:sms) | ||
sms.send_sms(ENV['MY_PHONE']) | ||
end | ||
|
||
describe '#send_sms' do | ||
it "takes a phone number as an argument" do | ||
expect(subject).to respond_to(:send_sms).with(1).argument | ||
end | ||
end | ||
|
||
it 'changes the status of sent? to true when a message is sent' do | ||
expect { subject.send_sms(ENV['MY_PHONE']) }.to change(subject, :sent?).to true | ||
end | ||
|
||
it 'confirms a message has been sent' do | ||
expect(subject.sms_sent_confirmation).to eq('A confirmation message has been sent to the number you provided') | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have implemented suggestion to move this to initialize, but have a question:
Which is better? The implemented initialize or the one below?
Both seem to get the same results... The first reads more clearly but makes for a longer argument