Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszreszke committed Jul 31, 2024
1 parent 4651992 commit 3c86340
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 94 deletions.
30 changes: 18 additions & 12 deletions rails_application/test/availability/update_availability_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

9 changes: 7 additions & 2 deletions rails_application/test/client_authentication/create_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
19 changes: 15 additions & 4 deletions rails_application/test/client_authentication/set_password_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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

Expand Down
51 changes: 30 additions & 21 deletions rails_application/test/integration/client_orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
13 changes: 9 additions & 4 deletions rails_application/test/integration/customers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rails_application/test/integration/discount_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def apply_discount_10_percent(order_id)
follow_redirect!
assert_select("td", "$123.30")
end
end

end
23 changes: 17 additions & 6 deletions rails_application/test/integration/login_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "test_helper"

class LoginTest < InMemoryRESIntegrationTestCase

def setup
super
Customers::Customer.destroy_all
Expand 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?
Expand All @@ -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
Expand Down
Loading

0 comments on commit 3c86340

Please sign in to comment.