diff --git a/spec/models/concerns/api_entreprise_token_concern_spec.rb b/spec/models/concerns/api_entreprise_token_concern_spec.rb index 7a6040af6..ce58d2b15 100644 --- a/spec/models/concerns/api_entreprise_token_concern_spec.rb +++ b/spec/models/concerns/api_entreprise_token_concern_spec.rb @@ -30,4 +30,55 @@ describe APIEntrepriseTokenConcern do it { is_expected.to be_truthy } end end + + describe '#set_api_entreprise_token_expires_at (before_save)' do + let(:procedure) { create(:procedure, api_entreprise_token: initial_api_entreprise_token) } + + before do + procedure.api_entreprise_token = api_entreprise_token + end + + subject { procedure.save } + + context "when procedure had no api_entreprise_token" do + let(:initial_api_entreprise_token) { nil } + + context 'when the api_entreprise_token is nil' do + let(:api_entreprise_token) { nil } + + it 'does not set the api_entreprise_token_expires_at' do + expect { subject }.not_to change { procedure.api_entreprise_token_expires_at }.from(nil) + end + end + + context 'when the api_entreprise_token is not valid' do + let(:api_entreprise_token) { "not a token" } + + it do + expect { subject }.not_to change { procedure.api_entreprise_token_expires_at }.from(nil) + end + end + + context 'when the api_entreprise_token is valid' do + let(:expiration_date) { Time.zone.now.beginning_of_minute } + let(:api_entreprise_token) { JWT.encode({ exp: expiration_date.to_i }, nil, 'none') } + + it do + expect { subject }.to change { procedure.api_entreprise_token_expires_at }.from(nil).to(expiration_date) + end + end + end + + context "when procedure had an api_entreprise_token" do + let(:initial_api_entreprise_token) { JWT.encode({ exp: 2.months.from_now.to_i }, nil, "none") } + + context 'when the api_entreprise_token is set to nil' do + let(:api_entreprise_token) { nil } + + it do + expect { subject }.to change { procedure.api_entreprise_token_expires_at }.to(nil) + end + end + end + end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 2453f7749..78f5a45d1 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -1835,57 +1835,6 @@ describe Procedure do end end - describe '#set_api_entreprise_token_expires_at (before_save)' do - let(:procedure) { create(:procedure, api_entreprise_token: initial_api_entreprise_token) } - - before do - procedure.api_entreprise_token = api_entreprise_token - end - - subject { procedure.save } - - context "when procedure had no api_entreprise_token" do - let(:initial_api_entreprise_token) { nil } - - context 'when the api_entreprise_token is nil' do - let(:api_entreprise_token) { nil } - - it 'does not set the api_entreprise_token_expires_at' do - expect { subject }.not_to change { procedure.api_entreprise_token_expires_at }.from(nil) - end - end - - context 'when the api_entreprise_token is not valid' do - let(:api_entreprise_token) { "not a token" } - - it do - expect { subject }.not_to change { procedure.api_entreprise_token_expires_at }.from(nil) - end - end - - context 'when the api_entreprise_token is valid' do - let(:expiration_date) { Time.zone.now.beginning_of_minute } - let(:api_entreprise_token) { JWT.encode({ exp: expiration_date.to_i }, nil, 'none') } - - it do - expect { subject }.to change { procedure.api_entreprise_token_expires_at }.from(nil).to(expiration_date) - end - end - end - - context "when procedure had an api_entreprise_token" do - let(:initial_api_entreprise_token) { JWT.encode({ exp: 2.months.from_now.to_i }, nil, "none") } - - context 'when the api_entreprise_token is set to nil' do - let(:api_entreprise_token) { nil } - - it do - expect { subject }.to change { procedure.api_entreprise_token_expires_at }.to(nil) - end - end - end - end - describe "#parsed_latest_zone_labels" do let!(:draft_procedure) { create(:procedure) } let!(:published_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2) }