[#10799] Add maintenance task to fill api_entreprise_token_expires_at for previous data

This commit is contained in:
Mathieu Magnin 2024-09-27 16:31:41 +02:00
parent 6b326b634e
commit f26ff30538
No known key found for this signature in database
GPG key ID: 8DCAFC82D7BA654E
2 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
module Maintenance
class UpdateAPIEntrepriseTokenExpiresAtTask < MaintenanceTasks::Task
def collection
Procedure.where.not(api_entreprise_token: nil)
end
def process(procedure)
procedure.set_api_entreprise_token_expires_at
procedure.save!
end
end
end

View file

@ -0,0 +1,20 @@
# frozen_string_literal: true
module Maintenance
RSpec.describe UpdateAPIEntrepriseTokenExpiresAtTask do
describe "#process" do
subject(:process) { described_class.process(procedure) }
let(:expiration) { 1.month.from_now.beginning_of_minute }
let(:procedure) { create(:procedure) }
before do
procedure.update_column(:api_entreprise_token, JWT.encode({ exp: expiration.to_i }, nil, "none"))
end
it do
expect { process }.to change { procedure.reload.api_entreprise_token_expires_at }.from(nil).to(expiration)
end
end
end
end