Skip to content

Commit

Permalink
Ajoute un model claim pour gérer les demandes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbfeldis committed Jun 4, 2024
1 parent e309512 commit 3da415b
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 2 deletions.
19 changes: 19 additions & 0 deletions app/interactors/create_claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateClaim < BaseInteractor
def call
claim = Claim.new(claim_params)
if claim.save
context.claim = claim
else
context.fail!(message: claim.errors.full_messages)
end
end

private

def claim_params
{
sub: context.identity.sub,
hubee_folder_id: context.folder.id,
}
end
end
2 changes: 2 additions & 0 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Claim < ApplicationRecord
end
5 changes: 5 additions & 0 deletions app/models/pivot_identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PivotIdentity
map from("info/last_name"), to("last_name")
map from("extra/raw_info/birthcountry"), to("birth_country")
map from("extra/raw_info/birthplace"), to("birthplace")
map from("extra/raw_info/sub"), to("sub")

map from("credentials/token"), to("token")

Expand All @@ -34,6 +35,10 @@ def authenticated?
@auth.present?
end

def sub
self[:sub]
end

def token
self[:token]
end
Expand Down
2 changes: 1 addition & 1 deletion app/organizers/store_quotient_familial.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class StoreQuotientFamilial < BaseOrganizer
organize UploadQuotientFamilialToHubEE
organize UploadQuotientFamilialToHubEE, CreateClaim
end
10 changes: 10 additions & 0 deletions db/migrate/20240603084727_create_claims.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateClaims < ActiveRecord::Migration[7.1]
def change
create_table :claims do |t|
t.string :sub
t.string :hubee_folder_id

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :claim do
sub { "uuid" }
hubee_folder_id { "folder_uuid" }
end
end
24 changes: 24 additions & 0 deletions spec/interactors/create_claim_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "rails_helper"

RSpec.describe CreateClaim, type: :interactor do
describe ".call" do
subject(:interactor) { described_class.call(**params) }

let(:folder) { instance_double("HubEE::Folder", id: "folder_uuid") }
let(:identity) { instance_double("PivotIdentity", sub: "real_uuid") }
let(:params) do
{
identity:,
folder:,
}
end

context "when the claim is created" do
it { is_expected.to be_a_success }

it "creates a claim" do
expect { interactor }.to change(Claim, :count).by(1)
end
end
end
end
31 changes: 31 additions & 0 deletions spec/organizers/store_quotient_familial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,41 @@
let(:interactors) do
[
UploadQuotientFamilialToHubEE,
CreateClaim,
]
end

it "setups the folder, sends it to HubEE and cleans afterwards" do
expect(described_class).to organize interactors
end

describe ".call" do
subject(:organizer) { described_class.call(**params) }

let(:folder) { build(:hubee_folder) }
let(:identity) { PivotIdentity.new(recipient:, auth: {info: {first_name: "David", last_name: "Heinemeier Hansson"}}) }
let(:recipient) { build(:hubee_recipient) }
let(:params) do
{
folder:,
identity:,
recipient:,
}
end

before do
allow(SecureRandom).to receive(:hex).and_return("abcdef1234567thiswontbeused")

stub_hubee_token
stub_hubee_create_folder
stub_hubee_upload_attachment
stub_hubee_mark_folder_complete
end

it { is_expected.to be_a_success }

it "creates a claim" do
expect { organizer }.to change(Claim, :count).by(1)
end
end
end

0 comments on commit 3da415b

Please sign in to comment.