-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webhooks): Retrieve user organisations when creating it from rdv…
…sp (#2369) * feat(webhooks): Retrieve user organisations when creating it from rdvsp * Apply review suggestions * move method from concern * apply new rdv_solidarites_session method to recent referent assignation script
- Loading branch information
1 parent
b9f724d
commit eccd042
Showing
10 changed files
with
136 additions
and
27 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
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
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,19 @@ | ||
module RdvSolidaritesApi | ||
class RetrieveUser < Base | ||
def initialize(rdv_solidarites_user_id:) | ||
@rdv_solidarites_user_id = rdv_solidarites_user_id | ||
end | ||
|
||
def call | ||
request! | ||
result.user = | ||
RdvSolidarites::User.new(rdv_solidarites_response_body["user"]) | ||
end | ||
|
||
private | ||
|
||
def rdv_solidarites_response | ||
@rdv_solidarites_response ||= rdv_solidarites_client.get_user(@rdv_solidarites_user_id) | ||
end | ||
end | ||
end |
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
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,53 @@ | ||
describe RdvSolidaritesApi::RetrieveUser, type: :service do | ||
subject do | ||
described_class.call(rdv_solidarites_user_id:) | ||
end | ||
|
||
let(:rdv_solidarites_client) { instance_double(RdvSolidaritesClient) } | ||
let!(:rdv_solidarites_user_id) { 1717 } | ||
|
||
describe "#call" do | ||
let!(:user_attributes) do | ||
{ | ||
"id" => 1717, | ||
"first_name" => "Léonard", | ||
"last_name" => "De Vinci" | ||
} | ||
end | ||
|
||
before do | ||
allow(Current).to receive(:rdv_solidarites_client).and_return(rdv_solidarites_client) | ||
allow(rdv_solidarites_client).to receive(:get_user) | ||
.with(rdv_solidarites_user_id) | ||
.and_return(OpenStruct.new(success?: true, body: { "user" => user_attributes }.to_json)) | ||
end | ||
|
||
context "when it succeeds" do | ||
it("is a success") { is_a_success } | ||
|
||
it "calls the rdv solidarites client" do | ||
expect(rdv_solidarites_client).to receive(:get_user) | ||
subject | ||
end | ||
|
||
it "returns the user" do | ||
expect(subject.user.id).to eq(rdv_solidarites_user_id) | ||
expect(subject.user.first_name).to eq("Léonard") | ||
expect(subject.user.last_name).to eq("De Vinci") | ||
end | ||
end | ||
|
||
context "when it fails" do | ||
before do | ||
allow(rdv_solidarites_client).to receive(:get_user) | ||
.and_return(OpenStruct.new(success?: false, body: { error_messages: ["some error"] }.to_json)) | ||
end | ||
|
||
it("is a failure") { is_a_failure } | ||
|
||
it "returns the error" do | ||
expect(subject.errors).to eq(["Erreur RDV-Solidarités: some error"]) | ||
end | ||
end | ||
end | ||
end |