Skip to content
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

Farzan's TakeAway Challenge 3/4 user stories #2241

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 7 additions & 9 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# Your name

Please write your full name here to make it easier to find your pull request.
# Farzan Imanzadeh

# User stories

Please list which user stories you've implemented (delete the ones that don't apply).

- [ ] User story 1: "I would like to see a list of dishes with prices"
- [ ] User story 2: "I would like to be able to select some number of several available dishes"
- [ ] User story 3: "I would like to check that the total I have been given matches the sum of the various dishes in my order"
- [X] User story 1: "I would like to see a list of dishes with prices"
- [X] User story 2: "I would like to be able to select some number of several available dishes"
- [X] User story 3: "I would like to check that the total I have been given matches the sum of the various dishes in my order"
- [ ] User story 4: "I would like to receive a text such as "Thank you! Your order was placed and will be delivered before 18:52" after I have ordered"

# README checklist

Does your README contains instructions for

- [ ] how to install,
- [ ] how to run,
- [ ] and how to test your code?
- [X] how to install,
- [X] how to run,
- [X] and how to test your code?

[Here is a pill](https://github.com/makersacademy/course/blob/main/pills/readmes.md) that can help you write a great README!
81 changes: 42 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
Takeaway Challenge
==================
# Takeaway Challenge

```
_________
r== | |
_ // | M.A. | ))))
_ // | F.I. | ))))
|_)//(''''': | |
// \_____:_____.-------D )))))
// \_____:_____.-------D )))))
// | === | / \
.:'//. \ \=| \ / .:'':./ )))))
:' // ': \ \ ''..'--:'-.. ':
'. '' .' \:.....:--'.-'' .'
.:'//. \ \=| \ / .:'':./ ))))))
: // : \ \ ''..'--:'-.. :
' '' ' \:.....:--'.-'' '
':..:' ':..:'

```

Instructions
-------
------

* Feel free to use google, your notes, books, etc. but work on your own
* If you refer to the solution of another coach or student, please put a link to that in your README
* If you have a partial solution, **still check in a partial solution**
* You must submit a pull request to this repo with your code by 9am Monday morning

Task
-----

* Fork this repo
* Clone to your local machine
* Run the command 'bundle' in the project directory to ensure you have all the gems
* Write a Takeaway program with the following user stories:
* Test the code using rspec in the cloned directory on the command line terminal
* Can also be tested using irb on the command line terminal and using the below to load all the files to implement all the methods
```
irb
require './lib/menu'
=> true
require './lib/view_menu'
=> true
require './lib/order'
=> true
```
<br>

## Task
------
* Write a Takeaway program with the below user stories:
<br>
<br>

```
As a customer
Expand All @@ -46,35 +57,27 @@ As a customer
So that I am reassured that my order will be delivered on time
I would like to receive a text such as "Thank you! Your order was placed and will be delivered before 18:52" after I have ordered
```
## My Approach
* Carried over learning from [Oystercard](https://github.com/Farzan-I/Oystercardday5) project
* Drew up a diagram using pen and paper for the first three user stories to aid the nouns and verbs that would become class names and method names
* Managed to get a total of 7 tests across 3 spec files to have 100% coverage and passing
* Didn't manage to implement the Twilio aspect of the code as I didn't have enough time. If I had, I'd look into doing this to complete the user stories
* The above would be done using tutorials on YouTube and using Google to aid the creation of the final piece of code

* Hints on functionality to implement:
* Ensure you have a list of dishes with prices
* The text should state that the order was placed successfully and that it will be delivered 1 hour from now, e.g. "Thank you! Your order was placed and will be delivered before 18:52".
* The text sending functionality should be implemented using Twilio API. You'll need to register for it. It’s free.
* Use the twilio-ruby gem to access the API
* Use the Gemfile to manage your gems
* Make sure that your Takeaway is thoroughly tested and that you use mocks and/or stubs, as necessary to not to send texts when your tests are run
* However, if your Takeaway is loaded into IRB and the order is placed, the text should actually be sent
* Note that you can only send texts in the same country as you have your account. I.e. if you have a UK account you can only send to UK numbers.

* Advanced! (have a go if you're feeling adventurous):
* Implement the ability to place orders via text message.
## Complications
* Had issues with the total instance variable (@total) as it would not return the total of the basket instance variable (@basket)
* This was rectified using solely a hash in the dishes instance variable (@dishes) rather than having the hash stored in an array as well
* One complication that hasn't been rectified is when a customer would add dishes (i.e. "meatball sub") to the basket, they could view the basket but it wouldn't give the total price. However, when the total method was called, it would give the total price of the basket but if the customer was to add something else, it would not increment the price accordingly
* If I had time, I would've wrote a whole new total method to rectify this issue as I tried to focus on user experience rather than anything else

* A free account on Twilio will only allow you to send texts to "verified" numbers. Use your mobile phone number, don't worry about the customer's mobile phone.

> :warning: **WARNING:** think twice before you push your **mobile number** or **Twilio API Key** to a public space like GitHub :eyes:
>
> :key: Now is a great time to think about security and how you can keep your private information secret. You might want to explore environment variables.

* Finally submit a pull request before Monday at 9am with your solution or partial solution. However much or little amount of code you wrote please please please submit a pull request before Monday at 9am


In code review we'll be hoping to see:
## Code Review

* All tests passing
* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good)
* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (100%)
* The code is elegant: every class has a clear responsibility, methods are short etc.



Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance will make the challenge somewhat easier. You should be the judge of how much challenge you want this at this moment.

Notes on Test Coverage
Expand Down
12 changes: 12 additions & 0 deletions lib/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Menu
attr_reader :dishes

def initialize
@dishes = {
"meatball sub" => 5,
"steak n cheese sub" => 6,
"low cal turkey sub" => 4
}
end

end
26 changes: 26 additions & 0 deletions lib/order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Order
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of variables are quite adequate and easy to understand what the code is trying to do

attr_reader :basket

def initialize
@total = 0
@menu = Menu.new.dishes
@basket = []
end

def choose_dish(dish)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might need to include a way ask for more than one of each dish. A hash for @Basket could help on that

@basket << dish
end

def total
@menu.each do |dish, price|
@basket.each do |selected_dish|
@total += price if selected_dish == dish
end
end
"Your basket's total is £#{@total}."
end

def check_basket
@basket
end
end
13 changes: 13 additions & 0 deletions lib/view_menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ViewMenu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might have been a method inside Menu class?


def initialize
@menu = Menu.new.dishes
end

def list_of_dishes
@menu.each do |dish, price|
puts "#{dish}: £#{price}"
end
end

end
15 changes: 15 additions & 0 deletions spec/menu_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'menu'

describe Menu do
describe "#dishes" do
it "contains a list of the dishes with prices" do
menu = {
"meatball sub" => 5,
"steak n cheese sub" => 6,
"low cal turkey sub" => 4
}
expect(subject.dishes).to eq menu
end
end

end
32 changes: 32 additions & 0 deletions spec/order_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'order'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All features seem to be tested thoroughly


describe Order do
describe "#select_dish" do
it "selects a dish from the menu" do
expect(subject).to respond_to(:choose_dish).with(1).argument
end

it "initializes with an empty order list" do
expect(subject.basket).to be_empty
end

it "adds a dish to the basket" do
subject.choose_dish("meatball sub")
expect(subject.basket).to include "meatball sub"
end
end

describe "#total" do
it "calculates total sum of order" do
subject.choose_dish("meatball sub")
expect(subject.total).to eq "Your basket's total is £5."
end
end

describe "#check_basket" do
it "shows what's in the basket" do
expect(subject.check_basket).to eq ([])
end
end

end
17 changes: 17 additions & 0 deletions spec/view_menu_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'view_menu'

describe ViewMenu do

describe "#list_of_dishes" do
it "provides a menu containing dishes and their prices" do
menu = double(:menu)
allow(menu).to receive(:dishes).and_return({
"meatball sub" => 5,
"steak n cheese sub" => 6,
"low cal turkey sub" => 4
})
expect(subject.list_of_dishes).to eq menu.dishes
end
end

end