-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into pivotal_188310207
- Loading branch information
Showing
4 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module Fdsh | ||
module H41 | ||
module Transmissions | ||
# Operation's job is to find or create an 'open' H41 Transmission of given type and reporting_year. | ||
class CreateRenewals | ||
include Dry::Monads[:result, :do] | ||
|
||
def call(params) | ||
renewal_year = yield validate(params) | ||
result = yield create(renewal_year) | ||
|
||
Success(result) | ||
end | ||
|
||
private | ||
|
||
def validate(params) | ||
errors = [] | ||
system_date = params[:system_date] | ||
system_month = system_date.month | ||
system_day = system_date.day | ||
|
||
feature = FdshGatewayRegistry[:h41_renewal_transmissions] | ||
feature_day = feature.settings(:day).item | ||
feature_month = feature.settings(:month).item | ||
|
||
errors << 'system_date missing' unless system_date | ||
errors << 'Feature is disabled' if feature.disabled? | ||
errors << 'system date does not match feature date' if system_day != feature_day || system_month != feature_month | ||
|
||
errors.empty? ? Success(system_date.year.next) : Failure([errors, {}]) | ||
end | ||
|
||
def create(reporting_year) | ||
hash = { reporting_year => [] } | ||
|
||
[:original, :corrected, :void].each do |transmission_type| | ||
result = ::Fdsh::H41::Transmissions::FindOrCreate.new.call(reporting_year: reporting_year, status: :open, | ||
transmission_type: transmission_type) | ||
|
||
hash[reporting_year] << { transmission: transmission_type, status: result.success? ? :success : :failed } | ||
end | ||
|
||
if hash[reporting_year].all? { |h| h[:status] == :success } | ||
Success(["Successfully created renewal transmissions for #{reporting_year}", hash]) | ||
else | ||
Failure(["Some or all renewal transmissions failed to create for #{reporting_year}", hash]) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
97 changes: 97 additions & 0 deletions
97
spec/operations/fdsh/h41/transmissions/create_renewals_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Fdsh::H41::Transmissions::CreateRenewals do | ||
subject { described_class.new } | ||
|
||
before :all do | ||
DatabaseCleaner.clean | ||
end | ||
|
||
after :each do | ||
DatabaseCleaner.clean | ||
end | ||
|
||
describe '#call' do | ||
before do | ||
allow(FdshGatewayRegistry[:h41_renewal_transmissions].feature).to receive(:is_enabled).and_return(true) | ||
end | ||
|
||
context 'with valid input params' do | ||
let(:system_date) { Date.new(Date.today.year, 8, 10) } | ||
let(:input_params) do | ||
{ | ||
system_date: system_date | ||
} | ||
end | ||
|
||
context 'without an open H41 renewal transmissions' do | ||
it 'creates an open H41 renewal transmissions' do | ||
expect(H41::Transmissions::Outbound::OriginalTransmission.open.count).to be_zero | ||
expect(H41::Transmissions::Outbound::VoidTransmission.open.count).to be_zero | ||
expect(H41::Transmissions::Outbound::CorrectedTransmission.open.count).to be_zero | ||
subject.call(input_params) | ||
expect(H41::Transmissions::Outbound::OriginalTransmission.open.count).to eq(1) | ||
expect(H41::Transmissions::Outbound::VoidTransmission.open.count).to eq(1) | ||
expect(H41::Transmissions::Outbound::CorrectedTransmission.open.count).to eq(1) | ||
end | ||
end | ||
|
||
context 'with open H41 renewal transmissions' do | ||
before do | ||
[:original, :corrected, :void].each do |transmission_type| | ||
Fdsh::H41::Transmissions::FindOrCreate.new.call(reporting_year: system_date.year.next, status: :open, | ||
transmission_type: transmission_type) | ||
end | ||
end | ||
|
||
it 'does not create H41 transmissions' do | ||
expect(H41::Transmissions::Outbound::OriginalTransmission.open.count).to eq(1) | ||
expect(H41::Transmissions::Outbound::VoidTransmission.open.count).to eq(1) | ||
expect(H41::Transmissions::Outbound::CorrectedTransmission.open.count).to eq(1) | ||
subject.call(input_params) | ||
expect(H41::Transmissions::Outbound::OriginalTransmission.open.count).to eq(1) | ||
expect(H41::Transmissions::Outbound::VoidTransmission.open.count).to eq(1) | ||
expect(H41::Transmissions::Outbound::CorrectedTransmission.open.count).to eq(1) | ||
end | ||
end | ||
end | ||
|
||
context 'for failure scenarios' do | ||
context 'system_date is outside the feature date' do | ||
let(:input_params) do | ||
{ | ||
system_date: Date.new(Date.today.year, 9, 10) | ||
} | ||
end | ||
|
||
it 'returns failure with errors' do | ||
result = subject.call(input_params) | ||
expect(result.failure).to eq( | ||
[["system date does not match feature date"], {}] | ||
) | ||
end | ||
end | ||
|
||
context 'feature is disabled' do | ||
before do | ||
allow(FdshGatewayRegistry[:h41_renewal_transmissions].feature).to receive(:is_enabled).and_return(false) | ||
end | ||
|
||
let(:input_params) do | ||
{ | ||
system_date: Date.new(Date.today.year, 8, 10) | ||
} | ||
end | ||
|
||
it 'returns failure with errors' do | ||
result = subject.call(input_params) | ||
expect(result.failure).to eq( | ||
[["Feature is disabled"], {}] | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
system/config/templates/features/aca_individual_market/aca_individual_market.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
registry: | ||
- namespace: | ||
- :fdsh_gateway | ||
- :aca_individual_market | ||
features: | ||
- key: :h41_renewal_transmissions | ||
is_enabled: <%= ENV['H41_RENEWAL_TRANSMISSIONS_IS_ENABLED'] || false %> | ||
settings: | ||
- key: :month | ||
item: 8 | ||
- key: :day | ||
item: 10 |