-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from HafizMassamTabraizKhan/integrations
Added Integration tests
- Loading branch information
Showing
17 changed files
with
251 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :food do | ||
name { 'Food Name' } | ||
measurement_unit { 'Unit' } | ||
price { 10 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FactoryBot.define do | ||
factory :inventory do | ||
name { 'Inventory Name' } | ||
user { create(:user) } | ||
user_id { user.id } | ||
description { 'Inventory Description' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :inventory_food do | ||
inventory { create(:inventory) } | ||
food { create(:food) } | ||
quantity { 10 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryBot.define do | ||
factory :recipe do | ||
name { 'Recipe Name' } | ||
preparation_time { 3 } | ||
cooking_time { 4 } | ||
description { 'Recipe Description' } | ||
public { true } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :user do | ||
name { 'User Name' } | ||
email { 'user@example.com' } | ||
password { 'password123' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Food Details', type: :feature do | ||
let(:food) { create(:food) } | ||
|
||
before do | ||
visit food_path(food) | ||
end | ||
|
||
scenario 'shows the food details' do | ||
expect(page).to have_content(food.name) | ||
expect(page).to have_content(food.measurement_unit) | ||
expect(page).to have_content("$ #{food.price}") | ||
end | ||
|
||
scenario 'has a back link' do | ||
expect(page).to have_link('Back', href: foods_path) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Inventory Index', type: :feature do | ||
let(:inventory) { create(:inventory) } | ||
|
||
before do | ||
create(:inventory_food, inventory:, food: create(:food)) | ||
visit inventory_path(inventory) | ||
end | ||
|
||
scenario 'shows the inventory name' do | ||
expect(page).to have_content(inventory.name) | ||
end | ||
|
||
scenario 'has an add food link' do | ||
expect(page).to have_link('Add Food', href: new_inventory_inventory_food_path(inventory)) | ||
end | ||
|
||
scenario 'shows the inventory foods' do | ||
expect(page).to have_content(inventory.inventory_foods.first.food.name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# spec/features/public_recipes_spec.rb | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.feature 'Public Recipes List', type: :feature do | ||
scenario 'User views the list of public recipes' do | ||
# Create some sample data for public recipes | ||
user = FactoryBot.create(:user, name: 'John Doe') | ||
public_recipe1 = FactoryBot.create(:recipe, name: 'Recipe 1', user:) | ||
public_recipe2 = FactoryBot.create(:recipe, name: 'Recipe 2', user:) | ||
|
||
# Visit the public recipes page | ||
visit root_path | ||
|
||
# Assertions to check the content of the page | ||
expect(page).to have_selector('h1', text: 'Public Recipes list') | ||
|
||
# Check for each public recipe in the list | ||
within('.card', text: 'Recipe 1') do | ||
expect(page).to have_link('Recipe 1', href: recipe_path(public_recipe1)) | ||
expect(page).to have_content('by John Doe') | ||
expect(page).to have_content('Total food items: 0') # Customize as needed | ||
expect(page).to have_content('Total price: $0') # Adjusted expectation | ||
end | ||
|
||
within('.card', text: 'Recipe 2') do | ||
expect(page).to have_link('Recipe 2', href: recipe_path(public_recipe2)) | ||
expect(page).to have_content('by John Doe') | ||
expect(page).to have_content('Total food items: 0') # Customize as needed | ||
expect(page).to have_content('Total price: $0') # Adjusted expectation | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Shopping List Page', type: :feature do | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:inventory) { FactoryBot.create(:inventory, user:, name: 'Sample Inventory') } | ||
let(:recipe) { FactoryBot.create(:recipe, user:, name: 'Sample Recipe') } | ||
let(:missing_foods) { [] } | ||
|
||
before do | ||
login_as(user) | ||
bread = FactoryBot.create(:food, name: 'Bread', price: 2.5) | ||
milk = FactoryBot.create(:food, name: 'Milk', price: 3.5) | ||
recipe.recipe_foods.create(food: bread, quantity: 1) | ||
recipe.recipe_foods.create(food: milk, quantity: 2) | ||
|
||
visit shopping_list_path(recipe_id: recipe.id, inventory_id: inventory.id, selected_inventory_id: inventory.id) | ||
end | ||
|
||
def calculate_missing_foods | ||
recipe.recipe_foods.each do |recipe_food| | ||
missing_quantity = recipe_food.quantity - inventory.inventory_foods.where(food: recipe_food.food).sum(:quantity) | ||
missing_foods << { food: recipe_food.food, quantity_needed: missing_quantity } if missing_quantity.positive? | ||
end | ||
end | ||
|
||
scenario 'User views the shopping list details' do | ||
# Calculate the missing foods | ||
calculate_missing_foods | ||
|
||
# Assertions to check the content of the page | ||
expect(page).to have_content('Shopping List') | ||
expect(page).to have_content('Amount of food to buy: 2') | ||
expect(page).to have_link('Sample Recipe', href: recipe_path(recipe)) | ||
expect(page).to have_content('Total value of food needed: $9.5') | ||
expect(page).to have_link('Sample Inventory', href: inventory_path(inventory)) | ||
|
||
within('table') do | ||
expect(page).to have_content('Bread') | ||
expect(page).to have_content('1') | ||
expect(page).to have_content('$2.5') | ||
expect(page).to have_content('Milk') | ||
expect(page).to have_content('2') | ||
expect(page).to have_content('$7.0') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# spec/features/shopping_list_spec.rb | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.feature 'Shopping List Page', type: :feature do | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:inventory) { FactoryBot.create(:inventory, user:, name: 'Sample Inventory') } | ||
let(:recipe) { FactoryBot.create(:recipe, user:, name: 'Sample Recipe') } | ||
let(:missing_foods) { [] } | ||
|
||
before do | ||
login_as(user) | ||
|
||
# Create two missing foods | ||
bread = FactoryBot.create(:food, name: 'Bread', price: 2.5) | ||
milk = FactoryBot.create(:food, name: 'Milk', price: 3.5) | ||
|
||
recipe.recipe_foods.create(food: bread, quantity: 1) | ||
recipe.recipe_foods.create(food: milk, quantity: 2) | ||
|
||
# Calculate the missing foods | ||
recipe.recipe_foods.each do |recipe_food| | ||
missing_quantity = recipe_food.quantity - inventory.inventory_foods.where(food: recipe_food.food).sum(:quantity) | ||
missing_foods << { food: recipe_food.food, quantity_needed: missing_quantity } if missing_quantity.positive? | ||
end | ||
|
||
visit shopping_list_path(recipe_id: recipe.id, inventory_id: inventory.id, selected_inventory_id: inventory.id) | ||
end | ||
|
||
scenario 'User views the shopping list details' do | ||
# Assertions to check the content of the page | ||
expect(page).to have_content('Shopping List') | ||
expect(page).to have_content("Amount of food to buy: #{missing_foods.count}") | ||
expect(page).to have_link('Sample Recipe', href: recipe_path(recipe)) | ||
# Calculate the total value of food needed | ||
total_value = missing_foods.map do |missing_food| | ||
missing_food[:food].price * missing_food[:quantity_needed] | ||
end.sum.to_f | ||
expect(page).to have_content("Total value of food needed: $#{total_value}") | ||
|
||
expect(page).to have_link('Sample Inventory', href: inventory_path(inventory)) | ||
within('table') do | ||
expect(page).to have_content('Bread') | ||
expect(page).to have_content('1') | ||
expect(page).to have_content('$2.5') | ||
|
||
expect(page).to have_content('Milk') | ||
expect(page).to have_content('2') | ||
expect(page).to have_content('$7.0') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters