Skip to content

Commit

Permalink
Merge pull request #2709 from internetee/fix-failed-tests
Browse files Browse the repository at this point in the history
fixed tests: updated gems; improve company register status job and te…
  • Loading branch information
OlegPhenomenon authored Nov 13, 2024
2 parents 34e13ff + 292a4fd commit b655d93
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 37 deletions.
88 changes: 79 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,67 @@
FROM internetee/ruby:3.0-buster
FROM --platform=linux/amd64 ruby:3.0.3-slim-buster

# # RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
# RUN apt-get update && apt-get install -y --no-install-recommends \
# git \
# postgresql-client \
# && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN apt-get update > /dev/null && apt-get install -y --no-install-recommends > /dev/null \
build-essential=* \
imagemagick=* \
curl \
wget \
gnupg2 \
git \
apt-utils \
&& apt-get dist-upgrade -yf\
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
RUN sed -i -e 's/# et_EE.UTF-8 UTF-8/et_EE.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=et_EE.UTF-8

ENV LANG et_EE.UTF-8
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc -s | apt-key add -
RUN sh -c 'echo "deb https://apt-archive.postgresql.org/pub/repos/apt bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN apt-get update > /dev/null && apt-get install -y --no-install-recommends > /dev/null \
postgresql-client-13=* \
libpq-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# add repository for Node.js in the LTS version
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -

RUN apt-get install -y --no-install-recommends > /dev/null \
nodejs=* \
qt5-default=* \
libqt5webkit5-dev=* \
gstreamer1.0-plugins-base=* \
libappindicator3-1=* \
gstreamer1.0-tools=* \
qtdeclarative5-dev=* \
fonts-liberation=* \
gstreamer1.0-x=* \
libasound2=* \
libnspr4=* \
libnss3=* \
libxss1=* \
libxtst6=* \
xdg-utils=* \
qtdeclarative5-dev=* \
fonts-liberation=* \
gstreamer1.0-x=* \
wkhtmltopdf \
libxslt1-dev \
libxml2-dev \
python-dev \
unzip \
# libc6-i386 \
# lib32gcc-s1 \
wkhtmltopdf \
xvfb \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN apt-get remove -y google-chrome-stable
RUN apt-get purge -y google-chrome-stable
RUN apt-get autoremove -y && apt-get clean

ENV CHROME_VERSION="128.0.6613.137"
Expand All @@ -21,6 +75,8 @@ RUN wget -q "https://storage.googleapis.com/chrome-for-testing-public/${CHROME_V
&& mv /opt/chromedriver-linux64/chromedriver /usr/local/bin/ \
&& rm -rf chromedriver-linux64.zip /opt/chromedriver-linux64

RUN npm install --global yarn

RUN mkdir -p /opt/webapps/app/tmp/pids
WORKDIR /opt/webapps/app
COPY Gemfile Gemfile.lock ./
Expand All @@ -29,4 +85,18 @@ RUN gem install bundler && bundle install --jobs 20 --retry 5

ENV PATH="/opt/chrome-linux64:${PATH}"

EXPOSE 3000
# RUN apt-get update && apt-get install -y --no-install-recommends > /dev/null \
# libc6-i386 \
# lib32gcc-s1 \
# wkhtmltopdf \
# xvfb \
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/*

RUN ln -s /lib/ld-linux.so.2 /lib/ld-linux.so.2 || true

# Обертка для wkhtmltopdf с xvfb
RUN echo '#!/bin/bash\nxvfb-run -a --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf "$@"' > /usr/local/bin/wkhtmltopdf \
&& chmod +x /usr/local/bin/wkhtmltopdf

EXPOSE 3000
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ group :development, :test do
end

group :test do
gem 'capybara'
gem 'capybara', '~> 3.40.0'
gem 'database_cleaner'
gem 'minitest', '~> 5.17'
gem 'minitest-stub_any_instance'
gem 'selenium-webdriver'
gem 'selenium-webdriver', '~> 4.26'
# gem 'webdrivers'
gem 'simplecov', '0.17.1', require: false # CC last supported v0.17
gem 'spy'
Expand Down
27 changes: 16 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ GEM
sassc (>= 2.0.0)
builder (3.3.0)
cancancan (3.3.0)
capybara (3.35.3)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (3.0.0)
chronic (0.10.2)
coderay (1.1.3)
coffee-rails (5.0.0)
Expand Down Expand Up @@ -308,6 +308,7 @@ GEM
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
Expand All @@ -329,10 +330,10 @@ GEM
money (~> 6.13.2)
railties (>= 3.0)
msgpack (1.7.2)
mutex_m (0.2.0)
net-ftp (0.3.7)
net-protocol
time
mutex_m (0.2.0)
net-protocol (0.1.3)
timeout
net-smtp (0.3.3)
Expand Down Expand Up @@ -434,7 +435,7 @@ GEM
redis-client (>= 0.9.0)
redis-client (0.14.1)
connection_pool
regexp_parser (2.1.1)
regexp_parser (2.9.2)
request_store (1.5.1)
rack (>= 1.4)
responders (3.0.1)
Expand Down Expand Up @@ -469,9 +470,12 @@ GEM
wasabi (>= 3.7, < 6)
select2-rails (4.0.13)
selectize-rails (0.12.6)
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
selenium-webdriver (4.26.0)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sidekiq (7.1.4)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
Expand Down Expand Up @@ -535,6 +539,7 @@ GEM
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket (1.2.11)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -557,7 +562,7 @@ DEPENDENCIES
bootsnap (>= 1.1.0)
bootstrap-sass (~> 3.4)
cancancan
capybara
capybara (~> 3.40.0)
coffee-rails (>= 5.0)
company_register!
countries
Expand Down Expand Up @@ -606,7 +611,7 @@ DEPENDENCIES
sass-rails
select2-rails (= 4.0.13)
selectize-rails (= 0.12.6)
selenium-webdriver
selenium-webdriver (~> 4.26)
sidekiq (~> 7.0)
simplecov (= 0.17.1)
simpleidn (= 0.2.3)
Expand All @@ -620,4 +625,4 @@ DEPENDENCIES
wkhtmltopdf-binary (~> 0.12.6.1)

BUNDLED WITH
2.5.19
2.5.23
23 changes: 14 additions & 9 deletions app/jobs/company_register_status_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ class CompanyRegisterStatusJob < ApplicationJob

def perform(days_interval = 14, spam_time_delay = 1, batch_size = 100)
sampling_registrant_contact(days_interval).find_in_batches(batch_size: batch_size) do |contacts|
contacts.reject { |contact| whitelisted_company?(contact) }.each { |contact| proceed_company_status(contact, spam_time_delay) }
contacts_to_check = contacts.reject { |contact| whitelisted_company?(contact) }

contacts_to_check.each do |contact|
proceed_company_status(contact, spam_time_delay)
end
end
end

Expand All @@ -17,13 +21,9 @@ def proceed_company_status(contact, spam_time_delay)
# avoid spamming company register
sleep spam_time_delay

puts "WHAT YOU GONNA DO WHEN I COME FOR YOU?"

company_status = contact.return_company_status
contact.update!(company_register_status: company_status, checked_company_at: Time.zone.now)

puts "company id #{contact.id} status: #{company_status}"

case company_status
when Contact::REGISTERED
lift_force_delete(contact) if check_for_force_delete(contact)
Expand All @@ -44,7 +44,6 @@ def sampling_registrant_contact(days_interval)
company_register_status IN (?)",
Contact::REGISTERED, days_interval.days.ago, [Contact::LIQUIDATED, Contact::BANKRUPT, Contact::DELETED]
)

end

def update_validation_company_status(contact:, status:)
Expand All @@ -66,7 +65,8 @@ def schedule_force_delete(contact)

def check_for_force_delete(contact)
contact.registrant_domains.any? do |domain|
domain.status_notes[DomainStatus::FORCE_DELETE].include?("Company no: #{contact.ident}")
notes = domain.status_notes[DomainStatus::FORCE_DELETE]
notes && notes.include?("Company no: #{contact.ident}")
end
end

Expand Down Expand Up @@ -107,9 +107,14 @@ def soft_delete_company(contact)
end

def whitelisted_companies
@whitelisted_companies ||= ENV['whitelist_companies'].split(',')
@whitelisted_companies ||= begin
raw_list = ENV['whitelist_companies'] || '[]'
JSON.parse(raw_list)
rescue JSON::ParserError
[]
end
end

def whitelisted_company?(contact)
whitelisted_companies.include?(contact.ident)
end
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/form_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require 'test_helper'
require 'minitest/mock'

class FormHelperTest < ActionView::TestCase
def test_legal_document_field
meth = MiniTest::Mock.new
meth = Minitest::Mock.new
returned_legal_document_field = ApplicationController.helpers.legal_document_field('Hello', meth)

assert returned_legal_document_field.include? 'data-legal-document="true"'
assert returned_legal_document_field.include? 'accept=".pdf,.asice,.asics,.sce,.scs,.adoc,.edoc,.bdoc,.zip,.rar,.gz,.tar,.7z,.odt,.doc,.docx"'
end
end
end
9 changes: 5 additions & 4 deletions test/jobs/company_register_status_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class CompanyRegisterStatusJobTest < ActiveSupport::TestCase
def test_if_company_wasn_not_checked_before_it_should_be_checked
original_new_method = CompanyRegister::Client.method(:new)
CompanyRegister::Client.define_singleton_method(:new) do
object = original_new_method.call
object = original_new_method.call
def object.simple_data(registration_number:)
[Company.new('1234567', 'ACME Ltd', REGISTERED)]
[Company.new('16752073', 'ACME Ltd', REGISTERED), Company.new('14112620', 'Jack', REGISTERED)]
end
object
end
Expand All @@ -43,10 +43,11 @@ def object.simple_data(registration_number:)

@registrant_acme.reload && @registrant_jack.reload

assert_not_nil @registrant_acme.checked_company_at
assert_not_nil @registrant_acme.company_register_status
assert_not_nil @registrant_jack.checked_company_at
assert_not_nil @registrant_jack.company_register_status
assert_not_nil @registrant_acme.checked_company_at
assert_not_nil @registrant_acme.company_register_status


CompanyRegister::Client.define_singleton_method(:new, original_new_method)
end
Expand Down

0 comments on commit b655d93

Please sign in to comment.