Skip to content

Commit

Permalink
travis and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buzuloiu committed Jun 4, 2019
1 parent 7e4b52d commit cf6d246
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 40 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: ruby
rvm: 2.6.0

services:
- postgresql


script:
- RAILS_ENV=test bundle exec rake db:schema:load --trace
- bundle exec rake test

before_script:
- cp config/database.yml.travis config/database.yml
- psql -c 'create database travis_ci_test' -U postgres
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ group :development, :test do
gem 'database_cleaner'
gem 'figaro'
gem 'pry'
gem 'graphiql-rails'
gem 'graphiql-rails'
end

group :development do
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Shopify Summer 2019 Application

![CI Status](https://travis-ci.org/buzuloiu/shopify-2019.svg?branch=master)
[![codecov](https://codecov.io/gh/buzuloiu/shopify-2019/branch/master/graph/badge.svg)](https://codecov.io/gh/buzuloiu/shopify-2019)

Welcome to my basic online store!

## Overview
Expand Down
16 changes: 4 additions & 12 deletions test/controllers/carts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,28 @@ class CartsControllerTest < ActionDispatch::IntegrationTest
end

test "should get index" do
get carts_url, as: :json
get api_v1_carts_url, as: :json
assert_response :success
end

test "should create cart" do
assert_difference('Cart.count') do
post carts_url, params: { cart: { completed_at: @cart.completed_at, total: @cart.total } }, as: :json
post api_v1_carts_url, params: { cart: { completed_at: @cart.completed_at, total_cents: @cart.total_cents } }, as: :json
end

assert_response 201
end

test "should show cart" do
get cart_url(@cart), as: :json
get api_v1_cart_url(@cart), as: :json
assert_response :success
end

test "should update cart" do
patch cart_url(@cart), params: { cart: { completed_at: @cart.completed_at, total: @cart.total } }, as: :json
post api_v1_cart_url(@cart), params: { cart: { completed_at: @cart.completed_at, total_cents: @cart.total_cents } }, as: :json
assert_response 200
end

test "should destroy cart" do
assert_difference('Cart.count', -1) do
delete cart_url(@cart), as: :json
end

assert_response 204
end

test "should not complete completed cart" do
end

Expand Down
10 changes: 5 additions & 5 deletions test/controllers/line_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ class LineItemsControllerTest < ActionDispatch::IntegrationTest
end

test "should get index" do
get line_items_url, as: :json
get api_v1_line_items_url, as: :json
assert_response :success
end

test "should create line_item" do
assert_difference('LineItem.count') do
post line_items_url, params: { line_item: { cart_id: @line_item.cart_id, product_id: @line_item.product_id, quantity: @line_item.quantity, total_price: @line_item.total_price } }, as: :json
post api_v1_line_items_url, params: { line_item: { cart_id: @line_item.cart_id, product_id: @line_item.product_id, quantity: @line_item.quantity, total_price: @line_item.total_price_cents } }, as: :json
end

assert_response 201
end

test "should show line_item" do
get line_item_url(@line_item), as: :json
get api_v1_line_item_url(@line_item), as: :json
assert_response :success
end

test "should update line_item" do
patch line_item_url(@line_item), params: { line_item: { cart_id: @line_item.cart_id, product_id: @line_item.product_id, quantity: @line_item.quantity, total_price: @line_item.total_price } }, as: :json
patch api_v1_line_item_url(@line_item), params: { line_item: { cart_id: @line_item.cart_id, product_id: @line_item.product_id, quantity: @line_item.quantity, total_price: @line_item.total_price_cents } }, as: :json
assert_response 200
end

test "should destroy line_item" do
assert_difference('LineItem.count', -1) do
delete line_item_url(@line_item), as: :json
delete api_v1_line_item_url(@line_item), as: :json
end

assert_response 204
Expand Down
20 changes: 7 additions & 13 deletions test/controllers/products_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,40 @@ class ProductsControllerTest < ActionDispatch::IntegrationTest
end

test "should get index" do
get products_url, as: :json
get api_v1_products_url, as: :json
assert_response :success
end

test "should create product" do
assert_difference('Product.count') do
post products_url, params: { product: { inventory_count: @product.inventory_count, price: @product.price, title: @product.title } }, as: :json
post api_v1_products_url, params: { product: { inventory_count: @product.inventory_count, price: @product.price_cents, title: @product.title } }, as: :json
end

assert_response 201
end

test "should show product" do
get product_url(@product), as: :json
get api_v1_product_url(@product), as: :json
assert_response :success
end

test "should update product" do
patch product_url(@product), params: { product: { inventory_count: @product.inventory_count, price: @product.price, title: @product.title } }, as: :json
put api_v1_product_url(@product), params: { product: { inventory_count: @product.inventory_count, price: @product.price_cents, title: @product.title } }, as: :json
assert_response 200
end

test "should destroy product" do
assert_difference('Product.count', -1) do
delete product_url(@product), as: :json
end

assert_response 204
end

test "should purchase product" do

put api_v1_product_purchase_url(@product), params: { product: { inventory_count: @product.inventory_count, price: @product.price_cents, title: @product.title } }, as: :json
assert_response 200
end

test "should not purchase out of stock item" do

end

test "should only show in stock products" do
get products_url, params: {qty_available: 0}, as: :json
get api_v1_products_url, params: {qty_available: 1}, as: :json
assert_response :success
end

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/carts.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
total: 1
total_cents: 1
completed_at: 2019-01-10 15:40:45

two:
total: 1
total_cents: 1
completed_at: 2019-01-10 15:40:45
4 changes: 2 additions & 2 deletions test/fixtures/line_items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ one:
product: one
cart: one
quantity: 1
total_price: 1
total_price_cents: 1

two:
product: two
cart: two
quantity: 1
total_price: 1
total_price_cents: 1
12 changes: 7 additions & 5 deletions test/fixtures/products.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

one:
title: MyString
price: 1
inventory_count: 1
price_cents: 239
inventory_count: 4
price_currency: USD

two:
title: MyString
price: 1
inventory_count: 1
title: MyString2
price_cents: 23
inventory_count: 3
price_currency: USD

0 comments on commit cf6d246

Please sign in to comment.