Skip to content

Commit

Permalink
fixed tests, added cuprite
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Nov 13, 2023
1 parent 536b2ce commit 4ec0f5a
Show file tree
Hide file tree
Showing 29 changed files with 250 additions and 162 deletions.
48 changes: 18 additions & 30 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,49 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'jsbundling-rails'
gem "propshaft"
gem 'cssbundling-rails'
gem 'view_component'
gem 'airbrake'
gem 'amazing_print'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'cancancan'
gem 'chartkick'
gem 'cssbundling-rails'
gem 'data_migrate'
gem 'delayed_job', '~> 4.1.0'
gem 'delayed_job_active_record'
gem 'devise'
gem 'directo', github: 'internetee/directo', branch: 'master'
gem 'faker'
gem 'faraday'
gem 'freezolite', require: false
gem 'hotwire-rails', '~> 0.1.3'
gem 'jbuilder', '~> 2.11'
gem 'jsbundling-rails'
gem 'jwt'
gem 'lograge'
gem 'mimemagic', '~> 0.4.3'
gem 'money'
gem 'noticed', '~> 1.6'
gem 'okcomputer', '~> 1.18.4'
gem 'omniauth-rails_csrf_protection'
gem 'omniauth-tara', github: 'internetee/omniauth-tara'
gem 'pagy', '~> 6.0'
gem 'pdfkit'
gem 'pg', '>= 0.18', '< 2.0'
gem 'pg_search'
gem 'propshaft'
gem 'puma', '~> 5.6.7'
gem 'rails', '>= 6.0.3.5'
gem 'rails-i18n'
gem 'recaptcha'
gem 'redis', '~> 5.0'
gem 'ruby-openai'
gem 'scenic'
gem 'simpleidn'
gem 'skylight'
gem 'turbo-rails'
gem 'webpush'
gem 'valvat'

gem 'jwt'
gem 'view_component'
gem 'webpush'

group :development, :test do
gem 'bullet'
Expand All @@ -51,37 +57,19 @@ group :development, :test do
end

group :development do
gem 'htmlbeautifier'
gem 'i18n-debug'
gem 'letter_opener', '~> 1.8'
gem 'listen', '>= 3.0.5', '< 3.9'
gem 'ruby-lsp-rails'
gem 'web-console', '>= 3.3.0'
gem 'htmlbeautifier'
gem "ruby-lsp-rails"
gem 'letter_opener', '~> 1.8'
end

group :test do
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
gem 'cuprite'
# gem 'selenium-webdriver'
gem 'simplecov', '~> 0.10', '< 0.18', require: false
gem 'spy'
gem 'webmock'
end

# frontend
gem 'hotwire-rails', '~> 0.1.3'
# Use Redis for Action Cable

# gem 'redis', '~> 5.0'
gem 'redis', '~> 5.0'

# For search
gem 'pg_search'

# For pagination
gem 'pagy', '~> 6.0'

# For mock username
gem 'faker'

gem 'noticed', '~> 1.6'
gem "freezolite", require: false
17 changes: 10 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ GEM
crass (1.0.6)
cssbundling-rails (1.2.0)
railties (>= 6.0.0)
cuprite (0.14.3)
capybara (~> 3.0)
ferrum (~> 0.13.0)
data_migrate (9.1.0)
activerecord (>= 6.0)
railties (>= 6.0)
Expand Down Expand Up @@ -152,6 +155,11 @@ GEM
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (3.0.2)
ferrum (0.13)
addressable (~> 2.5)
concurrent-ruby (~> 1.1)
webrick (~> 1.7)
websocket-driver (>= 0.6, < 0.8)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
Expand Down Expand Up @@ -378,14 +386,9 @@ GEM
faraday-multipart (>= 1)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
scenic (1.7.0)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
simplecov (0.17.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand Down Expand Up @@ -447,7 +450,7 @@ GEM
webpush (1.1.0)
hkdf (~> 0.2)
jwt (~> 2.0)
websocket (1.2.9)
webrick (1.8.1)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -468,6 +471,7 @@ DEPENDENCIES
capybara (>= 2.15)
chartkick
cssbundling-rails
cuprite
data_migrate
delayed_job (~> 4.1.0)
delayed_job_active_record
Expand Down Expand Up @@ -506,7 +510,6 @@ DEPENDENCIES
ruby-lsp-rails
ruby-openai
scenic
selenium-webdriver
simplecov (~> 0.10, < 0.18)
simpleidn
skylight
Expand Down
4 changes: 0 additions & 4 deletions app/assets/builds/application.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/assets/builds/application.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/controllers/english_offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def create
else
@show_checkbox_recaptcha = true unless @success
flash.now[:alert] = t('english_offers.form.captcha_verification')

redirect_to root_path, status: :see_other
end
end
Expand Down Expand Up @@ -151,7 +152,7 @@ def additional_check_for_bids(auction, current_bid)
end

def create_predicate(auction)
@offer.save! && auction.update_minimum_bid_step(create_params[:price].to_f) && @offer.reload
@offer.save && auction.update_minimum_bid_step(create_params[:price].to_f) && @offer.reload
end

def create_params
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/invoices_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ def fetch_errors_from_response(channel:, response:)
return 'OK' if response['transaction_result'] == 'completed'

fetch_everypay_errors(response)
# when 'SEB', 'LHV', 'Swedbank'
# fetch_banklink_errors(response)
end
end

Expand Down
3 changes: 0 additions & 3 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ def participant
can %i[read create update delete], Autobider, user_id: user.id

if user.banned?
puts '---- HERE ?'
restrictions_from_bans
elsif user.not_phone_number_confirmed_unique?
puts '---- or HERE ?'
phone_not_unique_restrictions
else
puts '------ or maybe HERE?'
no_restrictions_on_offers_and_users
end
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/concerns/auction/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ def search(params = {}, current_user = nil)
sort_direction = params[:direction].presence_in(%w[asc desc]) || 'desc'
is_from_admin = params[:admin] == 'true'

puts '---------'
puts params
puts '---------'

query =
with_highest_offers
.with_domain_name(params[:domain_name])
Expand Down
48 changes: 24 additions & 24 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class Notification < ApplicationRecord
include Noticed::Model
belongs_to :recipient, polymorphic: true

after_create_commit :broadcast_to_bell
after_create_commit :broadcast_to_recipient
# after_create_commit :broadcast_to_bell
# after_create_commit :broadcast_to_recipient

def self.notify
subscriptions = WebpushSubscription.all
Expand All @@ -30,27 +30,27 @@ def self.notify
end
end

def broadcast_to_recipient
broadcast_append_later_to(
recipient,
:notifications,
target: 'notifications-list',
partial: 'notifications/notification',
locals: {
notification: self
}
)
end
# def broadcast_to_recipient
# broadcast_append_later_to(
# recipient,
# :notifications,
# target: 'notifications-list',
# partial: 'notifications/notification',
# locals: {
# notification: self
# }
# )
# end

def broadcast_to_bell
broadcast_update_later_to(
recipient,
:notifications,
target: 'bell-broadcast',
partial: 'notifications/bell',
locals: {
any_unread: true
}
)
end
# def broadcast_to_bell
# broadcast_update_later_to(
# recipient,
# :notifications,
# target: 'bell-broadcast',
# partial: 'notifications/bell',
# locals: {
# any_unread: true
# }
# )
# end
end
13 changes: 5 additions & 8 deletions app/services/admin_bulk_action_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ def initialize(auction_elements:)
end

def self.apply_for_english_auction(auction_elements:)
admin_handler = new(auction_elements: auction_elements)

puts '---- DD --- CC --- SS'
puts auction_elements
puts '--- DD -- ZZ -- ERE -'
admin_handler = new(auction_elements:)

admin_handler.apply_english_auction
end
Expand All @@ -35,9 +31,10 @@ def apply_english_auction
wishlists = WishlistItem.where(domain_name: auction.domain_name)
wishlists.each do |wishlist|
Autobider.create(
user_id: wishlist.user_id,
domain_name: wishlist.domain_name,
cents: wishlist.cents
user_id: wishlist.user_id,
domain_name: wishlist.domain_name,
cents: wishlist.cents,
enable: true
)
end

Expand Down
60 changes: 48 additions & 12 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,59 @@
require 'test_helper'
require 'support/semantic_ui_helper'
require 'selenium/webdriver'
require 'support/cuprite_helpers'

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include Devise::Test::IntegrationHelpers
include CupriteHelpers

include SemanticUiHelper
# driven_by :headless_chrome
driven_by :rack_test

Capybara.register_driver(:headless_chrome) do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1400,1400')
options.add_argument('--disable-dev-shm-usage')
# Usually, especially when using Selenium, developers tend to increase the max wait time.
# With Cuprite, there is no need for that.
# We use a Capybara default value here explicitly.
Capybara.default_max_wait_time = 2

Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
# Normalize whitespaces when using `has_text?` and similar matchers,
# i.e., ignore newlines, trailing spaces, etc.
# That makes tests less dependent on slightly UI changes.
Capybara.default_normalize_ws = true

# Where to store system tests artifacts (e.g. screenshots, downloaded files, etc.).
# It could be useful to be able to configure this path from the outside (e.g., on CI).
Capybara.save_path = ENV.fetch("CAPYBARA_ARTIFACTS", "./tmp/capybara")

Capybara.singleton_class.prepend(Module.new do
attr_accessor :last_used_session

driven_by :headless_chrome
def using_session(name, &block)
self.last_used_session = name
super
ensure
self.last_used_session = nil
end
end)

Capybara.register_driver(:better_cuprite) do |app|
Capybara::Cuprite::Driver.new(
app,
**{
window_size: [1200, 800],
# See additional options for Dockerized environment in the respective section of this article
browser_options: {},
# Increase Chrome startup wait time (required for stable CI builds)
process_timeout: 10,
# Enable debugging capabilities
inspector: true,
# Allow running Chrome in a headful mode by setting HEADLESS env
# var to a falsey value
headless: !ENV["HEADLESS"].in?(%w[n 0 no false])
}
)
end

# Configure Capybara to use :better_cuprite driver by default
Capybara.default_driver = Capybara.javascript_driver = :better_cuprite

Capybara.server = :puma, { Silent: true }

private
Expand Down
2 changes: 1 addition & 1 deletion test/channel/auction_bidding_perfomance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_update_list_broadcast_should_be_in_queue

Turbo::StreamsChannel.broadcast_render_later_to("auctions",
template: "auctions/streams/updated_list",
locals: { auction: @auction }
locals: { auction: @auction, user: @user, updated: false }
)

assert_enqueued_jobs 1
Expand Down
Loading

0 comments on commit 4ec0f5a

Please sign in to comment.