From d8ea06217f732ca2057623f31ae91fdfb37c62ee Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Thu, 12 Oct 2023 13:34:20 -0400 Subject: [PATCH] Rc-release-5.7.71 setting employee counts (#2466) (#2470) * setting employee counts (#2466) * devcontainer support for enroll/ma for arm based macs (#2468) * initial commit of devcontainer with cucumber support * add brief readme * rubocop * had to create the gemset before using it * fixed a missing slash bug on env, and adding a auto-restart for selenium chrome * tweaking the healthcheck to be less agressive * tweaking the healthcheck further, we don't want it to die at the middle * workaround workspace mount --------- Co-authored-by: Nisanth Yaganti Co-authored-by: Marco (Polo) Ornelas --- .devcontainer/Dockerfile | 28 +++++ .devcontainer/devcontainer.json | 47 +++++++ .devcontainer/docker-compose.yml | 102 +++++++++++++++ .devcontainer/patches/cucumber_env.rb | 119 ++++++++++++++++++ .devcontainer/patches/mongoid-enroll.yml | 84 +++++++++++++ .../services/benefit_application_service.rb | 6 +- .../benefit_application_service_spec.rb | 19 ++- readme-devcontainer.md | 17 +++ 8 files changed, 417 insertions(+), 5 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/patches/cucumber_env.rb create mode 100644 .devcontainer/patches/mongoid-enroll.yml create mode 100644 readme-devcontainer.md diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000000..f16c00013a6 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,28 @@ +# # Note: You can use any Debian/Ubuntu based image you want. +# FROM mcr.microsoft.com/devcontainers/base:bullseye + +ARG RUBY_VARIANT=2-bullseye + +FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${RUBY_VARIANT} + +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends libsodium23 python2.7 python-is-python2 yarn + +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +RUN su vscode -c '/bin/bash -l -c ". /etc/profile.d/rvm.sh && rvm install 2.6.5"' +RUN su vscode -c '/bin/bash -l -c ". /etc/profile.d/rvm.sh && rvm gemset create enroll"' +RUN su vscode -c '/bin/bash -l -c ". /etc/profile.d/rvm.sh && rvm use 2.6.5@enroll"' + +USER vscode + +# [Optional] Uncomment this section to install additional OS packages. + +# [Optional] Uncomment this line to install additional gems. +# RUN sudo gem install bundler -v 1.17.3 + +# RUN gem update --system 3.3.26 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000000..52bab7287c6 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,47 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-outside-of-docker-compose +{ + "name": "enroll/MA", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/enroll-ma/", + // "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Use this environment variable if you need to bind mount your local source code into a new container. + "remoteEnv": { + // "LOCAL_BASENAME": "${localWorkspaceFolderBasename}", + // "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" + "LOCAL_WORKSPACE_FOLDER": "enroll-ma" + }, + + // "features": { + // // "ghcr.io/devcontainers/features/docker-outside-of-docker:1": { + // // "version": "20.10", + // // "enableNonRootDocker": "true", + // // "moby": "true" + // // }, + // "ghcr.io/devcontainers/features/ruby:1": {"version":"2.6.5"}, + // "ghcr.io/devcontainers/features/node:1": {"version":"14"}, + // // "ghcr.io/devcontainers/features/python:1": {"version":"2.7.18"}, + // "ghcr.io/devcontainers/features/common-utils:2": {"installZsh":"true", "configureZshAsDefaultShell":"true","upgradePackages":"true"} + // }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 3000 + ], + "customizations": { + "vscode": { + "extensions": [ + "GitHub.copilot", + "GitHub.vscode-pull-request-github" + ] + } + }, + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "docker --version", + // "postCreateCommand": "rvm install 2.6.5 && rvm use 2.6.5 && bundle install" + // "postCreateCommand": "cd $PWD" + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000000..24260032428 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,102 @@ +version: '3.4' + +services: + app: + platform: linux/amd64 + build: + context: . + dockerfile: Dockerfile + args: + BUNDLER_VERSION_OVERRIDE: '2.0.1' + NODE_VERSION: '12' + RUBY_VARIANT: '2.6-bullseye' + RVM_OVERRIDE: '2.6.5' + + volumes: + - /var/run/docker.sock:/var/run/docker-host.sock + # - ../../:/workspaces + - ../:/workspaces/enroll-ma + - ${PWD}/.devcontainer/patches/mongoid-enroll.yml:/workspaces/enroll-ma/config/mongoid.yml:ro + - ${PWD}/.devcontainer/patches/cucumber_env.rb:/workspaces/enroll-ma/features/support/env.rb:ro + command: sleep infinity + + # Uncomment the next four lines if you will use a ptrace-based debuggers like C++, Go, and Rust. + # cap_add: + # - SYS_PTRACE + # security_opt: + # - seccomp:unconfined + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + # chrome: + # image: seleniarm/node-chromium:latest + # shm_size: 2gb + # depends_on: + # - selenium-hub + # environment: + # - SE_EVENT_BUS_HOST=selenium-hub + # - SE_EVENT_BUS_PUBLISH_PORT=4442 + # - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 + + # selenium-hub: + # image: seleniarm/hub:latest + # container_name: selenium-hub + # ports: + # - "4442:4442" + # - "4443:4443" + # - "4444:4444" + + selenium-chrome: + hostname: selenium-chrome + image: seleniarm/standalone-chromium:latest + shm_size: 2gb + labels: + - "autoheal=true" + ports: + - "4444:4444" + - "7900:7900" + healthcheck: + test: '/opt/bin/check-grid.sh --host 0.0.0.0 --port 4444' + interval: 120s + timeout: 60s + retries: 30 + # start_period: 20s + + autoheal: + image: willfarrell/autoheal:latest + tty: true + restart: unless-stopped + environment: + - AUTOHEAL_INTERVAL=120 + - AUTOHEAL_START_PERIOD=300 + - AUTOHEAL_DEFAULT_STOP_TIMEOUT=10 + volumes: + - /var/run/docker.sock:/var/run/docker.sock + + redis: + # hostname: redis + image: redis:7.0 + ports: + - 6379 + environment: + - ALLOW_EMPTY_PASSWORD=yes + healthcheck: + test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ] + mongodb: + image: mongo:4.2 + hostname: mongodb + # mem_limit: 4000m #trying to replicate mongo memory on prod + volumes: + - mongodb:/data/db + - mongodb_config:/data/configdb + ports: + - 27017:27017 + healthcheck: + test: echo 'db.runCommand("ping").ok' | mongo mongodb:27017/test --quiet + # interval: 1s + # timeout: 5s + # retries: 30 + # start_period: 20s +volumes: + mongodb: + mongodb_config: diff --git a/.devcontainer/patches/cucumber_env.rb b/.devcontainer/patches/cucumber_env.rb new file mode 100644 index 00000000000..b431c00c7ae --- /dev/null +++ b/.devcontainer/patches/cucumber_env.rb @@ -0,0 +1,119 @@ +# frozen_string_literal: true + +# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file +# instead of editing this one. Cucumber will automatically load all features/**/*.rb +# files. +require_relative '../../spec/ivl_helper' + +require 'selenium-webdriver' +require 'cucumber/rails' +require 'email_spec/cucumber' +require 'rspec/expectations' +require 'capybara/cucumber' +require 'capybara-screenshot/cucumber' +require 'cucumber/rspec/doubles' + +Dir[File.expand_path("#{Rails.root}/lib/test/**/*.rb")].each { |f| load f } +require File.expand_path("#{File.dirname(__FILE__)}/../../config/environment") +require "rspec/rails" + +# Capybara defaults to CSS3 selectors rather than XPath. +# If you'd prefer to use XPath, just uncomment this line and adjust any +# selectors in your step definitions to use the XPath syntax. +# Capybara.default_selector = :xpath + +# By default, any exception happening in your Rails application will bubble up +# to Cucumber so that your scenario will fail. This is a different from how +# your application behaves in the production environment, where an error page will +# be rendered instead. +# +# Sometimes we want to override this default behaviour and allow Rails to rescue +# exceptions and display an error page (just like when the app is running in production). +# Typical scenarios where you want to do this is when you test your error pages. +# There are two ways to allow Rails to rescue exceptions: +# +# 1) Tag your scenario (or feature) with @allow-rescue +# +# 2) Set the value below to true. Beware that doing this globally is not +# recommended as it will mask a lot of errors for you! +# +ActionController::Base.allow_rescue = false + +# Remove/comment out the lines below if your app doesn't have a database. +# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. +begin + load "#{Rails.root}/db/seedfiles/english_translations_seed.rb" + DatabaseCleaner.strategy = :truncation, {:except => %w[translations]} +rescue NameError + raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." +end + +# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. +# See the DatabaseCleaner documentation for details. Example: +# +# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do +# # { :except => [:widgets] } may not do what you expect here +# # as Cucumber::Rails::Database.javascript_strategy overrides +# # this setting. +# DatabaseCleaner.strategy = :truncation +# end +# +# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do +# DatabaseCleaner.strategy = :transaction +# end +# + +# Possible values are :truncation and :transaction +# The :transaction strategy is faster, but might give you threading problems. +# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature +Cucumber::Rails::Database.javascript_strategy = :truncation + +Capybara::Screenshot.webkit_options = { width: 2280, height: 1800 } +Capybara::Screenshot.prune_strategy = :keep_last_run +# Webdrivers.cache_time = 86_400 + +Capybara::Screenshot.register_driver(:selenium_chrome_custom) do |driver, path| + driver.browser.save_screenshot(path) +end + +Capybara.register_driver :selenium_chrome_custom do |app| + options = Selenium::WebDriver::Chrome::Options.new + # options.headless! + options.add_argument("no-sandbox") + options.add_argument("--window-size=1024,768") + options.add_argument("--disable-dev-shm-usage") + + # client = Selenium::WebDriver::Remote::Http::Default.new + # client.open_timeout = 120 # instead of the default 60 + # client.read_timeout = 120 # instead of the default 60 + + Capybara::Selenium::Driver.new(app, + browser: :chrome, + url: "http://selenium-chrome:4444/wd/hub", + options: options) +end + +selenium_app_host = ENV.fetch("SELENIUM_APP_HOST") do + Socket.ip_address_list + .find(&:ipv4_private?) + .ip_address +end + +Capybara.configure do |config| + config.server = :puma, { Silent: true } + config.server_host = selenium_app_host + config.server_port = 4000 +end + + +Capybara.default_driver = :selenium_chrome_custom +# Capybara.use_default_driver +# Capybara.current_driver = :selenium_chrome_custom + +# https://thurlow.io/ruby/2020/11/06/remote-selenium-webdriver-servers-with-rails-capybara-and-rspec.html +puts "--------------------------------------------------------------------" +puts "the env.rb for cucumber was hacked by docker for running on M1 macs " +puts "--------------------------------------------------------------------" +puts "--------------------------------------------------------------------" diff --git a/.devcontainer/patches/mongoid-enroll.yml b/.devcontainer/patches/mongoid-enroll.yml new file mode 100644 index 00000000000..0cea8dadb70 --- /dev/null +++ b/.devcontainer/patches/mongoid-enroll.yml @@ -0,0 +1,84 @@ +development: + clients: + # Defines the default session. (required) + default: &default_development + # Defines the name of the default database that Mongoid can connect to. + # (required). + database: mhc_enroll_development + # Provides the hosts the default session can connect to. Must be an array + # of host:port pairs. (required) + hosts: + - mongodb:27017 + options: + # Change the default write concern. (default = { w: 1 }) + # write: + # w: 1 + + # Change the default consistency model to primary, secondary. + # 'secondary' will send reads to secondaries, 'primary' sends everything + # to master. (default: primary) + # read: secondary_preferred + + # How many times Moped should attempt to retry an operation after + # failure. (default: The number of nodes in the cluster) + # max_retries: 20 + + # The time in seconds that Moped should wait before retrying an + # operation on failure. (default: 0.25) + # retry_interval: 0.25 + + rocketjob: + <<: *default_development + rocketjob_slices: + <<: *default_development + + # Configure Mongoid specific options. (optional) + options: + # Includes the root model name in json serialization. (default: false) + # include_root_in_json: false + + # Include the _type field in serializaion. (default: false) + # include_type_for_serialization: false + + # Preload all models in development, needed when models use + # inheritance. (default: false) + # preload_models: false + + # Protect id and type from mass assignment. (default: true) + # protect_sensitive_fields: true + + # Raise an error when performing a #find and the document is not found. + # (default: true) + # raise_not_found_error: true + + # Raise an error when defining a scope with the same name as an + # existing method. (default: false) + # scope_overwrite_exception: false + + # Use Active Support's time zone in conversions. (default: true) + # use_activesupport_time_zone: true + + # Ensure all times are UTC in the app side. (default: false) + # use_utc: false +test: + clients: + default: + database: mhc_enroll_test<%= ENV['TEST_ENV_NUMBER'] %> + hosts: + - mongodb:27017 + options: + # In the test environment we lower the retries and retry interval to + # low amounts for fast failures. + max_retries: 1 + retry_interval: 0 +production: + clients: + default: + database: mhc_enroll_production + hosts: + - mongodb:27017 + options: + # In the test environment we lower the retries and retry interval to + # low amounts for fast failures. + max_retries: 1 + retry_interval: 0 diff --git a/components/benefit_sponsors/app/models/benefit_sponsors/services/benefit_application_service.rb b/components/benefit_sponsors/app/models/benefit_sponsors/services/benefit_application_service.rb index 1bc9d8ed507..7708cc950ec 100644 --- a/components/benefit_sponsors/app/models/benefit_sponsors/services/benefit_application_service.rb +++ b/components/benefit_sponsors/app/models/benefit_sponsors/services/benefit_application_service.rb @@ -180,9 +180,9 @@ def form_params_to_attributes(form) { effective_period: (format_string_to_date(form.start_on)..format_string_to_date(form.end_on)), open_enrollment_period: (format_string_to_date(form.open_enrollment_start_on)..format_string_to_date(form.open_enrollment_end_on)), - fte_count: form.fte_count, - pte_count: form.pte_count, - msp_count: form.msp_count + fte_count: form.fte_count.to_i, + pte_count: form.pte_count.to_i, + msp_count: form.msp_count.to_i } end diff --git a/components/benefit_sponsors/spec/models/benefit_sponsors/services/benefit_application_service_spec.rb b/components/benefit_sponsors/spec/models/benefit_sponsors/services/benefit_application_service_spec.rb index 1ce5b43977e..6f569f9078e 100644 --- a/components/benefit_sponsors/spec/models/benefit_sponsors/services/benefit_application_service_spec.rb +++ b/components/benefit_sponsors/spec/models/benefit_sponsors/services/benefit_application_service_spec.rb @@ -520,16 +520,31 @@ def fetch_bs_for_service(ba_form) end context 'not for admin_datatable_action' do + let(:end_on) { start_on.next_year.prev_day } + let(:create_ba_params) do + { + "start_on" => start_on, + "end_on" => end_on, + "fte_count" => "11", + "pte_count" => '', + "open_enrollment_start_on" => Date.new(start_on.year, start_on.prev_month.month, 1), + "open_enrollment_end_on" => Date.new(start_on.year, start_on.prev_month.month, 20), + "benefit_sponsorship_id" => benefit_sponsorship.id.to_s + } + end + before :each do @form = init_form_for_create fetch_bs_for_service(@form) @model_attrs = subject.form_params_to_attributes(@form) end - it 'should return true and instance as ba succesfully created' do + it 'should return true and instance as ba succesfully created and preserve default values' do result = subject.create_or_cancel_draft_ba(@form, @model_attrs) benefit_sponsorship.reload - expect(result).to eq [true, benefit_sponsorship.benefit_applications.first] + new_ba = benefit_sponsorship.benefit_applications.first + expect(result).to eq [true, new_ba] + expect(new_ba.pte_count).to eq 0 end end diff --git a/readme-devcontainer.md b/readme-devcontainer.md new file mode 100644 index 00000000000..c5b39f69a1d --- /dev/null +++ b/readme-devcontainer.md @@ -0,0 +1,17 @@ +# dev container instructions + +The configuration of the .devcontainer is towards M1 mac that are unable to compile some of the native gem requirements. + +The high level instructions will be: + +1. click on the bottom left corner of the vscode window where it says `><` and select `Remote-Containers: Reopen in Container` +2. wait for the container to build +3. run `bundle install` in the terminal +4. run `npm install` in the terminal +5. run `bin/webpack` in the terminal +6. get a dump of the database from your coworkers +7. run `rails s` in the terminal, the app should be available at `localhost:3001` + +`rspec` and `cucumber` command should work. + +Note: there are 2 files that are "hacked" to make it work on M1 macs, they are: mogoid.yml and env.rb from cucumber. \ No newline at end of file