diff --git a/rails_application/test/integration/client_orders_test.rb b/rails_application/test/integration/client_orders_test.rb deleted file mode 100644 index d2ea08c1..00000000 --- a/rails_application/test/integration/client_orders_test.rb +++ /dev/null @@ -1,216 +0,0 @@ -require_relative "../test_helper" - -class ClientOrdersTests < InMemoryRESIntegrationTestCase - include ActionView::Helpers::NumberHelper - - def setup - super - Rails.configuration.payment_gateway.call.reset - ClientOrders::Client.destroy_all - ClientOrders::Order.destroy_all - Orders::Order.destroy_all - end - - def test_happy_path - arkency_id = register_customer("Arkency") - async_remote_id = register_product("Async Remote", 39, 10) - fearless_id = register_product("Fearless Refactoring", 49, 10) - - get "/clients" - assert_select("button", { count: 0, text: "Log out" }) - assert_select("button", "Login") - assert_select("select", "Arkency") - - login(arkency_id) - assert_select("h1", "Arkency") - assert_select("p", "No orders to display.") - - order_id = SecureRandom.uuid - add_item_to_basket_for_order(async_remote_id, order_id) - get "/client_orders/#{order_id}/edit" - assert_match( - /#{Regexp.escape(remove_item_client_order_path(id: order_id, product_id: async_remote_id))}/, - response.body - ) - assert_no_match( - /#{Regexp.escape(remove_item_client_order_path(id: order_id, product_id: fearless_id))}/, - response.body - ) - - submit_order_for_customer(arkency_id, order_id) - get "/client_orders" - order_price = - number_to_currency(Orders::Order.find_by(uid: order_id).discounted_value) - - assert_select("td", "Submitted") - assert_select("td", order_price) - - pay_order(order_id) - get "/client_orders" - assert_select("td", "Paid") - - cancel_submitted_order_for_customer(arkency_id) - get "/client_orders" - assert_select("td", "Cancelled") - - assert_select("button", "Log out") - get "/logout" - follow_redirect! - assert_select("button", "Login") - assert_select("select", "Arkency") - end - - def test_creating_order_as_client - arkency_id = register_customer("Arkency") - async_remote_id = register_product("Async Remote", 39, 10) - - get "/clients" - login(arkency_id) - order_id = SecureRandom.uuid - get "/client_orders/new" - as_client_add_item_to_basket_for_order(async_remote_id, order_id) - as_client_submit_order_for_customer(order_id) - get "/client_orders" - order_price = - number_to_currency(Orders::Order.find_by(uid: order_id).discounted_value) - assert_select("td", "Submitted") - assert_select("td", order_price) - end - - def test_paid_orders_summary - customer_id = register_customer("Customer Shop") - product_1_id = register_product("Fearless Refactoring", 4, 10) - product_2_id = register_product("Asycn Remote", 3, 10) - - login(customer_id) - visit_client_orders - assert_select "Total paid orders", false - - order_and_pay(customer_id, SecureRandom.uuid, product_1_id, product_2_id) - visit_client_orders - - assert_orders_summary("$7.00") - - order_and_pay(customer_id, SecureRandom.uuid, product_1_id) - visit_client_orders - - assert_orders_summary("$11.00") - end - - def test_adding_the_same_product_twice_bug - customer_id = register_customer("Customer Shop") - product_id = register_product("Fearless Refactoring", 4, 10) - - login(customer_id) - visit_client_orders - - order_id = SecureRandom.uuid - as_client_add_item_to_basket_for_order(product_id, order_id) - as_client_add_item_to_basket_for_order(product_id, order_id) - end - - def test_adding_product_which_is_not_available_anymore - customer_1_id = register_customer("Arkency") - customer_2_id = register_customer("Customer Shop") - product_id = register_product("Fearless Refactoring", 4, 10) - - supply_product(product_id, 1) - session_1 = login_as(customer_1_id) - session_2 = login_as(customer_2_id) - - session_1.get "/client_orders" - session_2.get "/client_orders" - - order_1_id = SecureRandom.uuid - session_1.post "/client_orders/#{order_1_id}/add_item?product_id=#{product_id}" - order_and_pay(customer_1_id, order_1_id, product_id) - - order_2_id = SecureRandom.uuid - session_2.post "/client_orders/#{order_2_id}/add_item?product_id=#{product_id}" - - assert session_2.redirect? - assert session_2.response.location.include?( - "/client_orders/#{order_2_id}/edit" - ) - assert_equal "Product not available in requested quantity!", - session_2.flash[:alert] - end - - def test_adding_product_which_is_not_available_in_requested_quantity - customer_id = register_customer("Customer Shop") - product_id = register_product("Fearless Refactoring", 4, 10) - - supply_product(product_id, 1) - login(customer_id) - visit_client_orders - - order_id = SecureRandom.uuid - as_client_add_item_to_basket_for_order(product_id, order_id) - as_client_add_item_to_basket_for_order(product_id, order_id) - - assert_redirected_to "/client_orders/#{order_id}/edit" - assert_equal "Product not available in requested quantity!", flash[:alert] - end - - private - - def submit_order_for_customer(customer_id, order_id) - post "/orders", params: { order_id: order_id, customer_id: customer_id } - follow_redirect! - end - - def add_item_to_basket_for_order(async_remote_id, order_id) - post "/orders/#{order_id}/add_item?product_id=#{async_remote_id}" - end - - def as_client_submit_order_for_customer(order_id) - post "/client_orders", params: { order_id: order_id } - follow_redirect! - end - - def as_client_add_item_to_basket_for_order(async_remote_id, order_id) - post "/client_orders/#{order_id}/add_item?product_id=#{async_remote_id}" - end - - def cancel_order(order_id) - post "/orders/#{order_id}/cancel" - end - - def cancel_submitted_order_for_customer(customer_id) - order_id = SecureRandom.uuid - anti_if = register_product("Anti If", 99, 10) - - add_item_to_basket_for_order(anti_if, order_id) - add_item_to_basket_for_order(anti_if, order_id) - submit_order_for_customer(customer_id, order_id) - cancel_order(order_id) - end - - def order_and_pay(customer_id, order_id, *product_ids) - product_ids.each do |product_id| - as_client_add_item_to_basket_for_order(product_id, order_id) - end - submit_order_for_customer(customer_id, order_id) - pay_order(order_id) - end - - def assert_orders_summary(summary) - assert_select "tr" do - assert_select "td:nth-child(1)", "Total paid orders" - assert_select "td:nth-child(2)", summary - end - end - - def update_price(product_id, new_price) - patch "/products/#{product_id}", - params: { - "authenticity_token" => "[FILTERED]", - "product_id" => product_id, - :price => new_price - } - end - - def login_as(client_id) - open_session { |sess| sess.post "/login", params: { client_id: client_id } } - end -end diff --git a/rails_application/test/integration/coupons_test.rb b/rails_application/test/integration/coupons_test.rb deleted file mode 100644 index a3de86ce..00000000 --- a/rails_application/test/integration/coupons_test.rb +++ /dev/null @@ -1,36 +0,0 @@ - -require "test_helper" - -class CouponsTest < InMemoryRESIntegrationTestCase - def test_list_coupons - register_coupon("Coupon Number Uno", "enterme", "0.01") - - get "/coupons" - assert_response :success - assert_select("td", "Coupon Number Uno") - assert_select("td", "enterme") - assert_select("td", "0.01") - end - - def test_creation - register_coupon("Coupon Number Two", "fair_price", "6.69") - assert_response :success - assert_select("p", "Coupon was successfully created") - assert_select("td", "Coupon Number Two") - assert_select("td", "fair_price") - assert_select("td", "6.69") - end - - private - - def register_coupon(name, code, discount) - post "/coupons", params: { - coupon_id: SecureRandom.uuid, - name: name, - code: code, - discount: discount - } - - follow_redirect! - end -end diff --git a/rails_application/test/integration/login_test.rb b/rails_application/test/integration/login_test.rb deleted file mode 100644 index 05aa223b..00000000 --- a/rails_application/test/integration/login_test.rb +++ /dev/null @@ -1,70 +0,0 @@ -require "test_helper" - -class LoginTest < InMemoryRESIntegrationTestCase - def setup - super - Customers::Customer.destroy_all - end - - def test_login - password = "1234qwer" - customer_id = register_customer("Arkency") - set_password(customer_id, password) - - post "/login", params: { client_id: customer_id, password: password } - follow_redirect! - - assert_select("h1", "Arkency") - assert_equal customer_id, cookies["client_id"] - end - - def test_login_with_incorrect_password - password = "1234qwer" - customer_id = register_customer("Arkency") - set_password(customer_id, password) - - post "/login", - params: { - client_id: customer_id, - password: "Wrong password" - } - follow_redirect! - - refute cookies["client_id"].present? - end - - def test_cookies_set_to_not_existing_customer_should_log_out_and_redirect_to_login - cookies["client_id"] = "not-existing-customer" - - get "/client_orders" - follow_redirect! - follow_redirect! - - refute cookies["client_id"].present? - assert_equal "/clients", path - end - - private - - def set_password(customer_id, password) - account_id = SecureRandom.uuid - password_hash = Digest::SHA256.hexdigest(password) - - run_command(Authentication::RegisterAccount.new(account_id: account_id)) - run_command( - Authentication::ConnectAccountToClient.new( - account_id: account_id, - client_id: customer_id - ) - ) - run_command( - Authentication::SetPasswordHash.new( - account_id: account_id, - password_hash: password_hash - ) - ) - - cookies["client_id"] = nil - customer_id - end -end diff --git a/rails_application/test/integration/public_offer_test.rb b/rails_application/test/integration/public_offer_test.rb deleted file mode 100644 index dd8f0281..00000000 --- a/rails_application/test/integration/public_offer_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "test_helper" - -class PublicOfferTest < InMemoryRESIntegrationTestCase - def setup - super - end - - def test_happy_path - arkency_id = register_customer("Arkency") - register_product("Async Remote", 39, 10) - get "/clients" - login(arkency_id) - assert_select("a", "Products") - get "/client/products" - assert_select("td", "Async Remote") - assert_select("td", "$39.00") - end - - def test_showing_orders_with_information_about_the_lowest_price - client_id = register_customer("Arkency") - product1_id = register_product("Async Remote", 45, 10) - product2_id = register_product("Rails meets React.js", 50, 10) - update_price(product1_id, 30) - update_price(product2_id, 25) - update_price(product2_id, 70) - - get "/clients" - login(client_id) - get "/client/products" - assert css_select("#lowest-price-info-#{product1_id}").empty? - assert css_select("#lowest-price-info-#{product2_id}").present? - - info_icon = css_select("#lowest-price-info-#{product2_id}").first - assert_equal info_icon.attributes.fetch("title").value, - "Lowest recent price: $25.00" - end -end diff --git a/rails_application/test/integration/time_promotions_test.rb b/rails_application/test/integration/time_promotions_test.rb deleted file mode 100644 index cacbb393..00000000 --- a/rails_application/test/integration/time_promotions_test.rb +++ /dev/null @@ -1,39 +0,0 @@ - -require "test_helper" - -class TimePromotionsTest < InMemoryRESIntegrationTestCase - def test_happy_path - post "/time_promotions", params: { - label: "Last Minute June 2022", - discount: "50", - start_time: "2022-06-30 15:00:00 UTC", - end_time: "2022-07-01 00:00:00 UTC" - } - follow_redirect! - assert_response :success - - assert_select("p", "Time promotion was successfully created") - - post "/time_promotions", params: { - label: "Black Monday July 2022", - discount: "40", - start_time: "2022-07-04 01:00:00 UTC", - end_time: "2022-07-05 00:00:00 UTC" - } - follow_redirect! - assert_response :success - - assert_select("p", "Time promotion was successfully created") - - get "/time_promotions" - assert_select("td", "Last Minute June 2022") - assert_select("td", "50") - assert_select("td", "2022-06-30 15:00:00 UTC") - assert_select("td", "2022-07-01 00:00:00 UTC") - - assert_select("td", "Black Monday July 2022") - assert_select("td", "40") - assert_select("td", "2022-07-04 01:00:00 UTC") - assert_select("td", "2022-07-05 00:00:00 UTC") - end -end