[#10799] Display a warning about token expiration on token form page
This commit is contained in:
parent
2d9854dc01
commit
39fdb8ddbb
3 changed files with 53 additions and 0 deletions
|
@ -0,0 +1,14 @@
|
|||
- if procedure.api_entreprise_token_expires_at.present?
|
||||
- if procedure.api_entreprise_token_expires_at < Time.zone.now
|
||||
= render Dsfr::AlertComponent.new(state: :error, size: :sm, extra_class_names: 'fr-mb-2w') do |c|
|
||||
- c.with_body do
|
||||
%p
|
||||
Votre jeton API Entreprise est expiré.
|
||||
Merci de le renouveler.
|
||||
- else
|
||||
= render Dsfr::AlertComponent.new(state: :warning, size: :sm, extra_class_names: 'fr-mb-2w') do |c|
|
||||
- c.with_body do
|
||||
%p
|
||||
Votre jeton API Entreprise expirera le
|
||||
= procedure.api_entreprise_token_expires_at.strftime('%d/%m/%Y à %H:%M.')
|
||||
Merci de le renouveler avant cette date.
|
|
@ -18,6 +18,8 @@
|
|||
= link_to 'API Entreprise', "https://api.gouv.fr/les-api/api-entreprise/demande-acces"
|
||||
propre à votre démarche.
|
||||
|
||||
= render partial: 'administrateurs/procedures/api_entreprise_token_expiration_alert', locals: { procedure: @procedure }
|
||||
|
||||
.fr-input-group
|
||||
= f.label :api_entreprise_token, "Jeton", class: 'fr-label'
|
||||
= f.password_field :api_entreprise_token, value: @procedure.read_attribute(:api_entreprise_token), class: 'fr-input'
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe 'administrateurs/procedures/_api_entreprise_token_expiration_alert', type: :view do
|
||||
let(:procedure) { create(:procedure, api_entreprise_token:) }
|
||||
|
||||
subject { render 'administrateurs/procedures/api_entreprise_token_expiration_alert', procedure: procedure }
|
||||
|
||||
context "when there is no token" do
|
||||
let(:api_entreprise_token) { nil }
|
||||
|
||||
it "does not render anything" do
|
||||
subject
|
||||
expect(rendered).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "when the token is expired" do
|
||||
let(:api_entreprise_token) { JWT.encode({ exp: 2.days.ago.to_i }, nil, "none") }
|
||||
|
||||
it "should display an error" do
|
||||
subject
|
||||
|
||||
expect(rendered).to have_content("Votre jeton API Entreprise est expiré")
|
||||
end
|
||||
end
|
||||
|
||||
context "when the token is valid it should display the expiration date" do
|
||||
let(:expiration) { 2.days.from_now }
|
||||
let(:api_entreprise_token) { JWT.encode({ exp: expiration.to_i }, nil, "none") }
|
||||
|
||||
it "should display an error" do
|
||||
subject
|
||||
|
||||
expect(rendered).to have_content("Votre jeton API Entreprise expirera le\n#{expiration.strftime('%d/%m/%Y à %H:%M')}")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue