Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DTO builder and Spec #193

Open
wants to merge 1 commit into
base: feature/APPEALS-59232
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions app/models/builders/person_updated/dto_builder.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

class Builders::PersonUpdated::DtoBuilder
attr_reader :participant_id, :payload
attr_reader :payload

def initialize(person_updated_event)
MetricsService.record("Build person updated #{person_updated_event}",
service: :dto_builder,
name: "Builders::PersonUpdated::DtoBuilder.initialize") do
@event_id = person_updated_event.id
@person_updated = build_person_updated(person_updated_event.message_payload_hash)
@person = BasePerson.new
assign_attributes
end
end
Expand All @@ -30,50 +31,50 @@ def assign_attributes
private

def assign_first_name
@person.first_name = @person_updated_model.first_name
@person.first_name = @person_updated.first_name
end

def assign_last_name
@person.last_name = @person_updated_model.last_name
@person.last_name = @person_updated.last_name
end

def calculate_middle_name
@person.middle_name = @person_updated_model.middle_name
@person.middle_name = @person_updated.middle_name
end

def calculate_name_suffix
@person.name_suffix = @person_updated_model.name_suffix
@person.name_suffix = @person_updated.name_suffix
end

def assign_participant_id
@person.participant_id = @person_updated_model.participant_id
@person.participant_id = @person_updated.participant_id
end

def calculate_ssn
@person.ssn = @person_updated_model.ssn
@person.ssn = @person_updated.ssn
end

def calculate_date_of_birth
@person.date_of_birth = @person_updated_model.date_of_birth if @person_updated_model.date_of_birth
@person.date_of_birth = @person_updated.date_of_birth if @person_updated.date_of_birth
end

def calculate_email_address
@person.email_address = @person_updated_model.email_address
@person.email_address = @person_updated.email_address
end

def calculate_date_of_death
@person.date_of_death = @person_updated_model.date_of_death if @person_updated_model.date_of_death
@person.date_of_death = @person_updated.date_of_death if @person_updated.date_of_death
end

def assign_file_number
@person.file_number = @person_updated_model.file_number
@person.file_number = @person_updated.file_number
end

def assign_veteran_indicator
@person.is_veteran = @person_updated_model.is_veteran
@person.is_veteran = @person_updated.is_veteran
end

def build_person_updated(message_payload)
Transformers::PersonUpdated.new(@participant_id, message_payload)
Transformers::PersonUpdated.new(@event_id, message_payload)
end
end
53 changes: 39 additions & 14 deletions spec/models/builders/person_updated/dto_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

RSpec.describe Builders::PersonUpdated::DtoBuilder, type: :model do
let(:dto_builder) { described_class.new(person_updated_event) }
let(:person_updated_event) do
create(:event, type: "Events::PersonUpdatedEvent")
create(:person_updated_event, type: "Events::PersonUpdatedEvent")
end

let(:dto_builder) { described_class.new(person_updated_event) }
let(:event_id) { person_updated_event.id }
let(:person) { described_class.new(person) }

describe "initialize" do
it "calls MetricsService to record metrics" do
Expand All @@ -19,24 +21,47 @@
end

it "initializes instance variables" do
expect(dto_builder.instance_variable_get(:@participant_id)).to eq(participant_id)
expect(dto_builder.instance_variable_get(:@event_id)).to be_a(Integer)
expect(dto_builder.instance_variable_get(:@person_updated)).to be_a(Transformers::PersonUpdated)
expect(dto_builder.instance_variable_get(:@person)).to be_a(BasePerson)
end
end

describe "#assign_attributes" do
it "correctly assigns attributes" do
expect(dto_builder.first_name).to eq(person_updated_event.first_name)
expect(dto_builder.last_name).to eq(person_updated_event.last_name)
expect(dto_builder.middle_name).to eq(person_updated_event.middle_name)
expect(dto_builder.name_suffix).to eq(person_updated_event.name_suffix)
expect(dto_builder.participant_id).to eq(person_updated_event.participant_id)
expect(dto_builder.ssn).to eq(person_updated_event.ssn)
expect(dto_builder.date_of_birth).to eq(person_updated_event.date_of_birth)
expect(dto_builder.email_address).to eq(person_updated_event.email_address)
expect(dto_builder.date_of_death).to eq(person_updated_event.date_of_death)
expect(dto_builder.file_number).to eq(person_updated_event.file_number)
expect(dto_builder.is_veteran).to eq(person_updated_event.is_veteran)
expect(dto_builder.instance_variable_get(:@person_updated).first_name).to eq(
dto_builder.instance_variable_get(:@person).first_name
raymond-hughes marked this conversation as resolved.
Show resolved Hide resolved
)
expect(dto_builder.instance_variable_get(:@person_updated).last_name).to eq(
dto_builder.instance_variable_get(:@person).last_name
)
expect(dto_builder.instance_variable_get(:@person_updated).middle_name).to eq(
dto_builder.instance_variable_get(:@person).middle_name
)
expect(dto_builder.instance_variable_get(:@person_updated).name_suffix).to eq(
dto_builder.instance_variable_get(:@person).name_suffix
)
expect(dto_builder.instance_variable_get(:@person_updated).participant_id).to eq(
dto_builder.instance_variable_get(:@person).participant_id
)
expect(dto_builder.instance_variable_get(:@person_updated).ssn).to eq(
dto_builder.instance_variable_get(:@person).ssn
)
expect(dto_builder.instance_variable_get(:@person_updated).date_of_birth).to eq(
dto_builder.instance_variable_get(:@person).date_of_birth
)
expect(dto_builder.instance_variable_get(:@person_updated).email_address).to eq(
dto_builder.instance_variable_get(:@person).email_address
)
expect(dto_builder.instance_variable_get(:@person_updated).date_of_death).to eq(
dto_builder.instance_variable_get(:@person).date_of_death
)
expect(dto_builder.instance_variable_get(:@person_updated).file_number).to eq(
dto_builder.instance_variable_get(:@person).file_number
)
expect(dto_builder.instance_variable_get(:@person_updated).is_veteran).to eq(
dto_builder.instance_variable_get(:@person).is_veteran
)
end
end
end
Loading