Skip to content

Commit

Permalink
more specs for show
Browse files Browse the repository at this point in the history
  • Loading branch information
victormours committed Jan 17, 2025
1 parent cfbefe3 commit b26f09e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
9 changes: 8 additions & 1 deletion app/blueprints/rdv_plan_blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ class RdvPlanBlueprint < Blueprinter::Base
Rails.application.routes.url_helpers.edit_starts_at_agents_rdv_plan_url(rdv_plan, host: rdv_plan.planning_agent.domain.host_name)
end

association :rdv, blueprint: RdvBlueprint
field :rdv do |rdv_plan, _options|
next if rdv_plan.rdv.nil?

{
id: rdv_plan.rdv_id,
status: rdv_plan.rdv.status,
}
end
end
44 changes: 37 additions & 7 deletions spec/requests/api/v1/rdv_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
)
end

let(:agent) do
create(:agent, basic_role_in_organisations: [create(:organisation)])
end

before do
create(:agent_territorial_access_right, agent: agent, territory: agent.organisations.last.territory)
end

describe "#create" do
let(:params) do
{
Expand All @@ -27,13 +35,6 @@
},
}
end
let(:agent) do
create(:agent, basic_role_in_organisations: [create(:organisation)])
end

before do
create(:agent_territorial_access_right, agent: agent, territory: agent.organisations.last.territory)
end

context "when the user doesn't already exist" do
it "creates the user and the rdv plan" do
Expand Down Expand Up @@ -131,4 +132,33 @@
end
end
end

describe "#show" do
context "when there is a rdv" do
let(:rdv_plan) do
create(:rdv_plan, rdv: create(:rdv), planning_agent: agent)
end

it "returns the minimum information about the rdv" do
get "/api/v1/rdv_plans/#{rdv_plan.id}", headers: headers, params: {}, as: :json
expect(parsed_response_body.dig("rdv_plan", "rdv")).to match(
{
id: rdv_plan.rdv_id,
status: "unknown",
}
)
end
end

context "when the rdv_plan belongs to a different user" do
let(:rdv_plan) do
create(:rdv_plan, planning_agent: create(:agent))
end

it "returns an error" do
get "/api/v1/rdv_plans/#{rdv_plan.id}", headers: headers, params: {}, as: :json
expect(response.status).to eq 404
end
end
end
end

0 comments on commit b26f09e

Please sign in to comment.