From 09f828a6a217629d2b06b3e7a484d65e40b9ac79 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 13 Oct 2021 00:40:15 +0200 Subject: [PATCH] create_merge_token! --- app/models/france_connect_information.rb | 7 +++++++ spec/models/france_connect_information_spec.rb | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/models/france_connect_information.rb b/app/models/france_connect_information.rb index bdc6d5d5b..6f1d57c4a 100644 --- a/app/models/france_connect_information.rb +++ b/app/models/france_connect_information.rb @@ -42,6 +42,13 @@ class FranceConnectInformation < ApplicationRecord touch # needed to update updated_at column end + def create_merge_token! + merge_token = SecureRandom.uuid + update(merge_token: merge_token, merge_token_created_at: Time.zone.now) + + merge_token + end + def valid_for_merge? (MERGE_VALIDITY.ago < merge_token_created_at) && user_id.nil? end diff --git a/spec/models/france_connect_information_spec.rb b/spec/models/france_connect_information_spec.rb index ab321cec5..e005a0094 100644 --- a/spec/models/france_connect_information_spec.rb +++ b/spec/models/france_connect_information_spec.rb @@ -43,4 +43,15 @@ describe FranceConnectInformation, type: :model do it { is_expected.to be(false) } end end + + describe '#create_merge_token!' do + let(:fci) { create(:france_connect_information) } + + it 'returns a merge_token and register it s creation date' do + token = fci.create_merge_token! + + expect(fci.merge_token).to eq(token) + expect(fci.merge_token_created_at).not_to be_nil + end + end end