From 3c863402d74013376c0f0dfe826811d5e9d77a06 Mon Sep 17 00:00:00 2001 From: lukaszreszke Date: Wed, 31 Jul 2024 15:03:31 +0200 Subject: [PATCH] prettier --- .../availability/update_availability_test.rb | 30 ++++---- .../test/client_authentication/create_test.rb | 9 ++- .../set_password_test.rb | 19 +++-- .../test/integration/client_orders_test.rb | 51 ++++++++------ .../test/integration/customers_test.rb | 13 ++-- .../test/integration/discount_test.rb | 2 +- .../test/integration/login_test.rb | 23 ++++-- .../test/integration/orders_test.rb | 70 ++++++++++++------- .../test/integration/products_test.rb | 29 ++++---- .../test/integration/public_offer_test.rb | 9 ++- 10 files changed, 161 insertions(+), 94 deletions(-) diff --git a/rails_application/test/availability/update_availability_test.rb b/rails_application/test/availability/update_availability_test.rb index 2b0438c7f..5bc8f9c99 100644 --- a/rails_application/test/availability/update_availability_test.rb +++ b/rails_application/test/availability/update_availability_test.rb @@ -8,11 +8,25 @@ def test_availability_updates product_id = SecureRandom.uuid prepare_product(product_id) - event_store.publish(Inventory::AvailabilityChanged.new(data: { product_id: product_id, available: 0 })) + event_store.publish( + Inventory::AvailabilityChanged.new( + data: { + product_id: product_id, + available: 0 + } + ) + ) refute Availability.approximately_available?(product_id, 1) - event_store.publish(Inventory::AvailabilityChanged.new(data: { product_id: product_id, available: 1 })) + event_store.publish( + Inventory::AvailabilityChanged.new( + data: { + product_id: product_id, + available: 1 + } + ) + ) assert Availability.approximately_available?(product_id, 1) end @@ -23,19 +37,11 @@ def event_store end def prepare_product(product_id) + run_command(ProductCatalog::RegisterProduct.new(product_id: product_id)) run_command( - ProductCatalog::RegisterProduct.new( - product_id: product_id, - ) - ) - run_command( - ProductCatalog::NameProduct.new( - product_id: product_id, - name: "test" - ) + ProductCatalog::NameProduct.new(product_id: product_id, name: "test") ) run_command(Pricing::SetPrice.new(product_id: product_id, price: 50)) end end end - diff --git a/rails_application/test/client_authentication/create_test.rb b/rails_application/test/client_authentication/create_test.rb index aaad46ae4..ce8023e17 100644 --- a/rails_application/test/client_authentication/create_test.rb +++ b/rails_application/test/client_authentication/create_test.rb @@ -19,7 +19,10 @@ def test_set_create register_customer(customer_id) run_command( - Authentication::ConnectAccountToClient.new(account_id: account_id, client_id: customer_id) + Authentication::ConnectAccountToClient.new( + account_id: account_id, + client_id: customer_id + ) ) customer = Account.find_by(client_id: customer_id, account_id: account_id) @@ -29,7 +32,9 @@ def test_set_create private def register_customer(customer_id) - run_command(Crm::RegisterCustomer.new(customer_id: customer_id, name: "John Doe")) + run_command( + Crm::RegisterCustomer.new(customer_id: customer_id, name: "John Doe") + ) end def event_store diff --git a/rails_application/test/client_authentication/set_password_test.rb b/rails_application/test/client_authentication/set_password_test.rb index 10aaec1c5..6f048d973 100644 --- a/rails_application/test/client_authentication/set_password_test.rb +++ b/rails_application/test/client_authentication/set_password_test.rb @@ -19,7 +19,10 @@ def test_set_password connect_to_account(customer_id, account_id) run_command( - Authentication::SetPasswordHash.new(account_id: account_id, password_hash: password_hash) + Authentication::SetPasswordHash.new( + account_id: account_id, + password_hash: password_hash + ) ) account = Account.find_by(client_id: customer_id, account_id: account_id) @@ -34,7 +37,10 @@ def test_set_password_then_connect_account register_customer(customer_id) run_command( - Authentication::SetPasswordHash.new(account_id: account_id, password_hash: password_hash) + Authentication::SetPasswordHash.new( + account_id: account_id, + password_hash: password_hash + ) ) connect_to_account(customer_id, account_id) @@ -45,12 +51,17 @@ def test_set_password_then_connect_account private def register_customer(customer_id) - run_command(Crm::RegisterCustomer.new(customer_id: customer_id, name: "John Doe")) + run_command( + Crm::RegisterCustomer.new(customer_id: customer_id, name: "John Doe") + ) end def connect_to_account(customer_id, account_id) run_command( - Authentication::ConnectAccountToClient.new(account_id: account_id, client_id: customer_id) + Authentication::ConnectAccountToClient.new( + account_id: account_id, + client_id: customer_id + ) ) end diff --git a/rails_application/test/integration/client_orders_test.rb b/rails_application/test/integration/client_orders_test.rb index 044ff8422..d2ea08c1c 100644 --- a/rails_application/test/integration/client_orders_test.rb +++ b/rails_application/test/integration/client_orders_test.rb @@ -12,7 +12,7 @@ def setup end def test_happy_path - arkency_id = register_customer('Arkency') + arkency_id = register_customer("Arkency") async_remote_id = register_product("Async Remote", 39, 10) fearless_id = register_product("Fearless Refactoring", 49, 10) @@ -28,12 +28,19 @@ def test_happy_path 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) + 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) + order_price = + number_to_currency(Orders::Order.find_by(uid: order_id).discounted_value) assert_select("td", "Submitted") assert_select("td", order_price) @@ -54,7 +61,7 @@ def test_happy_path end def test_creating_order_as_client - arkency_id = register_customer('Arkency') + arkency_id = register_customer("Arkency") async_remote_id = register_product("Async Remote", 39, 10) get "/clients" @@ -64,7 +71,8 @@ def test_creating_order_as_client 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) + order_price = + number_to_currency(Orders::Order.find_by(uid: order_id).discounted_value) assert_select("td", "Submitted") assert_select("td", order_price) end @@ -102,7 +110,7 @@ def test_adding_the_same_product_twice_bug end def test_adding_product_which_is_not_available_anymore - customer_1_id = register_customer('Arkency') + customer_1_id = register_customer("Arkency") customer_2_id = register_customer("Customer Shop") product_id = register_product("Fearless Refactoring", 4, 10) @@ -121,8 +129,11 @@ def test_adding_product_which_is_not_available_anymore 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] + 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 @@ -167,7 +178,7 @@ def cancel_order(order_id) def cancel_submitted_order_for_customer(customer_id) order_id = SecureRandom.uuid - anti_if = register_product('Anti If', 99, 10) + 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) @@ -184,24 +195,22 @@ def order_and_pay(customer_id, order_id, *product_ids) 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 + 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, - } + params: { + "authenticity_token" => "[FILTERED]", + "product_id" => product_id, + :price => new_price + } end def login_as(client_id) - open_session do |sess| - sess.post "/login", params: { client_id: client_id } - end + open_session { |sess| sess.post "/login", params: { client_id: client_id } } end end diff --git a/rails_application/test/integration/customers_test.rb b/rails_application/test/integration/customers_test.rb index 0d232120a..3b5d39c01 100644 --- a/rails_application/test/integration/customers_test.rb +++ b/rails_application/test/integration/customers_test.rb @@ -66,9 +66,9 @@ def order_and_pay(customer_id, order_id, *product_ids) end def assert_customer_summary(customer_name, summary) - assert_select 'tr' do - assert_select 'td:nth-child(1)', customer_name - assert_select 'td:nth-child(3)', summary + assert_select "tr" do + assert_select "td:nth-child(1)", customer_name + assert_select "td:nth-child(3)", summary end end @@ -79,7 +79,12 @@ def assert_customer_details(customer_name, vip_status) assert_select "dd", vip_status end - def assert_customer_orders_table(order_number, order_state, order_discounted_value, paid_orders_summary) + def assert_customer_orders_table( + order_number, + order_state, + order_discounted_value, + paid_orders_summary + ) assert_select "table" do assert_select "tbody" do assert_select "tr" do diff --git a/rails_application/test/integration/discount_test.rb b/rails_application/test/integration/discount_test.rb index 7393aa11c..f659851ea 100644 --- a/rails_application/test/integration/discount_test.rb +++ b/rails_application/test/integration/discount_test.rb @@ -42,5 +42,5 @@ def apply_discount_10_percent(order_id) follow_redirect! assert_select("td", "$123.30") end +end -end \ No newline at end of file diff --git a/rails_application/test/integration/login_test.rb b/rails_application/test/integration/login_test.rb index 2fbb87628..05aa223b5 100644 --- a/rails_application/test/integration/login_test.rb +++ b/rails_application/test/integration/login_test.rb @@ -1,7 +1,6 @@ require "test_helper" class LoginTest < InMemoryRESIntegrationTestCase - def setup super Customers::Customer.destroy_all @@ -19,13 +18,16 @@ def test_login 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" } + post "/login", + params: { + client_id: customer_id, + password: "Wrong password" + } follow_redirect! refute cookies["client_id"].present? @@ -49,9 +51,18 @@ def set_password(customer_id, password) 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)) - Sidekiq::Job.drain_all + 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 diff --git a/rails_application/test/integration/orders_test.rb b/rails_application/test/integration/orders_test.rb index 2c5ee8c9d..7c6b272d7 100644 --- a/rails_application/test/integration/orders_test.rb +++ b/rails_application/test/integration/orders_test.rb @@ -1,7 +1,6 @@ require "test_helper" class OrdersTest < InMemoryRESIntegrationTestCase - def setup super Rails.configuration.payment_gateway.call.reset @@ -32,7 +31,7 @@ def test_happy_path another_order_id = SecureRandom.uuid async_remote_id = register_product("Async Remote", 39, 10) - fearless_id = register_product("Fearless Refactoring", 49, 10) + fearless_id = register_product("Fearless Refactoring", 49, 10) post "/orders", params: { @@ -188,10 +187,10 @@ def test_order_value_doesnt_change_after_changing_price def test_discount_is_applied_for_new_order order_id = SecureRandom.uuid async_remote_id = register_product("Async Remote", 39, 10) - fearless_id = register_product("Fearless Refactoring", 49, 10) + fearless_id = register_product("Fearless Refactoring", 49, 10) shopify_id = register_customer("Shopify") - assert_nothing_raised { apply_discount_10_percent(order_id)} + assert_nothing_raised { apply_discount_10_percent(order_id) } post "/orders/#{order_id}/add_item?product_id=#{async_remote_id}" post "/orders/#{order_id}/add_item?product_id=#{fearless_id}" @@ -213,19 +212,31 @@ def test_discount_is_applied_for_new_order private def assert_remove_buttons_visible(async_remote_id, fearless_id, order_id) - assert_match(/#{Regexp.escape(remove_item_order_path(id: order_id, product_id: async_remote_id))}/, response.body) - assert_match(/#{Regexp.escape(remove_item_order_path(id: order_id, product_id: fearless_id))}/, response.body) + assert_match( + /#{Regexp.escape(remove_item_order_path(id: order_id, product_id: async_remote_id))}/, + response.body + ) + assert_match( + /#{Regexp.escape(remove_item_order_path(id: order_id, product_id: fearless_id))}/, + response.body + ) end def assert_remove_buttons_not_visible(async_remote_id, fearless_id) url = request.original_url uri = URI.parse(url) puts uri.query - path_components = uri.path.split('/') + path_components = uri.path.split("/") order_uuid = path_components[-2] - assert_no_match(/#{Regexp.escape(remove_item_order_path(id: order_uuid, product_id: async_remote_id))}/, response.body) - assert_no_match(/#{Regexp.escape(remove_item_order_path(id: order_uuid, product_id: fearless_id))}/, response.body) + assert_no_match( + /#{Regexp.escape(remove_item_order_path(id: order_uuid, product_id: async_remote_id))}/, + response.body + ) + assert_no_match( + /#{Regexp.escape(remove_item_order_path(id: order_uuid, product_id: fearless_id))}/, + response.body + ) end def verify_shipping(order_id) @@ -234,14 +245,15 @@ def verify_shipping(order_id) assert_select("a", "Add shipment address") get "/orders/#{order_id}/shipping_address/edit" assert_select("label", "Addressee's full name (Person or Company)") - put "/orders/#{order_id}/shipping_address", params: { - "shipments_shipment" => { - address_line_1: "123 Main Street", - address_line_2: "Apt 1", - address_line_3: "San Francisco", - address_line_4: "US", - } - } + put "/orders/#{order_id}/shipping_address", + params: { + "shipments_shipment" => { + address_line_1: "123 Main Street", + address_line_2: "Apt 1", + address_line_3: "San Francisco", + address_line_4: "US" + } + } Shipments::SetShippingAddress.drain follow_redirect! assert_select("dd", "Your shipment has been queued for processing.") @@ -254,14 +266,15 @@ def verify_invoice_generation(order_id) assert_select("a", "Add billing address") get "/orders/#{order_id}/billing_address/edit" assert_select("label", "Addressee's full name (Person or Company)") - put "/orders/#{order_id}/billing_address", params: { - "invoices_invoice" => { - address_line_1: "44 Main Street", - address_line_2: "Apt 2", - address_line_3: "Francisco", - address_line_4: "UK", - } - } + put "/orders/#{order_id}/billing_address", + params: { + "invoices_invoice" => { + address_line_1: "44 Main Street", + address_line_2: "Apt 2", + address_line_3: "Francisco", + address_line_4: "UK" + } + } follow_redirect! assert_select("button", "Issue now") post "/orders/#{order_id}/invoice" @@ -275,12 +288,15 @@ def verify_invoice_generation(order_id) assert_select("td", "2") assert_select("td", "$88.20") assert_select("td", "$123.30") - end def assert_res_browser_order_history get "/res/api/streams/Orders%24all/relationships/events" - event_names = JSON.load(body).fetch("data").map { |data| data.fetch("attributes").fetch("event_type") } + event_names = + JSON + .load(body) + .fetch("data") + .map { |data| data.fetch("attributes").fetch("event_type") } assert(event_names.include?("Fulfillment::OrderConfirmed")) assert(event_names.include?("Ordering::ItemAddedToBasket")) diff --git a/rails_application/test/integration/products_test.rb b/rails_application/test/integration/products_test.rb index 096371166..55f6e1125 100644 --- a/rails_application/test/integration/products_test.rb +++ b/rails_application/test/integration/products_test.rb @@ -18,26 +18,31 @@ def test_happy_path "authenticity_token" => "[FILTERED]", "product_id" => product_id, "name" => "product name", - price: "20.01", + :price => "20.01", "vat_rate" => "10" } follow_redirect! - - Sidekiq::Job.drain_all - assert_equal "20.01", number_to_currency(Products::Product.find(product_id).price, unit: "") + assert_equal "20.01", + number_to_currency( + Products::Product.find(product_id).price, + unit: "" + ) assert_select "h1", "Products" get "/products/#{product_id}/edit" patch "/products/#{product_id}", - params: { - "authenticity_token" => "[FILTERED]", - "product_id" => product_id, - price: "20.02", - } - - Sidekiq::Job.drain_all - assert_equal "20.02", number_to_currency(Products::Product.find(product_id).price, unit: "") + params: { + "authenticity_token" => "[FILTERED]", + "product_id" => product_id, + :price => "20.02" + } + + assert_equal "20.02", + number_to_currency( + Products::Product.find(product_id).price, + unit: "" + ) end end diff --git a/rails_application/test/integration/public_offer_test.rb b/rails_application/test/integration/public_offer_test.rb index 3ec3fcbff..dd8f0281e 100644 --- a/rails_application/test/integration/public_offer_test.rb +++ b/rails_application/test/integration/public_offer_test.rb @@ -1,13 +1,12 @@ require "test_helper" class PublicOfferTest < InMemoryRESIntegrationTestCase - def setup super end def test_happy_path - arkency_id = register_customer('Arkency') + arkency_id = register_customer("Arkency") register_product("Async Remote", 39, 10) get "/clients" login(arkency_id) @@ -18,7 +17,7 @@ def test_happy_path end def test_showing_orders_with_information_about_the_lowest_price - client_id = register_customer('Arkency') + 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) @@ -32,7 +31,7 @@ def test_showing_orders_with_information_about_the_lowest_price 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" + assert_equal info_icon.attributes.fetch("title").value, + "Lowest recent price: $25.00" end - end