Skip to content

Commit

Permalink
improve agent factory
Browse files Browse the repository at this point in the history
  • Loading branch information
victormours committed Mar 4, 2025
1 parent d1670ed commit cc0c1e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 9 additions & 0 deletions spec/factories/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@

transient do
service { build(:service) }
no_services { false }

trait :no_services do
no_services { true }
end
end
after(:build) do |agent, evaluator|
next if evaluator.no_services
next if agent.agent_services.any?
next if agent.services.any?

if agent.agent_services.empty? && agent.services.empty?
agent.services = if evaluator.service
[evaluator.service]
Expand Down
6 changes: 1 addition & 5 deletions spec/services/admin_creates_agent_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RSpec.describe AdminCreatesAgent do
context "when inviting an agent that doesn't have any services" do
let(:agent) do
create(:agent, services: [], organisations: [])
create(:agent, :no_services, organisations: [])
end
let(:service1) { create(:service) }
let(:service2) { create(:service) }
Expand All @@ -12,10 +12,6 @@
create(:agent, admin_role_in_organisations: [organisation])
end

before do
agent.services.delete_all
end

it "adds the services to the agent" do
described_class.new(
agent_params: { email: agent.email, service_ids: [service1.id, service2.id] },
Expand Down

0 comments on commit cc0c1e8

Please sign in to comment.