-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9946 from colinux/fix-procedure-external-url
Tech: fix le job de vérification des liens externes des procédures lorsqu'un autre attribut est en erreur
- Loading branch information
Showing
3 changed files
with
103 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
describe ProcedureExternalURLCheckJob do | ||
subject(:perform) { described_class.new(procedure).perform_now; procedure.reload } | ||
let(:lien_dpo) { "https://example.com/dpo" } | ||
let(:lien_notice) { "https://example.com/notice" } | ||
let(:lien_dpo_error) { nil } | ||
let(:dpo_code) { 200 } | ||
let(:notice_code) { 200 } | ||
let(:procedure) { create(:procedure, lien_dpo:, lien_dpo_error:, lien_notice:) } | ||
|
||
before do | ||
allow(Typhoeus).to receive(:get).with("https://example.com/dpo", followlocation: true).and_return(Typhoeus::Response.new(code: dpo_code, mock: true)) | ||
allow(Typhoeus).to receive(:get).with("https://example.com/notice", followlocation: true).and_return(Typhoeus::Response.new(code: notice_code, mock: true)) | ||
end | ||
|
||
context 'with valid links' do | ||
it "changes nothing" do | ||
perform | ||
|
||
expect(procedure.lien_dpo).to be_present | ||
expect(procedure.lien_notice).to be_present | ||
expect(procedure.lien_dpo_error).to be_nil | ||
expect(procedure.lien_notice_error).to be_nil | ||
end | ||
end | ||
|
||
context 'with invalid dpo' do | ||
let(:dpo_code) { 404 } | ||
|
||
it "update dpo error" do | ||
perform | ||
expect(procedure.lien_dpo_error).to include("404") | ||
end | ||
end | ||
|
||
context "with invalid lien_dpo attribute" do | ||
before do | ||
procedure.lien_dpo = "http://localhost" | ||
procedure.save!(validate: false) | ||
end | ||
|
||
it "update dpo error" do | ||
perform | ||
|
||
expect(procedure.lien_dpo_error).to include("pas un lien valide") | ||
end | ||
end | ||
|
||
context 'when there was an error before' do | ||
let(:lien_dpo_error) { "old error" } | ||
|
||
it "removes error when link is valid" do | ||
perform | ||
|
||
expect(procedure.lien_dpo_error).to be_nil | ||
end | ||
end | ||
|
||
context 'with invalid notice link' do | ||
let(:notice_code) { 500 } | ||
|
||
it "updates lien_notice_error" do | ||
perform | ||
|
||
expect(procedure.lien_notice_error).to include("500") | ||
end | ||
end | ||
|
||
context 'when there are other errors' do | ||
let(:notice_code) { 404 } | ||
before do | ||
procedure.libelle = nil | ||
procedure.save!(validate: false) | ||
end | ||
|
||
it "does not fail the job" do | ||
perform | ||
|
||
expect(procedure.lien_notice_error).to include("404") | ||
end | ||
end | ||
end |