Skip to content
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
8 changes: 8 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
require 'simplecov'
require 'simplecov-json'
SimpleCov.start 'rails' do
# any custom configs like groups and filters can be here at a central place
enable_coverage :branch
formatter SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::JSONFormatter,
SimpleCov::Formatter::HTMLFormatter
]
add_filter 'phoenix-tests'
end
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ group :test do
gem "rails-controller-testing"
# Show code coverage.
gem 'simplecov'
gem 'simplecov-json'
# More concise test ("should") matchers
gem 'shoulda-matchers', '~> 6.2'
# Mock HTTP requests and ensure they are not called during tests.
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ GEM
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-json (0.2.3)
json
simplecov
simplecov_json_formatter (0.1.4)
sinatra (3.1.0)
mustermann (~> 3.0)
Expand Down Expand Up @@ -789,6 +792,7 @@ DEPENDENCIES
shoulda-matchers (~> 6.2)
simple_form
simplecov
simplecov-json
sprockets (~> 4.2.1)
standard (~> 1.40)
stimulus-rails
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ staging:

test:
<<: *default
database: diaper_test
database: diaper_test<%= ENV['TEST_ENV_NUMBER'] %>
timeout: 5000

# These env vars live in Cloud66 application settings. Don't change
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

require "rails_helper"

RSpec.describe Partners::AuthorizedFamilyMember do
describe '#display_name', :phoenix do
let(:authorized_family_member_with_full_name) { Partners::AuthorizedFamilyMember.new(first_name: 'John', last_name: 'Doe') }
let(:authorized_family_member_with_first_name_only) { Partners::AuthorizedFamilyMember.new(first_name: 'John', last_name: nil) }
let(:authorized_family_member_with_last_name_only) { Partners::AuthorizedFamilyMember.new(first_name: nil, last_name: 'Doe') }
let(:authorized_family_member_with_no_name) { Partners::AuthorizedFamilyMember.new(first_name: nil, last_name: nil) }

it 'returns full name when both first_name and last_name are present' do
expect(authorized_family_member_with_full_name.display_name).to eq('John Doe')
end

it 'returns first_name when last_name is nil' do
expect(authorized_family_member_with_first_name_only.display_name).to eq('John')
end

it 'returns last_name when first_name is nil' do
expect(authorized_family_member_with_last_name_only.display_name).to eq('Doe')
end

it 'returns an empty string when both first_name and last_name are nil' do
expect(authorized_family_member_with_no_name.display_name).to eq('')
end
end
end
6 changes: 6 additions & 0 deletions phoenix-tests/unit/tests/app/models/partners/base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

require "rails_helper"

RSpec.describe Partners::Base do

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

require "rails_helper"

RSpec.describe Partners::ChildItemRequest do
describe '#quantity', :phoenix do
let(:item_request) { ItemRequest.create(quantity: item_request_quantity) }
let(:children) { Array.new(children_count) { Child.create } }
let(:child_item_request) { Partners::ChildItemRequest.new(item_request: item_request, children: children) }

context 'when item_request quantity is zero' do
let(:item_request_quantity) { 0 }
let(:children_count) { 1 }

it 'returns zero' do
expect(child_item_request.quantity).to eq(0)
end
end

context 'when there are no children' do
let(:item_request_quantity) { 10 }
let(:children_count) { 0 }

it 'returns zero' do
expect(child_item_request.quantity).to eq(0)
end
end

context 'when there is one child' do
let(:item_request_quantity) { 10 }
let(:children_count) { 1 }

it 'returns correct quantity equal to item_request quantity' do
expect(child_item_request.quantity).to eq(10)
end
end

context 'when there are multiple children' do
let(:item_request_quantity) { 10 }
let(:children_count) { 2 }

it 'returns correct quantity divided by number of children' do
expect(child_item_request.quantity).to eq(5)
end
end

context 'when handling division by zero gracefully' do
let(:item_request_quantity) { 10 }
let(:children_count) { 0 }

it 'returns zero when dividing by zero' do
expect(child_item_request.quantity).to eq(0)
end
end
end
describe '#ordered_item_diaperid', :phoenix do
let(:item_request) { ItemRequest.new(item_id: item_id) }
let(:child_item_request) { Partners::ChildItemRequest.new(item_request: item_request) }

context 'when item_request is present' do
let(:item_id) { 1 }

it 'returns the item_id when item_request is present' do
expect(child_item_request.ordered_item_diaperid).to eq(item_id)
end
end

context 'when item_request is nil' do
let(:item_request) { nil }

it 'does not raise an error when item_request is nil' do
expect { child_item_request.ordered_item_diaperid }.not_to raise_error
end
end

context 'when item_id is nil' do
let(:item_id) { nil }

it 'returns nil when item_id is nil' do
expect(child_item_request.ordered_item_diaperid).to be_nil
end
end

context 'when item_id is invalid' do
let(:item_id) { 'invalid' }

it 'returns the invalid item_id as is' do
expect(child_item_request.ordered_item_diaperid).to eq('invalid')
end
end
end
end
106 changes: 106 additions & 0 deletions phoenix-tests/unit/tests/app/models/partners/child_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

require "rails_helper"

RSpec.describe Partners::Child do
describe '#display_name', :phoenix do
let(:child_with_full_name) { build(:partners_child, first_name: 'John', last_name: 'Doe') }
let(:child_with_first_name_only) { build(:partners_child, first_name: 'John', last_name: nil) }
let(:child_with_last_name_only) { build(:partners_child, first_name: nil, last_name: 'Doe') }
let(:child_with_no_name) { build(:partners_child, first_name: nil, last_name: nil) }

it 'returns full name when both first_name and last_name are present' do
expect(child_with_full_name.display_name).to eq('John Doe')
end

describe 'when first_name is present but last_name is nil' do
it 'returns only first_name with trailing space' do
expect(child_with_first_name_only.display_name).to eq('John ')
end
end

describe 'when last_name is present but first_name is nil' do
it 'returns only last_name with leading space' do
expect(child_with_last_name_only.display_name).to eq(' Doe')
end
end

describe 'when both first_name and last_name are nil' do
it 'returns a single space' do
expect(child_with_no_name.display_name).to eq(' ')
end
end
end
describe '.csv_export_headers', :phoenix do
it 'returns the correct CSV headers' do
expected_headers = %w[
id first_name last_name date_of_birth gender child_lives_with race agency_child_id
health_insurance comments created_at updated_at guardian_last_name guardian_first_name requested_items active archived
]
expect(Partners::Child.csv_export_headers).to eq(expected_headers)
end
end
describe '#csv_export_attributes', :phoenix do
let(:family) { build(:partners_family, guardian_first_name: 'John', guardian_last_name: 'Doe') }
let(:requested_item) { build(:item, name: 'Diapers') }
let(:child_with_family) { build(:partners_child, family: family, requested_items: [requested_item]) }
let(:child_without_family) { build(:partners_child, family: nil, requested_items: [requested_item]) }
let(:child_with_no_requested_items) { build(:partners_child, requested_items: []) }

it 'includes basic attributes' do
expect(child_with_family.csv_export_attributes).to include(
child_with_family.id,
child_with_family.first_name,
child_with_family.last_name,
child_with_family.date_of_birth,
child_with_family.gender,
child_with_family.child_lives_with,
child_with_family.race,
child_with_family.agency_child_id,
child_with_family.health_insurance,
child_with_family.comments,
child_with_family.created_at,
child_with_family.updated_at
)
end

describe 'when family association is present' do
it 'includes guardian last name' do
expect(child_with_family.csv_export_attributes).to include(family.guardian_last_name)
end

it 'includes guardian first name' do
expect(child_with_family.csv_export_attributes).to include(family.guardian_first_name)
end
end

describe 'when family association is nil' do
it 'handles missing guardian last name gracefully' do
expect(child_without_family.csv_export_attributes).to include(nil)
end

it 'handles missing guardian first name gracefully' do
expect(child_without_family.csv_export_attributes).to include(nil)
end
end

describe 'when requested_items are present' do
it 'joins requested item names with a comma' do
expect(child_with_family.csv_export_attributes).to include('Diapers')
end
end

describe 'when requested_items are empty' do
it 'handles empty requested items gracefully' do
expect(child_with_no_requested_items.csv_export_attributes).to include('')
end
end

it 'includes active attribute' do
expect(child_with_family.csv_export_attributes).to include(child_with_family.active)
end

it 'includes archived attribute' do
expect(child_with_family.csv_export_attributes).to include(child_with_family.archived)
end
end
end
Loading